订购的cout奇怪:MPI_Recv之前MPI_Send? [英] Ordering of cout weird: MPI_Recv before MPI_Send?

查看:199
本文介绍了订购的cout奇怪:MPI_Recv之前MPI_Send?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似的:

if (rank == winner) {
    ballPos[0] = rand() % 128;
    ballPos[1] = rand() % 64;
    cout << "new ball pos: " << ballPos[0] << " " << ballPos[1] << endl;
    MPI_Send(&ballPos, 2, MPI_INT, FIELD, NEW_BALL_POS_TAG, MPI_COMM_WORLD);
} else if (rank == FIELD) {
    MPI_Recv(&ballPos, 2, MPI_INT, winner, NEW_BALL_POS_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
    cout << "2 new ball pos: " << ballPos[0] << " " << ballPos[1] << endl;
}

但我在控制台看到:

new ball pos: 28 59
2 new ball pos: 28 59

为什么在接收打印之前, cout 打印之前发送?

Why isit that the cout after receive prints before the one before send?

推荐答案

这两个不同的进程同时执行输出。 MPI实现通常对所有进程执行标准输出重定向,但是它通常被缓冲以便提高性能和最小化网络利用率。然后将所有进程的输出发送到 mpiexec (或到 mpirun ,或发送到用于启动的任何其他命令MPI作业),并组合成其标准输出。来自不同进程的不同块/行在输出中的顺序大多是随机的,因此,除非采用某种过程同步方法,否则不能期望来自某个排名的消息首先出现。

These are two different processes doing output at the same time. MPI implementations usually perform standard output redirection for all processes, but it is usually buffered in order to improve performance and to minimise network utilisation. The output from all processes is then sent to mpiexec (or to mpirun, or to whatever other command is used to launch the MPI job) and combined into its standard output. The order in which different chunks/lines from different processes end up in the output is mostly random, so you must not expect that a message from a certain rank would come up first unless some sort of process synchronisatoin is employed.

另请注意,MPI标准并不保证所有行都可以写入标准输出。该标准提供了可以在 MPI_COMM_WORLD 上查询的 MPI_IO 预定义属性键,以便获得进程的排名允许执行标准输出。大多数MPI实现现在对MPI作业中的所有进程执行输出重定向,因此为这样的属性查询返回 MPI_ANY_SOURCE ,但不能保证始终是这样。

Also note that the MPI standard does not guarantee that it is possible for all ranks to write to the standard output. The standard provides the MPI_IO predefined attribute key that one can query on MPI_COMM_WORLD in order to obtain the rank of the process that is allowed to perform standard output. Most MPI implementations nowadays perform output redirection on all processes in the MPI job and thus return MPI_ANY_SOURCE for such attribute queries, but this is not guaranteed to always be the case.

这篇关于订购的cout奇怪:MPI_Recv之前MPI_Send?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆