Parallel Factorial |
|
Function fact takes an integer n and an output channel as parameters. The objective is to calculate n!. To do this the range of numbers [1..n] must be multiplied together. If the current range, [lo..hi], contains just one number it is output, opch!hi, and then (->) the process stops. If not, the range is divided in two, [lo..mid] and [mid+1..hi] and auxiliary processes are created to deal with each part and return the results on a scratch channel, ch. When the results are back, ch?x and ch?y, they are combined and output, opch!x*y. The auxiliary processes and the combining process run an parallel (||). The final result is written to standard output, output.
e.g. c1993
So if we had lots of processors and could sensibly spread the processes amongst them then this would be a parallel divide and conquer. |
|
↑ © L. Allison, www.allisons.org/ll/ (or as otherwise indicated). Created with "vi (Linux)", charset=iso-8859-1, fetched Wednesday, 24-Apr-2024 22:06:16 UTC. Free: Linux, Ubuntu operating-sys, OpenOffice office-suite, The GIMP ~photoshop, Firefox web-browser, FlashBlock flash on/off. |