gpt4 book ai didi

c++ - 为什么 MPI_Isend 卡在这里?

转载 作者:太空宇宙 更新时间:2023-11-04 13:07:05 25 4
gpt4 key购买 nike

我正在尝试从左向右发送缓冲区(0->1、1->2 2->3 等...)。我非常确定进程正在从正确的合作伙伴发送和接收,但代码挂起或输出段错误。

#include "mpi.h"
#include <iostream>
int main(int argc, char *argv[])
{
int comm_rank, num_procs, recieve1, send1;
int buffer[10];
MPI_Request request, request2;
MPI_Status status;

MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);


send1 = (comm_rank + 1) % num_procs;
recieve1 = comm_rank - 1;
if (recieve1 < 0)
recieve1 = num_procs - 1;

//std::cout << "Comm Rank = " << comm_rank << "\trecieve1 = " << recieve1 << "\tsend1 = " << send1 << std::endl;

if (comm_rank == 0)
send1 = 1;
if (comm_rank == num_procs-1)
recieve1 = num_procs-2;

if (comm_rank != 0)
{
MPI_Irecv(buffer, 10, MPI_INT, recieve1, 123, MPI_COMM_WORLD, &request);
std::cout << comm_rank << " <- " << recieve1 << std::endl;
}
if (comm_rank != num_procs-1)
{
MPI_Isend(buffer, 10, MPI_INT, send1, 123, MPI_COMM_WORLD, &request2);
std::cout << comm_rank << " -> " << send1 << std::endl;
}
MPI_Wait(&request, &status);
MPI_Wait(&request2, &status);


MPI_Finalize();
return 0;
}

最佳答案

您无条件地对 requestrequest2 执行 MPI_Wait,而您有条件地执行 MPI_Isend/MPI_Irecv。您只能等待实际发起的请求。

关于c++ - 为什么 MPI_Isend 卡在这里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41721159/

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