Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compile c++ code with and without fopenmp flag

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

in Fortran when compiling a (parallelized) code without enabling the -openmp option should compile the code in (default) serial mode

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

but in Fortran when you compile code without the -fopenmp flag it ignores any code which start with $!omp like

$!omp id = omp_get_thread_num()

Is there any option like that in C++?

like image 529
ali Avatar asked Oct 18 '22 04:10

ali


1 Answers

You can protect your C/C++ code with the _OPENMP define. This way you can avoid introducing calls to the OpenMP runtime whenever your application is not linked against it.

For instance, you can have the following code

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
}
like image 189
Harald Avatar answered Nov 15 '22 07:11

Harald