Reduction is used when you have code like the following:
- Code: Select all
int i = 0;
#pragma omp parallel reduction(+:i)
Without the reduction, this code would have a race condition on "i" and "i" would have to be protected with an atomic or critical. This can of course be done, but is not very efficient. The reduction makes use of private variables for each thread and usually has a pretty efficient algorithm to combine the values for the threads together.
This is a very simple case, but I hope it illustrates why there is a reduction clause. If you look at the OpenMP spec, you will find the general forms that it can handle. Since your other question was about MPI, you should note that MPI also has a way to handle reductions.