为什么 Visual Studio 2019 不支持关键字“max"?在减少Openmp? [英] why does Visual Studio 2019 not support the keyword "max" in for-reduction of Openmp?

查看:155
本文介绍了为什么 Visual Studio 2019 不支持关键字“max"?在减少Openmp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我像这样使用 openmp 时:

when I use openmp like this:

#pragma omp parallel for reduction(max: dumax)

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

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

推荐答案

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

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)

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

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

这篇关于为什么 Visual Studio 2019 不支持关键字“max"?在减少Openmp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆