Initial revision
This commit is contained in:
60
doc/occam/p9
Normal file
60
doc/occam/p9
Normal file
@@ -0,0 +1,60 @@
|
||||
.bp
|
||||
.NH
|
||||
Appendix B: Translation of a \fBPAR\fP construct to EM code using the library
|
||||
routines to simulate parallelism
|
||||
.PP
|
||||
Translation of the parallel construct:
|
||||
.DS
|
||||
.ft 5
|
||||
par
|
||||
P0
|
||||
par i = [ 1 for n ]
|
||||
P(i)
|
||||
.DE
|
||||
is
|
||||
.TS
|
||||
center;
|
||||
lf5 lf5.
|
||||
lal -20 ; Assume 20 bytes of local variables at this moment
|
||||
cal $parbegin ; Set up a process group
|
||||
asp 4 ; Assume pointersize = 4
|
||||
cal $parfork ; Split stack in two from local -20
|
||||
lfr 4 ; Assume wordsize = 4
|
||||
zne *23 ; One end jumps to second process, other continues here
|
||||
lor 0 ; Static link
|
||||
cal $P0
|
||||
asp 4
|
||||
bra *24 ; Jump to the outer parend
|
||||
23
|
||||
cal $parfork ; Fork off `par i = ...' process
|
||||
lfr 4
|
||||
zne *25 ; One end jumps to end of outer par
|
||||
lal -20 ; Place break just above i
|
||||
cal $parbegin ; Set up another process group for the P(i)
|
||||
loc 1
|
||||
stl -24 ; i:=1
|
||||
lol n ; Assume n can be addressed this simply
|
||||
stl -28 ; A nameless counter
|
||||
bra *26 ; Branch to counter test
|
||||
27
|
||||
cal $parfork ; Fork off one P(i)
|
||||
lfr 4
|
||||
zne *28 ; One jumps away to increment i, the other calls P(i)
|
||||
lol -24
|
||||
lor 0
|
||||
cal $P
|
||||
asp 8
|
||||
bra *29
|
||||
28
|
||||
inl -24 ; i:=i+1
|
||||
del -28 ; counter:=counter-1
|
||||
26
|
||||
lol -28
|
||||
zgt *27 ; while counter>0 repeat loop
|
||||
29
|
||||
cal $parend ; Wait for the P(i) to finish, then delete group
|
||||
bra *24 ; Jump to the higher up meeting place with P0
|
||||
25 ; Note that the bra will be optimized away
|
||||
24
|
||||
cal $parend ; Wait for both processes to end, then delete group
|
||||
.TE
|
||||
Reference in New Issue
Block a user