How to disable OpenMP directives in a nice way?

后端 未结 3 688
不思量自难忘°
不思量自难忘° 2020-12-15 06:10

I have C++ code with OpenMP pragmas inside. I want to test this code both for multithread mode (with OpenMP) and in single thread mode (no OpenMP).

For now, to swit

3条回答
  •  臣服心动
    2020-12-15 06:24

    The way such things are usually handled (the general case) is with #defines and #ifdef:

    In your header file:

    #ifndef SINGLETHREADED
    #pragma omp
    #endif
    

    When you compile, add -DSINGLETHREADED to disable OpenMP:

    cc  -DSINGLETHREADED  code.c
    

提交回复
热议问题