Title: Message Passing
1Message Passing
- All of the synchronization techniques so far work
only if shared memory is available - Two techniques that can be used in distributed
memory systems - Remote Procedure Calls
- Message Passing
2Remote Procedure Calls
3Remote Procedure Calls
- Language neutral
- Based on the semantics of procedure calls
- Issues
- Finding procedures (services)
- Data representation
-
4Message Passing
- Another synchronization tool is message passing
- Basic idea is that sender and receiver must be
ready to communicate - Only two basic operations
- Send( receiver, message )
- Receive( sender, message )
- Systems differ on how the sender and receiver
find each other
5OCCAM 2
- Based on C.A.R. Hoares CSP (Communicating
Sequential Processes) - Named for William of Occam, 14th century English
philosopher - Do not do with more, what you can do for less
- Includes
- Parallel Processes
- Synchronized message passing
- Guarded selection (based on Dijkstras guarded
command)
6OCCAM 2
- Developed by Sir David May at INMOS in England
- An OCCAM program consists of processes that
communicate using message passing - A well behaved OCCAM program will eventually
terminate - You do not want your OCCAM program to STOP
7OCCAM Types
- Primitive types
- INT, REAL, BOOL
- INT16, INT32, INT64,
- BYTE
- CHANNEL
- TIMER
- Arrays
- 1000 REAL64 amplitude
8Literals
- Integer, byte, and string literals are the usual
- Hexadecimal numbers are preceded with a
- Boolean literals are TRUE and FALSE
- Reals numbers
- You must specify the type 7.234(REAL32)
- You cannot omit the decimal
- There must be one digit before the decimal
- No signed literals!!
9Expressions
- Essentially what you would expect, but
- There is only one precedence level in OCCAM
- Comparisons , ltgt, lt, gt, and gt
- Arithmetic operations are not defined for bytes
- Booleans AND, OR, /\, \/, gtlt
- Logical shift ltlt and gtgt
10Basic OCCAM Processes
- Assignment
- Variable Expression
- Send
- Channel ! Expression
- Receive
- Channel ? Variable
- SKIP
- STOP
11OCCAM Constructors
- SEQ executes statements in sequence
- SEQ
- Statement 1
- Statement 2
- A SEQ terminates when its last component
terminates - A SEQ with no components is the same as a SKIP
12Conditional
- The conditional is familiar, the syntax is
different - IF
- I lt 0
- p I 100
- I 0
- p 200
- I lt 0
- p I
13Conditional
- Booleans are execute in sequence until one
evaluates to true - The IF terminates when the process following the
boolean terminates - The IF does not terminate if none of the boolean
expressions evaluate to TRUE
14Channels
- Channels can be used to connect processes
- Data flows in one direction only
- Although most implementation allow bi-directional
communication - Channels are typed
- Channels are not buffered
- Communication does not take place until both
processes are ready
15PAR
- A PAR executes processes in parallel
- PAR
- process1
- process2
-
- A PAR terminates when all of its processes
terminate
16Examples
- Pipeline
- PipeSort
- Hypercube routing
17ALT
- Basically provides a way to poll channels for
messages without blocking
ALT up ? increment x x increment
down ? decrement x x decrement read ?
request reply ! x
18A Simple Pipeline
PROC pipeline (CHAN OF BYTE stdin, stdout,
stderr) 15 CHAN OF BYTE chan VAL BYTE
end.char IS '!' PROC filter (CHAN OF BYTE
in, out) BYTE num SEQ num0
WHILE numltgtend.char SEQ in ?
num out ! num PROC generate
(VAL BYTE beg, end, CHAN OF BYTE out) BYTE
num SEQ numbeg WHILE numltend
SEQ out ! num
numnum1 out ! end.char
PROC display (CHAN OF BYTE in, out) BYTE
num SEQ WHILE numltgtend.char
SEQ in ? num out ! num
out ! 'n' PAR generate('A','z',ch
an0) PAR i0 FOR 14
filter(chani,chani1) display(chan14,std
out)
19Pipesort
PROC pipesort (CHAN OF BYTE stdin, stdout,
stderr) INCLUDE "consts.occ" INCLUDE
"utils.occ" VAL INT num IS 10 num1 CHAN
OF INT chan VAL INT end.number IS -1
PROC filter (CHAN OF INT in, out) INT
mynum,num SEQ in ? mynum WHILE
mynumltgtend.number SEQ in ? num
IF numltmynum
num,mynummynum,num TRUE
SKIP out ! num out ! mynum
PROC display (CHAN OF INT in, CHAN OF BYTE
out) INT num SEQ WHILE
numltgtend.number SEQ in ? num
out.number(num,5,out) out !
'n' PAR random(123,num,chan0)
PAR i0 FOR num filter(chani,chani1)
display(channum,stdout)