我自己实现的MPI_Gather

时间:2018-05-06 17:03:03

标签: c++ concurrency mpi

我正在尝试编写自己的MPI_Gather实现,但输入的数组不会随着输出而改变。正常的MPI_gather正常工作。

代码:

void My_MPI_Gather(int* sendbuf, int sendcount, MPI_Datatype d1, int* recvbuf, int recvcount, MPI_Datatype d2, int root, MPI_Comm comm)
{
    int numprocs, myid;
    int *temp = new int[sendcount];
    int temp2;
    MPI_Status status;
    MPI_Comm_size(comm, &numprocs);
    MPI_Comm_rank(comm, &myid);

    if (myid == root)
    {
        for (int i = 0; i < numprocs; i++)
        {
            if (i != root)
            {
                MPI_Recv(sendbuf, recvcount, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, *sendbuf, &status);
                for (int j = 0; j < recvcount; j++)
                {
                    recvbuf[recvcount*i + j] = *temp;
                }
            }
            recvbuf[root*recvcount] = *sendbuf;
        }

    }
    else
    {
        MPI_Send(temp, sendcount, d1, root, 99, *recvbuf);
    }
}

MPI中最糟糕的事情是我无法调试此功能,所以我会很高兴任何建议:)

0 个答案:

没有答案