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.
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 ();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With