p9 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. .bp
  2. .NH
  3. Appendix B: Translation of a \fBPAR\fP construct to EM code using the library
  4. routines to simulate parallelism
  5. .PP
  6. Translation of the parallel construct:
  7. .DS
  8. .ft CW
  9. par
  10. P0
  11. par i = [ 1 for n ]
  12. P(i)
  13. .DE
  14. is
  15. .TS
  16. center;
  17. lf5 lf5.
  18. lal -20 ; Assume 20 bytes of local variables at this moment
  19. cal $parbegin ; Set up a process group
  20. asp 4 ; Assume pointersize = 4
  21. cal $parfork ; Split stack in two from local -20
  22. lfr 4 ; Assume wordsize = 4
  23. zne *23 ; One end jumps to second process, other continues here
  24. lor 0 ; Static link
  25. cal $P0
  26. asp 4
  27. bra *24 ; Jump to the outer parend
  28. 23
  29. cal $parfork ; Fork off `par i = ...' process
  30. lfr 4
  31. zne *25 ; One end jumps to end of outer par
  32. lal -20 ; Place break just above i
  33. cal $parbegin ; Set up another process group for the P(i)
  34. loc 1
  35. stl -24 ; i:=1
  36. lol n ; Assume n can be addressed this simply
  37. stl -28 ; A nameless counter
  38. bra *26 ; Branch to counter test
  39. 27
  40. cal $parfork ; Fork off one P(i)
  41. lfr 4
  42. zne *28 ; One jumps away to increment i, the other calls P(i)
  43. lol -24
  44. lor 0
  45. cal $P
  46. asp 8
  47. bra *29
  48. 28
  49. inl -24 ; i:=i+1
  50. del -28 ; counter:=counter-1
  51. 26
  52. lol -28
  53. zgt *27 ; while counter>0 repeat loop
  54. 29
  55. cal $parend ; Wait for the P(i) to finish, then delete group
  56. bra *24 ; Jump to the higher up meeting place with P0
  57. 25 ; Note that the bra will be optimized away
  58. 24
  59. cal $parend ; Wait for both processes to end, then delete group
  60. .TE