A reduction variable must be shared in the parallel region(s) bound to the worksharing region(s) arising from the construct with the REDUCTION clause.
The REDUCTION clause creates a PRIVATE copy of each item on the list, initializes it appropriately for the specified operator. At the end of the region with the REDUCTION clause, the original item is updated by combining its original value with the final values of each of the PRIVATE copies using the specified operator (except that partial results of a subtraction reduction are added to form the final value).
The OpenMP* specification requires the REDUCTION variable (as that name is interpreted outside the scope of the construct) to be a shared variable. This allows each thread to stir in its contribution to the outer value when that thread hits the end of the construct. This would not be possible if the outer variable is private to the thread that first entered the region, hence the requirement that the REDUCTION variable be shared.
ID |
Observation |
Description |
---|---|---|
1 |
OpenMP usage error |
The location of the REDUCTION clause |
2 |
Definition |
The definition of the outer variable |
integer i, j real a a = 0.0 !$OMP PARALLEL REDUCTION(+: a) !Bad: can't make reduction variable private !$OMP DO PRIVATE(a) do j = 1, 10 a = a + j end do !$OMP END PARALLEL print *, a end
Copyright © 2010, Intel Corporation. All rights reserved.