Skip to content

Reductions and NaN values #467

@nspark

Description

@nspark

Description

Currently, the Specification does not specify the handling of NaN values in reductions over floating types.

Per C18 §7.12.14-1, a NaN value is unordered with respect to a numeric value or another NaN. For example, it is not clear what the result of shmem_double_max_reduce or shmem_double_max_to_all should be in the presence of NaN values.

In C, NaN values can be initially unintuitive; for example:

#include <math.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))

MAX(1.0, NAN) == NAN;
MAX(NAN, 1.0) == 1.0;

C provides fmax and fmin to handle these situations gracefully:

#include <math.h>
fmax(1.0, NAN) == 1.0;
fmax(NAN, 1.0) == 1.0;
fmax(NAN, NAN) == NAN;

In the tests I've performed on OpenSHMEM implementations readily accessible to me (certainly not all that exist), none handle min/max reductions correctly for NaN values. They did seem to handle sum reductions correctly.

Suggestions

  • MAX and MIN reductions with semantic equivalence to C's fmax and fmin functions.
    • Thus, such reductions will effectively drop NaN values unless all input values are NaN, in which case the result should be NaN.
  • SUM and PROD reductions should produce a NaN value if any input value is NaN.

Considerations

  • Some OpenSHMEM implementations leverage hardware-accelerated reductions. I am not aware of the state of NaN handling for such hardware.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions