使用 MPI,消息在发送之前似乎已收到 [英] Using MPI, a message appears to have been recieved before it has been sent

查看:17
本文介绍了使用 MPI,消息在发送之前似乎已收到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的测试程序中,我从一个进程向另一个进程发送消息.trace printfs 好像在发送之前就表明了正在接收的消息是什么,为什么会这样?

In my test program below I am sending a message from one process to another. The trace printfs seem to indicate what the message is being received before it is sent, why is this so?

#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
/* Run with two processes */
void main(int argc, char *argv[]) {
    int rank, i, count;
    float data[100],value[200];
    MPI_Status status;   
    MPI_Init(&argc,&argv);
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    printf("before if:%d
",rank);
    if(rank==1) {
        printf("in if:%d
",rank);
        for(i=0;i<100;++i) data[i]=i;
        MPI_Send(data,100,MPI_FLOAT,0,55,MPI_COMM_WORLD);
    } else {
        printf("else:%d
",rank);
        MPI_Recv(value,200,MPI_FLOAT,MPI_ANY_SOURCE,55,MPI_COMM_WORLD,&status);
        printf("P:%d Got data from processor %d 
",rank, status.MPI_SOURCE);
        MPI_Get_count(&status,MPI_FLOAT,&count);
        printf("P:%d Got %d elements 
",rank,count);
        printf("P:%d value[5]=%f 
",rank,value[5]);
    }
    MPI_Finalize();
}

/为了运行 8 个进程的程序,我得到了以下结果.如何在进程 1 发送之前进程 0 接收/

- RESULT:

-before if:4

-before if:8

-else:8

-before if:0

-else:0

-P:0 Got data from processor 1
 
-P:0 Got 100 elements 

-P:0 value[5]=5.000000 

-before if:1

-in if:1

-before if:2

-else:2

-before if:5

-else:5

-before if:6

-else:6

-before if:7

-else:7
  -before if:9
  -else:9
  -else:4
  -before if:3
  -else:3

*/

推荐答案

这里的问题不在于你打破了时间的因果关系,只是 MPI 不保证将消息打印到屏幕的顺序(参见MPI - 按订单打印了解更多详情).

The problem here isn't that you've broken the causality of time, just that MPI makes no guarantees about the order of printing messages to the screen (see MPI - Printing in an order for more details).

MPI 在打印之前将您所有的 stdoutstderr 转发回调用 mpiexec/mpirun 的进程它显示在屏幕上(因为那是用户连接的地方.来自所有不同进程的消息可以以任何顺序到达,因此您可能会看到一行表示已收到消息,然后另一行表示已发送消息. 消息仍然以正确的顺序出现,只是在传播过程中被延迟了.

MPI forwards all of your stdout and stderr back to the process that called mpiexec/mpirun before printing it to the screen (since that's where the user is connected. Those messages coming from all of the different processes can arrive in any order so you may be seeing one line saying a message was received before you get another line saying the message has been sent. The messages are still occurring in the right order, they're just getting delayed in the communication channels along the way.

这篇关于使用 MPI,消息在发送之前似乎已收到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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