I need to some how run one MPI node at a time. I am printing out information relevant to arrays specific to each MPI node. I have formatted print statements for each MPI node according to rank. However, I am having trouble printing out all the arrays without getting either a deadlock, or a mish mash of print formatting as all the nodes print their statements at once.
I am still new to MPI, and the only function I know about right now is MPI Barrier. Here is my code; I have been thinking about it and placing MPI barrier in different places...but, like I said, I seem to get only deadlocks after one or two arrays print out, or just random print statements.
In this current configuration, I am getting print statements in random order; however, there is no deadlock (shifting the bottom barrier up two lines to inside the for loop starting at line 4 would produce one or two properly formatted print statements, but results in a deadlock):
if (debug == 1) {
if (iterations == 0) {
MPI_Barrier(MPI_COMM_WORLD);
for (j = 0; j < mpi_nodes; j++) {
if (rank == j) {
printf("\n\nrank %d\n", j);
printf("\n");
for (i = 0; i < m2; i++) {
j = i / m;
k = i % m;
if (k == 0) {
printf("\n"); //
}
printf("%1.f ", f[i]);
}
printf("\n");
}
}
printf("\n reached.");
MPI_Barrier(MPI_COMM_WORLD);
printf("\n passed.\n");
}
}
How would I implement MPI commands such that the print loop--after the rank test at the 5th line--is run for each MPI node, one at a time (and preferably in order from rank 0 to n).
To get the code to run, it would just take the array,
int m = 5;
int m2 = m*m;
double f[m2] = etc.
But I think this is just a knowledge question...there must be some kind of atomic-esque block for MPI, right?