13.9 Implementing REDUCTION clause

The private struct mentioned in the previous section should have a pointer to an array of the type of the variable, indexed by the thread’s team_id. The thread stores its final value into the array, and after the barrier, the primary thread iterates over the array to collect the values.

In cases where an atomic update cannot be used (e.g. for a reduction involving more than one scalar), a critical section is required. Dedicated entry points are used rather than GOMP_atomic_start and GOMP_atomic_end so that OMPT can distinguish reduction critical sections from user-level atomic constructs. The section is bracketed by:

  void GOMP_reduction_start (void)
  void GOMP_reduction_end (void)