I start with OpenMP, I just compiled with gcc -fopenmp openmp_c_helloworld.c
following code snippet:
#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; }
I just run the executable on an Intel quad-core processor with HyperThreading, and I get the following output:
Hello World from thread 2 Hello World from thread 0 Hello World from thread 3 Hello World from thread 1 There are 4 threads
Technically speaking, I have 8 threads available on my processor and 4 processor cores, why does OpenMP show me only 4 threads?
source share