问题
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