runCollectActorMR :: CollectActor a b -> Process ()
runCollectActorMR (CollectActor step start fini) = do
    -- Obtain parameters
    (acp,ParamActor parent rnk grp) <- expect
    -- Create channels for communication
    (chSendParam,chRecvParam) <- newChan
    (chSendDst,  chRecvDst  ) <- newChan
    (chSendN,    chRecvN    ) <- newChan
    -- Send shell process description back
    let shell = Shell (SingleActor acp)
                      (RecvMR    [(chSendN,chSendParam)])
                      (SendVal    chSendDst)
    send parent (acp, wrapMessage shell)
    -- Start execution of an actor
    let loop n tot !b
          | n >= tot && tot >= 0 = return b
          | otherwise = do
              r <- liftP $ receiveWait [ matchChan chRecvParam (return . Right)
                                       , matchChan chRecvN     (return . Left)
                                       ]
              case r of
                Right (Just a) -> loop n tot =<< step b a
                Right Nothing  -> loop (n+1) tot b
                Left  k        -> loop n k b
    b <- runDNA acp rnk grp $ fini =<< loop 0 (-1) =<< start
    sendToDestChan chRecvDst b
runCollectActorMR :: CollectActor a b -> Process ()
runCollectActorMR (CollectActor step start fini) = do
    -- Obtain parameters
    (acp,ParamActor parent rnk grp) <- expect
    -- Create channels for communication
    (chSendParam,chRecvParam) <- newChan
    (chSendDst,  chRecvDst  ) <- newChan
    (chSendN,    chRecvN    ) <- newChan
    -- Send shell process description back
    let shell = Shell (SingleActor acp)
                      (RecvMR    [(chSendN,chSendParam)])
                      (SendVal    chSendDst)
    send parent (acp, wrapMessage shell)
    -- Start execution of an actor
    let loop n tot !b
          | n >= tot && tot >= 0 = return b
          | otherwise = do
              r <- liftP $ receiveWait [ matchChan chRecvParam (return . Right)
                                       , matchChan chRecvN     (return . Left)
                                       ]
              case r of
                Right (Just a) -> loop n tot =<< step b a
                Right Nothing  -> loop (n+1) tot b
                Left  k        -> loop n k b
    b <- runDNA acp rnk grp $ fini =<< loop 0 (-1) =<< start
    sendToDestChan chRecvDst b
runCollectActorMR (CollectActor step start fini) = do
    -- Obtain parameters
    (acp,ParamActor parent rnk grp) <- expect
    -- Create channels for communication
    (chSendParam,chRecvParam) <- newChan
    (chSendDst,  chRecvDst  ) <- newChan
    (chSendN,    chRecvN    ) <- newChan
    -- Send shell process description back
    let shell = Shell (SingleActor acp)
                      (RecvMR    [(chSendN,chSendParam)])
                      (SendVal    chSendDst)
    send parent (acp, wrapMessage shell)
    -- Start execution of an actor
    let loop n tot !b
          | n >= tot && tot >= 0 = return b
          | otherwise = do
              r <- liftP $ receiveWait [ matchChan chRecvParam (return . Right)
                                       , matchChan chRecvN     (return . Left)
                                       ]
              case r of
                Right (Just a) -> loop n tot =<< step b a
                Right Nothing  -> loop (n+1) tot b
                Left  k        -> loop n k b
    b <- runDNA acp rnk grp $ fini =<< loop 0 (-1) =<< start
    sendToDestChan chRecvDst b