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個線程?