Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore OpenMP on machine that does not have it

Tags:

c++

c

openmp

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();) ?

like image 668
Tim Avatar asked Aug 19 '09 14:08

Tim


People also ask

Can we execute OpenMP enabled program code without importing its library file?

Because OpenMP is built into a compiler, no external libraries need to be installed in order to compile this code.

Is OpenMP a library?

OpenMP is a library for parallel programming in the SMP (symmetric multi-processors, or shared-memory processors) model. When programming with OpenMP, all threads share memory and data. OpenMP supports C, C++ and Fortran. The OpenMP functions are included in a header file called omp.

Where is OpenMP program in Windows?

Set the project's platform toolset (project Properties -> General -> Platform Toolset) to "LLVM (clang-cl)". Enable Clang OpenMP support by adding -Xclang -fopenmp to the compiler options in project Properties -> C/C++ -> All Options -> Additional Options.

How do I enable OpenMP code in Visual Studio?

Enable OpenMPRight-click on your project in Solution Explorer, and select properties. Select C/C++ -> Language, and change OpenMP Support to Yes. Click ok, and make sure your application still compiles and runs.


1 Answers

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.

like image 164
Andrew Dalke Avatar answered Sep 19 '22 23:09

Andrew Dalke