parallel-1.0.0.0: parallel programming library

Portabilitynon-portable
Stabilityexperimental
Maintainerlibraries@haskell.org

Control.Parallel.Strategies

Contents

Description

Parallel strategy combinators. See http://www.macs.hw.ac.uk/~dsg/gph/papers/html/Strategies/strategies.html for more information.

Original authors: Phil Trinder, Hans-Wolfgang Loidl, Kevin Hammond et al.

Synopsis

Strategy Type, Application and Semantics

type Done = ()Source

type Strategy a = a -> DoneSource

A strategy takes a value and returns a Done value to indicate that the specifed evaluation has been performed.

(>|) :: Done -> Done -> DoneSource

Evaluates the first argument before the second.

(>||) :: Done -> Done -> DoneSource

Evaluates the first argument in parallel with the second.

using :: a -> Strategy a -> aSource

Takes a value and a strategy, and applies the strategy to the value before returning the value. Used to express data-oriented parallelism. x `using` s is a projection on x, i.e. both:

a retraction
x `using` sx
idempotent
(x `using` s) `using` s = x `using` s

demanding :: a -> Done -> aSource

Evaluates the second argument before the first. Used to express control-oriented parallelism. The second argument is usually a strategy application.

sparking :: a -> Done -> aSource

Evaluates the second argument in parallel with the first. Used to express control-oriented parallelism. The second argument is usually a strategy application.

Basic Strategies

r0 :: Strategy aSource

Performs no evaluation of its argument.

rwhnf :: Strategy aSource

Reduces its argument to weak head normal form.

class NFData a whereSource

Methods

rnf :: Strategy aSource

Reduces its argument to (head) normal form.

Instances

NFData Bool 
NFData Char 
NFData Double 
NFData Float 
NFData Int 
NFData Int8 
NFData Int16 
NFData Int32 
NFData Int64 
NFData Integer 
NFData Word8 
NFData Word16 
NFData Word32 
NFData Word64 
NFData () 
NFData IntSet 
NFData a => NFData [a] 
(Integral a, NFData a) => NFData (Ratio a) 
(RealFloat a, NFData a) => NFData (Complex a) 
NFData a => NFData (Maybe a) 
NFData a => NFData (Tree a) 
NFData a => NFData (IntMap a) 
NFData a => NFData (Set a) 
(NFData a, NFData b) => NFData (Either a b) 
(NFData a, NFData b) => NFData (a, b) 
(Ix a, NFData a, NFData b) => NFData (Array a b) 
(NFData k, NFData a) => NFData (Map k a) 
(NFData a, NFData b) => NFData (Assoc a b) 
(NFData a, NFData b, NFData c) => NFData (a, b, c) 
(NFData a, NFData b, NFData c, NFData d) => NFData (a, b, c, d) 
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5) => NFData (a1, a2, a3, a4, a5) 
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6) => NFData (a1, a2, a3, a4, a5, a6) 
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7) => NFData (a1, a2, a3, a4, a5, a6, a7) 
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7, NFData a8) => NFData (a1, a2, a3, a4, a5, a6, a7, a8) 
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7, NFData a8, NFData a9) => NFData (a1, a2, a3, a4, a5, a6, a7, a8, a9) 

Strategic Function Application

($|) :: (a -> b) -> Strategy a -> a -> bSource

Sequential function application. The argument is evaluated using the given strategy before it is given to the function.

($||) :: (a -> b) -> Strategy a -> a -> bSource

Parallel function application. The argument is evaluated using the given strategy, in parallel with the function application.

(.|) :: (b -> c) -> Strategy b -> (a -> b) -> a -> cSource

Sequential function composition. The result of the second function is evaluated using the given strategy, and then given to the first function.

(.||) :: (b -> c) -> Strategy b -> (a -> b) -> a -> cSource

Parallel function composition. The result of the second function is evaluated using the given strategy, in parallel with the application of the first function.

(-|) :: (a -> b) -> Strategy b -> (b -> c) -> a -> cSource

Sequential inverse function composition, for those who read their programs from left to right. The result of the first function is evaluated using the given strategy, and then given to the second function.

(-||) :: (a -> b) -> Strategy b -> (b -> c) -> a -> cSource

Parallel inverse function composition, for those who read their programs from left to right. The result of the first function is evaluated using the given strategy, in parallel with the application of the second function.

Tuples

seqPair :: Strategy a -> Strategy b -> Strategy (a, b)Source

Apply two strategies to the elements of a pair sequentially from left to right.

parPair :: Strategy a -> Strategy b -> Strategy (a, b)Source

Apply two strategies to the elements of a pair in parallel.

seqTriple :: Strategy a -> Strategy b -> Strategy c -> Strategy (a, b, c)Source

Apply three strategies to the elements of a triple in sequentially from left to right.

parTriple :: Strategy a -> Strategy b -> Strategy c -> Strategy (a, b, c)Source

Apply three strategies to the elements of a triple in parallel.

Lists: Parallel Strategies

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

Applies a strategy to every element of a list in parallel.

parListN :: Integral b => b -> Strategy a -> Strategy [a]Source

Applies a strategy to the first n elements of a list in parallel.

parListNth :: Int -> Strategy a -> Strategy [a]Source

Evaluates n elements of the spine of the argument list and applies the given strategy to the nth element (if there is one) in parallel with the result. E.g. parListNth 2 [e1, e2, e3] evaluates e3.

parListChunk :: Int -> Strategy a -> Strategy [a]Source

Splits a list into chunks (sub-sequences) of length n, and applies a strategy sequentially to the elements in each chunk. The chunks are evaluated in parallel. This is useful for increasing the grain size.

parMap :: Strategy b -> (a -> b) -> [a] -> [b]Source

Applies a function to each element of a list and and evaluates the result list in parallel, using the given strategy for each element.

parFlatMap :: Strategy [b] -> (a -> [b]) -> [a] -> [b]Source

Uses parMap to apply a list-valued function to each element of a list in parallel, and concatenates the results.

parZipWith :: Strategy c -> (a -> b -> c) -> [a] -> [b] -> [c]Source

Zips together two lists using a function, and evaluates the result list in parallel.

Lists: Sequential Strategies

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

Sequentially applies a strategy to each element of a list.

seqListN :: Integral a => a -> Strategy b -> Strategy [b]Source

Sequentially applies a strategy to the first n elements of a list.

seqListNth :: Int -> Strategy b -> Strategy [b]Source

Applies a strategy to the nth element of a list (if there is one) before returning the result. E.g. seqListNth 2 [e1, e2, e3] evaluates e3.

parBuffer :: Int -> Strategy a -> [a] -> [a]Source

Parallel n-buffer function added for the revised version of the strategies paper. parBuffer supersedes the older fringeList. It has the same semantics.

Arrays

seqArr :: Ix b => Strategy a -> Strategy (Array b a)Source

Apply a strategy to all elements of an array sequentially.

parArr :: Ix b => Strategy a -> Strategy (Array b a)Source

Apply a strategy to all elements of an array in parallel.

Deprecated types and functions

sPar :: a -> Strategy bSource

A strategy corresponding to par: x `par` e = e `using` sPar x.

sPar has been superceded by sparking. Replace e `using` sPar x with e `sparking` rwhnf x.

sSeq :: a -> Strategy bSource

A strategy corresponding to seq: x `seq` e = e `using` sSeq x.

sSeq has been superceded by demanding. Replace e `using` sSeq x with e `demanding` rwhnf x.

data Assoc a b Source

Constructors

a := b 

Instances

(NFData a, NFData b) => NFData (Assoc a b) 

force :: NFData a => a -> aSource

sforce :: NFData a => a -> b -> bSource