📄 node72.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.5 Asynchronous Communication</TITLE>
</HEAD>
<BODY>
<meta name="description" value="6.5 Asynchronous 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=tex2html2811 HREF="node71.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node71.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=tex2html2819 HREF="node73.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node73.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=tex2html2817 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=tex2html2821 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=tex2html2822 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=tex2html2820 HREF="node73.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node73.html">6.6 Determinism</A>
<B>Up:</B> <A NAME=tex2html2818 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=tex2html2812 HREF="node71.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node71.html">6.4 Unstructured Communication</A>
<BR><HR><P>
<H1><A NAME=SECTION03350000000000000000>6.5 Asynchronous Communication</A></H1>
<P>
<A NAME=secfmprobe> </A>
<P>
<A NAME=9241> </A>
Recall that the need for asynchronous communication can arise when the
<A NAME=9242> </A>
tasks involved in a computation must access elements of a shared data
<A NAME=9243> </A>
structure in an unstructured manner (Section <A HREF="node17.html#seccommas" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node17.html#seccommas">2.3.4</A>). One
implementation approach is to encapsulate the data structure in
a set of specialized <em> data tasks
</em> to which read and write
requests can be directed. This approach is easily implemented using
FM constructs: for example, the process structure illustrated in
Figure <A HREF="node71.html#figfmmany" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node71.html#figfmmany">6.4</A> could be used to connect four computation
tasks with three data tasks.
<P>
An alternative implementation approach is to distribute the
<A NAME=9247> </A>
shared data structure among the computation tasks. Individual
computation tasks must then <em> poll
</em> periodically for pending
read and
<A NAME=9249> </A>
write requests. This approach is supported in FM by the <tt> PROBE</tt>
<A NAME=9251> </A>
statement, which allows a process to determine whether messages are
pending on the channel or merger associated with an inport. This is
a potentially nondeterministic operation, since the result returned by a
<tt> PROBE</tt> statement can vary depending on the time at which it is
executed. A <tt> PROBE</tt> statement has the general form
<P>
<tt> PROBE(<em> inport</em>, empty=<em> logical
</em>)</tt>
<P>
and sets the logical variable named by the <tt> empty</tt> specifier to
true if the channel is empty (meaning a <tt> RECEIVE</tt> on the inport
would block) and to false otherwise.
<P>
Optional <tt> iostat=</tt> and <tt> err=</tt> specifiers can be included in
the control list; these are as in the Fortran <tt> inquire</tt> statement.
Hence, applying a <tt> PROBE</tt> statement to an undefined port causes an
integer variable named in an <tt> iostat</tt> specifier to be set to a
nonzero value and causes execution to branch to a label provided in an
<tt> err=</tt> specifier.
<P>
Knowledge about send operations is presumed to take a nonzero but
finite time to become known to a process probing an inport. Hence, a
probe of an inport that references a nonempty channel may signal true
if a value was only recently communicated. However, if applied
repeatedly without intervening receives, <tt> PROBE</tt> will eventually
signal false and will then continue to do so until values are
received.
<P>
The <tt> PROBE</tt> statement is useful whenever a process needs to
interrupt local computation to handle communications that arrive at
some unpredictable rate. For example, the following code might be
used in an implementation of the branch-and-bound search algorithm of
Section <A HREF="node21.html#secfloor" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node21.html#secfloor">2.7</A>.
<P>
<PRE><TT>
<tt> inport (<b>T</b>) requests</tt> ! <b>T</b> an arbitrary type
<P>
<tt> logical eflag</tt>
<P>
<tt> do while (.true.)</tt> ! Repeat:
<P>
<tt> call advance_local_search</tt> ! Compute
<P>
<tt> PROBE(requests,empty=eflag)</tt> ! Poll for requests
<P>
<tt> if(.not. eflag) call respond_to_requests</tt>
<P>
<tt> enddo</tt>
<P>
</TT></PRE>
<P>
This code fragment alternates between advancing a local search and
responding to requests for search problems from other processes.
<P>
<P><A NAME=progfmprobe2> </A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img893.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img893.gif"><P>
<P>
<A NAME=9301> </A>
<P>
The <tt> PROBE</tt> statement can also be used to receive data that
arrive in a nondeterministic fashion from several sources. For
example, Program <A HREF="node72.html#progfmprobe2" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node72.html#progfmprobe2">6.7</A> handles messages of types
<em> T1</em>
and <em> T2</em>
received on ports <tt> data1</tt> and <tt> data2</tt>,
respectively. A disadvantage of this program is that if no messages
are pending, it consumes resources by repeatedly probing the two
channels. This busy waiting strategy is acceptable if no other
computation can be performed on the processor on which this process is
executing. In general, however, it is preferable to use a
<A NAME=9308> </A>
different technique. If <em> T1=T2</em>
, we can introduce a merger
<A NAME=9310> </A>
to combine the two message streams, as follows. The <tt> handlemsgs2</tt>
process then performs receive operations on its single inport,
blocking until data are available.
<P>
<PRE> MERGER(in=datai, out=data1o, out=data2o)
PROCESSES
PROCESSCALL source1(data1o)
PROCESSCALL source2(data2o)
PROCESSCALL handlemsgs2(datai)
ENDPROCESSES
</PRE>
<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=tex2html2811 HREF="node71.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node71.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=tex2html2819 HREF="node73.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node73.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=tex2html2817 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=tex2html2821 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=tex2html2822 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=tex2html2820 HREF="node73.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node73.html">6.6 Determinism</A>
<B>Up:</B> <A NAME=tex2html2818 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=tex2html2812 HREF="node71.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node71.html">6.4 Unstructured Communication</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 + -