📄 node70.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>6.3 Communication</TITLE>
</HEAD>
<BODY>
<meta name="description" value="6.3 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=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>
<H1><A NAME=SECTION03330000000000000000>6.3 Communication</A></H1>
<P>
<A NAME=8802> </A>
FM processes, like the tasks introduced in Part I, cannot share data
directly. Instead, they coordinate their execution and exchange data
<A NAME=8803> </A>
by sending and receiving messages on single-producer, single-consumer
channels and multiple-producer, single-consumer mergers. Hence, the
next step in program implementation after processes have been defined
is to establish the channels and mergers needed for communication.
<P>
In this section, we focus on the constructs and techniques used to
specify structured, ``synchronous'' communication operations
(Section <A HREF="node17.html#seccomm" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node17.html#seccomm">2.3</A>). In subsequent sections we examine both
unstructured and asynchronous communication.
<P>
<H2><A NAME=SECTION03331000000000000000>6.3.1 Creating Channels</A></H2>
<P>
<A NAME=secfmchan> </A>
<P>
<A NAME=8807> </A>
The basic building block from which communication structures are
<A NAME=8808> </A>
constructed is the channel, created by executing the <tt> CHANNEL</tt>
<A NAME=8810> </A>
statement. This statement has the general form
<P>
<tt> CHANNEL(in=</tt><em> inport</em>, <tt> out=</tt><em> outport</em><tt> )</tt>
<P>
and both creates a new channel and defines <em> inport
</em> and <em>
outport
</em> to be references to this channel, with <em> inport
</em>
able to receive messages and <em> outport
</em> able to send messages.
The two ports must be of the same type.
<P>
Optional <tt> iostat=</tt> and <tt> err=</tt> specifiers can be used to detect
error conditions, as in Fortran file input/output statements. An <tt>
err=<em> label
</em></tt> specifier causes execution to continue at the
statement with the specified <em> label
</em> if an error occurs while
creating the channel. An <tt> iostat=<em> intval
</em></tt> specifier
causes the integer variable <em> intval
</em> to be set to zero if no
error occurs and to a nonzero value otherwise. If neither <tt> err=</tt>
nor <tt> iostat=</tt> specifiers are provided, an error causes the FM
computation to terminate.
<P>
For succinctness, we use Fortran 90 <em> array sections
</em> in the
<tt> CHANNEL</tt> statement. An array section is like an array element
but with a range rather than an index provided for one or more of its
subscripts. A range is represented by a triplet with the following
general form.
<em> lower-bound
</em> : <em> upper-bound
</em> : <em> stride</em>
<P>
Bounds
can be omitted if the corresponding bounds of the array are required;
a stride of 1 is assumed if <em> stride
</em> is omitted.
See Figure <A HREF="node84.html#figasection" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node84.html#figasection">7.1</A> in Chapter <A HREF="node82.html#chaphpf" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node82.html#chaphpf">7</A> for examples
of array sections.
<P>
Array sections provided in the <tt> in=</tt> and <tt> out=</tt> components of
a <tt> CHANNEL</tt> statement must be <em> conformant</em>, that is, of the same
<A NAME=8844> </A>
size and shape. A channel is created for each pair of corresponding
<A NAME=8845> </A>
elements, as illustrated in Figure <A HREF="node70.html#figfmchan" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node70.html#figfmchan">6.1</A>.
<P>
<P><A NAME=10108> </A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img875.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img875.gif">
<BR><STRONG>Figure 6.1:</STRONG> <em> Array sections and the FM <tt> CHANNEL</tt> statement.
In (a), a single statement creates four channels and, for <em> i=1..4</em>
,
defines outport <tt> po(<em> i</em>
)</tt> and inport <tt> pi(<em> i</em>
)</tt> to
reference the same channel. Hence, for example, a message sent on
<tt> po(1)</tt> can be received on <tt> pi(1)</tt>. In (b), two statements
are used to define a ``staggered'' mapping of inports to outports, in
which outport <tt> qo(mod(<em> i</em>
,4)+1)</tt> and inport <tt> qi(<em> i</em>
)</tt>
reference the same channel. Therefore, a message sent on <tt> qo(1)</tt> can
be received on <tt> qi(4)</tt>.</em><A NAME=figfmchan> </A><BR>
<P><H2><A NAME=SECTION03332000000000000000>6.3.2 Sending Messages</A></H2>
<P>
<A NAME=secfmsend> </A>
A process sends a message by applying the <tt> SEND</tt> statement to an
<A NAME=8863> </A>
outport. Doing this adds the message to the message queue associated
with the outport, with the outport declaration specifying the message
format. For example, in the following code fragment the <tt> SEND</tt>
statement sends a message consisting of the integer <tt> i</tt> followed
by the first ten elements of the real array <tt> a</tt>.
<P>
<PRE> OUTPORT (integer, real x(10)) po
...
SEND(po) i, a
</PRE>
<P>
A process sends a sequence of messages by repeated calls to <tt>
<A NAME=8868> </A>
SEND</tt>; it can also call <tt> ENDCHANNEL</tt> to send an end-of-channel
<A NAME=8870> </A>
(EOC) message. This usage is illustrated in
Program <A HREF="node68.html#progfmbuild" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node68.html#progfmbuild">6.1</A>, where the <tt> foundry</tt> process uses the
<tt> SEND</tt> and <tt> ENDCHANNEL</tt> statements to send a total of 100
integer messages. <tt> ENDCHANNEL</tt> also sets the value of the outport
variable to be <tt> NULL</tt>, thereby preventing further messages from
being sent on that port.
<P>
Like Fortran's <tt> write</tt> and <tt> endfile</tt> statements, <tt> SEND</tt>
and <tt> ENDCHANNEL</tt> are nonblocking (asynchronous); that is, they complete
immediately. Variables named in a <tt> SEND</tt> statement can be
modified in subsequent statements, without affecting the send
operation.
<P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -