haskell-cnc-0.1.3: Library for parallel programming in the Intel Concurrent Collections paradigm.




This module implements the Intel Concurrent Collections (CnC) programming model. The variations of this module (Intel.Cnc3, Intel.Cnc5, Intel.Cnc6, and Intel.Cnc8) each implement the same programming model using different runtime schedulers. All of them internally use the IO monad but expose a pure interface. (The module Intel.CncPure is an alternative implementation that exposes the same interface as this module but is internally pure.)

CnC is a data-flow like deterministic parallel programming model. To use it, one constructs a CnC graph of computation steps. Steps are arbitrary Haskell functions (which may themselves expose parallelism through par). Edges in the graph are control and data relationships, implemented by tag and item collections respectively.

A brief introduction to CnC using this module can be found at http://software.intel.com/en-us/blogs/2010/05/27/announcing-intel-concurrent-collections-for-haskell-01/. General documentation on the CnC model can be found at http://software.intel.com/en-us/articles/intel-concurrent-collections-for-cc/.



type Step a = a -> StepCode ()Source

Steps are functions that take a single tag as input and perform a computation in the StepCode monad, which may perform puts and gets.

The GraphCode monad represents computations for constructing CnC graphs.

The StepCode monad represents computations running inside individual nodes of CnC graphs (in parallel).

newItemCol :: (Eq tag, Ord tag, Show tag) => GraphCode (ItemCol tag val)Source

Construct a new item collection.

newTagCol :: GraphCode (TagCol tag)Source

Construct a new tag collection.

prescribe :: TagCol tag -> Step tag -> GraphCode ()Source

Attach a computation step to a supply of control tags. This adds a new node in the computation graph.

putt :: TagCol tag -> tag -> StepCode ()Source

Put-Tag. Push a control tag out into the computation graph.

put :: (Eq tag, Ord tag, Show tag) => ItemCol tag val -> tag -> val -> StepCode ()Source

Put an item. Subsequently, any steps waiting on the item may subsequently execute.

get :: (Eq tag, Ord tag, Show tag) => ItemCol tag val -> tag -> StepCode valSource

Get an item. Synchronous read-data operation.

initialize :: StepCode a -> GraphCode aSource

Run an initial step which populates the CnC graph with input tags and items. Presently only a single initialize is allowed within a graph execution.

finalize :: StepCode a -> GraphCode aSource

Run a final step which collects outputs of the graph that are of interest to the larger application. Presently only a single finalize is allowed within a graph execution.

runGraph :: GraphCode a -> aSource

Construct a CnC graph and execute it to completion. Completion is defined as the finalize action having completed.

itemsToList :: (Eq tag, Ord tag, Show tag) => ItemCol tag b -> StepCode [(tag, b)]Source

Convert an entire item collection into an association list. In general, this can only be done from the finalize step and requires selecting a runtime scheduler which supports quiescence, that is, a scheduler that waits for all active steps to complete before executing finalize. (Currently, all schedulers but version 3 support quiescence.)

stepPutStr :: String -> StepCode ()Source

Print a message within a step (unsafe side effect).

cncPutStr :: String -> GraphCode ()Source

Print a message within the graph construction code (unsafe side effect).

cncVariant :: StringSource

An informal identifier of the CnC version presently in use (for example, identifying a scheduler implementation).

cncFor :: Int -> Int -> (Int -> StepCode ()) -> StepCode ()Source

"cncFor start end body" runs body in parallel over the inclusive range [start..end].

Frequently, CnC graphs are serial within steps but parallel at the level of the graph. In contrast, cncFor exposes parallelism within a step. Whether the body of the parallel for is doing work, or just spawning work via putt, cncFor can help distribute the work more efficiently.

cncFor2D :: (Int, Int) -> (Int, Int) -> (Int -> Int -> StepCode ()) -> StepCode ()Source

A two dimensional loop.

Example Program

Below is a simple program that prints "Hello World 99". Item collections are indexed by string tags (keys). The CnC graph consists of one node.

myStep items tag =
  do word1 <- get items "left"
     word2 <- get items "right"
     put items "result" (word1 ++ word2 ++ show tag)

cncGraph = 
  do tags  <- newTagCol
     items <- newItemCol
     prescribe tags (myStep items)
     initialize $
        do put items "left"  "hello "
           put items "right" "world "
           putt tags 99
     finalize $ 
        do get items "result"

main = putStrLn (runGraph cncGraph)