4
我在使用OpenMP一开始,我只是编译gcc -fopenmp openmp_c_helloworld.c
下面的一段代码:OpenMP的行为检测CPU和线程
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[]) {
int th_id, nthreads;
#pragma omp parallel private(th_id)
{
th_id = omp_get_thread_num();
printf("Hello World from thread %d\n", th_id);
#pragma omp barrier
if (th_id == 0) {
nthreads = omp_get_num_threads();
printf("There are %d threads\n",nthreads);
}
}
return EXIT_SUCCESS;
}
我只是一个四核Intel CPU超线程上运行的可执行文件我得到以下的输出:
Hello World from thread 2
Hello World from thread 0
Hello World from thread 3
Hello World from thread 1
There are 4 threads
从技术上讲,我有我的可用CPU和4个CPU核心8线程,为什么OpenMP的显示我只有4个线程?