Skip to content

Commit

Permalink
Map-reduce features working, with fault tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
jepst committed May 9, 2011
1 parent 75205c0 commit 06797cd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main (main) where

import Distribution.Simple (defaultMain)

main :: IO ()
main = defaultMain
47 changes: 47 additions & 0 deletions Test-MapReduce.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{-# LANGUAGE TemplateHaskell #-}
module Main where

import Remote.Process
import Remote.Task
import Remote.Init
import Remote.Call

import Control.Monad.Trans
import Control.Monad

import Debug.Trace

type Line = String
type Word = String

mrMapper :: [Line] -> TaskM [(Word, Promise Int)]
mrMapper lines =
do one <- asPromise (1::Int)
return $ concat $ map (\line -> map (\w -> (w,one)) (words line)) lines

mrReducer :: Word -> [Promise Int] -> TaskM (Word,Int)
mrReducer w p =
do m <- trace w $ mapM readPromise p
return (w,sum m)

$( remotable ['mrMapper, 'mrReducer] )

myMapReduce = MapReduce
{
mtMapper = mrMapper__closure,
mtReducer = mrReducer__closure,
mtChunkify = chunkify 5
}

initialProcess "MASTER" =
do
file <- liftIO $ readFile "journal"
ans <- startMaster $
do
res <- mapReduce myMapReduce (lines file)
return res
say $ show ans
initialProcess "WORKER" = receiveWait []

main = remoteInit (Just "config") [Main.__remoteCallMetaData] initialProcess

0 comments on commit 06797cd

Please sign in to comment.