why does Visual Studio 2019 not support the keyword “max” in for-reduction of Openmp?

廉价感情. 提交于 2021-01-29 08:06:53

问题


when I use openmp like this:

#pragma omp parallel for reduction(max: dumax)

the IDE will raise an error "max" in Openmp "reduction" is invalid

#pragma omp parallel for reduction(max: dumax)
for (int i = 1; i < n + 1; i++)
{
    for (int j = 1; j < n + 1; j++)
    {
    u[i][j] = 0.25 * u[i - 1][j] + 0.25 * u[i][j - 1] + 0.25 * u[i + 1][j] + 0.25 * u[i][j + 1] + h * h * f[i][j];
    dumax = max(dumax, abs(u[i][j] - uold[i][j]));
    }
}

回答1:


MSVC compiler is stuck with OpenMP version 2.0, and unfortunately for you, reduction(max:) was only introduced with version 3.1 of the OpenMP C/C++ standard (that was in September 2011)

So you can either change of compiler, or doing the reduction operation the old way with some private variables and a final reduction with critical accumulations



来源:https://stackoverflow.com/questions/58449246/why-does-visual-studio-2019-not-support-the-keyword-max-in-for-reduction-of-op

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!