5

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?

Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
  • 1
    `MPI_Irecv` is from the C bindings. It does not return the request but rather passes it out in the last argument. All functions in the C bindings with a very small set of exemptions return the MPI status code. Note that the C++ bindings have been deleted from the MPI-3.0 standard and were previously deprecated in MPI-2.2. You shuold be using the C bindings in C++ applications. – Hristo Iliev Nov 13 '12 at 14:24
  • @HristoIliev, it seems like the last param is `MPI_Request`? Which is just an `int`? How can I cancel it then? – Jiew Meng Nov 13 '12 at 14:35
  • @JiewMeng , you can _either_ use the C++ syntax, `Request Comm::Irecv(void* buf,...` which returns an MPI::Request, *or* you can use the C syntax, `MPI_Irecv(&ballChallenges[i], 2, MPI_INT, i, TAG_AT_BALL, MPI_COMM_WORLD, &req);` which takes a variable of type `MPI_Request` as the last variable. You use the request (which ever way you get it) to cancel, either through (C++ syntax) `Request::Cancel()` or (C syntax) `MPI_Cancel(&req);` – Jonathan Dursi Nov 13 '12 at 16:31
  • @JonathanDursi, either way I will still need to pass a MPI_Request? – Jiew Meng Nov 14 '12 at 00:13

1 Answers1

5

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;
}
Jonathan Dursi
  • 50,107
  • 9
  • 127
  • 158
  • 1
    Is it true that the C++ syntax will be deprecated? From 1st comment in my original question, "*Note that the C++ bindings have been deleted from the MPI-3.0 standard and were previously deprecated in MPI-2.2. You shuold be using the C bindings in C++ applications*" – Jiew Meng Nov 14 '12 at 06:08
  • 1
    They were *deprecated* in 2.2, they're actually deleted in 3.0 -- http://blogs.cisco.com/performance/the-mpi-c-bindings-are-gone-what-does-it-mean-to-you/ – Jonathan Dursi Nov 14 '12 at 12:28