General OpenMP discussion
Forum rules
The OpenMP Forums are now closed to new posts. Please visit Stack Overflow if you are in need of help: https://stackoverflow.com/questions/tagged/openmp
Posts: 10
Joined: Wed Jan 11, 2017 7:21 am


Post by pdupre »


I started a parallel session and I cannot get the right value of a variable ("normal_fact").
Before the parallel sssion, normal_fact has a value which is modified in the parallel session (it depends on "param" with is also modified
in the parallel session)
By using firspriavte, the value of normal_fact is that when entering in the parallel session while I need the value calculated during the
parallel session (it only depends on "param")

Here is the example

double normal_fact = A ;
double x [nbpt], y [nbpt] ;
gsl_function fcn ;
#pragma omp parallel private (fcn) firstprivate (normal_fact)
cluster_V_str param ; // To declare inside the parallel section
fcn.function = (function_gsl) funct ;
fcn.params = &param ;
pre_init_crossover_V (&param, etc..) ;
#pragma omp for
for (unsigned int i = 0 ; i < nbpt ; i++) {
setting_V2 (&param, x ) ;
y = fcn.function (delta, fcn.params) ;
#pragma omp barrier

In theory, I could avoid to start the parallel session like it is, and start it only when entering in the for loop.
However, I am in trouble because param (and fcn) needs a copy in the parallel session.

Could you make some suggestions?


Posts: 808
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: loop

Post by MarkB »

Where is normal_fact modified? (Your code snippet doesn't show this).