omp section - reading access on same objects

General OpenMP discussion

omp section - reading access on same objects

Postby mlimberger » Tue Nov 27, 2012 1:37 am

Hi there,

I got the following problem:

I got a function that is doing some computations inside a for-loop.
My idea was to set up section-parts depending on the number of cpu's. E.g.: 4 cpus = 4 section parts
In case of 1000 integrations, section1 : for loop 1-250, section2:250-500, section2:500-750, section4: 750-1000.

It has to be considered that each for each computation data from a shared object must be read.

This is my code:
...
...
int loop_limit1a=0;
int loop_limit1b=250;

int loop_limit2a=250;
int loop_limit2b=500;

int loop_limit3a=500;
int loop_limit3b=750;

int loop_limit4a=750;
int loop_limit4b=1000;

#pragma omp parallel
{

#pragma omp sections
{

#pragma omp section //Thread 1
{
function(Shared object1, Shared Object2, loop_limit1a, loop_limit1b)
}

#pragma omp section //Thread 2
{
function(Shared object1, Shared Object2, loop_limit2a, loop_limit2b)
}

#pragma omp section //Thread 3
{
function(Shared object1, Shared Object2, loop_limit3a, loop_limit3b)
}

#pragma omp section //Thread 4
{
function(Shared object1, Shared Object2, loop_limit4a, loop_limit4b)
}

}
}



and the function:


void Neprofiles(Type *SharedObject1, Type *SharedObject2, int lim1, int lim2){

for(int i=lim1,i<lim1;i++){
... some computation with access on SharedObject1 and SharedObject2;
}


}


When I run the code, some computations are made using all cpus I have, but then it stops without error message.
Do you have an idea or similar experiences? Also, I would really appreciate it if you could give me a hint, how you would realize such problem.

Thank you in advance!
Marco
mlimberger
 
Posts: 1
Joined: Mon Nov 26, 2012 3:34 am

Re: omp section - reading access on same objects

Postby MarkB » Tue Nov 27, 2012 3:22 am

Hi Marco,

A neater solution which does not require hard coding the number of threads would be:

Code: Select all
#pragma omp parallel
{
#pragma omp for
   for(int i=0,i<1000;i++){
   ... some computation with access on SharedObject1 and SharedObject2;
   }
}


However, your solution ought to work: there is no problem if multiple threads read shared objects.
Does the error message come from your code, or from the system? What happens to the results of the computation?

Mark.
MarkB
 
Posts: 450
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

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