简体   繁体   English

cout 的排序很奇怪:MPI_Recv 在 MPI_Send 之前?

[英]Ordering of cout weird: MPI_Recv before MPI_Send?

I have something like:我有类似的东西:

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;
}

But I see in console:但我在控制台中看到:

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

Why isit that the cout after receive prints before the one before send?为什么接收后的cout打印在发送前的之前?

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. MPI 实现通常为所有进程执行标准输出重定向,但它通常被缓冲以提高性能并最小化网络利用率。 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.然后将所有进程的输出发送到mpiexec (或mpirun ,或用于启动 MPI 作业的任何其他命令)并合并到其标准输出中。 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.来自不同进程的不同块/行在输出中的最终顺序大多是随机的,因此除非采用某种进程同步,否则您不能期望来自某个级别的消息会首先出现。

Also note that the MPI standard does not guarantee that it is possible for all ranks to write to the standard output.另请注意,MPI 标准不保证所有等级都可以写入标准输出。 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.该标准提供了MPI_IO预定义属性键,可以在MPI_COMM_WORLD上查询,以获得允许执行标准输出的进程的等级。 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.现在,大多数 MPI 实现对 MPI 作业中的所有进程执行输出重定向,从而为此类属性查询返回MPI_ANY_SOURCE ,但不能保证始终如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM