@@ -10,10 +10,8 @@ fib = go (0, 1)
10 go (!a, !b) !n | n == 0 = a
10 go (!a, !b) !n | n == 0 = a
11 | otherwise = go (b, a + b) (n - 1)
11 | otherwise = go (b, a + b) (n - 1)
13−slave :: () -> Process ()
13+slave :: (ProcessId, Integer) -> Process ()
14−slave () = forever $ do
16− send pid (fib n)
14+slave (pid, n) = send pid (fib n)
18remotable ['slave]
16remotable ['slave]
@@ -21,12 +19,9 @@ master :: Integer -> [NodeId] -> Process Integer
21master n slaves = do
19master n slaves = do
22 us <- getSelfPid
20 us <- getSelfPid
24− -- Start processes on the slaves that compute Fibonacci numbers
25− slaveProcesses <- forM slaves $ flip spawn ($(mkClosure 'slave) ())
27 -- Distribute 1 .. n amongst the slave processes
22 -- Distribute 1 .. n amongst the slave processes
28− forM_ (zip [1 .. n] (cycle slaveProcesses)) $ \(m, them) ->
23+ forM_ (zip [1 .. n] (cycle slaves)) $ \(m, them) ->
29− send them (us, m)
24+ spawn them ($(mkClosure 'slave) (us, m))
31 -- Wait for the result
26 -- Wait for the result
32 partials <- replicateM (fromInteger n) (expect :: Process Integer)
27 partials <- replicateM (fromInteger n) (expect :: Process Integer)