GSL quadrature and OpenMP

General OpenMP discussion

GSL quadrature and OpenMP

Postby franz » Sat Dec 03, 2011 4:06 am

Hi everybody,

I would like to parallelize a loop containing a GSL quadrature. The contain of the loop is the function call
Code: Select all
gsl_integration_qag (&F, 0, Pi, 0, 1e-4, 1000, 1, w, &result, &error);

where F is a gsl_function type (F.function, F.params), i.e., the function to be integrated, and w is the integration workspace.

I am using the openMP directives:
Code: Select all
F.function = &f; //function f(x,params) to be integrated
F.params = &i; //parameter of  f(x,params)

#pragma omp parallel default(none) \
   private(i) shared(F,w,result,error)
{
#pragma omp for schedule(dynamic)
   for(i=0;i<1001;i=i+200)
   {
      gsl_integration_qag (&F, 0, Pi, 0, 1e-4, 1000, 1, w, &result, &error);
      printf ("%d\t %e\t %e\n", i, result, error);
#pragma omp flush(abort)
   }
}// end parallel fork

The result is something like:
Code: Select all
400    0.000000e+00    0.000000e+00
200    0.000000e+00    0.000000e+00
0    0.000000e+00    0.000000e+00
600    0.000000e+00    0.000000e+00
1000    0.000000e+00    0.000000e+00
800    0.000000e+00    0.000000e+00


Of course, when compiling without openMP it gives the non-zero results that I expect.
What am I missing?

Thanks,
f
franz
 
Posts: 2
Joined: Sat Dec 03, 2011 4:03 am

Re: GSL quadrature and OpenMP

Postby anv » Mon Dec 05, 2011 11:40 am

You have several issues in your code:
1. In parallel code you saved in "F.params" the address of shared variable "i" outside of parallel region, so all iterations work with the same value you assigned to it outside of parallel. In serial code your routine works with address of loop iteration variable which has different values for different iterations.
2. You declare variables "result" and "error" as shared, so all threads will place something there asynchronously, and re-write each others values. If you want each iteration to write some specific values there, you would better declare these variables as private.

Hope this helps,
Regards,
Andrey
anv
 
Posts: 31
Joined: Wed Dec 12, 2007 9:36 am

Re: GSL quadrature and OpenMP

Postby franz » Tue Dec 06, 2011 1:56 am

Thanks, I didn't think at all at your point 1.

Regards,
f
franz
 
Posts: 2
Joined: Sat Dec 03, 2011 4:03 am


Return to Using OpenMP

Who is online

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