scc-0.5: Streaming component combinatorsSource codeContentsIndex
Control.Concurrent.Configuration
Contents
The Component type
Utility functions
Constructors
Description
This module can be used to optimize any complex computation that can be broken down into parallelizable sub-computations. The computations in question may be pure values, monadic values, list or stream transformations or anything else provided that it's parallelizable and has a relatively predictable computation cost. Each elementary sub-computation needs to be packaged as a Component using the constructor atomic. Sub-computations can then be combined into larger computations using the other constructors.
Synopsis
data Component c = Component {
name :: String
subComponents :: [AnyComponent]
maxUsableThreads :: Int
usingThreads :: Int -> Component c
usedThreads :: Int
cost :: Int
with :: c
}
showComponentTree :: forall c. Component c -> String
atomic :: String -> Int -> c -> Component c
lift :: Int -> String -> (c1 -> c2) -> Component c1 -> Component c2
liftParallelPair :: String -> (Bool -> c1 -> c2 -> c3) -> Component c1 -> Component c2 -> Component c3
liftSequentialPair :: String -> (c1 -> c2 -> c3) -> Component c1 -> Component c2 -> Component c3
parallelRouterAndBranches :: String -> (Bool -> c1 -> c2 -> c3 -> c4) -> Component c1 -> Component c2 -> Component c3 -> Component c4
recursiveComponentTree :: forall c1 c2. String -> ([(Bool, c1)] -> c2) -> Component c1 -> Component c2
The Component type
data Component c Source
A Component carries a value and metadata about the value. It can be configured to use a specific number of threads.
Constructors
Component
name :: StringReadable component name.
subComponents :: [AnyComponent]Returns the list of all children components.
maxUsableThreads :: IntReturns the maximum number of threads that can be used by the component.
usingThreads :: Int -> Component cConfigures the component to use the specified number of threads. This function affects usedThreads, cost, and subComponents methods of the result, while name and maxUsableThreads remain the same.
usedThreads :: IntThe number of threads that the component is configured to use. The default number is usually 1.
cost :: IntThe cost of using the component as configured. The cost is a rough approximation of time it would take to do the job given the usedThreads.
with :: cThe content.
Utility functions
showComponentTree :: forall c. Component c -> StringSource
Show details of the given component's configuration.
Constructors
atomic :: String -> Int -> c -> Component cSource
Function atomic takes the component name and its cost creates a single-threaded component with no subcomponents.
liftSource
:: Intcombinator cost
-> Stringname
-> (c1 -> c2)combinator
-> Component c1
-> Component c2
Applies a unary combinator to the component payload. The resulting component has the original one as its subComponents, and its cost is the sum of the original component's cost and the combinator cost.
liftParallelPair :: String -> (Bool -> c1 -> c2 -> c3) -> Component c1 -> Component c2 -> Component c3Source
Combines two components into one, applying combinator to their contents. The combinator takes a flag denoting if its arguments should run in parallel. The cost and usingThreads of the result assume the parallel execution of the argument components.
liftSequentialPair :: String -> (c1 -> c2 -> c3) -> Component c1 -> Component c2 -> Component c3Source
Combines two components into one, applying combinator to their contents. The cost and usingThreads of the result assume the sequential execution of the argument components.
parallelRouterAndBranches :: String -> (Bool -> c1 -> c2 -> c3 -> c4) -> Component c1 -> Component c2 -> Component c3 -> Component c4Source
Combines three components into one. The first component runs in parallel with the latter two, which are considered alternative to each other.
recursiveComponentTree :: forall c1 c2. String -> ([(Bool, c1)] -> c2) -> Component c1 -> Component c2Source
Builds a tree of recursive components. The combinator takes a list of pairs of a boolean flag denoting whether the level should be run in parallel and the value.
Produced by Haddock version 2.7.2