Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Critical section in MPI?

I have some code to print a 2D array to the standard output. The problem is that when I run it, every process writes to the output and the data overlaps, rendering it unusable.

How can i build a critical section in MPI so that only one process at a time enters the section where I display the output?

I'm using OpenMPI.

like image 737
alexsardan Avatar asked Jan 12 '12 19:01

alexsardan


1 Answers

Separate it out by using MPI_Barriers.

rank = 0;
while (rank < total_processes) {
   if (myrank == rank) {
       printf ("Array printed by rank: %d\n", myrank);
       print_array();
       fflush (stdout);
   }
   rank ++;
   MPI_Barrier ();
}
like image 100
jman Avatar answered Nov 06 '22 12:11

jman