为什么 Visual Studio 2019 不支持 Openmp 的 for-reduction 中的关键字“max”?

Ric*_* Li 2 c++ openmp visual-studio-2019

当我像这样使用 openmp 时:

#pragma omp parallel for reduction(max: dumax)
Run Code Online (Sandbox Code Playgroud)

IDE 将在 Openmp 中引发错误“max”“reduction”无效

#pragma omp parallel for reduction(max: dumax)
Run Code Online (Sandbox Code Playgroud)

Gil*_*les 6

MSVC 编译器受 OpenMP 2.0 版困扰,不幸的是,reduction(max:)它仅在 OpenMP C/C++ 标准 3.1 版中引入(2011 年 9 月)

因此,您可以更改编译器,或者使用一些私有变量以旧方式进行归约操作,并通过critical累积进行最终归约