我有一个 int
值,我打算从根节点广播它(rank==(FIELD=0)
)。
int winner
if (rank == FIELD) {
winner = something;
}
MPI_Barrier(MPI_COMM_WORLD);
MPI_Bcast(&winner, 1, MPI_INT, FIELD, MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD);
if (rank != FIELD) {
cout << rank << " informed that winner is " << winner << endl;
}
但是看起来我得到了。
[JM:6892] *** An error occurred in MPI_Bcast
[JM:6892] *** on communicator MPI_COMM_WORLD
[JM:6892] *** MPI_ERR_TRUNCATE: message truncated
[JM:6892] *** MPI_ERRORS_ARE_FATAL: your MPI job will now abort
我发现可以在 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
打印winner
时,它应该是-1