A REDUCTION variable is used in an improper way within a parallel region.
The REDUCTION clause is used to perform some sort of recurring mathematical calculation in parallel. A private temporary is created for each task. At the end of the region, the values of these temporaries are combined to update the outer variable. For example, you might add all the temporaries to form the final sum of a number of terms.
Within the body of the parallel region, the value of the REDUCTION variable is unpredictable, since the distribution of work to individual threads may vary. Therefore, the only legal use of a REDUCTION variable in the region is to update itself. Furthermore, when the reduction variable is updated, each update must the same operator as was specified in the REDUCTION clause. For example, it makes no sense to use add values to a REDUCTION variable if the final result will be computed by multiplying the partial computations together.
Together, these rules impose severe restrictions on what can be done with a REDUCTION variable. These are really the only legal patterns, and the last two of these do not apply for FORTRAN:
ID |
Observation |
Description |
---|---|---|
1 |
Invalid operation |
The place the REDUCTION variable was misused |
#include <omp.h> int main(int argc, char **argv) { int i, sum = 0; #pragma omp parallel for reduction(+:sum) for (i = 0; i < 1000; i++) { sum = 2 - sum; // wrong operator } return 0; }
Copyright © 2010, Intel Corporation. All rights reserved.