Array transfer parallelize

General OpenMP discussion

Array transfer parallelize

Postby vsm » Sun Aug 05, 2012 1:22 pm

Hello,
I would like to paralyze this averaging algorithm with OpenMP:

Code: Select all
for (int n=0;n<nmax; n++){
int start = index[n]; int stop = indexstop[n];
Avg_i = 0;
  for (int c = start; c<stop; c++){
   AvgData[Avg_i]+=LocalData[c];
   Avg_i++;
   }
}


nmax variable is 1 to 100 range. Internally for cycle takes aprox. 10M iterations => the second loop is the candidate for parallelization.
Data dependecy in AvgData array could be a problem I think.
May you give me any advice how to parallelize this for? Iam very interesting in this problem....

Thank for your answer
vsm
vsm
 
Posts: 1
Joined: Sun Aug 05, 2012 10:30 am

Re: Array transfer parallelize

Postby MarkB » Mon Aug 06, 2012 3:54 am

Hi there,

If you want to parallelise the inner loop, then there are no dependencies on AvgData, since each iteration of this loop writes a different element of the array. However, you do need to remove the (trivial) loop carried dependence on Avg_i, so think the following should work OK:

Code: Select all
for (int n=0;n<nmax; n++){
    int start = index[n]; int stop = indexstop[n];
#pragma omp parallel for default(none) shared (start, stop, AvgData, LocalData)
      for (int c = start; c<stop; c++){
       AvgData[c-start]+=LocalData[c];
       }
    }
MarkB
 
Posts: 479
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

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