DPOS Programming Manual
John D. Evans
Departm ent of Computer Science
University of Utah
Salt Lake City, Utah
1
Introduction
T h i s m a n u a l d e s c rib e s t h e b a s ic c o n c e p t s o f th e D P O S M e t a l a n g u a g e a n d t h e p r o g r a m m i n g l a n g u a g e D P O S S c h e m e .
2
D PO S Concepts
D P O S is a m e t a l a n g u a g e for defin in g pa r a lle l p r o g r a m n e t w o r k s b a s e d on t h e c o m m o n r e q u ir e m e n ts o f d i s t r i b u t e d p a r a lle l c o m p u t i n g t h a t is p o r t a b l e across l a n g u a g e s , m o d u l a r , a n d h ig h ly flexible. T h e s y s t e m uses t h e c o n c e p t o f s t r a t i f i c a t i o n t o s e p a r a t e p r o c e ss n e t w o r k c r e a t i o n a n d t h e c o n tro l o f p a r a lle l is m f ro m c o m p u t a t i o n a l w ork. I n d i v i d u a l p roce sses are defined w i t h i n th e p r o c e s s o b j e c t la y e r as t r a d i t i o n a l sin gle t h r e a d e d p r o g r a m s w i t h o u t p a r a lle l la n g u a g e c o n s t r u c t s . P r o c e s s n e t w o r k s an d c o m m u n i c a t i o n are d e fined g r a p h i c a l l y w i t h i n t h e s y s t e m la y e r a t a high level o f a b s t r a c t i o n as r ec u rsiv e g r a p h s . C o m m u n i c a t i o n is f a c i l i t a t e d in D P O S by e x t e n d i n g m e ssage - p a s s in g s e m a n t i c s in s e v eral w a y s t o i m p l e m e n t hig hly flexible m e s s a g e - p a s s i n g c o n s t r u c t s . D P O S p ro ce sses e x c h a n g e m e s s a g e s th r o u g h b i- d ir e c tio n a l c h a n n e l o b j e c t s u sin g g u a r d e d , buffe re d, s y n c h r o n o u s a n d a s y n c h r o n o u s c o m m u n i c a t i o n s e m a n t ic s . A D P O S p r o g r a m is defin ed as a n e t w o r k o f a c tiv e p r o c e s s e s ca lle d P r o c e s s O b j e c t s ( P O s ) a n d c o m m u n i c a t i o n lines called C h a n n e l s t h a t a r e g r o u p e d i n t o s u b n e t w o r k s c a lle d N e tw o r k M o d u le s ( N M s). In D P O S a c o m m u n i c a t i n g p r o c e s s n e t w o r k m o d e l is used.
2.1
P ro c e s s O b je c ts
P ro c e s s O b j e c t s ( P O ) a r e single t h r e a d e d p r o g r a m f u n c t i o n s w i t h ca llin g p a r a m e t e r s id e n tic a l to t r a d i tio n a l s e q u e n ti a l p r o g r a m fu n c ti o n s . M u lt ip le P r o cess O b j e c t s e x e c u t e c o n c u r r e n tly . T h e s e a c tiv e o b j e c t s e m p lo y m u c h o f t h e m o d u l a r i t y , e n c a p s u l a t i o no f f u n c t i o n , a n d e n c a p s u l a t i o n o f d a t a found in se q u e n t ia l o b j e c t - o r i e n t e d p r o g r a m m i n g .
P ro c e s s O b j e c t s c o m m u n i c a t e w ith ea ch o t h e r by s e n d in g a n d receiveing m e ssa g e s. D P O S m e ssage se m a n t i c s a re s i m ila r t o file I / O in s e q u e n ti a l p r o g r a m m in g . P ro c e s s O b j e c t s m a y b l o c k w h ile a t t e m p t i n g to send t o o r receive m e s s a g e s f r o m c h a n n e l s if t h e c h a n nel t r a n s a c t i o n c a n n o t b e c o m p l e t e d im m e d ia te ly . T h i s c a u se s t h e e x e c u t i o n t o s u s p e n d , b u t leaves th e r u n t i m e s ta c k i n t a c t . P r o g r e s s m a y r e s u m e at a la te r t i m e if t h e t r a n s a c t i o n c a n b e c o m p l e t e d . T h i s bloc k in g a c t i v i t y is t r a n s p a r e n t t o th e P r o c e s s O b j e c t p ro g r a m . T h e c o n n e c t io n lin k s ( C h a n n e l s ) b e t w e e n P ro c ess O b j e c t s a p p e a r as v a r ia b le s p a s se d in as ca lling p a r a m e t e r s s im ila r t o files o r s t r e a m s in t r a d i t i o n a l p ro g r a m m i n g . P ro c e s s O b j e c t s c o m m u n i c a t e w ith each o t h e r v ia c h a n n e l ac ce sso r f u n c t i o n s like s e n d or r e c e i v e . No a d d i t i o n a l s y n t a x or la n g u a g e e x te n s io n s a r e r e q u ir e d , sin c e s im p le fu n c ti o n call s y n t a x is used. T h e c o n tro l flow o f P r o c e s s O b j e c t s is i n t e r n a l . T h e p r o g re s s o f c o m p u t a t i o n , h o w e v e r, m a y b e controlled b y r e g u l a t i n g m e s s a g e traffic i n t o a n d out o f th e P ro cess O b j e c t c a u s in g th e P O t o b loc k w a i t i n g for c o m m u n i c a t i o n t o p r o c e e d . T h e s y n c h r o n i z a t i o n required for c o m m u n i c a t i o n is c o n t r o l le d by t h e c o m m u n i c a tio n c h a n n e l . B e c a u s e o f t h is a P O m a y follow a b o u n d e d se q u e n ti a l c o m p u t a t i o n or m a y be an u n b o u n d e d cyclical c o m p u t a t i o n (like an o p e r a t i n g sys t e m pro ce ss) t h a t is I / O d riv e n via its c o m m u n ic a ti o n c h a n n e ls .
T h e c r e a tio n o f P r o c e s s O b j e c t s is specified w ith in t h e p a r e n t N e tw o r k M o d u le . T h e t e r m i n a t i o n o f p r o cess o b j e c t s o c c u r s w h e n t h e e x e c u t i o n o f th e code s e g m e n t for t h e p r o c e s s o b j e c t t e r m i n a t e s . T h e s e q u e n ti a l n a t u r e o f P r o c e s s O b j e c t s allows t h e m to b e d e v e lo p e d a n d d e b u g g e d i n d iv i d u a ll y as s e p a r a t e p r o g r a m s b efo re in t e g r a t i o n i n t o a n etw o rk m o d u l e . S im p le t e r m i n a l i n p u t a n d o u t p u t is s u b s t i t u t e d for c h a n n e l c o m m u n i c a t i o n d u r i n g se q u e n tia l d e b u g g i n g . A lib r a r y o f c h a n n e l d e fin itio n s in the
b a s e l a n g u a g e h a s b e e n d e v e lo p e d for s e q u e n ti a l d e b u g g i n g (n o t disc u sse d h e r e ) . G l o b a l d a t a s t r u c t u r e s a re n o t defined w i t h i n th e D P O S m o d e l. T h e u se o f c h a n n e l o b j e c t s to i m p l e m e n t d a t a t h a t is s h a r e d b e t w e e n m a n y p ro c e sse s is d is c u s s e d b e lo w (see s u b s e c t i o n s 2.2 a n d 8.1).
2.2
C h a n n e ls
C o m m u n i c a t i o n a n d s y n c h r o n i z a t i o n b e t w e e n P r o cess O b j e c t s is a c c o m p l i s h e d b y m e s s a g e - p a s s in g . D P O S p r o c e s s e s e x c h a n g e m e s s a g e s t h r o u g h b i d i r e c tio n a l c h a n n e l o b je c ts . In D P O S a c h a n n e l is t r e a t e d a s a s e p a r a t e o b j e c t in t h e o b j e c t - o r i e n t e d sense a n d n o t j u s t as a c o m m u n i c a t i o n r e l a t i o n s h i p (as it is in m o s t c h a n n e l o r ie n t e d c o m m u n i c a t i o n s y s t e m s ) . T h i s allows th e s e m a n t i c s o f c h a n n e l s t o b e e x t e n d e d in se veral w ays. T h e s e m a n t i c s o f c h a n n e l c o m m u n i c a t i o n is an a t t r i b u t e o f t h e c h a n n e l . D P O S c h a n n e l s e n c a p s u l a t e b o t h f u n c t i o n a l s e m a n t i c s a n d in s o m e cases d a t a s to r a g e . T h i s e n c a p s u l a t i o n h a s se v eral a d v a n t a g e s : 1. C o m m u n i c a t i o n is in d ir e c t. A llo w in g c h a n n e ls t o b e accessed b y m u l t i p l e s e n d e r a n d receiv er p ro ce sses. T h e a r b i t r a t i o n for access is h a n d led w ith in t h e c h a n n e l o b j e c t . F o r e x a m p l e , t h e m e r g i n g a n d s p l i t t i n g s t r e a m s o f d a t a is t r i v ially i m p l e m e n t e d u sin g s h a r e d ch a n n e ls. M u l t i p le p r o c e s s access to c h a n n e l s allo ws c h a n n e l s to b e used to i m p l e m e n t s h a re d d a t a values. 2. I n d ire c t c o m m u n i c a t i o n also f a c i l i t a t e s d y n a m i c p r o c e s s c r e a t i o n . It a llow s n e w p ro ce sses t o be a d d e d t o a n e t w o r k t h a t c o m m u n i c a t e t h r o u g h e x i s tin g c h a n n e l s w i t h o u t n o tif y in g e x i s tin g p r o cesses. 3. It r e m o v e s t h e need for la n g u a g e c o n s t r u c t s to i m p l e m e n t c o m m u n i c a t i o n s e m a n t ic s . B e c a u s e o f th is , t h e P O d e f in i tio n s o f a D P O S p r o g r a m n e e d n o e x t e n s i o n s b e y o n d t r a d i t i o n a l s in gle t h r e a d e d p r o g r a m m i n g c o n s tr u c ts . 4. It allow s b i - d ir e c tio n a l c o m m u n i c a t i o n . 5. I t allo ws m u l t i p l e classes of ch a n n e ls. In D P O S t h e class o f a c h a n n e l specifies t h e s e m a n tic s o f c o m m u n i c a t i o n for t h a t p a r t i c u l a r c h a n nel. D P O S c h a n n e l class in c lu d e: s y n c h ro n iz e d g u a r d e d i n p u t , s y n c h r o n iz e d g u a r d e d o u t p u t , a s y n c h r o n o u s , buffe re d, a n d s y n c h r o n o u s .2.3
N e tw o rk M o d u le s
N e tw o r k M o d u l e s ( N M s ) are a b s t r a c t i o n s used for d efin in g s u b n e t w o r k s in D P O S p r o g r a m s . N e tw o r k
M o d u l e s a r e c o m p o s e d o f P r o c e s s O b j e c t s , C h a n n e l s a n d o t h e r n e s t e d N e tw o r k M o d u le s . N e tw o r k M o d u le classes are defin ed as g r a p h s t r u c t u r e s (see F i g u r e ]). N e t w o r k M o d u l e d e f in i tio n s h a v e lo cal e n v i r o n m e n t a n d h a v e f o rm a l p a r a m e t e r s t h a t c o r r e s p o n d t o d a t a v a lu e s a n d c h a n n e l i n s t a n c e s . I n v o k in g an N M re q u ir e s a c t u a l p a r a m e t e r a r g u m e n t s t o b e p r o v id e d . T h e a r g u m e n t s a r e t h e a c t u a l a c ce ss c h a n n e l s t h a t c o n n e c t t o t h e N M a s well as a n y r e q u ir e d values c o m p u t e d w i t h i n t h e sc o p e o f t h e in v o k in g e n v iro n m e n t . N e tw o r k M o d u le s m a y b e n e s t e d a n d re c u r sively o r m u t u a l l y r e c u rsiv e ly n e s t e d . In th e t r a d i t i o n a l o b j e c t - o r i e n t e d f r a m e w o r k , a N e tw o r k M odule d e fin itio n c o n s t i t u t e s a class d e fin itio n a n d m a y be i n s t a n c e d n u m e r o u s t i m e s in t h e d e fin itio n o f a pro cess n e t w o r k .
G lo b a l v a lu e s are not defin ed w i t h i n D P O S . T h e o n ly e x t e r i o r e n v i r o n m e n t visible fro m w ith in a N e t w o rk M o d u l e co n s ists o f t h e a c t u a l a r g u m e n t s passed in a t t h e i n s t a n t i a t i o n o f t h e N M . A N e tw o r k M odule th e n is c o m p l e t e l y e n c a p s u l a t e d by t h e a c tu a l a r g u m e n t s a n d p e r i p h e r a l c h a n n e l s a n d m a y he an a ly z ed as a u n i t . T h i s m o d u l a r i t y allo ws a N e tw o r k M odule t o b e d e v e lo p e d a n d d e b u g g e d as a u n it by i n s t a n t i a t i n g it a n d its p e r i p h e r a l c h a n n e l s a n d w ith o u t cre a t i n g t h e o u t l y i n g p r o g r a m n e t w o r k .
A N e tw o r k M o d u le i n s t a n c e m i g h t not b e i n s t a n t i a t e d w h e n th e p a r e n t N M is i n s t a n t i a t e d . T h e i n s t a n t i a t i o n o f t h e N M m a y b e de la y e d u n til a d e m a n d is m a d e for its c r e a t i o n . D e la y e d N e tw o r k M o d u le s are i n s t a n t i a t e d w h e n e v e r d a t a flow o c c u r s in one o f its p e r i p h e r a l c h a n n e l s . A l t e r n a t i v e l y t h e i n s t a n t i a t i o n m a y b e c o n d i t i o n a l in w h ic h case a c o n s tra in t c o n d i tio n is e v a l u a t e d w i t h i n t h e p a r e n t N M e n v i ro n m e n t to d e t e r m i n e w h e t h e r or not t h e i n s t a n c e is to be in s t a n t i a t e d . C o n s t r a i n t c o n d i t i o n s a n d in s t a n t i a t i o n d e la y s are sp ecified w i t h i n t h e p a r e n t N M definition. T h e s e p r o p e r t i e s allow p r o c e s s n e t w o r k s t o b e s p e c i fied in a m a n n e r s i m i l a r t o a b s t r a c t d a t a t y p e s such as tr e e s a n d g r a p h s in high-le vel l a n g u a g e s . For e x a m p le , a g e n e r ic b i n a r y t r e e N e tw o r k M o d u le m a y be d efined w hich is th e n u se d t o define a specific, irreg u l a r e x t e n d e d tr e e p r o c e s s n e t w o r k .
3
Example:
Producer and
Consumer
T h i s s e c ti o n d e s c r ib e s a s h o rt e x a m p l e D P O S p ro g r a m u sin g D P O S S c h e m e a n d D P O S p r o g r a m g r a p h s . D P O S S c h e m e is a c o n c u r r e n t S c h e m e d i alect a n d is d e s c rib e d in s e c ti o n 4. T h e e x a m p l e p r o g r a m p r e s e n ts the p r o d u c e r / c o n s u m e r p r o b l e m . A p r o d u c e r process<
p[ttiafrrtfyt 2) producar-contojter; child of <>„ ---- ,„ ---- ,---- n
---Ll l2 i-3 L4 | produeer:p i — E J - f * o on tver:c | U R2 R3 M u i A! 1 Hi 1 JM
Figure 1: producer-consumer Network Module
(define (producer-po CHAN cnt)
(do ((a 0 (+ a 1)))
((= a cnt))
(display (list 'produced a))
(newline)
(send CHAN a))
(display 'producer-quits))
(define (consumer-po CHAN cnt)
(let ((input # 0 )
(do ((a 0 (+ a 1)))
((= a cnt))
(set! input (receive CHAN))
(display
(list 'consumer 'receives a input))
(newline)))
(display ’
consumer-quits))
Figure 2: Process Object Code
load channel.scm
DEFS
load producer-consumer.dp
load producer.dp
load consumer.dp
BODIES
(producer-consumer 3)
ENDBODIES
Fig ure 3: Prod ucer-consum er Run File
(produced 0.000000)
(produced 1.000000)
(consumer receives 0.000000 0.000000)
(produced 2.000000)
(consumer receives 1.000000 1.000000)
producer-quits
(consumer receives 2.000000 2.000000)
consumer-quits
Figure 4: Program O utput
creates data objects and sends them to a c o n s u m e r process. The Network Module for this program is shown in Figure 1. T his Network Module contains three objects. T w o processes are created p r o d u c e r and c o n s u m e r . The producer PO is of class p r o d u c e r and has instance name p . The consumer PO is of class c o n s u m e r and has instance name c. A channel is also created (labeled A ). The p r o d u c e r - c o n s u m e r Network Module has a single parameter c n t which is passed to each o f the Process Objects. The source code for the individual processes is shown in Figure 2. The producer s e n d s to the channel and the consumer r e c e iv e s from the channel. A run file for the program is given in Figure 3 and the output generated is shown in Figure 4.
4
Basic DPOS Scheme Con
cepts
D PO S Scheme includes a subset of standard se quential Scheme features, and introduces several ad ditional features. D PO S Scheme is a concurrent Scheme dialect. It includes features for generating and executing parallel Schem e. The parallel features specify process creation, process management and m essage passing and synchronization constructs.
The language was designed to be programmed us ing the D PO S m etalanguage and graphical interface to generate parallel process networks. This section describes the basic concepts of D PO S Scheme. An overview and list of D PO S Scheme standard features is presented in section 10.
4.1
T op L evel P r o g ra m m in g
There is no top level read-eval-print loop in DPOS Scheme. In DPO S Scheme a single run file (see Figure 3) is evaluated which specifies all top level definitions. Definitions may be specified directly or by loading Process Object and Network Module files generated
by t h e D P O S g r a p h i c a l i n te r f a c e . A s e q u e n c e o f c o m m a n d fo rm s follows t h e d e f initions. T h e c o m m a n d f o rm s a r e e v a l u a t e d in t h e e n v i r o n m e n t c r e a t e d by t h e t o p level d e finitions. T h e c o m m a n d f o r m s sp e cify s t a n d a r d se q u e n ti a l S c h e m e c o m p u t a t i o n s a n d also t h e c r e a t i o n , m a n a g e m e n t a n d c o m m u n i c a t i o n s o f c o n c u r r e n t l y e x e c u t i n g S c h e m e p rocesses. D P O S S c h e m e allow s b o t h s h a r e d m e m o r y a n d d i s t r i b u t e d m e m o r y p a ra lle l p r o g r a m m i n g . In m a n y p r o g r a m s t h e d is t i n c t i o n b e t w e e n s h a r e d a n d d i s t r i b u t e d m e m o r y s e m a n t i c s d o e s n o t h a v e a n y effect on t h e D P O S p r o g r a m d efinition. D P O S S c h e m e m a y b e u s e d t o i m p l e m e n t D P O S N e tw o r k M o d u le a n d P r o c e s s O b j e c t d e finitions. D P O S N e tw o r k M o d u l e a n d P ro c e s s O b j e c t defini t i o n s a r e g e n e r a t e d b y t h e D P O S G r a p h i c a l I n te r f a c e as D P O S S c h e m e lo a d files. T h e c o n t e n t s o f N e tw o r k M o d u l e d e fin itio n files a r e n o t in t e n d e d t o b e m o d i fied b y p r o g r a m m e r s a n d a r e n o t disc u sse d here.
4.2
P ro c e s s O b je c t D e fin itio n s
T h e d e fin i tio n s o f D P O S P r o c e s s O b j e c t s a r e s p e c i fied b y p r o g r a m m e r s u s in g a t e x t e d i to r . P ro c e s s O b j e c t d e f in i tio n s a r e s e q u e n ti a l S c h e m e f u n c ti o n s (see F i g u r e 2). E a c h P ro c e s s O b j e c t h a s a c ce ss t o all t h e f u n c t i o n d e f in i tio n s in t h e t o p level e n v i r o n m e n t . T h e o n ly c o n t a c t b e t w e e n m u l t i p l e P r o c e s s O b j e c t s o r b e t w e e n P r o c e s s O b j e c t s a n d t h e o u t e r N e tw o r k M o d u le E n v i r o n m e n t is t h e a c t u a l a r g u m e n t list s u p p lie d to t h e f u n c t i o n at e v a l u a t i o n . T h e a r g u m e n t list c o n ta i n s c h a n n e l s a n d d a t a p a r a m e t e r v alu es. D P O S S c h e m e P r o c e s s O b j e c t s c o m p ly w ith t h e definition o f P r o c e s s O b j e c t s giv e in s u b s e c ti o n 2.1. T h e P r o cess O b j e c t d e f in itio n s m a y use a n y o f t h e f e a tu r e s listed in s u b s e c ti o n 10.2. In a d d i t i o n , P ro c e s s O b j e c t d e fin itio n s m a y use c o n c u r r e n t e x t e n s i o n s lis ted
in s u b s e c t i o n 10.3.
T h e P r o c e s s O b j e c t S o u rc e files a re r e a d by t h e D P O S G r a p h i c a l i n te r f a c e , m o d if ie d a n d o u t p u t as P ro c e s s O b j e c t loa d files. P r o c e s s O b j e c t loa d files h a v e t h e e x t e n s i o n . d p . I n s t a n c e s o f P ro c e s s O b j e c t s a r e specified w i t h i n N e tw o r k M o d u le definitions. T h e a r g u m e n t s su p p li e d to P O i n s t a n c e s are also specified w ith t h e p a r e n t N e tw o r k M o d u le d efinition.
4.3
N e tw o rk M o d u le D e fin itio n s
T h e d e f in i tio n s o f D P O S N e tw o r k M o d u le s a r e s p e c ified by p r o g r a m m e r s u sin g th e D P O S G r a p h i c a l I n te rf a c e (see F i g u r e 1). T h e so u rc e code for N e tw o r k M o d u l e d e f in itio n s is g e n e r a t e d by t h e g r a p h i c a l in t e r f a c e in N e tw o r k M o d u le load files. N e tw o r k M o d ule load files h a v e t h e e x t e n s i o n . d p . N e tw o r k M o d ule lo a d files a re n o t i n t e n d e d t o b e m o d ifie d by pro g r a m m e r s .
D P O S S c h e m e N e tw o r k M o d u le s c o m p ly w i t h th e d e fin itio n o f N e tw o r k M o d u le s give n in su b se ctio n 2.3. N e tw o r k M o d u l e d e fin itio n s h a v e i n t e r n a l P O , NM a n d c h a n n e l i n s t a n c e s specified b y t h e p r o g r a m m e r . All i n s t a n c e s a r e n a m e d . N a m e s a r e specified by th e p r o g r a m m e r . N e tw o r k M o d u l e d e f in itio n s h a v e p a r a m e t e r s specified b y t h e p r o g r a m m e r . P a r a m e t e r s for t h e n e s t e d i n s t a n c e s a r e specifie d b y t h e p r o g r a m m e r a n d m a y cont ain t h e r e s u l t s o f ex p r e s s io n s using lo c al v a l u e s a n d c h a n n e l in s t a n c e s .
4.4
C h a n n e l D e fin itio n s
C h a n n e l in s t a n c e s a r e sp ecified b y p r o g r a m m e r s u s in g t h e D P O S G r a p h i c a l I n t e r f a c e as p a r t o f a n e t w ork m o d u l e d e f in itio n . T h r e e c h a n n e l classes are p r e s e n tly s u p p o r t e d by D P O S S c h e m e : a . c l i a n n e l , b . c h a n n e l , a n d i . c h a n n e l . D P O S S c h e m e ch a n n els c o m p ly w i t h t h e d e fin itio n o f c h a n n e l s giv en in s u b s e c ti o n 2.2. C h a n n e l c o m m u n i c a t i o n is specified in t h e P r o c e s s O b j e c t d e fin itio n files u sin g th e s y n ta x a n d s e m a n t i c s lis te d below. A . c h a n n e l class ch a n n els i m p l e m e n t a s y n c h r o n o u s c o m m u n i c a t i o n . A single i t e m m a y b e buffe re d in t h e c h a n n e l . T h e o p e r a t i o n s on a . c h a n n e l s are: 1. ( s e n d c h a n d a t a ) : T h e s e n d o p e r a t i o n inse rts d a t a i n t o c h a n if c h a n is e m p ty . If c h a n is n o t e m p t y th e n t h e P O b loc ks u n til it b ec o m e s e m p ty . 2. ( r e c e i v e c h a n ) : R e t u r n s t h e c o n t e n t s of chan a n d c le a rs t h e c h a n n e l . I f c h a n is e m p t y th e n t h e P O b lo c k s u n t i l it b e c o m e s full. 3. ( c h a n - r e a d c h a n ) : R e t u r n s t h e c o n t e n t s of chan b u t does not c le a r t h e c h a n n e l . If c h a n is e m p ty t h e n t h e P O b loc ks u n til it b e c o m e s full. S u b s e c tio n S .l d e m o n s t r a t e s all a . c l i a n n e l o p e r a tions.
B _ c h a n n c l class c h a n n e l s im p lem e n t a s y n c h r o n o u s buffered c o m m u n i c a t i o n . A buffer s i z e lim it is sp ecified w h e n t h e c h a n n e l is specified in an N M defin itio n . T h e o p e r a t i o n s on b . c l i a n n e l s are:
1. ( s e n d c h a n d a t a ) : T h e s e n d o p e r a t i o n inse rts d a t a i n t o c h a n if c h a n c o n t a i n s less t h a n s i z e e l e m e n ts . I f c h a n is full t h e n t h e P O blo cks until i t c o n t a i n s less t h a n s i z e e le m e n ts .
2. ( r e c e i v e c h a n ) : R e t u r n s t h e first i t e m in chan ( F I F O o r d e r ) a n d r e m o v e s it from t h e ch a n n el.
If chan is em pty then the PO blocks until it be com es non-empty.
Subsections 8.1 and 8.3 dem onstrate b - c h a n n e l op erations.
I - c h a n n e l class channels im plem ent guarded in put com m unication. Com m unication is synchronized and no m essages are buffered. A s iz e value is spec ified when the channel instance is defined within an NM definition. S iz e specifies the number of message typ es recognized by the channel. Message types are sim ple integers. If s iz e is 3 then the channel will rec ognize m essage types 0, 1 and 2. The operations on i_ c h a n n e ls s are:
1. (r e a d -g channel type-list): The tvpe-list is a list o f integers. The integers m ust be between 0 and s iz e . T hese integers specify the types o f mes sages that are acceptable. Returns a m essage of a specified type from the channel. The return value is a list ( t y p e d a t a ) , where type is one of the types in type-list.
2. (w r it e - g channel type data): Sends a message o f “typ e” to “channel” which contains “data” . If no writer of an acceptable type is blocked trying to w r it e - g to the channel then the reader blocks until one com es along. If a reader is not blocked trying to r e a d -g the m essage type of a writer then writer blocks. Readers are serviced by the channel on a first com e first served basis. This means that if readerl is blocked trying to read a type 1 m essage then no other readers may be serviced until a type 1 writer com es along. Subsections 5.2 and 8.2 dem onstrate i_ c h a n n e l usage.
5
Example Programs
This section presents exam ple programs using DPOS Network M odules and DPO S Scheme Process O bject definitions. Run files for the D PO S Scheme sim ula tor are also included. T he programs are not meant to display highly efficient parallel programs, but only to dem onstrate basic D PO S parallel programming con cepts.
5.1
M u ltip le
P r o d u c e r s
a n d
C o n
s u m e rs
T his exam ple is a sim ple extension of the pro ducer/consum er problem to handle m ultiple produc ers and consumers. It dem onstrates the use of nested Network Module definitions. It also dem onstrates the
Figure 5: P c-net Network Module
Figure 6: Producer-2 Network Module
(produced 0.000000)
(produced 0.000000)
(produced 1.000000)
(consumer receives 0.000000 0.000000)
producer-quits
(consumer receives 0.000000 1.000000)
(produced 1.000000)
(consumer receives 1.000000 0.000000)
consumer-quits
producer-quits
(consumer receives 1.000000 1.000000)
consumer-quits
Figure 7: Program Output
use o f m u l t i p l e s e n d e r s a n d receivers ac ce ssing a c h a n nel. T h e N e tw o r k M o d u l e s for t h is p r o g r a m a r e sh o w n in F ig u r e s 5 a n d 6. T h e p r o d u c e r class P O s in t h e p r o d u c e r - 2 N M ( F i g u r e 6) a r e c o n n e c t e d to t h e o u t p u t p o r t R 2 . T h e p o r t R 2 c o r r e s p o n d s t o t h e p o r t s h o w n on p r o d u c e r - 2 : p in F i g u re 5. W h e n t h e p r o g r a m is r u n t h e p r o d u c e r P O s h a v e a c ce ss v i a t h i s p o r t t o t h e c h a n n e l in t h e o u t l y i n g p c - n e t N M . T h e v a lu e o f “c n t ” in p c - n e t is p a s s e d as a n a r g u m e n t to t h e n e s t e d n e t w o r k m o d u l e s a n d in t u r n t o t h e n e s te d P r o c e s s O b j e c t s . T h e c o n s u m e r - 2 N e tw o r k M o d u le is s i m ila r t o t h e p r o d u c e r - 2 N e tw o r k M o d u le sh o w n in F i g u r e 6. W h e n t h e p r o g r a m is r u n u s in g t h e c o m m a n d ( p c - n e t 2 ) , a p c - n e t N M is c r e a t e d . T h i s c a u se s th e c r e a t i o n o f t h e c h a n n e l a n d t h e n e s t e d N M s w h ich in t u r n c r e a t e t h e n e s t e d P O s . All P O s access t h e c h a n nel. T h e s y n c h r o n i z a t i o n o f accesses is c o n tro lle d by t h e c h a n n e l a n d allow s only a sin gle p ro c e s s at a ti m e t o o p e r a t e on th e c h a n n e l . T h i s r e s u lts in s e r ia liz a tio n if s i m u l t a n e o u s acce sse s o c c u r . I t also r e s u lt s in a n o n d e t e r m i n i s t i c m e r g i n g o f t h e o u t p u t s t r e a m s o f th e p r o d u c e r s i n t o t h e c h a n n e l , a n d th e n o n d e t e r m i n i s t i c b r a n c h i n g o f in p u t s t r e a m s i n t o t h e c o n s u m e r s . T h e p r o g r a m o u t p u t is sh o w n in F i g u r e 7. T h e s e q u e n c e o f o u t p u t s t a t e m e n t s is not d e t e r m i n is tic. R u n n i n g th e p r o g r a m several ti m e s c o u ld re sult in slight v a r i a t i o n s in t h e o u t p u t s e q u e n c e . T h e c h a n n e l in t h i s a n d th e p r e v io u s e x a m p l e s is a n a s y n c h r o n o u s c h a n n e l . T h i s c h a n n e l class a llow s a s e n d e r t o d e p o s it a m e s s a g e a n d c o n t in u e w i t h o u t w a i t i n g for a r ec eiv e r proce ss. T h i s k in d o f m e ssa g e p a s s in g a llow s a h ig h e r d e g r e e o f p a r a lle l is m t h a n s tr ic tly s y n c h r o n i z e d m e s s a g e p a s sin g .
5.2
B a n k A c c o u n t P r o g ra m
T h i s e x a m p l e p r o g r a m p r e s e n t s a b a n k ac c o u n t m a n a g e m e n t p r o b l e m . In t h is p r o b l e m a b a n k ac c o u n t p r o c e s s receives r e q u e s t s for d e p o s its a n d w i th d r a w ls . D e p o s i t s a r e a lw a y s po ssib le a n d are se rvic ed in F I F O o rd e r. W i t h d r a w l s are also se rv ic e d in F I F O o rd e r, h o w ev e r, if in sufficient f u n d s are a v a ila b le a w ith d r a w ] will be d e l a y e d u n til f u n d s b e c o m e ava ila ble .
T h e N e tw o r k M o d u le for t h i s p r o g r a m is sh o w n in F i g u r e 8 a n d t h e s o u rc e code for t h e p r o c e ss o b j e c t s is sh o w n in F i g u r e 9. In F i g u re 8 th e p a r a m e t e r s “d - c n t ” a n d “w - c n t ” in d i c a t e h ow m a n y d e p o s its a n d w i t h d r a w l s ea c h p r o c e s s is t o a t t e m p t . F i g u re 10 sh o w s p r o g r a m o u t p u t for th e i n v o c a t i o n o f ( b a n k - n e t 2 1 ) . T h e s o lu t io n i l l u s t r a t e s t h e use o f a g u a r d e d in p u t c h a n n e l . T h e s o lu t io n b e c o m e s m u c h m o r e com -(1> bar*-net: child of () p*r Meter*: d-cnt, went Ti 1 T2 1 T3 1 14 Li 12 L3 L4 deposltcr:dl 1 R1 depositor^ ■ ^ T D --- ■ ba*:b ^ R2 R3 R4 wlthd'«wer:wl^ »ltiTdreeer:w21 Bl 1 B2 1 Si 1 K4 F i g u r e 8: B a n k - n e t N e tw o r k M o d u le
plex t o i m p l e m e n t w h e n o t h e r c h a n n e l classes are u se d . T h e c h a n n e l r e c o g n iz e s t h r e e m e ssa g e ty pes: d e p o s i t , w - r e q u r s t , a n d w - o k . D e p o s i t o r and w i t h d r a w e r p roce sses a lw a y s w r i t e - g to t h e c h a n nel a n d t h e b a n k a lw a y s r e a d - g s t o th e c h a n n e l. A d e p o s i t o r p r o c e s s use s d e p o s i t m e s s a g e t y p e . A w i t h d r a w e r p r o c e s s uses w - r e q u e s t m e s s a g e to e n t e r a r e q u e s t , t h e n uses w - o k m e s s a g e to a c k n o w led g e t h e t r a n s a c t i o n . T h e b a n k p r o c e s s m a n a g e s a lis t of allo w ab le m e s sa ge t y p e s t h a t it will a c c e p t . I n itia lly t h e b a n k will a c c e p t w - r e q u e s t a n d d e p o s i t . If a w - r e q u e s t is receiv ed it s e ts t h e list t o i n c lu d e only d e p o s i t . W h e n sufficient f u n d s to s e rv ic e a w ith d r a w ] are avail ab le, w - o k is a d d e d t o t h e g u a r d l i s t . W h e n t h e w - o k is rec eiv e d fro m t h e w i t h d r a w e r th e list is reset to its o rigina l f o rm .
N o tic e t h a t re c e ip t o f f u n d s by t h e w i t h d r a w e r is signified by th e successful r e c e i p t o f a m e ssag e by th e b a n k . T h i s k in d o f t r a n s a c t i o n is c o m m o n in g u a r d e d m e s s a g e s e n d in g , b u t t a k e s s o m e g e t t i n g used to.
5.3
F a c to ria l P r o g ra m
T h i s e x a m p l e p r o g r a m c o m p u t e s f a c t o r i a l o f N (see F ig u r e s 11, 12, 13, a n d 14). It p r e s e n ts n o new D P O S c o n c e p t s , b u t d e m o n s t r a t e s a ty p ic a l p a r a l lel p r o g r a m m i n g c o n c e p t . I t uses a c o n t ro l le r p r o cess ( f c o n t r o l : f c ) a n d a g r o u p o f s e r v a n t processes (class f - u n i t ) t h a t c a r r y o u t w o rk t a s k s defin ed by t h e c o n t ro l le r . A s e r v a n t p r o c e s s e s receiv es lim its for a s u b s e t o f t h e f a c t o r i a l c o m p u t a t i o n f ro m ch a n n el T O P - C H . W h e n ea ch h a s c o m p l e t e d its s u b s e t, it re ceives t h e t o t a l fro m t h e n e x t left s e rv a n t from c h a n nel L E F T - C H , m u lt ip lie s in its s u b t o t a l a n d se nds t h e r e s u l t to R I G H T - C H . T h e c o n t ro l le r receives t h e t o t a l f ro m t h e t h i r d s e rv a n t “F 3 ' \(define (bank-po BANK-CH)
(let
((balance 0)
(pending #f)
(guards (list w-request deposit)))
(display (list 'start-balance balance))
(do ((request (read-g BANK-CH guards)
(read-g BANK-CH guards)))
(#f)
(cond
((= (car request) w-ok)
(set! guards (list w-request deposit)))
((= (car request) w-request)
(set! pending (cadr request))
(set! guards (list deposit)))
(#t (set! balance (+ balance
(cadr request)))
(display (list 'balance balance))))
(if (and pending (<= pending balance))
(begin
(set! guards (list w-ok deposit))
(set! balance (- balance pending))
(display (list 'balance balance))
(set! pending # f ))))))
(define (withdrawer-po BANK-CH cnt)
(do ((a 0 (+ a 1)))
((= a cnt ))
(let ((amount (random)))
(write-g BANK-CH w-request amount)
(write-g BANK-CH w-ok)
(display (list 'withdrew a amount)))))
(define (depositor-po BANK-CH cnt)
(do ((a 0 (+ a 1)))
((= a cnt))
(let ((amount (random)))
(write-g BANK-CH deposit amount)
(display (list 'deposit a amount)))))
Figure 9: Process O b je ct definitions
(start-balance 0.000000)
(balance 11.900600)
(deposit 0.000000 11.900600)
(balance 15.767471)
(deposit 1.000000 3.866871)
(balance 53.135357)
(balance 35.591751)
(deposit 0.000000 37.367886)
(withdrew 0.000000 17.543608) •
(balance 27.355316)
(balance 29.170748)
(deposit 1.000000 1.815432)
(withdrew 0.000000 8.236435)
F i g u r e 10: P r o g r a m O u t p u t F i g u r e 11: F a c t o r i a l N e tw o r k M o d u le(define (fcontrol n
0U T 0 DUT1DUT2 0UT3 INI)
(let ((size (truncate (/ n 3))))
(send
0U T1(list
0size))
(send 0UT2 (list size (* 2 size)))
(send 0UT3 (list (* size 2) (+ n 1))))
(send
0U T 0 1 )(display
(list 'factorial-of n (receive INI))))
(define (f-unit-po LEFT TOP RIGHT)
(let ((limits (receive TOP))
(result 1))
(do ((a (car limits) (+ a 1)))
((= a (cadr limits)))
(set! result (* result a)))
(send RIGHT (* (receive LEFT) result))))
load channel_debug.scm
DEFS
load factorial.dp
load fcontrol.dp
load f-unit.dp
(define (factorl n)
(if (> n 1 )
(* n (factorl (- n 1)))
1))
BODIES
(init-debug ’
factorial)
(factorial 20)
(display (list 'factorl (factorl 20)))
ENDBODIES
F i g u r e 13: F a c t o r i a l R u n File(factorl
2432902023163674500.000000)
(factorial-of
20.000000 2432902023163674500.000000)
F i g u r e 14: P r o g r a m O u t p u t6
DPOS Graphical Interface
T h i s s e c ti o n p r e s e n t s a n o v e rv ie w o f t h e D P O S G r a p h i c a l I n t e r f a c e a n d its use for g e n e r a t i n g sim p le D P O S p r o g r a m s . T h i s se c tio n c ove rs in d e t a il th e f e a t u r e s n e c e s s a r y t o g e n e r a t e t h e e x a m p l e p r o g r a m s a l r e a d y p r e s e n t e d . T h e D P O S g r a p h i c a l i n te r f a c e is used t o g e n e r a t e N e tw o r k M o d u le d e finitions, t o d e fine P r o c e s s O b j e c t in te r fa c e s , t o g e n e r a t e load files for P r o c e s s O b j e c t s a n d N e tw o r k M o d u le s in t a r g e t la n g u a g e s , a n d t o d e b u g p r o g r a m s . T h e discussion in t h is s e c ti o n is co nfin ed t o d e fin itio n o f N M s, defin i t io n o f P O s , a n d t h e g e n e r a t i o n o f load files in D P O S S c h e m e .
6.1
S ta r tin g th e G ra p h ic a l In te rfa c e
T h e in te r f a c e uses t h e X - l l W i n d o w s y s t e m . X - l l m u s t b e r u n n i n g t o r u n t h e D P O S G r a p h i c a l I n t e r face. A b la c k a n d w h i t e versio n o f t h e in te rfa c e can b e r u n b y t y p in g ;dpos -bw
T h e i n te r f a c e also uses colors:
dpos -bO lightgray -fO black
Specifies a g ra y b a c k g r o u n d a n d bla ck fo r e g r o u n d .
| i « & : 1
il J r v s : S f i F f T m j e c i I
1 E X IT I I NEM Nn 1 1 NEM TO 1 1 SAVE 1 1 R B it 1 1 COnrtENl |1 1 CLEAR 1 1 DELETE
1
p i s r o w e n ] | c e t i k s t | t n m h i e i | o u t p u t | DEBUGR A IS E 1 | E M T 1 1 C t W t C T | SET P IF T | |5ET IE L B Y | BET S T R E W ! I LO IE R | | EXPAK1"1 | 2D * | L S S t U I ACTIVATE
F i g u r e 15: T o p Level M e n u
dpos -brdr lightgray -bO lightgray -fO black
-b4 MediumVioletRed -f4 Navy
-b5 HediumGoldenrod -f5 vhite
S e ts u p colors for d e b u g g i n g . M o re s o p h is tic a te d color s e le c tio n is p o ssib le, b u t is n o t covered here.
6.2
T o p L evel M e n u
W h e n t h e p r o g r a m is ru n t h e t o p level m e n u a p p e a r s (see F i g u re 15). I n t e r a c t i o n w ith t h e in te r fa c e is b y m o u s e b u t t o n s a n d b y k e y b o a r d . O n l y t h e basic fea t u r e s will b e d isc u sse d h e r e . A d v a n c e d f e a t u r e s are disc u sse d in a l a t e r se c ti o n . T o p level m e n u c o m m a n d s in c lu d e: 1. E X I T : E x it t h e i n te r fa c e ( a n d d o n 't b o t h e r s a v ing a n y t h i n g ) . 2. N E W N M : O p e n a N e tw o r k M o d u le t e m p l a t e for e d i t i n g . 3. N E W P O : O p e n a P r o c e s s O b j e c t t e m p l a t e for e d i tin g .
4.
S AV E: S ave a P O or N M t e m p l a t e definition. 5. R E A D : R e a d a n e x i s tin g N M or P O t e m p l a t e d efinition. 6. C O M M E N T : G e n e r a t e a c o m m e n t line for an NM t e m p l a t e . . 7. C L E A R : C l e a r a t e m p l a t e w in d o w for reuse. 8. D E L E T E : D e le te a p a r a m e t e r m e n u , P O , NM, or c o m m e n t i n s t a n c e f ro m an N M t e m p l a t e . 9. D I S C O N N E C T : D is c o n n e c t a n in s t a n c e p ort f ro m a c h a n n e l o r t e m p l a t e p o r t . 10. G E T I N S T : R e a d a P O or N M in s t a n c e defini tio n for in s e rt io n i n t o a n N M t e m p l a t e . 11. G E T C H A N N E L : R e a d a n in s t a n c e de s c rip tio n for in s e rt io n i n t o a N M t e m p l a t e .12. O U T P U T : G e n e r a t e s o u r c e code lo a d file for an N M or P O t e m p l a t e . 13. D E B U G : E n t e r t h e p r o g r a m a n i m a t o r for g r a p h ic al d e b u g g i n g . 14. R A I S E : R a is e a n i n s t a n c e w i t h i n a n N M t e m p l a t e . 15. E D I T : O p e n a t e x t m e n u e d i t o r for t e m p l a t e or i n s t a n c e p a r a m e t e r s . 16. C O N N E C T : C r e a t e a c o n n e c t io n f r o m a n in s t a n c e p o r t to a c h a n n e l i n s t a n c e or t e m p l a t e p o r t . 17. S E T P O R T : T o g g le P O t e m p l a t e p o r ts . 18. S E T D E L A Y : T o g g le in s t a n c e p o r t s as d e la y con n e c tio n s . 19. S E T S T R E A M : T o g g le c h a n n e l i n s t a n c e s a s t r e a m s o f c h a n n e l s o r single c h a n n e ls . 20. L O W E R : L o w e r a n i n s t a n c e w i t h i n a n N M t e m p l a t e . 21. E X P A N D : E x p a n d t h e d i s t a n c e s b e t w e e n o b j e c t s w i t h i n a n N M t e m p l a t e . 22. Z O O M : E n l a r g e t h e size o f o b j e c t s a n d e x p a n d as in “E X P A N D ” . 23. M O V E : M o v e a n i n s t a n c e w ith in a n N M t e m p l a t e . 24. S C R O L L : Scroll all o b j e c t s w i t h i n a n N M t e m p l a t e . 25. R E S I Z E : R e siz e a n in s t a n c e w ith in a n N M t e m p l a t e . 26. A C T I V A T E : O p e n a n ew N M t e m p l a t e for an i n s t a n c e in a n N M t e m p l a t e .
6.3
D e fin in g P ro c e s s O b je c ts
T h e so u r c e code for b a s ic P r o c e s s O b j e c t s a n d th e i r r e p r e s e n t a t i o n as b lo c k s in N e tw o r k M o d u le s h a s b e e n disc u sse d in p re v io u s s e c ti o n s (see S e c tio n 5 a n d F ig u r e s 6 a n d 8). P ro c e s s O b j e c t classes a r e defined w i t h i n D P O S b y e d i t i n g P r o c e s s O b j e c t t e m p l a t e s (see F i g u re 16). S e le c ti n g t h e t o p level m e n u c o m m a n d “N E W P O ” g e n e r a t e s a n e w b la n k P ro c e s s O b j e c t t e m p l a t e . T h e g r a p h i c a l in te r f a c e spe c ific a t io n o f a P O class defin es t h e p o r t c o n n e c t io n s for th e g r a p h i c a l blo c k , t h e p a r a m e t e r s for t h e P O a n d a lso t h e in t e r f a c e to t h e u se r defined so u r c e code.L2
B1 I B2 I B3 I B4
F i g u r e 16: P ro c e s s O b j e c t T e m p l a t e
» TEHPLATE
PMttim
-cUss rmie:: producer
include file::producer.sc«_________ functiai cal 1::<produco—po R2 cnt>
user_deflned::cnt________________ user.deflned;;___________________ user.deflned::___________________ user_defined; i___________________ user_defined;:___________________ user-defined:;___________________ user_defined::___________________ F i g u r e 17: P O P a r a m e t e r M e n u T h e P r o c e s s O b j e c t t e m p l a t e o f F i g u r e 16 corre s p o n d s to t h e p r o d u c e r P O in s t a n c e s in F ig u r e 6. S e le c ti n g t h e “S E T P O R T ” c o m m a n d se ts th e i n t e r ace m o d e to to g g le P O p o r t s . S e le c ti n g a P O t e m p l a t e p o r t will to g g le t h e t e m p l a t e p o r t on or off. In t h e F i g u r e 16 p o r t “R 2 ” h a s b e e n to g g le d on. T h e P O p a r a m e t e r s a n d so u r c e code in te r f a c e are specified by e d i t i n g t h e P O p a r a m e t e r m e n u . S e le ct in g t h e “E D I T ” c o m m a n d s e ts th e in te r fa c e m o d e to e d i t o b j e c t s . S e le c ti n g t h e P O t e m p l a t e will open a P O t e m p l a t e m e n u (see F i g u r e 17). T h e user s e le c ts o n e o f th e lines w i t h t h e m o u s e , th e n uses t h e k e y b o a r d t o spe cify t h e e n t ry . T h e use r m u s t specify t h e P O “class n a m e ” . T h e u se r m a y sp e c ify “u s e r - d e f in e d ” p a r a m e t e r s . In t h is case th e one p a r a m e t e r “c n t ” is define d. T h e “in c lu d e file” s p e c ifies t h e file w hich i n c lu d e s th e use r defined source code. T h e f u n c t i o n call specifies a f u n c t i o n w ith in th e so u r c e code file a n d t h e c a llin g se q u e n c e . T h e “f u n c tio n c a ll” in F i g u re 17 c o r r e s p o n d s w ith t h e P ro c ess O b j e c t so u r c e code sh o w n in F i g u r e 2.
T h e “in c lu d e file” a n d “f u n c t i o n c a ll” m u s t b e set. T h e n a m e o f t h e ca lle d f u n c t i o n s h o u ld b e different f ro m t h e P O class n a m e . P ro c e s s O b j e c t t e m p l a t e s m a y b e sa v ed using the “S A V E ” c o m m a n d . “S A V E ” p r o d u c e s a defin ition file w h ich m a y b e r e s to r e d i n t o a b la n k P O t e m p l a t e u sin g t h e “R E A D ” c o m m a n d . A l t e r n a t e l y , SA V E D 9
NM TEMPLATE PARAfETERS d a t a nwt: :prc*icer-2 user_deflr>ed::cttt_____ user_deflned::________ user defined::________ user. defined::________ user, defined::________ user_deflned::________ user_deflned::________ user_defined::________ user.defined::________
Figure 18: NM Parameter Menu
l E B n EhTER CHlNHEL FILE Nut IE 1
i i
ASYNC. SUFFER IN GUARS
Figure 19: Channel Selection Menu
tem plates m ay be read as instance blocks in a tem plate (see subsection 6.6 below). Resaving a tem plate modifies the class definition but does not affect the instances already placed within other tem plates. T hese existing instances may have to be replaced if the interface for the tem plate is modified.
The “CLEAR” com m and may be used to clear out the contents of a PO tem plate to allow another defi nition to be read in and edited.
6.4
D e fin in g N e tw o rk M o d u le s
Network Module classes are defined by editing N et work M odule tem plates (see Figures 5,6, and 8). The m eanings of these Network Modules has been dis cussed in previous sections.
The main window of a Network Module tem plate may contain, PO blocks, NM blocks, chan nel blocks, comm ent blocks and connection lines. The graphical interface provides window m anage m ent facilities for m anaging the blocks. The top level menu com m ands “ZOOM” , “E X PA N D ” , “MOVE” , “SCROLL” , “RAISE” , “LO W ER” and “RESIZE” are for m anipulating blocks in tem plate windows. The tem plates them selves may be resized, moved, etc. using the regular X window commands.
The contents of an NM tem plate may be saved as an NM class definition using the “SAVE” com mand. “SAVE” produces a definition file which may be re stored into a blank NM tem plate using the “R EA D ” com m and. Alternately, saved tem plates may be read as instance blocks in a tem plate (see subsection 6.6 below). R esaving a tem plate modifies the class defini tion but does not affect the instances already placed within other tem plates. These existing instances may have to be replaced if the interface for the tem plate is modified.
The command “NEW NM” opens a new blank NM tem plate for editing. The graphical interface
speci-Figure 20: Buffer Channel Param eter Menu
fication of an NM com pletely defines the NM class. NM class parameters are specified similarly to PO class parameters by opening an NM parameter menu (see Figure 18). NM parameters include “class name” and “user-defined” parameters.
An alternate method of opening a new tem plate for editing is to use the “ACTIVATE” command. “AC TIVATE” lets a user open a tem plate window by se lecting an NM instance that is visible within a tem plate being edited. A new NM tem plate is created with the class definition of the selected instance.
The “CLEAR” command m ay be used to clear out the contents of a PO tem plate to allow another defi nition to be read in and edited.
The “COM M ENT” com m and allows the user to enter a text string which m ay then be instanced within tem plates.
The following subsections define basic manipula tions of NM tem plates to specify NM, PO and chan nel instances.
6.5
S p e c ify in g C h a n n e ls
Instances o f channel classes may be included in NM tem plates. Selecting “G ET CH ANNEL” opens the channel selection menu 19. Selecting a channel class puts the interface into channel instancing mode. Se lecting locations in NM tem plates will create in stances o f the specified channel type in the NM tem plate.
Channels have parameters which must be speci fied by the user. Channel parameter menus may be opened similarly to PO and NM parameter menus. Different channel classes have different parameter menus:
6.7
C on n ection s
F i g u r e 21: G e t I n s t a n c e M e n u
producer
cla55 : IWSTAHTt MWHETEIS
Instance rw c : p 2 ___________________ constraint: cnt:cnt F i g u r e 22: P r o c e s s O b j e c t I n s t a n c e M e n u 1. A s y n c h r o n o u s c h a n n e l s h a v e o n ly a “n a m e ” p a r a m e t e r .
2. B uffered c h a n n e l s h a v e “n a m e ” a n d “buffer siz e” (see F i g u r e 20). 3. G u a r d e d i n p u t c h a n n e l s h a v e “n a m e ” an d “g u a r d l i s t siz e” .
6.6
S p e c ify in g In s ta n c e s
N M a n d P O in s t a n c e s m a y be in c lu d e d in N M t e m p la te s . S e le c ti n g “G E T I N S T A N C E ” will c a u se th e in te r f a c e t o r e q u e s t an i n s t a n c e class n a m e (see F i g u r e 21). O n c e a c o r r e c t P O o r N M class n a m e h a s b e e n e n t e r e d t h e u se r m a y se lec t l o c a t i o n s in NM t e m p l a t e s t o p la c e in s t a n c e s . I n s t a n c e s h a v e p a r a m e t e r s w h ic h m u s t b e specified b y th e user. I n s t a n c e s p a r a m e t e r m e n u s a r e o p e n e d s i m ila rly t o o t h e r p a r a m e t e r m e n u s . F ig u re 22 show s t h e i n s t a n c e p a r a m e t e r m e n u for p r o d u c e r : p 2 in F i g u r e 6. “I n s t a n c e n a m e ” h a s b e e n set t o “p 2 ” an d t h e i n s t a n c e p a r a m e t e r “c n t ” w a s a u se r defined p a r a m e t e r disc u sse d a b o v e a n d specifie d in F i g u r e 17. “C n t ” h a s b e e n s e t t o t h e v a l u e o f “c n t ” in th e NM t e m p l a t e . S p e c ific ia tio n of th e “c n t ” v a lu e in t h e NM t e m p l a t e w a s disc u sse d a b o v e a n d sh o w n in F ig u re 18. T h e v a l u e of “c o n s t r a i n t ” is u n s e t . “C o n s t r a i n t ” is t h e o n ly p a r a m e t e r t h a t m a y be left u n s e t. T h e m e a n i n g of “c o n s t r a i n t ” is disc usse d la t e r a n d is n o t used in t h e p r e v io u s e x a m p le s . P O s c o m m u n i c a t e v ia c h a n n e l s . T h e accessibility of a c h a n n e l f r o m a P O i n s t a n c e is r e p r e s e n te d by a c o n n e c t io n line in an N M t e m p l a t e b e t w e e n t h e P O i n s t a n c e a n d t h e c h a n n e l . N M t e m p l a t e p o r t s m a y se rv e a s s u r r o g a t e c h a n n e l s a n d P O i n s t a n c e s m a y c o n n e c t t o NM t e m p l a t e p o r t s (see F i g u r e 6). W h e n a n i n s t a n c e o f t h e NM class is c r e a t e d w ith in a n o t h e r N M class t e m p l a t e t h e p o r t s o f t h e N M in s t a n c e m a y b e c o n n e c t e d t o c h a n n e l s in t h e n e w N M t e m p l a t e (see F i g u re 5). A l t e r n a t e l y t h e t e m p l a t e p o r t s o f th e n e w N M t e m p l a t e m a y se rv e a s s u r r o g a t e s p r o d u c in g a n y n u m b e r o f level's o f in d ir e c t i o n . T h e in d ir e c tio n o f c o n n e c t i o n s t h r o u g h N M p o r t s d o e s not effect the efficiency or c o s t o f c o m m u n i c a t i o n in an}- way.T h e r e c a n b e o n ly a sin g le c o n n e c t i o n fro m an in s t a n c e p o r t . M u l t i p l e c o n n e c t i o n s m a y be m a d e to a c h a n n e l i n s t a n c e o r t e m p l a t e p o r t . C o n n e c t i o n m o d e is e n t e r e d by s e le c tin g th e “C O N N E C T ” c o m m a n d . A c o n n e c t i o n is m a d e by selecting a n NM or P O i n s t a n c e p o r t , t h e n se le c tin g a c h a n nel i n s t a n c e or t e m p l a t e p o r t . I f a b e n t c o n n e c tio n line is desire d t h e n s e le c t p o i n t s w ith in th e t e m p l a t e b a c k g r o u n d b ef o r e s e le c tin g t h e c h a n n e l i n s t a n c e or t e m p l a t e p o r t .
D is c o n n e c t m o d e is e n t e r e d b y s e le c tin g th e “D IS C O N N E C T ” c o m m a n d . S e le c ti n g a c o n n e c t e d in s t a n c e p o r t will d e l e te t h e c o n n e c t io n .
6.8
G e n e r a tin g L oad F iles
O n c e an NM t e m p l a t e or P O t e m p l a t e definition is c o m p l e t e l y defin ed w i t h i n t h e g r a p h i c a l in te rfa ce , load files m a y b e g e n e r a t e d . T h e “O U T P U T " c o m m a n d allow s t h e u s e r t o s e le c t th e t a r g e t la n g u a g e an d file n a m e for a loa d file. C u r r e n t l y four ta rg e t l a n g u a g e s a re s u p p o r t e d . C o n c u r r e n t U t a h S chem e, D P O S S c h e m e , D P O S - D E B U G S c h e m e , a n d M u lt i s c h e m e (or B u t t e r f l y S c h e m e ) . D P O S S c h e m e and D P O S - D E B U G S c h e m e use t h e D P O S S ch em e di a l e c t d e s c r ib e d in t h is d o c u m e n t .
7
Further DPOS Concepts
T h i s se c ti o n p r e s e n t s s e v eral D P O S c o n c e p t s not dis c ussed in e a r lie r se c tio n s. T h e c o n c e p t s p re se n te d he r e f a c i l i t a t e t h e m a n a g e m e n t o f g r o u p s o f processes u sin g r ec u rsiv e N e tw o r k M o d u le s a n d th e d y n a m ic a l lo c a ti o n o f p ro ce sses. In p r e v i o u s e x a m p l e p r o g ra m s proce sses h a v e b e e n s t a t i c a l l y defined. T h e t y p e and n u m b e r o f p r o c e sse s w e re d e t e r m i n e d p r io r to exe c u t io n o f t h e p r o g r a m . D P O S p r o v id e s tw o m e c h a n is m s for m a n a g e m e n t o f d y n a m i c p ro c e ss cre a tio n ,
c o n s t r a in t s and d e la y s .
7.3
C h a n n e l S tre a m s
7.1
C o n s tra in ts
C o n s t r a in t conditions allow the creation of pro cesses to be controlled at run tim e. A c o n s tr a in t condition is a test condition that constrains the creation of Network M odules and Process O bjects. C o n s t r a in t s m ay be specified for nested NM and PO instances in Network Module class definitions. T he c o n s t r a in t condition appears in the parame ter m enus of Process O bject and Network Module instances (see Figure 22). If the c o n s t r a in t con dition is unset then the NM or PO will autom ati cally be created when the parent NM is created. If the c o n s t r a in t condition is set then the condition will be evaluated autom atically when the parent NM is created. The c o n s t r a in e d NM or PO instance will be created only if the evaluation returns non-nil. The c o n s t r a in t condition may use any values visible within the scope of the parent NM.
The use of constraint conditions allows the recur sive and m utually recursive definition of Network M odule classes.
7.2
D e la y s
In addition to c o n s t r a in t s , PO and NM instances may be d e la y e d . If a PO or NM instance is d e la y e d then it is not created when the parent NM instance is created. Its creation is d e la y e d and may or may not be carried out at some future tim e. The creation of d e la y e d NM and PO instances is triggered by m es sage traffic through one of its connecting channels. The trigger channel is called a d e la y channel. The first m essage access to a d e la y channel will cause the creation of the d e la y e d instance.
If a PO or NM instance is to be d e la y e d then it must have at least one connecting d e la y channel. The d e la y relationship between a channel and a PO or NM instance is specified within the parent Network Module definition as an attribute of the connection. A channel may be a d e la y channel for any number of connected instances.
The use of d e la y e d instances allows (he recursive and m utually recursive definition of Network Module classes.
The d e la y attribute o f a channel is specified by using the “SET DELAYS" interface mode command. Then selecting connections to be d e la y e d .
In previous sections channels have been specified as single entities. DPO S channels may alternately be specified as streams. A DPO S s tr e a m channel is a delayed stream of channels. A s t r e a m channel is like a lis t of similar channels. It differs from a lis t in several ways:
1. The stream is of potentially infinite length. 2. The channel instances are d e la y e d (not initially
created).
3. The s t r e a m m ay be accessed only using stream accessor functions.
4. The first access of a stream element autom ati cally triggers the creation of that element.
A number of stream accessor functions are pro vided:
1. h -s tr m : returns the first channel (head) of the stream.
2. t- s tr m : returns the remainder of the stream (following the head).
3. h t-s tr m : returns the second channel of the stream . T his is equivalent to (h-strm (t-strm channel-strm )).
4. h t t - s t r m : returns the third channel of the stream.
5. h t t t - s t r m : returns the fourth channel of the stream.
S tr e a m channels are a convenient way to create m ultiple channels without having to worry about the number of channels actually needed. A channel in stance may be specified to be a s t r e a m channel us ing the “SET ST R E A M ” interface mode command. A s tr e a m channel may not be used as a d e la y chan nel.
Connections may be made to a s tr e a m channel just as to a non-stream channel. A Proress Object may receive a s tr e a m channel as a parameter. A Process Object may only access a s tr e a m channel by using s tr e a m accessor functions. So. for example, a Process O bjcct may send a m essage to the second channel of a s tr e a m channel of type a _ c lia n n e l by using the command ( s e n d ( h t - s t r m c h a n ) d a ta ).
Alternately connections to a s tr e a m channels in Network Module class definitions may invoke acces sor functions. This allows a connection to be made to
TfJsrfllJct f>ofct
lacxessc*- function :h-strw
F i g u r e 23: I n s t a n c e P o r t P a r a m e t e r M e n u
F i g u r e 24: M a t r i x M u l t i p l i c a t i o n N e tw o r k M o d u le
only one m e m b e r o f th e s t r e a m c h a n n e l. So a n e s te d N M or P O i n s t a n c e w o u ld o n ly see a sin gle c h a n n e l o b j e c t as its p a r a m e t e r . T h e acce ssor f u n c t i o n m a y b e specified for a c o n n e c t i o n by u sin g th e “E D I T ” in te r f a c e f u n c t i o n t o e d i t t h e i n s t a n c e p o r t p a r a m e te r m e n u (see F i g u r e 23). I f t h e acce ssor f u n c t i o n is le ft u n s e t t h e n t h e c o n n e c t io n is m a d e to t h e e n t ir e s t r e a m c h a n n e l .
8
Further Examples
T h i s s e c ti o n c o n t a i n s e x a m p l e p r o g r a m s u sin g th e f e a t u r e s d e s c r ib e d in se c ti o n 7.
8.1
M a tr ix M u ltip lic a tio n
T h i s e x a m p l e p r o g r a m m u l t i p l i e s an L x M m a t r i x ( A ) by a M x N m a t r i x (B ) . T h e p r o b l e m is ty p ic a l of m a n y n u m e r i c a l c o m p u t a t i o n s a n d o t h e r p r o b l e m s w ith v e r y r e g u l a r s t r u c t u r e . T h e s o lu t io n uses th e s a m e b asic s t r a t e g y as t h e e x a m p l e p r o g r a m in s u b s e c ti o n 5.3. I t uses a p o o l o f s e rv a n t processes to c a r r y o u t s im ila r c o m p u t a t i o n s . N e tw o r k M o d u l e s for th e p r o g r a m a r e sh o w n in F i g u r e s 24 a n d 25. In t h e p r o g r a m a co n tro l p r o cess o f class m m c o n t r o l first s e n d s th e B m a t r i x to a c h a n n e l la b e le d “B m a t r i x ” w h ere it is re a d each of th e r o w m m class s e rv a n t p roce sses defined in r o w
-F i g u r e 25: S e r v e r P ro c e s s L ist N e tw o rk M o d u le
(define (row-mn-po ROWS-II B-MATRII RESULT-OUT) (let ((matb (chan-read B-MATRII)))
(do ((ros (receive ROWS-II) (receive ROWS-II))) ((not row))
(let ((index (car row)) (x (cadr ros)) (y (caddr ro®))
(rosvec (cadr (cddr row)))) (send
RESULT-OUT
(list index (ro*-x-nat x y rowvec natb)))))))
(define (nmcontrol-po A-MAT-II B-MAT-II
ROWS-II B-MATRII ROW-CIT cnt) (let* ((natb (receive B-MAT-II))
(nata (receive A-MAT-II)) (x (vector-length nata)) (y (vector-length natb))
(z (vector-length (vector-ref natb 0)))) (send B-MATRIX matb))
(tend ROW-CIT x)
(do ((a 0 (+ a 1))) ;send ont the rows ((= a x))
(send ROWS-II (list a y z (vector-ref Data a)))) (do ((a 0 (+ a 1))) ;«end ont terminations
((= a cnt))
(send ROWS-II #f))))
(define (anont-po RESII RESOUT SIZEII) (let ((size (receive SIZEII))
(resvec tf) (newres #f))
(set! resvec (make-vector size)) (do ((a 0 (+ a 1)))
((= a size))
(set! newres (receive RESII)) (vector-set! resvec
(car newres) (cadr newres))) (send RESOUT resvec)))
Figure 26: Process Object Code
8.2
F ib o n a c c i N u m b e rs
T h i s p r o g r a m p r e s e n t s t h e n a i v e rec ursive a l g o r i t h m for c o m p u t i n g t h e f ib o n ac ci s e q u e n c e (see F ig u r e s 27, 28 a n d 29). T h e p r o g r a m in c lu d e s tw o P ro c e s s O b j e c t classes, a c o n t ro l l e r p r o c e s s o f class f - s t a r t a n d w o r k e r p ro ce sses o f class f i b - u n i t . T h e e n t ir e P ro c e s s O b j e c t s o u r c e lis tin g is g ive n in F i g u r e 29. P r o c e s s o b j e c t s f - s t a r t a n d f i b - u n i t use i n te r f a c e f u n c ti o n s f - s t a r t - p o a n d f i b - u n i t - p o re s p e c tiv e ly (see F ig u r e 29). T h e N e tw o r k M o d u l e d e f in itio n s a r e sh o w n in F i g u r e s 27 a n d 28. F i g u r e 27 sh o w s t h e to p -le v e l N e t w o rk M o d u le . F i g u r e 27 c o n t a i n s an f - s t a r t class P ro c e s s O b j e c t c a lle d f - s t a r t : s t a n d a f i b - t r e e class N e tw o r k M o d u le ca lle d f i b - t r e e : t r e e . T h e f i b - t r e e N e tw o r k M o d u l e is sh o w n in F i g u re 28. It c o n t a in s a f i b - u n i t P O a n d t w o de la y e d f i b - t r e e N M s. T h e blo ck visible at t h e i n s t a n c e p o r t o f ea ch n e s te d f ib - t r e e NM signifies t h a t t h e c o n n e c t io n is a d e la ycon-(define (f-start-po CHAH size) (erite-guard CHAH ask size) (display
(list 'anseer (read-guard CHAH (list reply))))) (define (fib n)
(if (< n 3)
1
(+ (fib (- n 1)) (fib (- n 2))))) (define (fib-unit-po TOP BOT)
(let ((size (cadr (read-guard TOP (list ask)))) (grainsize 7))
(if (< size grainsize)
(erite-guard TOP reply (fib size)) (begin
(erite-guaxd BOT ask (- size 1)) (write-guard BOT ask (- size 2))
(let ((resl (cadr (read-guard BOT (list reply)))) (res2 (cadr (read-guard BOT (list reply))))) (erite-guard TOP REPLY (+ resl res2)))))))