Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPI - Asynchronous Broadcast/Gather

Tags:

c++

process

mpi

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?

like image 247
xxf8xx Avatar asked Oct 10 '12 00:10

xxf8xx


People also ask

Is MPI broadcast blocking?

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.

How does MPI broadcast work?

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.

What does the MPI routine Mpi_barrier () do?

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.

What is collective communication in MPI?

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.


1 Answers

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;
like image 192
Geoff Montee Avatar answered Oct 11 '22 14:10

Geoff Montee