gpt4 book ai didi

c - MPI 发送和接收不适用于超过 8182 双

转载 作者:行者123 更新时间:2023-11-30 16:57:24 27 4
gpt4 key购买 nike

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

    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

出了什么问题?

最佳答案

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

我猜您没有收到 n <= 8192 错误的原因是,在内部深处,MPI 使用不同的协议(protocol)来交换 64K 字节或更少的消息(与消息大于 64K。对于较小的消息,您很幸运,发送正确完成而无需调用 Finalize()。

关于c - MPI 发送和接收不适用于超过 8182 双,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39548353/

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