gpt4 book ai didi

mpi - 数据传输问题 : MPI_Isend followed by MPI_Probe and MPI_Recv

转载 作者:行者123 更新时间:2023-12-04 03:47:07 25 4
gpt4 key购买 nike

我有以下代码

int main(int argc, char* argv[])
{
int rank, size;

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

MPI_Request mpiRequest;
MPI_Status myStatus;
int tag = 11;


int testData = 12;
MPI_Isend(&testData,1,MPI_INT,(rank+1)%size,tag,MPI_COMM_WORLD,&mpiRequest);
MPI_Wait (&mpiRequest,&myStatus);

int source = (rank+size-1)%size;
int sizeProb = MPI_Probe(source,tag,MPI_COMM_WORLD,&myStatus);
int * recvTransferArray = new int [sizeProb];

MPI_Recv(recvTransferArray,sizeProb,MPI_INT,source,tag,MPI_COMM_WORLD,&myStatus);

MPI_Finalize();

return 0;
}

问题是在 sizeProb 中我得到 0,我应该得到 1。

我可以使用 MPI_ISend 发送数据并使用 MPI_Probe/MPI_Recv 组合接收数据吗?

最佳答案

事实sizeProb永远是0是件好事! MPI_Probe()返回一个错误代码,意思是 MPI_SUCCESS在你的情况下。要检索其他进程发送的数组的大小,您可以使用 MPI_Get_count(&myStatus, MPI_INT, &sizeProb);
两个链接:

  • 示例 http://mpitutorial.com/dynamic-receiving-with-mpi-probe-and-mpi-status/
  • MPI_Get_count() http://www.mpich.org/static/docs/v3.1/www3/MPI_Get_count.html

  • 这是一个基本示例:
    #include "mpi.h"

    int main(int argc, char* argv[]) { int rank, size;

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

    MPI_Request mpiRequest;
    MPI_Status myStatus;
    int tag = 11;


    int testData = rank;
    MPI_Isend(&testData,1,MPI_INT,(rank+1)%size,tag,MPI_COMM_WORLD,&mpiRequest);
    MPI_Wait (&mpiRequest,&myStatus);

    int source = (rank+size-1)%size;
    MPI_Probe(source,tag,MPI_COMM_WORLD,&myStatus);
    int sizeProb;
    MPI_Get_count(&myStatus, MPI_INT, &sizeProb);
    int * recvTransferArray = new int [sizeProb];

    MPI_Recv(recvTransferArray,sizeProb,MPI_INT,source,tag,MPI_COMM_WORLD,&myStatus);
    std::cout<<"proc "<<rank<<" received "<<sizeProb<<" int, first being "<<recvTransferArray[0]<<std::endl;
    MPI_Finalize();

    return 0;

    }

    关于mpi - 数据传输问题 : MPI_Isend followed by MPI_Probe and MPI_Recv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24842118/

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