Compile C ++ code with and without fopenmp flag

I installed the C ++ and Fortran compiler and tested (C ++) programs (serial and parallel versions).

in Fortran, when compiling (parallel) code without enabling the option, -openmpyou must compile the code in (default) serial mode

but in C ++ I get errors like an undefined reference to omp_get_thread_num

but in Fortran, when compiling code without the -fopenmp flag, it ignores any code starting with $!omp, like

$!omp id = omp_get_thread_num()

Is there such a way in C ++?

+4
source share
1 answer

C/++ _OPENMP. , OpenMP, .

,

void foo (void)
{
#ifdef _OPENMP
   printf ("I have been compiled with OpenMP support\n");
#else
   printf ("I have been compiled without OpenMP support\n");
#endif
}
+2

Source: https://habr.com/ru/post/1650780/


All Articles