MPI发送和接收问题 [英] MPI Send and receive questions

查看:252
本文介绍了MPI发送和接收问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对MPI问题,发送和接收操作。

I have questions about MPI send and receive operations.

假设,我们有2 MPI线程试图发送消息给对方。以下是三个code片段这样做:

Suppose, we have 2 MPI threads that try to send message to each other. Following are three code snippets doing that:

第一(阻塞'发送'和'接收')

First (Blocking 'send' and 'receive'):

...
int data = ...;
...
MPI_Send( &data, sizeof( int ), MPI_INT, 
        (my_id == 0)?1:0, 0, MPI_COMM_WORLD );

MPI_Status status; 
MPI_Recv( &data, sizeof( int ), MPI_INT,
        (my_id == 0)?1:0, 0, MPI_COMM_WORLD, &status );
...

二(非阻塞发送,但阻止接收):

Second (Non-blocking 'send' but blocking 'receive'):

...
int data = ...;
...
MPI_Request request;
MPI_Isend( &data, sizeof( int ), MPI_INT, 
        (my_id == 0)?1:0, 0, MPI_COMM_WORLD, &request);

MPI_Status status; 
MPI_Recv( &data, sizeof( int ), MPI_INT,
        (my_id == 0)?1:0, 0, MPI_COMM_WORLD, &status );
// Synchronize sender & receiver
MPI_Wait( &request, &status);
...

三(非阻塞接收与阻止发送):

Third (Non-blocking 'receive' with blocking 'send'):

...
int data = ...;
...
MPI_Request request;
MPI_Irecv( &data, sizeof( int ), MPI_INT,
        (my_id == 0)?1:0, 0, MPI_COMM_WORLD, &request );

MPI_Send( &data, sizeof( int ), MPI_INT, 
        (my_id == 0)?1:0, 0, MPI_COMM_WORLD);

MPI_Status status; 

// Synchronize sender & receiver
MPI_Wait( &request, &status);
...

我想有与上述三个code潜在的问题,但我想你的意见。所以,我有以下问题:

I guess there are potential problems with above three code but I want your opinion. So, I have the following questions:


  1. 什么是上面给出的(潜在的)的问题(如果有的话)3 codeS?

  1. What are the (potential) problems (if any) with 3 codes given above?

其中上述三个$ C $的c是有效的/正确考虑MPI标准,以便它可以与所有MPI实现工作?

Which of the above three code are valid/correct considering MPI standard so that it can work with all MPI implementations?

什么是最好的方式(如果上述3不是一,请写出来),这样做吗?

What is the best way (if not one of above 3 please write it) to do that?

在第三code,如果我们改变MPI_Irecv和MPI_SEND调用的顺序?

In the third code, what if we change the order of MPI_Irecv and MPI_Send call?

PS:顺便说一句,我试图执行这些使用斯卡利MPI和他们都合作

PS: By the way, I have tried executing them using Scali MPI and all of them worked!

推荐答案

您第一次执行很可能导致死锁,特别是在人际交往在同步模式下进行(也许它的工作在你的测试,因为通信是缓冲;它不太可能是大数据的情况下)。

Your first implementation is likely to cause a deadlock, especially if the comminication is done in synchronized mode (maybe it worked in your tests, because the communication was buffered; it's not likely to be the case for large data).

另外两种实现方式应该不会死锁。我相信,它被认为更好的做法,开始接收操作之前发送,所以我个人赞成第三实施。从 MPI标准, 3.7节

The other two implementations should work without deadlocking. I believe it's considered better practice to initiate receive operations before sends, so I would personally favour the 3rd implementation. From the MPI standard, section 3.7:

给用户的建议

[...]

的消息传递模型意味着通信由发送者发起的。通信通常具有较低的开销,如果接收已发布当发送者发起通信(数据可以直接移动到接收缓冲区,并没有需要排队一个挂起发送请求)。然而,一个接收操作可以完成已经发生匹配发送之后。使用非阻塞的接收使人们能实现更低的通信开销,而不在等待发送阻止接收器。

The message-passing model implies that communication is initiated by the sender. The communication will generally have lower overhead if a receive is already posted when the sender initiates the communication (data can be moved directly to the receive buffer, and there is no need to queue a pending send request). However, a receive operation can complete only after the matching send has occurred. The use of nonblocking receives allows one to achieve lower communication overheads without blocking the receiver while it waits for the send.

第三个实现与秩序 MPI_SEND / MPI_Irecv 可以在 MPI_SEND 调用同样的原因作为第一个实施

The third implementation with order MPI_Send/MPI_Irecv can deadlock in the MPI_Send call for the same reasons as the first implementation.

这篇关于MPI发送和接收问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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