📄 52.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <style type="text/css"> body { font-family: Verdana, Arial, Helvetica, sans-serif;} a.at-term { font-style: italic; } </style> <title>Receiving a Message with Point-to-Point Protocol</title> <meta name="Generator" content="ATutor"> <meta name="Keywords" content=""></head><body> <p>While there are a variety of methods for sending messages, there is only one for receiving a message from a remote processor. The MPI_RECV function has the following characteristics:</p>
<h3>Standard Receive</h3>
<ul>
<li>
Completion Criteria: Completes when data has been received and can be used in the program</li>
<li>
Has remote completion semantics</li>
</ul>
<p>While only one version of the receive function exists, this function does exist in both blocking and non-blocking form.</p>
<p class="codelang">
C:</p>
<pre><code>int MPI_Recv(void *buf, int count, MPI_Datatype datatype,
int source, int tag, MPI_Comm comm, MPI_Status *status)</code></pre>
<p class="codelang">
Fortran:</p>
<pre><code>CALL MPI_RECV(BUF, COUNT, DATATYPE, SOURCE, TAG, COMM, STATUS, IERROR)
TYPE BUF(*)
INTEGER COUNT, DATATYPE, DEST, TAG
INTEGER COMM, STATUS(MPI_STATUS_SIZE), IERROR</code></pre>
<h3>Example</h3>
<p>Building on the MPI_SEND example, code will be added to have the process with Rank 1 receive the data sent by the process with Rank 0. To be run with only 2 processes.</p>
<p class="codelang">
Fortran:</p>
<pre><code> PROGRAM SEND_EXAMPLE
INCLUDE 'mpif.h'
PARAMETER ELEMENTS=10
REAL PRESSURE(ELEMENTS)
INTEGER SOURCE,DESTINATION,IERROR
CALL MPI_INIT(IERROR)
DESTINATION=1
DO I=1,ELEMENTS
PRESSURE(I)=I*2.334
ENDDO
IF (MYID.EQ.0) THEN
CALL MPI_SEND(PRESSURE,ELEMENTS,MPI_REAL,DESTINATION,
& 0,MPI_COMM_WORLD,IERROR)
ENDIF
IF (MYID.EQ.1) THEN
CALL MPI_RECV(NEW_PRESS,ELEMENTS,MPI_REAL,SOURCE,
& 0,MPI_COMM_WORLD,STATUS,IERROR)
ENDIF
CALL MPI_FINALIZE(IERROR)
STOP
END</code></pre>
<p>For a communication to succeed:</p>
<ul>
<li>
Sender must specify a valid destination rank</li>
<li>
Receiver must specify a valid source rank</li>
<li>
The communicator must be the same</li>
<li>
Tags must match</li>
<li>
Receiver's buffer must be large enough</li>
</ul></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -