Quite new to MPI, I want every process to broadcast its array to other processes.
nproc is the number of processes in total (3), myid is the current processes' id and array has size DATASIZE.
What confuses me here is receiving an array from root may occur before root actually broadcasts its array. How does receiving even work in this case?
For example:
Process #0 receives array {1, 2} from Process #1 happens before Process #1 broadcasts its array.
for(int i = 0; i < nproc; i++){
root = i;
if(root == myid){
printf("Process #%d broadcasts its array {", root);
printArray(array);
printf("}\n");
MPI_Bcast(array, DATASIZE, MPI_INT, root, MPI_COMM_WORLD);
}
else{
MPI_Bcast(array, DATASIZE, MPI_INT, root, MPI_COMM_WORLD);
printf("Process #%d receives array {", myid);
printArray(array);
printf("} from Process #%d\n", root);
}
}