scc-0.6.1: Streaming component combinators

Control.Concurrent.Configuration

Contents

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

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 

Fields

name :: String

Readable component name.

subComponents :: [AnyComponent]

Returns the list of all children components.

maxUsableThreads :: Int

Returns the maximum number of threads that can be used by the component.

usingThreads :: Int -> Component c

Configures 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 :: Int

The number of threads that the component is configured to use. The default number is usually 1.

cost :: Int

The 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 :: c

The content.

Instances

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

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.

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 -> 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.