Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use MPI_Irecv?

Tags:

c++

openmpi

From OpenMPI docs: C++ syntax

Request Comm::Irecv(void* buf, int count, const Datatype&
    datatype, int source, int tag) const

So I imagine I do something like:

MPI::Request req;
req = MPI_Irecv(&ballChallenges[i], 2, MPI_INT, i, TAG_AT_BALL, MPI_COMM_WORLD);

But it complains:

error: too few arguments to function ‘int MPI_Irecv(void*, int, MPI_Datatype, int, int, MPI_Comm, ompi_request_t**)’

Seems like I am missing ompi_request_t**, but its not documented? Tried

MPI_Irecv(&ballChallenges[i], 2, MPI_INT, i, TAG_AT_BALL, MPI_COMM_WORLD, &req);

But fails with

error: cannot convert ‘MPI::Request*’ to ‘ompi_request_t**’ for argument ‘7’ to ‘int MPI_Irecv(void*, int, MPI_Datatype, int, int, MPI_Comm, ompi_request_t**)’

So whats with the ompi_request_t part?

like image 521
Jiew Meng Avatar asked Nov 13 '12 13:11

Jiew Meng


People also ask

What is MPI_ Irecv?

Definition. MPI_Irecv stands for MPI Receive with Immediate return; it does not block until the message is received. To know if the message has been received, you must use MPI_Wait or MPI_Test on the MPI_Request filled.

What is Mpi_status_ignore?

Definition. MPI_STATUS_IGNORE informs MPI to not fill an MPI_Status, which saves some time. It is used in message reception (MPI_Recv), non-blocking operations wait (MPI_Wait, MPI_Waitany) and test (MPI_Test, MPI_Testany). A version of MPI_STATUS_IGNORE exists also for arrays of statuses: MPI_STATUSES_IGNORE.

What is MPI wait?

MPI_Wait is a blocking call that returns only when a specified operation has been completed (e.g., the send buffer is safe to access). This call should be inserted at the point where the next section of code depends on the buffer, because it forces the process to block until the buffer is ready.

What is status in MPI?

MPI Point-to-Point: Status Status is not simply a flag value, but an object with several useful fields. The status variable provides information on the message source and tag, as well as any error incurred on the communication call.


1 Answers

This works (C):

#include <stdio.h>
#include <string.h>
#include <mpi.h>

int main(int argc, char **argv) {
    int rank;
    const char *msg="Hello!";
    const int len=strlen(msg)+1;
    char  buf[len];

    MPI_Request isreq, irreq;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    if (rank == 0) {
        MPI_Isend((void*)msg, len, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &isreq);
        MPI_Irecv(buf, len, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &irreq);
        MPI_Cancel(&irreq);
        MPI_Cancel(&isreq);
    }


    MPI_Finalize();
    return 0;
}

Or this works (C++)

#include <cstring>
#include <mpi.h>

using namespace MPI;

int main(int argc, char **argv) {
    const char *msg="Hello!";
    const int len=strlen(msg)+1;
    char *buf = new char[len];

    Init(argc, argv);
    int rank = COMM_WORLD.Get_rank();

    if (rank == 0) {
        Request isreq = COMM_WORLD.Isend(msg, len, MPI_CHAR, 0, 0);
        Request irreq = COMM_WORLD.Irecv(buf, len, MPI_CHAR, 0, 0);
        isreq.Cancel();
        irreq.Cancel();
    }

    Finalize();
    return 0;
}
like image 195
Jonathan Dursi Avatar answered Oct 28 '22 05:10

Jonathan Dursi