I have the following block of code that runs MPI_Bcat. Strangely the process sometimes hangs sometimes when I run it but not others. The debug info shows all processes reached line 129 (all process 0 to n-1 printed bcast start). But they never reached line 132.
128 if (n_procs > 1) {
129 debug("[%d] bcast start\n", dgrid->rank);
130 // broadcast to other workers to stop their process
131 MPI_Bcast(finished, 1, MPI_INT, root, MPI_COMM_WORLD);
132 debug("[%d] bcast end\n", dgrid->rank);
133 }
What could be a possible cause of this problem? I have tried to look for a solution but all seems different. Could this be a system-level problem or is just my code?
The root process (0) is often the last process to reach line 129 judging from the terminal output.
Thanks in advance.