Control.Concurrent.Configuration
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.
- 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 -> c2) -> Component c1 -> Component c2
The Component type
A Component carries a value and metadata about the value. It can be configured to use a specific number of
threads.
Constructors
| Component | |
Fields
| |
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.
Arguments
| :: Int | combinator cost |
| -> String | name |
| -> (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.