Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ MPI_ERR_TRUNCATE:在广播中_C++_Mpi_Broadcast_Openmpi - Fatal编程技术网

C++ MPI_ERR_TRUNCATE:在广播中

C++ MPI_ERR_TRUNCATE:在广播中,c++,mpi,broadcast,openmpi,C++,Mpi,Broadcast,Openmpi,我有一个int我打算从根目录广播(rank==(FIELD=0)) 发现我可以在Bcast MPI_Bcast(&winner, NUMPROCS, MPI_INT, FIELD, MPI_COMM_WORLD); 其中NUMPROCS是正在运行的进程数。(实际上,我似乎只需要它是2)。然后它运行,但给出意外的输出 1 informed that winner is 103 2 informed that winner is 103 3 informed that winner is

我有一个
int
我打算从根目录广播(
rank==(FIELD=0)

发现我可以在
Bcast

MPI_Bcast(&winner, NUMPROCS, MPI_INT, FIELD, MPI_COMM_WORLD);
其中
NUMPROCS
是正在运行的进程数。(实际上,我似乎只需要它是2)。然后它运行,但给出意外的输出

1 informed that winner is 103
2 informed that winner is 103
3 informed that winner is 103
5 informed that winner is 103
4 informed that winner is 103

当我
cout
成为
赢家时,它应该是
-1

您的代码中有一个错误:

if(秩==字段){
//随机放置球,然后向球员广播
ballPos[0]=rand()%128;
ballPos[1]=rand()%64;
MPI_Bcast(ballPos,2,MPI_INT,FIELD,MPI_COMM_WORLD);
}
这是一个非常常见的错误
MPI_Bcast
是一个集合操作,必须由所有进程调用才能完成。在您的情况下,此广播不是由
MPI\u COMM\u WORLD
中的所有进程调用的(但仅由根进程调用),因此会干扰下一个广播操作,即循环内的广播操作。第二个广播操作实际上接收第一个广播操作(两个
int
元素)发送到一个缓冲区的消息,该缓冲区只接收一个
int
,因此接收截断错误消息。在OpenMPI中,每个广播在内部使用相同的消息标记值,因此不同的广播可能会相互干扰,而不是按顺序发出。这符合(旧)MPI标准-在MPI-2.2中,一个不能有多个未完成的集合操作(在MPI-3.0中,一个可以有多个未完成的非阻塞集合操作)。您应该将代码重写为:

if(秩==字段){
//随机放置球,然后向球员广播
ballPos[0]=rand()%128;
ballPos[1]=rand()%64;
}
MPI_Bcast(ballPos,2,MPI_INT,FIELD,MPI_COMM_WORLD);

我对编写的代码没有任何问题;如何定义字段?你能发布更多的代码吗;你绝对确定是这个广播造成了这个问题吗?@JonathanDursi,我希望在对我的答案进行三次编辑后,你的问题的根本原因现在是可读和可理解的:)
MPI_Bcast(&winner, NUMPROCS, MPI_INT, FIELD, MPI_COMM_WORLD);
1 informed that winner is 103
2 informed that winner is 103
3 informed that winner is 103
5 informed that winner is 103
4 informed that winner is 103