@@ -20,16 +20,30 @@ sumIntegers = go 0
20 m <- expect
20 m <- expect
21 go (acc + m) (n - 1)
21 go (acc + m) (n - 1)
23+data SpawnStrategy = SpawnSyncWithReconnect
24+ | SpawnSyncNoReconnect
26+ deriving (Show, Read)
23−master :: Integer -> [NodeId] -> Process Integer
28+master :: Integer -> SpawnStrategy -> [NodeId] -> Process Integer
24−master n slaves = do
29+master n spawnStrategy slaves = do
25 us <- getSelfPid
30 us <- getSelfPid
27 -- Distribute 1 .. n amongst the slave processes
32 -- Distribute 1 .. n amongst the slave processes
28− spawnLocal $
33+ spawnLocal $ case spawnStrategy of
34+ SpawnSyncWithReconnect ->
35+ forM_ (zip [1 .. n] (cycle slaves)) $ \(m, there) -> do
36+ them <- spawn there ($(mkClosure 'slave) (us, m))
38+ SpawnSyncNoReconnect ->
29− forM_ (zip [1 .. n] (cycle slaves)) $ \(m, there) -> do
39+ forM_ (zip [1 .. n] (cycle slaves)) $ \(m, there) -> do
40+ _them <- spawn there ($(mkClosure 'slave) (us, m))
43+ forM_ (zip [1 .. n] (cycle slaves)) $ \(m, there) -> do
30− spawnAsync there ($(mkClosure 'slave) (us, m))
44+ spawnAsync there ($(mkClosure 'slave) (us, m))
31− _ <- expectTimeout 0 :: Process (Maybe DidSpawn)
45+ _ <- expectTimeout 0 :: Process (Maybe DidSpawn)
32− return ()
46+ return ()
34 -- Wait for the result
48 -- Wait for the result
35 sumIntegers (fromIntegral n)
49 sumIntegers (fromIntegral n)