依赖于编译器的OpenMP最小/最大减少编译指示

问题描述 投票:1回答:1

我的C ++代码使用OpenMP指令,需要与GCC和Visual Studio 2019一起编译。OpenMP 3.1中引入了OpenMP最小/最大缩减运算符,但Visual Studio 2019 only supports OpenMP 2.0

我希望我的代码在Visual Studio下恢复为串行循环,但我知道the preprocessor cannot represent a conditional pragma是这样的:

// 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]);
}

有没有办法做到这一点?

c++ visual-c++ openmp
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.