📄 node70.html
字号:
An operation on an undefined port is treated as erroneous. Optional
<tt> err=</tt> and <tt> iostat=</tt> specifiers (described in
Section <A HREF="node70.html#secfmchan" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node70.html#secfmchan">6.3.1</A>) can be included in <tt> SEND</tt> and <tt>
ENDCHANNEL</tt> statements to indicate how to recover from this and other
exceptional conditions.
<P>
<H2><A NAME=SECTION03333000000000000000>6.3.3 Receiving Messages</A></H2>
<P>
<A NAME=secfmrecv> </A>
<P>
A process receives a value by applying the <tt> RECEIVE</tt> statement to
<A NAME=8890> </A>
an inport. The inport declaration specifies the message format. For
example, the <tt> bridge</tt> process in Program <A HREF="node68.html#progfmbuild" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node68.html#progfmbuild">6.1</A> makes
repeated calls to the <tt> RECEIVE</tt> statement to receive a sequence of
integer messages, detecting end-of-sequence by using the <tt> iostat</tt>
specifier. A <tt> RECEIVE</tt> statement is blocking (synchronous); that is, it
does not complete until data is available. Hence, a consumer process
such as <tt> bridge</tt> cannot ``run ahead'' of the corresponding
producer.
<P>
An array size can be included in a message, thereby allowing arrays of
different sizes to be communicated on the same channel. For example,
the following code fragment receives a message comprising the integer
<tt> num</tt> followed by <tt> num</tt> real values. The incoming data are
placed in array elements <tt> a(1,offset), a(1,offset+1), ...,
a(1,offset+num-1)</tt>.
<P>
<PRE> INPORT (integer n, real x(n)) pi
integer num
real a(128, 128)
RECEIVE(pi) num, a(1,offset)
</PRE>
<P>
An operation on an undefined port is treated as erroneous. A <tt>
RECEIVE</tt> statement can include optional <tt> err=</tt> and <tt> iostat=</tt>
specifiers to indicate how to recover from this and various
exceptional conditions. In addition, an <tt> end=<em> label
</em></tt>
specifier causes execution to continue at the statement with the
specified <em> label
</em> upon receipt of a end-of-channel message.
This mechanism can be used to rewrite the <tt> bridge</tt> process of
Program <A HREF="node68.html#progfmbuild" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node68.html#progfmbuild">6.1</A> as follows.
<P>
<PRE><TT>
<tt> PROCESS bridge(pi)</tt> ! Process definition
<P>
<tt> INPORT (integer) pi</tt> ! Argument: inport
<P>
<tt> integer num</tt> ! Local variable
<P>
<tt> do while(.true.)</tt> ! While not done:
<P>
<tt> RECEIVE(port=pi, end=10) num</tt> ! Receive message
<P>
<tt> call use_girder(num)</tt> ! Process message
<P>
<tt> enddo</tt> !
<P>
<tt> 10</tt> <tt> end</tt> ! End of process
<P>
</TT></PRE>
<P>
<BR><HR>
<b> Example <IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img877.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img877.gif">.<IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img876.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img876.gif"> Ring Pipeline</b>:<A NAME=exfmring1> </A>
<P>
Program <A HREF="node70.html#progfmring" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node70.html#progfmring">6.2</A> implements the ring-based pairwise
<A NAME=10013> </A>
interactions algorithm of Section <A HREF="node10.html#exinteractions" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node10.html#exinteractions">1.4.2</A>. It comprises
<A NAME=8924> </A>
a main program and a process definition. The main program uses two
<A NAME=8925> </A>
channel statements to create <tt> P</tt> channels
(Figure <A HREF="node70.html#figfmchan" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node70.html#figfmchan">6.1</A>) and a process do-loop to create <tt> P</tt>
processes. One inport and one outport are passed to each process as
arguments, thereby connecting the processes in a unidirectional ring
(Figure <A HREF="node70.html#figfmring" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node70.html#figfmring">6.2</A>). The variables <tt> i</tt> and <tt> P</tt> are
also passed to the processes as arguments; this capability is
discussed in Section <A HREF="node74.html#secarg" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node74.html#secarg">6.7</A>.
<P>
The <tt> ringnode</tt> process's four arguments are a unique identifier,
the total number of processes, and an inport and outport referencing
channels from one neighbor and to the other neighbor in the ring. The
process first initializes its local state and then performs <tt> n-1</tt>
send-receive-compute steps before terminating.
<P>
<BR><HR>
<P>
<P><A NAME=progfmring> </A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img878.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img878.gif"><P>
<P>
<A NAME=8968> </A>
<P>
<P><A NAME=10154> </A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img879.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img879.gif">
<BR><STRONG>Figure 6.2:</STRONG> <em> FM implementation of three-process ring pipeline showing channel
connections.</em><A NAME=figfmring> </A><BR>
<P>
<P>
<BR><HR>
<b> Example <IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img882.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img882.gif">.<IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img880.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img880.gif"> Search</b>:<A NAME=exsearchx> </A>
<P>
Program <A HREF="node70.html#progfmtree" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node70.html#progfmtree">6.3</A> implements a prototypical tree-structured
computation. The program explores a binary tree recursively in the
manner of
<A NAME=8976> </A>
Algorithm <A HREF="node10.html#algsearch" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node10.html#algsearch">1.1</A>, creating a task for each tree node and
<A NAME=8978> </A>
returning the total number of leaf nodes that represent solutions. In
this simple program, the tree is not represented by an explicit data
structure; instead, a process's position in the tree is represented by
an integer.
<P>
The main program makes an initial call to the process <tt> tree</tt>.
This process uses a process block to create recursively a set of
<em> 2n-1</em>
(<em> n</em>
a power of 2) processes connected in a binary tree
of depth <IMG BORDER=0 ALIGN=MIDDLE ALT="" SRC="img881.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img881.gif">. Each process is connected to its parent by a
channel; nonleaf processes also have channels from their two
offspring. Notice the use of a subroutine call within a process
block, as discussed in Section <A HREF="node69.html#secfmproc" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node69.html#secfmproc">6.2.2</A>.
<P>
<BR><HR>
<P>
<P><A NAME=progfmtree> </A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img883.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img883.gif"><P>
<P>
<A NAME=9014> </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=tex2html2787 HREF="node69.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node69.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=tex2html2795 HREF="node71.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node71.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=tex2html2793 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=tex2html2797 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=tex2html2798 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=tex2html2796 HREF="node71.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node71.html">6.4 Unstructured Communication</A>
<B>Up:</B> <A NAME=tex2html2794 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=tex2html2788 HREF="node69.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node69.html">6.2 Concurrency</A>
<BR><HR><P>
<P><ADDRESS>
<I>© 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 + -