OpenMP and poiters to member function

General OpenMP discussion

OpenMP and poiters to member function

Postby stkubr » Tue Jan 24, 2012 9:20 am

Hi, i have a paralleled class with a integrand function and multidimensional integration routine:

Code: Select all
class NiceClass

    double P;
    double (NiceClass::*nrfunc)(double,double,double);

void NiceClass(void){P=0;} //constructor

// Integrator (sure it`s only blank construction)
double qgaus5(double (NiceClass::*func) (double), double a, double b)
   double x;
   return (this->*func)(x);

// Multidimensional integration routine
double Multi_int_3d(double (NiceClass::*func)(double, double, double), double x1, double x2)
return qgaus5(&NiceClass::f1,x1,x2);

double f1(double k)
return qgaus5(&NiceClass::f2,-1,1);

double f2(double z)
return qgaus5(&NiceClass::f3,-1,1);

double f3(double y)
return (this->*nrfunc)(ksav,zsav,y);
// End of multidimensional integration routine

double Integrand(double x, double y, double z )
   return P*x*y*z;

void calc_int(double a)

//here is paralleled section
void get_result()
   double res[3];

#pragma omp parallel num_threads(2)
   #pragma omp for
   for (int i = 0; i < 3; i++)
      res[i]=calc_int( i );

}//end pragma   


  NiceClass int;

The problem is all threads become entangled and it all become messy and the result is wrong.
How to make it right?

Re: OpenMP and poiters to member function

Postby MarkB » Fri Feb 17, 2012 5:07 am

The problem is that all threads are trying to use the same P.
One way to fix this would be to create a new instance of NiceClass for each iteration of the parallel loop.
Posts: 746
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 3 guests