From 4f4a7cb91c622877f54d341f0cb17f2e028d9c6d Mon Sep 17 00:00:00 2001 From: Aggelos Giantsios <aggelgian@gmail.com> Date: Wed, 19 Nov 2014 23:44:29 +0200 Subject: [PATCH] Add GenClos data in Utils to use in Bench --- Bench.hs | 17 +++++++-------- MasterWorker.hs | 25 ++++++---------------- Sequential.hs | 4 ++-- Table.hs | 2 +- Utils.hs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 31 deletions(-) diff --git a/Bench.hs b/Bench.hs index bc9d24e..dca9c49 100644 --- a/Bench.hs +++ b/Bench.hs @@ -6,14 +6,13 @@ module Bench( -- sequential benchmarks , dist, dist_seq ) where -import Control.Distributed.Process (Process, NodeId) +import Control.Distributed.Process import Data.List (lookup) import Data.Maybe (fromMaybe) import Prelude hiding (seq) -import MasterWorker (HostInfo(..), MaybeHosts(..), - GenClos, MasterStats, orbit) -import Table (Vertex) +import MasterWorker (HostInfo(..), MaybeHosts(..), + MasterStats, orbit) import Utils ----------------------------------------------------------------------------- @@ -23,32 +22,32 @@ import Utils -- * number of processors P > 0 (per node) -- * list of Workers (in short node name format 'name@host') -- sequential orbit computation -seq :: (Int -> GenClos) -> Int -> Process String +seq :: (Vertex -> GenClos) -> Vertex -> Process String seq generators n = orbit (generators n) [0] (Seq (2 * n)) >>= return . sz . snd -- parallel orbit computation (par_seq/3 does not spawn image computation) -par :: (Int -> GenClos) -> Int -> Int -> Process String +par :: (Vertex -> GenClos) -> Vertex -> Int -> Process String par generators n p = orbit (generators n) [0] (Par (JustOne (p, ((2 * n) `div` p) + 1, 0, True))) >>= return . sz . snd -par_seq :: (Int -> GenClos) -> Int -> Int -> Process String +par_seq :: (Vertex -> GenClos) -> Vertex -> Int -> Process String par_seq generators n p = orbit (generators n) [0] (Par (JustOne (p, ((2 * n) `div` p) + 1, 0, False))) >>= return . sz . snd -- distributed orbit computation (dist_seq/4 does not spawn image computation) -dist :: (Int -> GenClos) -> Int -> Int -> [NodeId] -> Process String +dist :: (Vertex -> GenClos) -> Vertex -> Int -> [NodeId] -> Process String dist generators n p workers = orbit (generators n) [0] (Par (Many [(h, p, (2 * n) `div` (w * p) + 1, 1, True) | h <- workers])) >>= return . sz . snd where w = length workers -dist_seq :: (Int -> GenClos) -> Int -> Int -> [NodeId] -> Process String +dist_seq :: (Vertex -> GenClos) -> Vertex -> Int -> [NodeId] -> Process String dist_seq generators n p workers = orbit (generators n) [0] (Par (Many [(h, p, (2 * n) `div` (w * p) + 1, 1, False) | h <- workers])) diff --git a/MasterWorker.hs b/MasterWorker.hs index e9ad82e..6499176 100644 --- a/MasterWorker.hs +++ b/MasterWorker.hs @@ -1,10 +1,9 @@ -{-# LANGUAGE TemplateHaskell, DeriveDataTypeable #-} +{-# LANGUAGE TemplateHaskell #-} -- -- orbit-int master (controlling orbit computation) -- module MasterWorker( -- Master - GenClos - , HostInfo (..) + HostInfo (..) , MasterStats , MaybeHosts(..) , orbit @@ -26,27 +25,15 @@ module MasterWorker( -- Master import Control.Distributed.Process import Control.Distributed.Process.Closure -import Data.Binary import Data.Hashable (hash) import Data.Maybe (fromJust) -import Data.Typeable import Prelude hiding (init) import Credit -import qualified Sequential as Sq (Generator, orbit) +import qualified Sequential as Sq (orbit) import Table -import Utils (dispatcher, now) - --- Trying to serialize ParConf closures... -newtype GenClos = GenClos (String, Int, [Sq.Generator]) - deriving (Typeable) - -instance Show GenClos where - showsPrec p (GenClos (name, _, _)) = (name ++) - -instance Binary GenClos where - put (GenClos (name, n, _)) = put (name, n) - get = get >>= \(name, n) -> return $ GenClos (name, n, dispatcher name n) +import Utils (GenClos (..), Generator, + dispatcher, now) -- counters/timers record data Ct = Ct { verts_recvd :: Int -- #vertices received by this server so far @@ -281,7 +268,7 @@ distribute_vetices staticMachConf credit (x : xs) = do -- send_image sends image of X under G to the worker determined by -- the hash of G(X); the message is tagged with atomic credit K. -send_image :: ParConf -> Vertex -> Sq.Generator -> ACredit -> Process () +send_image :: ParConf -> Vertex -> Generator -> ACredit -> Process () send_image staticMachConf x g k = send_vertex staticMachConf (g x) k -- send_vertex hashes vertex X and sends it to the worker determined by diff --git a/Sequential.hs b/Sequential.hs index 5e7a715..cbc7a30 100644 --- a/Sequential.hs +++ b/Sequential.hs @@ -12,9 +12,9 @@ import Data.Hashable (hash) import Table (Freq, Vertex, VTable, freq_to_stat, get_freq, insert, is_member, new, to_list) -import Utils (now) +import Utils (Generator, now) + -type Generator = Vertex -> Vertex type SeqConf = ([Generator], Int) type SeqStats = [(String, String)] diff --git a/Table.hs b/Table.hs index e66c99e..39c8f2f 100644 --- a/Table.hs +++ b/Table.hs @@ -25,9 +25,9 @@ module Table( -- Types ) where import Data.Array (Array, elems, listArray, (!), (//)) +import Utils (Vertex) type Freq = [Int] -type Vertex = Int type VTable = Array Int [Vertex] type TableStats = [(String, String)] diff --git a/Utils.hs b/Utils.hs index 0a17fc9..4a8afb1 100644 --- a/Utils.hs +++ b/Utils.hs @@ -1,5 +1,23 @@ +{-# LANGUAGE DeriveDataTypeable #-} module Utils where +import Data.Binary +import Data.Typeable + +-- Trying to serialize ParConf closures... +newtype GenClos = GenClos (String, Int, [Generator]) + deriving (Typeable) + +instance Show GenClos where + showsPrec p (GenClos (name, _, _)) = (name ++) + +instance Binary GenClos where + put (GenClos (name, n, _)) = put (name, n) + get = get >>= \(name, n) -> return $ GenClos (name, n, dispatcher name n) + +type Generator = Vertex -> Vertex +type Vertex = Int + ----------------------------------------------------------------------------- -- generators @@ -58,6 +76,7 @@ f5 n x = r n $ (fib (p3 10 0 (s5 0 900 999 1000 (r 1000 x)))) + p2 1 x -- sets (= lists) of generators g _ = [] +gg n = GenClos ("g", n, (g n)) g1 n = [f1 n] g2 n = [f2 n] @@ -65,6 +84,13 @@ g3 n = [f3 n] g4 n = [f4 n] g5 n = [f5 n] +gg1, gg2, gg3, gg4, gg5 :: Vertex -> GenClos +gg1 n = GenClos ("g1", n, (g1 n)) +gg2 n = GenClos ("g2", n, (g2 n)) +gg3 n = GenClos ("g3", n, (g3 n)) +gg4 n = GenClos ("g4", n, (g4 n)) +gg5 n = GenClos ("g5", n, (g5 n)) + g12 n = g1 n ++ g2 n g13 n = g1 n ++ g3 n g14 n = g1 n ++ g4 n @@ -76,6 +102,15 @@ g34 n = g3 n ++ g4 n g35 n = g3 n ++ g5 n g45 n = g4 n ++ g5 n +gg12, gg13, gg14, gg15, gg23, gg24, gg24 :: Vertex -> GenClos +gg12 n = GenClos ("g12", n, (g12 n)) +gg13 n = GenClos ("g13", n, (g13 n)) +gg14 n = GenClos ("g14", n, (g14 n)) +gg15 n = GenClos ("g15", n, (g15 n)) +gg23 n = GenClos ("g23", n, (g23 n)) +gg24 n = GenClos ("g24", n, (g24 n)) +gg25 n = GenClos ("g25", n, (g25 n)) + g123 n = g12 n ++ g3 n g124 n = g12 n ++ g4 n g125 n = g12 n ++ g5 n @@ -87,14 +122,36 @@ g235 n = g23 n ++ g5 n g245 n = g24 n ++ g5 n g345 n = g34 n ++ g5 n +gg123, gg124, gg125, gg134, gg135, gg145, gg234, gg235, gg245, gg345 :: Vertex -> GenClos +gg123 n = GenClos ("g123", n, (g123 n)) +gg124 n = GenClos ("g124", n, (g124 n)) +gg125 n = GenClos ("g125", n, (g125 n)) +gg134 n = GenClos ("g134", n, (g134 n)) +gg135 n = GenClos ("g135", n, (g135 n)) +gg145 n = GenClos ("g145", n, (g145 n)) +gg234 n = GenClos ("g234", n, (g234 n)) +gg235 n = GenClos ("g235", n, (g235 n)) +gg245 n = GenClos ("g245", n, (g245 n)) +gg345 n = GenClos ("g345", n, (g345 n)) + g1234 n = g123 n ++ g4 n g1235 n = g123 n ++ g5 n g1245 n = g124 n ++ g5 n g1345 n = g134 n ++ g5 n g2345 n = g234 n ++ g5 n +gg1234, gg1235, gg1245, gg1345, gg2345 :: Vertex -> GenClos +gg1234 n = GenClos ("g1234", n, (g1234 n)) +gg1235 n = GenClos ("g1235", n, (g1235 n)) +gg1245 n = GenClos ("g1245", n, (g1245 n)) +gg1345 n = GenClos ("g1345", n, (g1345 n)) +gg2345 n = GenClos ("g2345", n, (g2345 n)) + g12345 n = g1234 n ++ g5 n +gg12345 :: Vertex -> GenClos +gg12345 n = GenClos ("g12345", n, (g12345 n)) + dispatcher :: String -> Int -> [Int -> Int] dispatcher "g" = g dispatcher "g1" = g1 -- 2.18.1