These tests show 3 different outcomes of the OpenMP C code execution:
- OpenMP is not enabled in the compiler: this situation can be detected by checking whether the
_OPENMP
macro is defined or not - OpenMP is enabled and deployed at full scale: the master thread in an OpenMP parallel region checks the
omp_get_num_threads()
value, and the system-default number of available hardware threads is returned - OpenMP is enabled, but the parallelism is limited to 1 thread, by user's choice
►make
gcc openmp_check_enabled.c -o test1 && ./test1
OpenMP is not enabled in compile time!
gcc -fopenmp openmp_check_enabled.c -o test2 && ./test2
nthreads = 8
gcc -fopenmp openmp_check_enabled.c -o test3 && OMP_NUM_THREADS=1 ./test3
nthreads = 1
warning: only one thread is deployed!