【问题标题】:Why doesn't process 0 receive data from itself?为什么进程 0 不从自身接收数据?
【发布时间】:2017-02-26 06:37:46
【问题描述】:

我刚刚开始学习 MPI,我并不清楚我遇到问题的原因。

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <mpi.h>


int main(int argc, char *argv[])
{
    int myRank, size;
    double myLeftBound, myRightBound;
    MPI_Status status1;
    MPI_Status status2;
    MPI_Request request1;
    MPI_Request request2;   

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


    if (myRank == 0)
    {
        int counter;

        for (counter = size - 1; counter >= 0; counter--)
        {
            myLeftBound = 0;
            myRightBound = 1;
            MPI_Isend(&myLeftBound, 1, MPI_DOUBLE, counter, 2 * counter, MPI_COMM_WORLD, &request1);
            MPI_Isend(&myRightBound, 1, MPI_DOUBLE, counter, 2 * counter + 1, MPI_COMM_WORLD, &request2);   
        }
    }

    MPI_Recv(&myLeftBound, 1, MPI_DOUBLE, 0, myRank * 2, MPI_COMM_WORLD, &status1);
    MPI_Recv(&myRightBound, 1, MPI_DOUBLE, 0, myRank * 2 + 1, MPI_COMM_WORLD, &status2);
    printf ("I received my left boundary %f\n, I'm %d\n", myLeftBound, myRank);
    MPI_Finalize();
    return 0;
}

其中一个输出如下(进程数为 4)

我收到了我的左边界 0.000000

,我是 1

我收到了我的左边界 0.000000

,我是 2 岁

我收到了我的左边界 0.000000

,我 3 岁

文件 src/mpid/ch3/src/ch3u_buffer.c 第 77 行的断言失败:FALSE memcpy 参数内存范围重叠,dst_=0x7ffcc26963d0 src_=0x7ffcc26963d0 len_=8

内部 ABORT - 进程 0

进程 0 出了什么问题?

【问题讨论】:

    标签: c mpi blocking nonblocking


    【解决方案1】:

    您不能将接收到您发送的同一个缓冲区。从技术上讲,在完成非阻塞发送操作之前,您不得修改发送缓冲区的任何部分。您还应该完成发送操作,这意味着您应该将其存储在多个请求对象中。

    无论如何,只需使用MPI_Bcast 并将非阻塞操作留到以后,当您对 MPI 更有经验时。由于某种原因,它们经常被初学者过度使用和错误使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-22
      • 2020-02-29
      • 2015-06-01
      • 2021-12-04
      • 1970-01-01
      相关资源
      最近更新 更多