简单的MPI_GATHER测试带有memcpy错误

Simple MPI_Gather test with memcpy error

本文关键字:memcpy 错误 测试 GATHER MPI 简单      更新时间:2023-10-16

我正在学习MPI,并尝试创建某些功能的示例。我已经工作了几个工作,但是我与MPI_Gather有问题。我进行了更复杂的拟合测试,但是将其修剪为最简单的代码。但是,我仍然会遇到以下错误:

root@master:/home/sgeadmin# mpirun ./expfitTest5
Assertion failed in file src/mpid/ch3/src/ch3u_request.c at line 584: FALSE
memcpy argument memory ranges overlap, dst_=0x1187e30 src_=0x1187e40 len_=400
internal ABORT - process 0

我正在通过AWS EC2运行一个主实例和两个节点实例。我已经安装了所有适当的库,因为我得到了其他MPI示例。我的程序是:

int main()
{
    int world_size, world_rank;
    int nFits = 100;
    double arrCount[100];
    double *rBuf = NULL;
    MPI_Init(NULL,NULL);
    MPI_Comm_size(MPI_COMM_WORLD, &world_size);
    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
    assert(world_size!=1);
    int nElements = nFits/(world_size-1);
    if(world_rank>0){
    for(int k = 0; k < nElements; k++)
    {
            arrCount[k] = k;
    }}
    MPI_Barrier(MPI_COMM_WORLD);
    if(world_rank==0)
    {
            rBuf = (double*) malloc( nFits*sizeof(double));
    }
    MPI_Gather(arrCount, nElements, MPI_DOUBLE, rBuf, nElements, MPI_DOUBLE, 0, MPI_COMM_WORLD);
    if(world_rank==0){
    for(int i = 0; i < nFits; i++)
    {
            cout<<rBuf[i]<<"n";
    }}
    MPI_Finalize();
  exit(0);
}

在malloc或mpi_gather中我不了解一些东西吗?我将代码与其他样本进行了比较,找不到任何区别。

收集操作中的root进程确实参与了操作。IE。它将数据发送到其自己的接收缓冲区。这也意味着您必须在接收缓冲区中分配内存。

现在,您可以使用MPI_Gatherv并在0的根上指定recvcounts[0]/sendcount以密切关注您的示例。但是通常,您希望以同等参与操作的方式编写MPI应用程序,即int nElements = nFits/world_size