Dear All,
I need to fill 2Dim array while each cell of the array gets an integral (of some function) as a function of free parameters. Since I deal with a very large arrays (here I simplified my case), I need to use OpenMP parallelism in order to speed my calculations up. Here I use simple #pragma omp parallel for directive.
Without using “#pragma omp parallel for”, the code executes perfectly. But adding the parallel directive, produces race conditions in the output.
I tried to cure it by making “private(i,j,par)”, it did not help. It seems like the problem is in the integrator itself. Each thread has its own copies of i,j and par, so there is no reason for the race condition.
I am totally frustrated with this problem and cannot find the way out.
Please, help!
P.S. I use VS2008 Professional with OpenMP 2.0 and ROOT 5.26 under WIndows 7 OS
[size=85]
testfunc(const double* var, const double* par)
{
// here is some simple function to be integrated over var[0] and var[1] and two free parameters par[0] and par[1]
return …
}
static double tmp[100][100];
int main()
{
double par[2];
double a[]={0,0} // limits of 2D integration
double b[]={1,1};// limits of 2D integration
ROOT::Math::AdaptiveIntegratorMultiDim ig; // creation of the multidim integrator
ROOT::Math::WrappedParamFunction<> f1(&testfunc, 2, 2); // wrapping of the function in order to pass it to the integrator
ig.SetFunction(f1); // setting the function
int i,j;
#pragma omp parallel for private(i,j,par)
for (i=0;i<100;i++)
{
for (j=0;j<100;j++)
{
par[0] = i;
par[1] = j*j;
f1.SetParameters(par); // each cell of "tmp" gets integral of "testfunc" with different values of "par"
tmp[i][j] = ig.Integral(a,b); // filling the cell with the value
}
}
}
[/size]