📄 node69.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.2 Concurrency</TITLE>
</HEAD>
<BODY>
<meta name="description" value="6.2 Concurrency">
<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=tex2html2775 HREF="node68.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node68.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=tex2html2783 HREF="node70.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node70.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=tex2html2781 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=tex2html2785 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=tex2html2786 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=tex2html2784 HREF="node70.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node70.html">6.3 Communication</A>
<B>Up:</B> <A NAME=tex2html2782 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=tex2html2776 HREF="node68.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node68.html">6.1 FM Introduction</A>
<BR><HR><P>
<H1><A NAME=SECTION03320000000000000000>6.2 Concurrency</A></H1>
<P>
<A NAME=secfmconc> </A>
<P>
We next give a more complete description of FM. The presentation
<A NAME=8731> </A>
is loosely structured according to the design methodology given in
<A NAME=8732> </A>
Chapter <A HREF="node14.html#chap2" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node14.html#chap2">2</A>. First, we describe how FM programs define and
create processes. Then, we explain how to specify various
communication structures. Finally, we describe FM's mapping
constructs. Along the way, we also address the issues of modularity
and determinism.
<P>
<H2><A NAME=SECTION03321000000000000000>6.2.1 Defining Processes</A></H2>
<P>
<A NAME=secfmport> </A>
<P>
<A NAME=8736> </A>
The first step in the development of an FM program is typically to
define the tasks from which a computation will be constructed. As
noted in Example <A HREF="node68.html#exfmbridge" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node68.html#exfmbridge">6.1</A>, a task is implemented in FM as a
process. A process definition has the same syntax as a subroutine
<A NAME=8738> </A>
except that the keyword <tt> PROCESS</tt> is used in place of <tt>
subroutine</tt>, and <tt> common</tt> data are labeled <tt> PROCESS COMMON</tt> to
<A NAME=8743> </A>
emphasize that they are common only to the process and any subroutines
that it calls. Processes cannot share common data.
<P>
<A NAME=8744> </A>
A process definition also defines the process's interface to its
environment. A process's dummy arguments (formal parameters) are a
set of typed port variables. (For convenience, conventional
argument passing is also permitted between a process and its parent.
This feature 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>.) A port variable
declaration has the general form
<P>
<em> port_type</em> ( <em> data_type_list</em> ) <em> name_list</em>
<P>
<A NAME=8751> </A>
The <em> port_type
</em> is <tt> OUTPORT</tt> or <tt> INPORT</tt> and
<A NAME=8755> </A>
specifies whether the port is to be used to send or receive data,
respectively. The <em> data_type_list
</em> is a comma-separated
list of type declarations and specifies the format of the messages
that will be sent on the port, much as a subroutine's dummy argument
declarations define the arguments that will be passed to the
subroutine.
<P>
In Program <A HREF="node68.html#progfmbuild" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node68.html#progfmbuild">6.1</A>, both <tt> pi</tt> and <tt> po</tt> are used to
communicate messages comprising single integers. The following are
examples of more complex message formats. In the second and third
declaration, the names <tt> m</tt> and <tt> x</tt> have scope local to the
port declaration. Notice how in the third declaration, the size of
the array <tt> x</tt> is specified in the message.
<P>
<PRE><TT>
<tt> INPORT (integer, real) p1</tt> ! One integer, one real
<P>
<tt> INPORT (real x(128)) p2</tt> ! Array of <tt> 128</tt> reals
<P>
<tt> INPORT (integer m, real x(m)) p3</tt> ! One integer (<tt> m</tt>); <tt> m</tt> reals
<P>
</TT></PRE>
<P>
The value of a port variable is initially a distinguished value <tt>
<A NAME=8771> </A>
NULL</tt> and can be defined to be a reference to a channel by means of
the <tt> CHANNEL</tt>, <tt> RECEIVE</tt>, <tt> MERGER</tt>, or <tt> MOVEPORT</tt>
statements, to be defined in the following sections.
<P>
<H2><A NAME=SECTION03322000000000000000>6.2.2 Creating Processes</A></H2>
<P>
<A NAME=secfmproc> </A>
<P>
<A NAME=8778> </A>
Having defined one or more processes, we next construct a concurrent
computation by creating instances of these processes. An FM program
executes initially as a single process. This process can both execute
sequential Fortran code and use process block and process do-loop
constructs to create additional processes.
<A NAME=8779> </A>
A process block has the general form
<P>
<PRE> PROCESSES
statement_1
...
statement_n
ENDPROCESSES
</PRE>
<P>
where <IMG BORDER=0 ALIGN=MIDDLE ALT="" SRC="img874.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img874.gif"> and the statements are process calls, process
do-loops, and/or at most one subroutine call. A process call has the
<A NAME=8781> </A>
same syntax as a subroutine call except that the keyword <tt>
<A NAME=8782> </A>
PROCESSCALL</tt> is used in place of the keyword <tt> call</tt>.
<P>
Statements in a process block execute <em> concurrently</em>. For
example, the following parallel block creates three concurrent
processes: two <tt> worker</tt>s and a single <tt> process_master</tt>.
<P>
<PRE> PROCESSES
PROCESSCALL worker(pi1)
PROCESSCALL worker(pi2)
PROCESSCALL process_master(po1,po2)
ENDPROCESSES
</PRE>
<P>
A process block terminates when all constituent statements
terminate; execution then proceeds to the next executable statement.
Thus, the parent process in this example proceeds to the statement
after the parallel block only when both the the master and the workers
have terminated execution.
<P>
A subroutine call in a parallel block allows the parent process to
execute concurrently with the newly created processes. For example,
the following variant of the preceding parallel block causes the
current process to execute the subroutine <tt> subroutine_master</tt>
concurrently with the two <tt> worker</tt> processes. Only two new
processes are created, rather than three, and the subroutine can share
common data with the calling process.
<P>
<PRE> PROCESSES
PROCESSCALL worker(pi1)
PROCESSCALL worker(pi2)
call subroutine_master(po1,po2)
ENDPROCESSES
</PRE>
<P>
A <em> process do-loop
</em> creates multiple instances of the same
<A NAME=8792> </A>
process. It is identical in form to the do-loop except that the
<A NAME=8793> </A>
keyword <tt> PROCESSDO</tt> is used in place of the keyword <tt> do</tt> and
the body can include only a process do-loop or a process call. For
example, the following code creates ten instances of <tt> myprocess</tt>.
<P>
<PRE> PROCESSDO i = 1,10
PROCESSCALL myprocess
ENDPROCESSDO
</PRE>
<P>
Process do-loops can be nested inside both process do-loops and
process blocks. Hence, the following code creates ten <tt> worker</tt>
processes and one <tt> master</tt>.
<P>
<PRE> PROCESSES
PROCESSCALL master
PROCESSDO i = 1,10
PROCESSCALL worker
ENDPROCESSDO
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=tex2html2775 HREF="node68.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node68.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=tex2html2783 HREF="node70.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node70.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=tex2html2781 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=tex2html2785 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=tex2html2786 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=tex2html2784 HREF="node70.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node70.html">6.3 Communication</A>
<B>Up:</B> <A NAME=tex2html2782 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=tex2html2776 HREF="node68.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node68.html">6.1 FM Introduction</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 + -