forked from jepst/CloudHaskell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Map-reduce features working, with fault tolerance
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|