Ignore OpenMP on machine that does not have it

后端 未结 5 1298
暖寄归人
暖寄归人 2021-02-03 20:21

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 O

5条回答
  •  执念已碎
    2021-02-03 21:02

    There is another approach that I like, borrowed from Bisqwit:

    #if defined(_OPENMP)
    #include 
    extern const bool parallelism_enabled = true;
    #else
    extern const bool parallelism_enabled = false;
    #endif
    

    Then, start your OpenMP parallel for loops like this:

    #pragma omp parallel for if(parallelism_enabled)
    

    Note: there are valid reasons for not using pragma, which is non-standard, hence why Google and others do not support it.

提交回复
热议问题