【发布时间】:2020-02-19 09:32:59
【问题描述】:
我的 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]);
}
有没有办法做到这一点?
【问题讨论】:
-
您可以尝试在两个不同的函数(串行循环,OpenMP循环)中提取循环部分,并根据这两个函数描述您的定义
-
确实如此,但由于我有几个这样的循环,因此需要大量重构以避免重复代码。
标签: c++ visual-c++ openmp