gpt4 book ai didi

c++ - 如何使用 MPI_Irecv?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:30:37 24 4
gpt4 key购买 nike

来自 OpenMPI 文档:C++ 语法

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

所以我想我会做类似的事情:

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

但它提示:

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

好像我缺少 ompi_request_t**,但它没有记录在案?尝试过

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

但是失败了

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**)’

ompi_request_t 部分是怎么回事?

最佳答案

这有效(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;
}

或者这有效(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;
}

关于c++ - 如何使用 MPI_Irecv?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13362016/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com