I want to switch on/off openmp parallel for loops, in specific parts of my code, where as parallelization in other parts will remain intact. Also I do not want to change the source code of that parts every time, so tried some macro hack like following.
#ifdef USE_PARALLEL
#define USE_OPENMP_FOR #pragma omp parallel for
#else
#define USE_OPENMP_FOR
#endif
So that in the source code, I could simply use...
USE_OPENMP_FOR
for ( int i = 0 ; i < 100 ; ++i ) {
// some stuffs
}
And define the macro USE_PARALLEL
in main.cpp
file if I need those parallel loops.
But unfortunately this does not work at all. I know the problem is in #define QIC_LIB_OPENMP_FOR #pragma omp parallel for
line. But could not find any solution.
Is there any way to solve this problem, with or without the macro hack?
EDIT::
This question is different from disable OpenMP in nice way as I wanted to switch off openmp in specific parts, not for the whole program.
As suggested by Jarod42 and Anedar, _Pagma("...")
solved my problem.