### C/C++ min/max reduction with real floating type

Posted:

**Sun Sep 23, 2012 4:29 pm**For C/C++ min/max reduction operators with list items of type float, double, or long double, what should the initial values of the private copies be? E.g., for a min reduction, the initial value of the private copy should be the "largest representable value in the reduction list item type" (OpenMP 3.1, p. 104, l. 1). For a list item of type float, would that be FLT_MAX, or infinity (assuming the C/C++ implementation supports infinities)?

Consider the following program:

Out of four compilers I tested, two resulted in an output of "FLT_MAX", while the other two resulted in an output of "inf".

I think that infinity makes more sense, but it isn't clear to me whether or not the C11 standard considers infinity a "representable value" for real floating types.

If FLT_MAX is the correct answer, it would be beneficial to change the wording in the OpenMP spec on p. 104, l. 1 to:

If infinity is the correct answer for C/C++ implementations supporting infinities, it would be helpful to make that explicit in the OpenMP spec.

Consider the following program:

- Code: Select all
`#include <float.h>`

#include <math.h>

#include <stdio.h>

int main(void) {

float min_val = 0.0f;

#pragma omp parallel reduction(min:min_val) num_threads(1)

if (isinf(min_val))

printf("initial min_val: inf\n");

else if (min_val == FLT_MAX)

printf("initial min_val: FLT_MAX\n");

}

Out of four compilers I tested, two resulted in an output of "FLT_MAX", while the other two resulted in an output of "inf".

I think that infinity makes more sense, but it isn't clear to me whether or not the C11 standard considers infinity a "representable value" for real floating types.

If FLT_MAX is the correct answer, it would be beneficial to change the wording in the OpenMP spec on p. 104, l. 1 to:

max Least representable finite value in the reduction list item type

min Largest representable finite value in the reduction list item type

If infinity is the correct answer for C/C++ implementations supporting infinities, it would be helpful to make that explicit in the OpenMP spec.