1

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]));
    }
}
MSalters
  • 167,472
  • 9
  • 150
  • 334
Richard Li
  • 17
  • 1

1 Answers1

5

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

Gilles
  • 8,961
  • 4
  • 32
  • 51