define shared variables inside OpenMP parallel region

General OpenMP discussion

define shared variables inside OpenMP parallel region

Postby tipus » Mon Feb 06, 2012 8:52 am

Hi,
Is there any way to define a shared variable inside a parallel region?

I would like to do something like:

int main
{
#pragma omp parallel
{
...
f = work_in_a_function(arg0);
...
}
}

int f
{
int i
#pragma omp shared(i)
#pragma omp master
{
MPI_Bcast(i,1,MPI_INT,root,comm);
}
}

Is it possible? Do you suggest any performance-wise workaround?

Thank you,
Tipus
tipus
 
Posts: 2
Joined: Mon Feb 06, 2012 8:29 am

Re: define shared variables inside OpenMP parallel region

Postby MarkB » Fri Feb 17, 2012 3:24 am

You can make i shared in this example by declaring it as
static int i;
MarkB
 
Posts: 480
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: define shared variables inside OpenMP parallel region

Postby tipus » Wed Mar 28, 2012 5:39 am

This worked!
Thank you!!
tipus
 
Posts: 2
Joined: Mon Feb 06, 2012 8:29 am


Return to Using OpenMP

Who is online

Users browsing this forum: Exabot [Bot] and 10 guests