General OpenMP discussion


Postby rashmi_k28 » Fri Mar 14, 2008 12:07 am


In which senerio reduction clause is used.
Posts: 8
Joined: Wed Mar 12, 2008 4:20 am

Re: Reduction

Postby ejd » Fri Mar 14, 2008 9:21 am

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.
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 5 guests