📄 node100.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.6 Other MPI Features</TITLE>
</HEAD>
<BODY>
<meta name="description" value="8.6 Other MPI Features">
<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=tex2html3165 HREF="node99.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node99.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=tex2html3173 HREF="node101.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node101.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=tex2html3171 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=tex2html3175 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=tex2html3176 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=tex2html3174 HREF="node101.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node101.html">8.7 Performance Issues</A>
<B>Up:</B> <A NAME=tex2html3172 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=tex2html3166 HREF="node99.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node99.html">8.5 Modularity</A>
<BR><HR><P>
<H1><A NAME=SECTION03560000000000000000>8.6 Other MPI Features</A></H1>
<P>
In this section, we discuss MPI's derived datatype
mechanism. We also list MPI features not covered in this book.
<P>
<H2><A NAME=SECTION03561000000000000000>8.6.1 Derived Datatypes</A></H2>
<P>
<A NAME=secmptyp> </A>
<P>
<A NAME=13203> </A>
In earlier sections of this chapter, MPI routines have been used to communicate <em>
simple
</em> datatypes, such as integers and reals, or arrays of
these types. The final set of MPI functions that we describe
implements <em> derived types</em>, a mechanism allowing noncontiguous data
elements to be grouped together in a message. This mechanism permits
us to avoid data copy operations. Without it, the sending of a
row of a two-dimensional array stored by columns would require
that these noncontiguous elements be copied into a buffer before being
sent.
<P>
<P><A NAME=13831> </A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img1037.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img1037.gif">
<BR><STRONG>Figure 8.12:</STRONG> MPI derived datatype functions.
<A NAME=figmpiderived> </A><BR>
<P>
<A NAME=13252> </A>
<P>
Three sets of functions are applied for manipulating derived types.
Derived datatypes are constructed by applying <i> constructor
</i>
functions to simple or derived types; we describe three constructor
functions <tt> MPI_TYPE_CONTIGUOUS</tt>, <tt> MPI_TYPE_VECTOR</tt>, and
<tt> MPI_TYPE_INDEXED</tt>. The <em> commit
</em> function, <tt>
MPI_TYPE_COMMIT</tt>, must be applied to a derived type before it can be
used in a communication operation. Finally, the <em> free
</em>
function, <tt> MPI_TYPE_FREE</tt>, should be applied to a derived type
after use, in order to reclaim storage. These functions are summarized in
Figure <A HREF="node100.html#figmpiderived" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node100.html#figmpiderived">8.12</A>.
<P>
The constructor <tt> MPI_TYPE_CONTIGUOUS</tt> is used to define a type
<A NAME=13263> </A>
comprising one or more contiguous data elements. A call of the form
<tt> MPI_TYPE_CONTIGUOUS(count, oldtype, newtype)</tt>
<P>
defines a derived type <tt> newtype</tt> comprising <tt> count</tt>
consecutive occurrences of datatype <tt> oldtype</tt>. For example, the
sequence of calls
<PRE> call MPI_TYPE_CONTIGUOUS(10, MPI_REAL, tenrealtype, ierr)
call MPI_TYPE_COMMIT(tenrealtype, ierr)
call MPI_SEND(data, 1, tenrealtype, dest, tag,
$ MPI_COMM_WORLD, ierr)
CALL MPI_TYPE_FREE(tenrealtype, ierr)
</PRE>
is equivalent to the following single call.
<PRE> call MPI_SEND(data, 10, MPI_REAL, dest, tag,
$ MPI_COMM_WORLD, ierr)
</PRE>
Both code fragments send a sequence of ten contiguous real values at
location <tt> data</tt> to process <tt> dest</tt>.
<P>
<A NAME=13272> </A>
The constructor <tt> MPI_TYPE_VECTOR</tt> is used to define a type
comprising one or more blocks of data elements separated by a constant
stride in an array. A call of the form
<P>
<tt> MPI_TYPE_VECTOR(count, blocklen, stride, oldtype, newtype)</tt>
<P>
defines a derived type <tt> newtype</tt> comprising <tt> count</tt>
consecutive blocks of data elements with datatype <tt> oldtype</tt>, with
each block containing <tt> blocklen</tt> data elements, and the start of
successive blocks separated by <tt> stride</tt> data elements. For
example, the sequence of calls
<PRE> float data[1024];
MPI_Datatype floattype;
MPI_Type_vector(10, 1, 32, MPI_FLOAT, &floattype);
MPI_Type_commit(&floattype);
MPI_Send(data, 1, floattype, dest, tag, MPI_COMM_WORLD);
MPI_Type_free(&floattype);
</PRE>
is equivalent to the following code.
<PRE> float data[1024], buff[10];
for (i=0; i<10; i++) buff[i] = data[i*32];
MPI_Send(buff, 10, MPI_FLOAT, dest, tag, MPI_COMM_WORLD);
</PRE>
Both send ten floating-point numbers from locations <tt> data[0]</tt>,
<tt> data[32]</tt>,..., <tt> data[288]</tt>.
<P>
<BR><HR>
<b> Example <IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img1040.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img1040.gif">.<IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img1038.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img1038.gif"> Finite Difference Stencil</b>:<A NAME=exfds> </A>
<P>
Program <A HREF="node100.html#progmpfd" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node100.html#progmpfd">8.8</A> uses derived types to communicate the north
and south rows and the west and east columns of a <IMG BORDER=0 ALIGN=MIDDLE ALT="" SRC="img1039.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img1039.gif"> Fortran
array.
<A NAME=13288> </A>
As illustrated in Figure <A HREF="node100.html#figbounds" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node100.html#figbounds">8.13</A>, a column of this array is
stored in contiguous locations and can be accessed by using a contiguous
derived type. On the other hand, row <em> i</em>
of this array
(comprising elements <tt> array(<em> i</em>
,1)</tt>, <tt> (<em> i</em>
,2)</tt>,
<em> ...</em>
, <tt> (<em> i</em>
,6)</tt>) is located in elements <em> i</em>
,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -