⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 node59.html

📁 Design and building parallel program
💻 HTML
📖 第 1 页 / 共 2 页
字号:
object/thread pair on a processor selected at random.
Program <A HREF="node59.html#progccprog2" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node59.html#progccprog2">5.9</A> uses the <tt> Mapping</tt> class of
Program <A HREF="node59.html#progccmap2" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node59.html#progccmap2">5.8</A> to implement this behavior.  There are
three significant differences between this program and
Program <A HREF="node55.html#progcctree" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node55.html#progcctree">5.4</A>.  First, a global <tt> Mapping</tt> object is
defined and initialized at the beginning of <tt> main</tt> to contain the
names of the processors on which the program is to execute.  These
names are read from a file.  Second, a constructor is provided for the
processor object class <tt> Tree</tt> that copies the <tt> Mapping</tt> object
to each new processor object as it is created.  Third, one of the
processor object allocation calls in the <tt> search</tt> function is
augmented with a call to <tt> random_p</tt>, which returns a <tt>
proc_t</tt> structure on a randomly selected processor.
<P>
<BR><HR>
<P>
<P><A NAME=progccprog2>&#160;</A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img853.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img853.gif"><P><H2><A NAME=SECTION03282000000000000000>5.8.2 Mapping Threads to Processor Objects</A></H2>
<P>
<A NAME=secccvf>&#160;</A>
<P>
<A NAME=7488>&#160;</A>
An alternative approach to mapping in CC++
  is to create a
fixed number of processor objects onto which threads are then placed.
<A NAME=7489>&#160;</A>
This approach is often used in SPMD computations, in which case a
<A NAME=7490>&#160;</A>
single thread is mapped to each processor object.  Another important
application is in situations where a computation creates a large
number of lightweight threads that interact only via global pointers.
We can map these threads to a static number of processor objects,
hence avoiding the overhead of creating a new processor object when
creating a new thread; as the threads do not share local data
structures, the mapping of threads to processor objects does not
influence the result computed.
<P>
Program <A HREF="node59.html#progccpo" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node59.html#progccpo">5.10</A> supports this general approach by defining a
class <tt> POArray</tt> that can be used to create an array of processor
objects of specified size and type.  Each processor object is
initialized to contain an array of pointers to the other processor
objects, so that communication between the different processor objects
can be achieved.
<P>
The class <tt> POArray</tt> provides an initialization function, <tt>
init</tt>, that creates the processor objects.  The arguments to this
function specify the number and names of the processors on which
processor objects are to be created.  The <tt> init</tt> function first
makes repeated calls to <tt> create_pobj</tt> to create an array of
processor objects with type <tt> POArrayNode</tt>.  It then initializes
these processor objects by calling the function <tt> init_pobj</tt> with
a copy of the <tt> POArray</tt> object (accessed by the C++
  keyword <tt>
this</tt>) as an argument.
<P>
We would like to be able to use <tt> POArray</tt> to create processor
objects of arbitrary type.  Hence, we use the keyword <tt> virtual</tt>
and the notation <tt> =0</tt> to declare <tt> create_pobj</tt> and <tt>
init_pobj</tt> to be <em> virtual functions</em>.  This means that these
functions can be defined in classes derived from the classes <tt>
POArrary</tt> and <tt> POArrayNode</tt>, respectively.  To create an array of
virtual functions of some type <em> T</em>
, we simply derive new classes
from <tt> POArray</tt> and <tt> POArrayNode</tt> and define the functions <tt>
create_pobj</tt> and <tt> init_pobj</tt> in these classes to create and
initialize new processor objects of type <em> T</em>
.  This mechanism is
used in the following example and in Program <A HREF="node63.html#progccda" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node63.html#progccda">5.16</A>, both of
which use <tt> POArray</tt> for mapping.
<P>
<P><A NAME=progccpo>&#160;</A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img854.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img854.gif"><P>
<P>
<BR><HR>
<b> Example <IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img857.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img857.gif">.<IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img855.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img855.gif">    Coupled Climate Model</b>:<A NAME=exccmxc>&#160;</A>
<P>
<A NAME=7527>&#160;</A>
A coupled climate modeling system comprising an ocean model and an
atmosphere model can be structured as a <em> parallel
composition
 </em> of the two component models, in which each model
executes on one half of <tt> P</tt> processors.  This structure is
implemented in Program <A HREF="node59.html#progccoa" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node59.html#progccoa">5.11</A>.  Mapping is achieved using
the <tt> POArray</tt> class of Program <A HREF="node59.html#progccpo" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node59.html#progccpo">5.10</A>.  The class <tt>
AtmOcn</tt> is derived from <tt> POArray</tt>.  It extends it by defining the
virtual function <tt> create_pobj</tt> used by <tt> POArray</tt> to create a
processor object, as well as the functions <tt> atmosphere</tt> and <tt>
ocean</tt> that implement the atmosphere and ocean models.  Similarly, the
processor object class <tt> AtmOcnNode</tt> is derived from <tt>
POArrayNode</tt> and defines the virtual function <tt> init_pobj</tt> that
initializes an ocean/atmosphere model processor object, as well as the
functions <tt> atm_proc</tt> and <tt> ocn_proc</tt> that will be executed in
each processor object.  The <tt> init_pobj</tt> function creates a local
instance of the <tt> AtmOcn</tt> object passed as an argument, hence
providing each processor object with access to the other processor
objects.
<P>
The main program first reads a list of processor names, <tt> nodes</tt>.
Then, it creates two instances of the <tt> AtmOcn</tt> class (<tt> atm</tt>
and <tt> ocn</tt>), and uses the member function <tt> init</tt> to create
arrays of processor objects located on the lower <tt> P/2</tt> and upper
<tt> P/2</tt> processors named in <tt> nodes</tt>, respectively.  The <tt>
AtmOcn</tt> objects are passed as arguments to the ocean and atmosphere
model components, which use them to perform local mapping.  The
functions <tt> atmosphere</tt> and <tt> ocean</tt> initiate SPMD computation,
placing a distinct instance of <tt> atm_proc</tt> (or <tt> ocn_proc</tt>) on
each of the <tt> posize</tt> processor objects named in the <tt> AtmOcn</tt>
object passed as an argument.
<P>
<P><A NAME=progccoa>&#160;</A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img856.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img856.gif"><P>
<P>
The advantage of the structure employed in Program <A HREF="node59.html#progccoa" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node59.html#progccoa">5.11</A> is
that mapping decisions are specified separately from other aspects of
program logic.  As a result, the same program can be structured as a
<A NAME=7577>&#160;</A>
<em> concurrent composition</em>, in which the ocean and atmosphere models
execute concurrently on the same processors, simply by changing the
calls to <tt> init</tt> in the main program, as shown in
Program <A HREF="node59.html#progccoa2" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node59.html#progccoa2">5.12</A>.
<P>
<BR><HR>
<P>
<P><A NAME=progccoa2>&#160;</A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img858.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img858.gif"><P>
<P>
<A NAME=7586>&#160;</A>
<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=tex2html2643 HREF="node58.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node58.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=tex2html2651 HREF="node60.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node60.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=tex2html2649 HREF="node51.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node51.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=tex2html2653 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=tex2html2654 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=tex2html2652 HREF="node60.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node60.html">5.9 Modularity</A>
<B>Up:</B> <A NAME=tex2html2650 HREF="node51.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node51.html">5 Compositional C++
 </A>
<B> Previous:</B> <A NAME=tex2html2644 HREF="node58.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node58.html">5.7 Determinism</A>
<BR><HR><P>
<P><ADDRESS>
<I>&#169 Copyright 1995 by <A href="msgs0.htm#6" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/tppmsgs/msgs0.htm#6">Ian Foster</a></I>
</ADDRESS>
</BODY>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -