简体   繁体   中英

Detect at runtime if OPENMP is being used in a C++ program

I'd like to know at runtime if a C++ program has been compiled with OPENMP enabled or not. There are some things that OPENMP 2.0 cannot easily do so I'd like to fake them with another mechanism. However if the code is compiled with OPENMP disabled then I'd like to also disable my other mechanism and run everything serially.

For example

if( isOpenMPEnabled() )
    runFakeParallelAlgorithm();
else
    runSequentialAlgorithm();

How could I implement

bool isOpenMPEnabled()

I should say we are using OPENMP 2.0

If the /openmp flag was passed to the compiler and compilation was successful, a preprocessor directive will be added that you can use to check this at runtime:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM