【问题标题】:MPI Send and Receive don't work with more then 8182 doubleMPI 发送和接收不适用于 8182 双倍以上
【发布时间】:2016-09-17 15:09:24
【问题描述】:

我在使用以下代码时遇到了一些问题:

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

int id, p, n, ln, i, j, retCode;
double *buffer;

MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &p);
MPI_Comm_rank(MPI_COMM_WORLD, &id);


n = strtol(argv[1],NULL,10); // total number of elements to be distributed

ln = n/p;   // local number of elements

buffer = (double*)calloc(ln, sizeof(double));

if (id == p-1)  // Process p-1 send to other processes
{
    for (i=0; i< p-1; i++)
    {
        fprintf(stdout, "Process %d is sending %d elements to process %d\n", p-1, ln, i);
        retCode = MPI_Ssend (buffer, ln, MPI_DOUBLE, i, 0, MPI_COMM_WORLD);

        if(retCode)
            fprintf(stdout, "MPISend error at file %s, line %d  code %d\n", __FILE__, __LINE__, retCode);

        fprintf(stdout, "Process %d completed sending to process %d\n", p-1, i);

    }

} 
else    // other processes receive from process p-1
{
    fprintf(stdout, "Process %d is receiving %d elements from process %d\n", id, ln,p-1);
    retCode = MPI_Recv (buffer, ln, MPI_DOUBLE, p-1, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
    if(retCode)
        fprintf(stdout, "MPI_Recv error at file %s, line %d  code %d\n", __FILE__, __LINE__, retCode);
    fprintf(stdout, "Process %d received from process %d\n", id, p-1);
}
free(buffer);
MPI_Finalize(); 
return 0;
}

这个想法是用进程 p-1 打开一个数据集,然后将其分发给其余进程。当变量 ln(本地元素数)小于 8182 时,此解决方案有效。当我增加元素数时,出现以下错误:

    mpiexec -np 2   ./sendreceive 16366
    Process 0 is receiving 8183 elements from process 1
    Process 1 is sending 8183 elements to process 0
    Fatal error in MPI_Recv: Other MPI error, error stack:
    MPI_Recv(224)...................: MPI_Recv(buf=0x2000590, count=8183,         MPI_DOUBLE, src=1, tag=MPI_ANY_TAG, MPI_COMM_WORLD, status=0x1) failed
    PMPIDI_CH3I_Progress(623).......: fail failed
    pkt_RTS_handler(317)............: fail failed
    do_cts(662).....................: fail failed
    MPID_nem_lmt_dcp_start_recv(288): fail failed
    dcp_recv(154)...................: Internal MPI error!  cannot read from remote process

出了什么问题?

【问题讨论】:

    标签: c parallel-processing mpi


    【解决方案1】:

    我认为问题在于您在退出程序之前没有调用 MPI_Finalize()。如果我在我的笔记本电脑上运行你的代码,我会得到一个错误(一个不同的错误!)即使是“n”的小值,如果我在返回之前调用 MPI_Finalize(),它就会消失。

    我猜您没有收到 n

    【讨论】:

    • 谢谢大卫。我修复了代码,但我的问题不在 MPI_Finalize() 中,在我的原始代码中。我也使用您的修复程序运行代码,但问题仍然存在。
    【解决方案2】:

    我猜如果您使用 MPI_Send 而不是 MPI_Ssend,代码可以工作? 如果您尝试使用其他通信设备,它是否有效?

    如果其中至少一个问题的答案是肯定的,那么我会尝试检查这是否是您使用的 MPI 实现的已知错误。

    【讨论】:

    • 正如您所建议的,问题出在我正在使用的 MPI 实现中。
    • 您愿意将您的问题标记为已回答吗?
    猜你喜欢
    • 2013-04-15
    • 1970-01-01
    • 2018-03-12
    • 2013-12-20
    • 2016-06-15
    • 2012-03-13
    • 2013-01-28
    • 2011-07-04
    • 2016-10-03
    相关资源
    最近更新 更多