Need help to parallelize for loop

General OpenMP discussion

Need help to parallelize for loop

Postby Munich » Thu Mar 21, 2013 10:15 am

Hello,

First some background info:

Using Visual Studio 2010 professional - usings openmp 2.0

The following is my C++ code.

Code: Select all
#pragma omp parallel for schedule(dynamic,1)
   for (int j = 0; j < ncells; j++ ){
      double elemsum_1 = 0.0;
      for (int k = 0; k < n; k++){
         Radial r(Point[j],C[k]);
         elemsum_1 += Level[k] * methods::Kernel(r,Subset); // static member function of class methods
      }
      double elemsum_2 = 0.0;
      for (int k = 0; k < N; k++){
         Radial r(Point[j],C[k+n]);
         elemsum_2 += Level[n + k] * methods::DKernel(r,Subset,'x');  // static member function of class methods
      }
      #pragma omp critical
      {
                      double dv =elemsum_1 + elemsum_2;
            valuev[j] = dv;
      }
   }


The for loop over index j works fine without the openmp parallization. I have had no trouble with this kind of loop in the past. The only thing different is that I am calling static member functions from within the parallized loop.

Any help is appreciated.

Thank you :)
Munich
 
Posts: 1
Joined: Thu Mar 21, 2013 9:30 am

Re: Need help to parallelize for loop

Postby MarkB » Thu Mar 21, 2013 11:39 am

Hi there,

There may be a race condition on something which is being unintentionally shared.
Do Kernel() or DKernel() modify Subset, or any static data members of the "methods" class?

Hope that gives you an idea of where to start,
Mark.
MarkB
 
Posts: 456
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Need help to parallelize for loop

Postby ftinetti » Thu Mar 21, 2013 12:26 pm

Hi,

Besides that pointed out by Mark, take a look at how is used C in Radial_r() since there would be race conditions if C is used other than as function/method data input. Also, I think you do not need the critical (dv is private and there would not be race conditions on valuev[j]).

HTH,

Fernando.
ftinetti
 
Posts: 582
Joined: Wed Feb 10, 2010 2:44 pm


Return to Using OpenMP

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 10 guests