简体   繁体   English

如何使用MPI_Irecv?

[英]How to use MPI_Irecv?

From OpenMPI docs: C++ syntax 来自OpenMPI文档:C ++语法

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? 好像我缺少ompi_request_t** ,但是没有记录? 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? 那么ompi_request_t部分又如何呢?

This works (C): 这有效(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++) 还是行得通(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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM