I have a project which requires 'n' number of processes to work until the problem is solved. Each slave process executes the same code. When a certain condition arises, the process needs to notify all of the other processes in a non-blocking way. The other processes also need to receive this message in a non-blocking way.
Is there a way to do with without threading a separate loop?
Broadcast is a non blocking operation, so processes continue running as soon as the information has been sent/received. After the operation, all process will have a copy of the data from the root process in their buffers.
Broadcasting with MPI_Bcast During a broadcast, one process sends the same data to all processes in a communicator. One of the main uses of broadcasting is to send out user input to a parallel program, or send out configuration parameters to all processes.
MPI_BARRIER(comm) If comm is an intracommunicator, MPI_BARRIER blocks the caller until all group members have called it. The call returns at any process only after all group members have entered the call.
Collective communication is defined as communication that involves a group of processes. The functions of this type provided by MPI are the following: Barrier synchronization across all group members (Sec. Barrier synchronization ). Broadcast from one member to all members of a group (Sec.
It's been a while since I've used MPI. But the I functions are non-blocking. Maybe something like this:
int comm_size = comm.Get_size();
int comm_rank = comm.Get_rank();
int* data = new int[comm_size];
while (some_condition)
{
//During each iteration, check for messages from other nodes
for (int node = 0; node < comm_size; node++)
{
if (node != comm_rank)
{
if (comm.Iprobe(node, TAG_NUM))
{
comm.Irecv(data[node], 1, MPI_INT, node, TAG_NUM);
}
}
}
if (some_other_condition)
{
//Send the message to every node
for (int node = 0; node < comm_size; node++)
{
if (node != comm_rank)
{
comm.Isend(data[node], 1, MPI_INT, node, TAG_NUM);
}
}
}
//do normal work here.
}
delete [] data;
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