OpenACC min reduction

Hi,
the following code does not work as expected, the min reduction returns 1e+10 as result value.

double minVal = 1.0e10;
#pragma acc parallel loop copyin(arr[0:n]) reduction(min:minVal)
for (int i=0; i<n; i++)
{
    minVal = min(minVal, arr[i]);
}

The values in arr are all smaller than 1e+10.

The compilation info is:

pgc++ -acc -Minfo=accel test.cpp
main:
      9, Generating copyin(arr[:n])
         Accelerator kernel generated
          9, Min reduction generated for minVal
         11, #pragma acc loop gang, vector(128) /* blockIdx.x threadIdx.x */
      9, Generating copy(minVal)
         Generating Tesla code
const T1 & std::min<double>(const T1 &, const T1 &):
      1, include "iostream"
          39, include "ostream"
               38, include "ios"
                    40, include "char_traits.h"
                         39, include "stl_algobase.h"
                             194, Generating implicit acc routine seq
                                  Generating Tesla code

I use PGC++ Version 15.4.

Am I doing something wrong or does the reduction simply not work?
Is there a workaround? (I tried it without the reduction clause to let the compiler detect the reduction automatically, but this doesn’t work)

Thank you for your help,
Marco

Hi Marco,

How is your “min” defined? Can you try using the standard C “fmin” routine instead?

  • Mat

Hi Mat,
I used the standard C++ min: std::min().
Changing this to fmin works well, thank you.
Marco