My C++ code uses OpenMP directives and needs to compile with GCC and Visual Studio 2019. OpenMP min/max reduction operators were introduced in OpenMP 3.1, but Visual Studio 2019 only supports OpenMP 2.0.
I'd like my code to revert to a serial loop under Visual Studio, but I understand that the preprocessor cannot represent a conditional pragma like this:
// invalid use of preprocessor:
#ifdef _MSC_VER
#define OMP_MIN(expr)
#else
#define OMP_MIN(expr) #pragma omp parallel for reduction(min:(expr))
#endif
double x = 10.0;
OMP_MIN(x)
for (int i = 0; i < array_size; i++) {
x = fmin(x, array[i]);
}
Is there a way to achieve this?