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.
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_reduceorshmem_double_max_to_allshould be in the presence of NaN values.In C, NaN values can be initially unintuitive; for example:
C provides
fmaxandfminto handle these situations gracefully: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
fmaxandfminfunctions.Considerations