Reduction

General OpenMP discussion

Reduction

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

Hi,

In which senerio reduction clause is used.
rashmi_k28
 
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)
i+=2;

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


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 7 guests

cron