Doubt about private variables

General OpenMP discussion

Doubt about private variables

Postby augarte » Wed Jul 28, 2010 3:27 am

Hi everyone,

I have parallelized the following piece of code:

Code: Select all
#pragma omp parallel
  {
    #pragma omp for ordered schedule (dynamic, chunk)
    for (CntCds = 0; CntCds < NbCds; CntCds++) {
   
        /* Calcul the lambdas using the bisection method */
      lcMKTcpsLmbBisMth (CpsTyp, CalDat, LdMkt, CdsCrv, CntCds);

        /* Calcul cumulative probability for the calculated lambda */
      MKTcrvFind   (LlCps, CdsCrv, &LdCps);
      MKTcpsPrbCum (CntCds, LdCps);

        /* Calcul BPV */
      lcMKTcpsCalBpv (CpsTyp, CalDat, LdMkt, LdCps, CdsCrv, CntCds);
    }
  }


The problem is that I want some internal variables of one of the functions I call inside the loop (lcMKTcpsLmbBisMth) to be private for each thread. I guess I have to do something inside the function but what? Do I have to create a parallel section or something? How can I set these variables as private?

Thanks in advance.

Kind regards,
Aitor.
augarte
 
Posts: 18
Joined: Thu Oct 08, 2009 12:50 am

Re: Doubt about private variables

Postby ejd » Wed Jul 28, 2010 7:35 am

If you look at the OpenMP V3.0 spec, section 2.9.1.2 Data-sharing Attribute Rules for Variables Referenced in a Region but not in a Construct, it states:
The data-sharing attributes of variables that are referenced in a region, but not in a construct, are determined as follows:
...
• Other variables declared in called routines in the region are private.

So you should not have to do anything.
ejd
 
Posts: 732
Joined: Wed Jan 16, 2008 7:21 am

Re: Doubt about private variables

Postby augarte » Wed Jul 28, 2010 8:31 am

Thanks ejd,

Do you mean with this that all the variables I declare inside the functions that are in my parallel region will behave as private copies for each thread?

Kind regards,
Aitor
augarte
 
Posts: 18
Joined: Thu Oct 08, 2009 12:50 am

Re: Doubt about private variables

Postby ejd » Wed Jul 28, 2010 9:26 am

I should have shown the entire section, because they are a number of rules. I hope this clarifies the issue better.
The data-sharing attributes of variables that are referenced in a region, but not in a construct, are determined as follows:

• Static variables declared in called routines in the region are shared.

• Variables with const-qualified type having no mutable member, and that are declared in called routines, are shared.

• File-scope or namespace-scope variables referenced in called routines in the region are shared unless they appear in a threadprivate directive.

• Variables with heap-allocated storage are shared.

• Static data members are shared unless they appear in a threadprivate directive.

• Formal arguments of called routines in the region that are passed by reference inherit the data-sharing attributes of the associated actual argument.

• Other variables declared in called routines in the region are private.
ejd
 
Posts: 732
Joined: Wed Jan 16, 2008 7:21 am


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 1 guest

cron