c++ - 为什么 Visual Studio 2019 在 Openmp 的 for-reduction 中不支持关键字“max”?
问题描述
当我像这样使用openmp时:
#pragma omp parallel for reduction(max: dumax)
IDE 将在 Openmp “reduction” 中引发错误 “max” 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:)
它仅在 OpenMP C/C++ 标准的 3.1 版中引入(即 2011 年 9 月)
因此,您可以更改编译器,也可以使用一些私有变量以旧方式进行归约操作,并通过critical
累积进行最终归约
推荐阅读
- html - Django:在模板中显示特定组级别的按钮
- python - 在 jupyter 实验室中使用 matplotlib 3d 绘制的错误图片
- elasticsearch - Elasticsearch -- 确定给定时间是否在 TIME 范围内
- apache-kafka - 管道损坏后如何修复代理可能不可用
- azure-devops - Azure Devops 发布管道 - 获取源(构建管道)值的变量?
- python - 使用列表选择器就地添加
- python - 列出所有可能的随机 3 个字符或 4 个字符
- python - 使用 pypdf2 读取 pdf 元数据
- react-native - React Native 0.60 中“react-native 弹出”的替代方法是什么来重新生成 iOS 和 android 文件夹?
- migration - IBM Bluemix 应用程序迁移问题