📄 node97.html
字号:
<html><!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Converted with LaTeX2HTML 95.1 (Fri Jan 20 1995) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE>8.3 Global Operations</TITLE>
</HEAD>
<BODY>
<meta name="description" value="8.3 Global Operations">
<meta name="keywords" value="book">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<BR> <HR><a href="msgs0.htm#2" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/tppmsgs/msgs0.htm#2"><img ALIGN=MIDDLE src="asm_color_tiny.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/asm_color_tiny.gif" alt="[DBPP]"></a> <A NAME=tex2html3129 HREF="node96.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node96.html"><IMG ALIGN=MIDDLE ALT="previous" SRC="previous_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/previous_motif.gif"></A> <A NAME=tex2html3137 HREF="node98.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node98.html"><IMG ALIGN=MIDDLE ALT="next" SRC="next_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/next_motif.gif"></A> <A NAME=tex2html3135 HREF="node94.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node94.html"><IMG ALIGN=MIDDLE ALT="up" SRC="up_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/up_motif.gif"></A> <A NAME=tex2html3139 HREF="node1.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node1.html"><IMG ALIGN=MIDDLE ALT="contents" SRC="contents_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/contents_motif.gif"></A> <A NAME=tex2html3140 HREF="node133.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node133.html"><IMG ALIGN=MIDDLE ALT="index" SRC="index_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/index_motif.gif"></A> <a href="msgs0.htm#3" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/tppmsgs/msgs0.htm#3"><img ALIGN=MIDDLE src="search_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/search_motif.gif" alt="[Search]"></a> <BR>
<B> Next:</B> <A NAME=tex2html3138 HREF="node98.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node98.html">8.4 Asynchronous Communication</A>
<B>Up:</B> <A NAME=tex2html3136 HREF="node94.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node94.html">8 Message Passing Interface</A>
<B> Previous:</B> <A NAME=tex2html3130 HREF="node96.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node96.html">8.2 MPI Basics</A>
<BR><HR><P>
<H1><A NAME=SECTION03530000000000000000>8.3 Global Operations</A></H1>
<P>
As explained in Chapter <A HREF="node14.html#chap2" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node14.html#chap2">2</A>, parallel algorithms often call
for coordinated communication operations involving multiple processes.
For example, all processes may need to cooperate to transpose a
distributed matrix or to sum a set of numbers distributed one per
process. Clearly, these global operations can be implemented by a
programmer using the send and receive functions introduced in
Section <A HREF="node96.html#secmpibasics" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node96.html#secmpibasics">8.2</A>. For convenience, and to permit
optimized implementations, MPI also
<A NAME=12580> </A>
provides a suite of specialized <em>
<A NAME=12581> </A>
collective communication
</em> functions that perform commonly used
<A NAME=12582> </A>
operations of this type. These functions include the following.
<P>
<UL><LI> Barrier: Synchronizes all processes.
<P>
<LI> Broadcast: Sends data from one process to all processes.
<P>
<LI> Gather: Gathers data from all processes to one process.
<P>
<LI> Scatter: Scatters data from one process to all processes.
<P>
<LI> Reduction operations: Sums, multiplies, etc., distributed data.
<A NAME=12584> </A>
</UL>
<P>
These operations are summarized in Figure <A HREF="node97.html#figmpiglobal" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node97.html#figmpiglobal">8.2</A>.
All are executed collectively, meaning that each process in
a process group calls the communication routine with the same
parameters.
<P>
<P><A NAME=13816> </A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img1014.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img1014.gif">
<BR><STRONG>Figure 8.2:</STRONG> MPI global communication functions.
<A NAME=figmpiglobal> </A><BR>
<P><H2><A NAME=SECTION03531000000000000000>8.3.1 Barrier</A></H2>
<P>
<A NAME=secmpbar> </A>
<P>
<tt> MPI_BARRIER</tt> is used to synchronize execution of a group of
<A NAME=12650> </A>
processes. No process returns from this function until all processes
<A NAME=12651> </A>
have called it. A barrier is a simple way of separating two phases of
<A NAME=12652> </A>
a computation to ensure that messages generated in the two phases do
not intermingle. For example, a call to <tt> MPI_BARRIER</tt> could be
inserted before the second send operation in
Program <A HREF="node96.html#progmpnondet" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node96.html#progmpnondet">8.4</A> to ensure deterministic execution. Of
course, in this example as in many others, the need for an explicit
barrier can be avoided by the appropriate use of tags, source specifiers,
and/or contexts.
<P>
<H2><A NAME=SECTION03532000000000000000>8.3.2 Data Movement</A></H2>
<P>
<A NAME=secmpmov> </A>
<P>
<tt> MPI_BCAST</tt>, <tt> MPI_GATHER</tt>, and <tt> MPI_SCATTER</tt> are
collective <em> data movement
</em> routines, in which all processes
interact with a distinguished <tt> root</tt> process to broadcast, gather,
or scatter data, respectively. The operation of these functions is illustrated in
Figure <A HREF="node97.html#figmpdata" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node97.html#figmpdata">8.3</A>. In each case, the first three arguments
specify the location (<tt> inbuf</tt>) and type (<tt> intype</tt>)
of the data to be communicated
and the number of elements to be sent to each
destination (<tt> incnt</tt>). Other arguments specify the location and
type of the result (<tt> outbuf</tt>, <tt> outtype</tt>) and the number of
elements to be received from each source (<tt> outcnt</tt>).
<P>
<P><A NAME=13960> </A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img1017.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img1017.gif">
<BR><STRONG>Figure 8.3:</STRONG> <em> MPI collective data movement functions, illustrated for a
group of 4 processes. In each set of 16 boxes, each row represents
data locations in a different process. Thus, in the one-to-all
broadcast, the data <tt> A</tt><IMG BORDER=0 ALIGN=MIDDLE ALT="" SRC="img1016.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img1016.gif"> is initially located just in process
0; after the call, it is replicated in all processes. In each case,
both <tt> incnt</tt> and <tt> outcnt</tt> are 1, meaning that each message
comprises a single data element.</em><A NAME=figmpdata> </A><BR>
<P>
<P>
<tt> MPI_BCAST</tt> implements a one-to-all <em> broadcast
</em>
<A NAME=12677> </A>
operation whereby a single named process (<tt> root</tt>) sends the same
<A NAME=12679> </A>
data to all other processes; each process receives this data from the
root process. At the time of call, the data are located in <tt>
inbuf</tt> in process <tt> root</tt> and consists of <tt> incnt</tt> data items of
a specified <tt> intype</tt>. After the call, the data are replicated in
<tt> inbuf</tt> in all processes. As <tt> inbuf</tt> is used for input at the
<tt> root</tt> and for output in other processes, it has type <tt> INOUT</tt>.
<P>
<tt> MPI_GATHER</tt> implements an all-to-one <em> gather
</em>
<A NAME=12690> </A>
operation. All processes (including the <tt> root</tt> process) send data
<A NAME=12692> </A>
located in <tt> inbuf</tt> to <tt> root</tt>. This process places the data in
contiguous nonoverlapping locations in <tt> outbuf</tt>, with the data
from process <em> i</em>
preceding that from process
<em> i+1</em>
. Hence, the <tt> outbuf</tt> in the root process must be
<em> P</em>
times larger than <tt> inbuf</tt>, where <em> P</em>
is the number of
processes participating in the operation. The <tt> outbuf</tt> in
processes other than the <tt> root</tt> is ignored.
<P>
<tt> MPI_SCATTER</tt> implements a one-to-all <em> scatter
</em>
<A NAME=12706> </A>
operation; it is the reverse of <tt> MPI_GATHER</tt>. A specified <tt>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -