2

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
  • 173,980
  • 10
  • 155
  • 350
Richard Li
  • 27
  • 1

1 Answers1

6

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
  • 9,269
  • 4
  • 34
  • 53