In my program, I want only a for-loop to be run in parallel. The rest of the code should run serially. Even though this might not be the best way, I want to use the approach described here (see answer by Chris):
So in short, I let rank 0 do the serial part.
Now the problem is that I have several loops including a while loop. The structure is as follows:
# serial part
# start of while loop {
# parallel part
# end of while loop
# end of serial part
The code strukture looks like this:
boost::mpi::environment env;
boost::mpi::communicator comm;
if(comm.rank()==0)
{
while(...)
{
} // !!!! end the if loop here?
// start parallel for loop here
for(....){}
// continue serial part
if(comm.rank()==0)
{
//...
} // end of while loop
} // end of if loop
Is it right to close the serial part (if-loop) directly after the while-loop was opened?
And secondly, how do I tell the other ranks to wait for rank 0 to be finished?