[Omp] Why the slowdown?

Brendan brendanofallon at fastmail.fm
Wed Aug 8 13:44:43 PDT 2007


 Hi all,
 I'm new to omp, but recently have been interested in parallelizing some 
code for a simulation I often run at school. The simulation is written 
in C++, takes place over a few thousand discrete 'generations', and 
basically has a few hundred individuals that are mostly independent, but 
at the end of each generation interact a bit.  Since individuals act 
independently for the most part, it seemed logical to have a few threads 
that would each be responsible for some fraction of the individuals. At 
the end of each generation, the master thread could then handle the 
interaction among the individuals. Confusingly, this implementation 
results in a 2x-3x slowdown compared to a single-thread version. Here's 
a bit of pseudocode for what I've implemented (it assumes there's at 
most two threads)...

#pragma omp parallel shared(individuals, various state variables)
{

for( loop of generations) {

    if (thread_id = 0)
          take care of interactions among individuals

     #pragma omp barrier
     #pragma omp sections
     {
       #pragma omp section
            have one thread take care of 1/2 the individuals
       #pragma omp section
           have the other thread take care of the other 1/2
    }

}//end loop through generations

}//end parallel section

Is there some obvious reason why this would be way slower when running 
with two threads? Is there an obvious different implementation I should 
try? (Unfortunately, just burying all the parallel business inside the 
'generations' loop also results in a big slowdown, but I think that's 
from spawning off new threads 1000 times every 5 seconds. The 
implementation above always maintains the same two threads, but just 
only uses them for parallel stuff when needed).
 Sorry for the long/potentially confusing post. Any thoughts would be 
much appreciated.

 thanks,
 Brendan O'Fallon
 University of Utah
 Department of Biology



More information about the Omp mailing list