Alex Rivera | Logout

Ignore OpenMP on machine that does not have it

Asked 2009-08-19T14:05:52.970
38

I have a C++ program using OpenMP, which will run on several machines that may have or not have OpenMP installed.

How could I make my program know if a machine has no OpenMP and ignore those #include <omp.h>, OpenMP directives (like #pragma omp parallel ...) and/or library functions (like tid = omp_get_thread_num();) ?

Edit
Report

1 Answer

71

OpenMP compilation adds the preprocessor definition "_OPENMP", so you can do:

#if defined(_OPENMP)
   #pragma omp ...
#endif

For some examples, see http://bisqwit.iki.fi/story/howto/openmp/#Discussion and the code which follows.

answered 2011-12-09T14:36:33.200

Your Answer