Reputation: 135
I want to write an MPI Program where each process has a boolean value initiate
which is initially set to false. Then, rank 0 checks if the value (i
,j
) of a large 2D Boolean Array is true and if it is then rank 0 sets its value of initiate
to true. If rank 0's value of initiate
is true then I would like rank 0 to broadcast the new value of initiate
to other processes, indirectly telling each of them to kickstart execution of another method.
How could I go about doing this efficiently? Would appreciate to hear any ideas.
-Thanks
PS. I considered sending the 2d boolean array to every process, but that 2d array can be very big under certain circumstances and I am worried that my code would not scale well.
Upvotes: 1
Views: 247
Reputation: 11
I assume you want to make use of the wait time. Elaborating on Gilles Gouaillardet's comment, you can build an "interrupt" kind of structure.
bool initiate = false;
if (rank == 0)
for(int k = 0; k < I * J; k++)
if(!bool_arr[k]) {
initiate = true;
break;
}
MPI_Request request;
MPI_Ibcast(&initiate, 1, MPI_C_BOOL, 0, MPI_COMM_WORLD, &request);
for (int iter = 0; iter < numiter; iter++) {
; // DO WHATEVER YOU WANT!
// TEST IF THE BROADCAST COMPLETE ONCE IN A WHILE
bool complete;
MPI_Test(&request, &complete, MPI_STATUS_IGNORE);
if (complete && initiate) {
function();
initiate = false; // Avoid calling function() twice
}
}
// DO NOT MOVE ON WITHOUT WAITING FOR BROADCAST
MPI_Wait(&request, MPI_STATUS_IGNORE);
if (initiate)
function();
Upvotes: 1