ali
ali

Reputation: 85

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++?

Upvotes: 5

Views: 396

Answers (1)

Harald
Harald

Reputation: 3180

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
}

Upvotes: 3

Related Questions