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

📄 node71.html

📁 Design and building parallel program
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<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>6.4 Unstructured Communication</TITLE>
</HEAD>
<BODY>
<meta name="description" value="6.4 Unstructured Communication">
<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=tex2html2799 HREF="node70.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node70.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=tex2html2807 HREF="node72.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node72.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=tex2html2805 HREF="node67.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node67.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=tex2html2809 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=tex2html2810 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=tex2html2808 HREF="node72.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node72.html">6.5 Asynchronous Communication</A>
<B>Up:</B> <A NAME=tex2html2806 HREF="node67.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node67.html">6 Fortran M</A>
<B> Previous:</B> <A NAME=tex2html2800 HREF="node70.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node70.html">6.3 Communication</A>
<BR><HR><P>
<H1><A NAME=SECTION03340000000000000000>6.4 Unstructured Communication</A></H1>
<P>
<A NAME=9016>&#160;</A>
In the preceding section, we saw how channels are used to implement
<A NAME=9017>&#160;</A>
regular communication structures such as a ring and a tree.  Next, we
examine the techniques used to implement <em> unstructured
 </em>
communication algorithms in which the identity of communication
partners changes during program execution
(Section <A HREF="node17.html#seccommunstruc" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node17.html#seccommunstruc">2.3.3</A>).  These patterns require many-to-one
and many-to-many communication structures, which can be implemented
using FM's <tt> MERGER</tt> construct.  They can also require the dynamic
creation of channels during program execution.
<P>
<H2><A NAME=SECTION03341000000000000000>6.4.1 Many-to-One Communication</A></H2>
<P>
<A NAME=secfmmerge>&#160;</A>
<P>
FM's <tt> MERGER</tt> statement creates a first-in/first-out message
<A NAME=9024>&#160;</A>
queue, just as <tt> CHANNEL</tt> does.  Unlike <tt> CHANNEL</tt>, however, it
allows multiple outports
<A NAME=9027>&#160;</A>
to reference this queue and hence defines a many-to-one communication
structure.  Messages sent on any outport are appended to the queue,
with the order of messages sent on each outport being preserved and
any message sent on an outport eventually appearing in the queue.  The
<tt> MERGER</tt> statement has the general form
<tt> MERGER(in=</tt><em> inport</em>, <tt> out=</tt><em> outport_specifier</em><tt> )</tt>
<P>
where an <em> outport_specifier
 </em> can be a single outport, a
comma-separated list of <em> outport_specifiers</em>, or an array section
from an outport array.  The statement creates a new merger and
associates the named inport
and
outports with this merger.  The inport and the outports must be of the
same type.  Optional <tt> iostat=</tt> and <tt> err=</tt> specifiers can be
used to detect error conditions, as in the <tt> CHANNEL</tt> statement.
<P>
<P><A NAME=10197>&#160;</A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img884.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img884.gif">
<BR><STRONG>Figure 6.3:</STRONG> <em> A many-to-one communication structure connecting four
producer processes to a single consumer.</em><A NAME=figfmmerge>&#160;</A><BR>
<P>
<P>
The following code fragment implements a typical many-to-one
communication structure.  As illustrated in Figure <A HREF="node71.html#figfmmerge" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node71.html#figfmmerge">6.3</A>,
<A NAME=9046>&#160;</A>
this uses a merger to connect four <tt> producer</tt> processes with a
<A NAME=9048>&#160;</A>
single consumer.
<P>

<PRE><TT> 
		<tt> INPORT (integer) pi</tt>            						 ! Single inport
<P>
		<tt> OUTPORT(integer) pos(4)</tt>        						 ! Four outports
<P>
		<tt> MERGER(in=pi,out=pos(:))</tt>      						 ! Merger
<P>
		<tt> PROCESSES</tt>                      						 !
<P>
				<tt> call consumer(pi)</tt>              				 ! Single consumer
<P>
				<tt> PROCESSDO i=1,4</tt>                				 !
<P>
						<tt> PROCESSCALL producer(pos(i))</tt>   		 ! Four producers
<P>
				<tt> ENDPROCESSDO</tt>                   				 !
<P>
		<tt> ENDPROCESSES</tt>                   						 !
<P>
</TT></PRE>

<P>
<BR><HR>
<b> Example <IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img887.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img887.gif">.<IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img885.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img885.gif">    Manager/Worker</b>:<A NAME=exmwx>&#160;</A>
<P>
<A NAME=9062>&#160;</A>
As an additional example of many-to-one communication, we consider the
manager/worker structure used in the parameter study problem described
in Section <A HREF="node10.html#exdatabase" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node10.html#exdatabase">1.4.4</A>.  As illustrated in
Figure <A HREF="node10.html#figmerge" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node10.html#figmerge">1.14</A>, this structure comprises one manager task, one
output task, and multiple workers.  The FM implementation
(Programs <A HREF="node71.html#progfmmw2" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node71.html#progfmmw2">6.4</A> and <A HREF="node71.html#progfmmw1" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node71.html#progfmmw1">6.5</A>) comprises a main
program and two process definitions.  The <tt> output</tt> process
definition is not shown.
<P>
<P><A NAME=progfmmw2>&#160;</A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img886.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img886.gif"><P>
<P>
The main program (Program <A HREF="node71.html#progfmmw2" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node71.html#progfmmw2">6.4</A>) creates two mergers to
implement the many-to-one communication structures connecting the
workers to the manager and output tasks.  It also creates <tt> NW</tt>
channels to connect the manager to each worker.
<P>
Each worker (Program <A HREF="node71.html#progfmmw1" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node71.html#progfmmw1">6.5</A>) repeatedly requests a task
descriptor from the manager, waits to receive this task descriptor,
and executes the task represented by the descriptor.  A worker
terminates when the channel from the manager is closed.  The manager
repeatedly receives and replies to requests for task descriptors until
no more tasks remain.  A request comprises the identifier of the
requesting worker, an integer in the range <tt> 1..NW</tt>.  The manager
responds to the request by sending a new task descriptor (generated by
the function <tt> newtask</tt>, and represented by a real number) on the
appropriate channel.  When all task descriptors have been allocated,
the manager signals termination by closing the channels to the
workers.
<P>
<BR><HR>
<P>
<P><A NAME=progfmmw1>&#160;</A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img888.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img888.gif"><P><H2><A NAME=SECTION03342000000000000000>6.4.2 Many-to-Many Communication</A></H2>
<P>
<P><A NAME=10255>&#160;</A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img889.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img889.gif">
<BR><STRONG>Figure 6.4:</STRONG> <em> A many-to-many communication structure connecting four
producer processes to three consumers.  Each producer has an array of

⌨️ 快捷键说明

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