hdph-0.0.1: Haskell distributed parallel Haskell

Safe HaskellNone

Control.Parallel.HdpH.Strategies

Contents

Synopsis

Strategy type

type Strategy a = a -> Par aSource

A Strategy for type a is a (semantic) identity in the Par monad. For an elaboration of this concept (in the context of the Eval monad) see the paper: Marlow et al. Seq no more: Better Strategies for parallel Haskell. Haskell 2010.

using :: a -> Strategy a -> Par aSource

Strategy application is actual application (in the Par monad).

Basic sequential strategies

r0 :: Strategy aSource

Do Nothing strategy.

rseq :: Strategy aSource

Evaluate head-strict strategy; probably not very useful in HdpH.

rdeepseq :: NFData a => Strategy aSource

Evaluate fully strategy.

Fully forcing Closure strategy

forceC :: (NFData a, ToClosure a) => Strategy (Closure a)Source

forceC is the fully forcing Closure strategy, ie. it fully normalises the thunk inside an explicit Closure. Importantly, forceC alters the serialisable Closure represention so that serialisation will not force the Closure again.

forceCC :: ForceCC a => Closure (Strategy (Closure a))Source

forceCC is a Closure wrapping the fully forcing Closure strategy forceC; see the tutorial in module Closure for details on the implementation of forceCC.

class (NFData a, ToClosure a) => ForceCC a whereSource

Indexing class, recording which types support forceCC; see the tutorial in module Closure for a more thorough explanation.

Methods

locForceCC :: LocT (Strategy (Closure a))Source

Only method of class ForceCC, recording the source location where an instance of ForceCC is declared.

Instances

type StaticForceCC a = Static (Env -> Strategy (Closure a))Source

Type synonym for declaring the Static deserialisers required by ForceCC instances; see the tutorial in module Closure for a more thorough explanation.

staticForceCC :: ForceCC a => StaticForceCC aSource

Static deserialiser required by a ForceCC instance; see the tutorial in module Closure for a more thorough explanation.

Proto-strategies for generating parallelism

type ProtoStrategy a = a -> Par (IVar a)Source

A ProtoStrategy is almost a Strategy. More precisely, a ProtoStrategy for type a is a delayed (semantic) identity function in the Par monad, ie. it returns an IVar (rather than a term) of type a.

sparkClosure :: Closure (Strategy (Closure a)) -> ProtoStrategy (Closure a)Source

sparkClosure clo_strat is a ProtoStrategy that sparks a Closure; evaluation of the sparked Closure is governed by the strategy unClosure clo_strat.

pushClosure :: Closure (Strategy (Closure a)) -> NodeId -> ProtoStrategy (Closure a)Source

pushClosure clo_strat n is a ProtoStrategy that pushes a Closure to be executed in a new thread on node n; evaluation of the pushed Closure is governed by the strategy unClosure clo_strat.

Strategies for lists

evalList :: Strategy a -> Strategy [a]Source

Evaluate each element of a list according to the given strategy.

evalClosureListClosure :: Strategy (Closure a) -> Strategy (Closure [Closure a])Source

Specialisation of evalList to a list of Closures (wrapped in a Closure). Useful for building clustering strategies.

parClosureList :: Closure (Strategy (Closure a)) -> Strategy [Closure a]Source

Evaluate each element of a list of Closures in parallel according to the given strategy (wrapped in a Closure). Work is distributed by lazy work stealing.

pushClosureList :: Closure (Strategy (Closure a)) -> [NodeId] -> Strategy [Closure a]Source

Evaluate each element of a list of Closures in parallel according to the given strategy (wrapped in a Closure). Work is pushed round-robin to the given list of nodes.

pushRandClosureList :: Closure (Strategy (Closure a)) -> [NodeId] -> Strategy [Closure a]Source

Evaluate each element of a list of Closures in parallel according to the given strategy (wrapped in a Closure). Work is pushed randomly to the given list of nodes.

Clustering strategies

parClosureListClusterBy :: ([Closure a] -> [[Closure a]]) -> ([[Closure a]] -> [Closure a]) -> Closure (Strategy (Closure a)) -> Strategy [Closure a]Source

parClosureListClusterBy cluster uncluster is a generic parallel clustering strategy combinator for lists of Closures, evaluating clusters generated by cluster in parallel. Clusters are distributed by lazy work stealing. The function uncluster must be a left inverse of cluster, that is uncluster . cluster must be the identity.

parClosureListChunked :: Int -> Closure (Strategy (Closure a)) -> Strategy [Closure a]Source

parClosureListChunked n evaluates chunks of size n of a list of Closures in parallel according to the given strategy (wrapped in a Closure). Chunks are distributed by lazy work stealing. For instance, dividing the list [c1,c2,c3,c4,c5] into chunks of size 3 results in the following list of chunks [[c1,c2,c3], [c4,c5]].

parClosureListSliced :: Int -> Closure (Strategy (Closure a)) -> Strategy [Closure a]Source

parClosureListSliced n evaluates n slices of a list of Closures in parallel according to the given strategy (wrapped in a Closure). Slices are distributed by lazy work stealing. For instance, dividing the list [c1,c2,c3,c4,c5] into 3 slices results in the following list of slices [[c1,c4], [c2,c5], [c3]].

Task farm skeletons

Task farm skeletons are parallel maps, applying a function to a list in parallel. For technical reasons, the function to be applied must wrapped in a Closure (ie. a function Closure).

Lazy task placement

parMap :: ToClosure a => Closure (Strategy (Closure b)) -> Closure (a -> b) -> [a] -> Par [b]Source

Task farm, evaluates tasks (function Closure applied to an element of the input list) in parallel and according to the given strategy (wrapped in a Closure). Note that parMap should only be used if the terms in the input list are already in normal form, as they may be forced sequentially otherwise.

parMapNF :: (ToClosure a, ForceCC b) => Closure (a -> b) -> [a] -> Par [b]Source

Specialisation of parMap to the fully forcing Closure strategy. That is, parMapNF forces every element of the output list to normalform.

parMapChunked :: ToClosure a => Int -> Closure (Strategy (Closure b)) -> Closure (a -> b) -> [a] -> Par [b]Source

Chunking task farm, divides the input list into chunks of given size and evaluates tasks (function Closure mapped on a chunk of the input list) in parallel and according to the given strategy (wrapped in a Closure). parMapChunked should only be used if the terms in the input list are already in normal form.

parMapChunkedNF :: (ToClosure a, ForceCC b) => Int -> Closure (a -> b) -> [a] -> Par [b]Source

Specialisation of parMapChunked to the fully forcing Closure strategy.

parMapSliced :: ToClosure a => Int -> Closure (Strategy (Closure b)) -> Closure (a -> b) -> [a] -> Par [b]Source

Slicing task farm, divides the input list into given number of slices and evaluates tasks (function Closure mapped on a slice of the input list) in parallel and according to the given strategy (wrapped in a Closure). parMapSliced should only be used if the terms in the input list are already in normal form.

parMapSlicedNF :: (ToClosure a, ForceCC b) => Int -> Closure (a -> b) -> [a] -> Par [b]Source

Specialisation of parMapSliced to the fully forcing Closure strategy.

parClosureMapM :: Closure (Closure a -> Par (Closure b)) -> [Closure a] -> Par [Closure b]Source

Monadic task farm for Closures, evaluates tasks (Par-monadic function Closure applied to a Closure of the input list) in parallel. Note the absence of a strategy argument; strategies aren't needed because they can be baked into the monadic function Closure.

parMapM :: ToClosure a => Closure (a -> Par (Closure b)) -> [a] -> Par [b]Source

Monadic task farm, evaluates tasks (Par-monadic function Closure applied to an element of the input list) in parallel. Note the absence of a strategy argument; strategies aren't needed because they can be baked into the monadic function Closure. parMap should only be used if the terms in the input list are already in normal form, as they may be forced sequentially otherwise.

parMapM_ :: ToClosure a => Closure (a -> Par b) -> [a] -> Par ()Source

Specialisation of parMapM, not returning any result.

Round-robin task placement

pushMap :: ToClosure a => Closure (Strategy (Closure b)) -> [NodeId] -> Closure (a -> b) -> [a] -> Par [b]Source

Task farm like parMap but pushes tasks in a round-robin fashion to the given list of nodes.

pushMapNF :: (ToClosure a, ForceCC b) => [NodeId] -> Closure (a -> b) -> [a] -> Par [b]Source

Task farm like parMapNF but pushes tasks in a round-robin fashion to the given list of nodes.

pushClosureMapM :: [NodeId] -> Closure (Closure a -> Par (Closure b)) -> [Closure a] -> Par [Closure b]Source

Monadic task farm for Closures like parClosureMapM but pushes tasks in a round-robin fashion to the given list of nodes.

pushMapM :: ToClosure a => [NodeId] -> Closure (a -> Par (Closure b)) -> [a] -> Par [b]Source

Monadic task farm like parMapM but pushes tasks in a round-robin fashion to the given list of nodes.

pushMapM_ :: ToClosure a => [NodeId] -> Closure (a -> Par b) -> [a] -> Par ()Source

Monadic task farm like parMapM_ but pushes tasks in a round-robin fashion to the given list of nodes.

Random task placement

pushRandClosureMapM :: [NodeId] -> Closure (Closure a -> Par (Closure b)) -> [Closure a] -> Par [Closure b]Source

Monadic task farm for Closures like parClosureMapM but pushes to random nodes on the given list.

pushRandMapM :: ToClosure a => [NodeId] -> Closure (a -> Par (Closure b)) -> [a] -> Par [b]Source

Monadic task farm like parMapM but pushes to random nodes on the given list.

pushRandMapM_ :: ToClosure a => [NodeId] -> Closure (a -> Par b) -> [a] -> Par ()Source

Monadic task farm like parMapM_ but pushes to random nodes on the given list.

Divide and conquer skeletons

divideAndConquer :: (a -> Bool) -> (a -> [a]) -> (a -> [b] -> b) -> (a -> b) -> a -> bSource

Sequential divide-and-conquer skeleton. didvideAndConquer trivial decompose combine f x repeatedly decomposes the problem x until trivial, applies f to the trivial sub-problems and combines the solutions.

parDivideAndConquer :: Closure (Closure a -> Bool) -> Closure (Closure a -> [Closure a]) -> Closure (Closure a -> [Closure b] -> Closure b) -> Closure (Closure a -> Par (Closure b)) -> Closure a -> Par (Closure b)Source

Parallel divide-and-conquer skeleton with lazy work distribution. parDivideAndConquer trivial_clo decompose_clo combine_clo f_clo x follows the divide-and-conquer pattern of divideAndConquer except that, for technical reasons, all arguments are Closures.

pushDivideAndConquer :: [NodeId] -> Closure (Closure a -> Bool) -> Closure (Closure a -> [Closure a]) -> Closure (Closure a -> [Closure b] -> Closure b) -> Closure (Closure a -> Par (Closure b)) -> Closure a -> Par (Closure b)Source

Parallel divide-and-conquer skeleton with eager random work distribution, pushing work to the given list of nodes. pushDivideAndConquer nodes trivial_clo decompose_clo combine_clo f_clo x follows the divide-and-conquer pattern of divideAndConquer except that, for technical reasons, all arguments are Closures.

This module's Static declaration