pointer to a function: private or shared?

General OpenMP discussion

pointer to a function: private or shared?

Postby gideonsimpson » Sun Apr 14, 2013 7:46 pm

I have a function in which I want to perform a reduction loop that looks like:

double compute_observable(double *xarray, double(* observable_func)(const double x, const void *p),
const void *obs_params, const void * params){

int i, n;
double x;
double y;
double obs = 0;

n = params->n;

#pragma omp parallel for default(none) shared(xarray, n) private(i, x, y, obs_params) reduction(+:obs)
for(i = 0;i<n;i++){
x = xarray[i];
y = observable_func(y, obs_params);
obs += y;
}

obs = obs/n;
return obs;
}

Now, my question is should the observable_func variable, which is a pointer to a function defined elsewhere, be a shared or private variable?
gideonsimpson
 
Posts: 6
Joined: Sun Feb 22, 2009 8:39 pm

Re: pointer to a function: private or shared?

Postby ftinetti » Mon Apr 15, 2013 3:41 am

Hi,

Now, my question is should the observable_func variable, which is a pointer to a function defined elsewhere, be a shared or private variable?


I didn't check in the Spec. if there is some specific rule for pointers to functions, but I think it could be shared, since every thread will be calling the same code. However, given that "every thread will be calling the same code" there should be no update of global/heap data in that function in order to avoid race conditions, otherwise you should add specific synchronization constructs.

HTH,

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


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 7 guests