Control.Monad.Par.Scheds.Trace

monad-par-0.3.4.8: A library for parallel programming based on a monad

Safe Haskell | None
Language | Haskell98

Control.Monad.Par.Scheds.Trace

Contents

- Orphan instances

Description

This is the scheduler described in the paper "A Monad for Deterministic Parallelism". It is based on a lazy `Trace` data structure that separates the scheduler from the `Par` monad method implementations.

Synopsis

- data Par a
- runPar :: Par a -> a
- runParIO :: Par a -> IO a
- fork :: Par () -> Par ()
- data IVar a
- new :: Par (IVar a)
- newFull :: NFData a => a -> Par (IVar a)
- newFull_ :: a -> Par (IVar a)
- get :: IVar a -> Par a
- put :: NFData a => IVar a -> a -> Par ()
- put_ :: IVar a -> a -> Par ()
- spawn :: NFData a => Par a -> Par (IVar a)
- spawn_ :: Par a -> Par (IVar a)
- spawnP :: NFData a => a -> Par (IVar a)

# Documentation

data Par a #

Instances

Monad Par # |
Methods (>>=) :: Par a -> (a -> Par b) -> Par b # (>>) :: Par a -> Par b -> Par b # return :: a -> Par a # fail :: String -> Par a #
Functor Par # |
Methods fmap :: (a -> b) -> Par a -> Par b # (<$) :: a -> Par b -> Par a #
Applicative Par # |
Methods pure :: a -> Par a # (<*>) :: Par (a -> b) -> Par a -> Par b # (*>) :: Par a -> Par b -> Par b # (<*) :: Par a -> Par b -> Par a #

runPar :: Par a -> a #

Run a parallel, deterministic computation and return its result.

Note: you must NOT return an IVar in the output of the parallel computation. This is unfortunately not enforced, as it is with `runST` or with newer libraries that export a Par monad, such as `lvish`.

runParIO :: Par a -> IO a #

A version that avoids an internal `unsafePerformIO` for calling contexts that are already in the `IO` monad.

Returning any value containing IVar is still disallowed, as it can compromise type safety.

fork :: Par () -> Par () #

data IVar a #

Instances

ParFuture IVar ParIO # |
Methods spawn :: NFData a => ParIO a -> ParIO (IVar a) # spawn_ :: ParIO a -> ParIO (IVar a) # get :: IVar a -> ParIO a # spawnP :: NFData a => a -> ParIO (IVar a) #
ParIVar IVar ParIO # |
Methods fork :: ParIO () -> ParIO () # new :: ParIO (IVar a) # put :: NFData a => IVar a -> a -> ParIO () # put_ :: IVar a -> a -> ParIO () # newFull :: NFData a => a -> ParIO (IVar a) # newFull_ :: a -> ParIO (IVar a) #
Eq (IVar a) # | Equality for IVars is physical equality, as with other reference types.
Methods (==) :: IVar a -> IVar a -> Bool # (/=) :: IVar a -> IVar a -> Bool #
NFData (IVar a) # |
Methods rnf :: IVar a -> () #

new :: Par (IVar a) #

Creates a new `IVar`

newFull :: NFData a => a -> Par (IVar a) #

Creates a new `IVar` that contains a value

newFull_ :: a -> Par (IVar a) #

Creates a new `IVar` that contains a value (head-strict only)

get :: IVar a -> Par a #

Read the value in an `IVar`. The `get` operation can only return when the value has been written by a prior or parallel `put` to the same `IVar`.

put :: NFData a => IVar a -> a -> Par () #

Put a value into an `IVar`. Multiple `put`s to the same `IVar` are not allowed, and result in a runtime error.

`put` fully evaluates its argument, which therefore must be an instance of `NFData`. The idea is that this forces the work to happen when we expect it, rather than being passed to the consumer of the `IVar` and performed later, which often results in less parallelism than expected.

Sometimes partial strictness is more appropriate: see `put_`.

put_ :: IVar a -> a -> Par () #

Like `put`, but only head-strict rather than fully-strict.

spawn :: NFData a => Par a -> Par (IVar a) #

spawn_ :: Par a -> Par (IVar a) #

spawnP :: NFData a => a -> Par (IVar a) #

# Orphan instances

ParFuture IVar Par # |
Methods spawn :: NFData a => Par a -> Par (IVar a) # spawn_ :: Par a -> Par (IVar a) # get :: IVar a -> Par a # spawnP :: NFData a => a -> Par (IVar a) #
ParIVar IVar Par # |
Methods fork :: Par () -> Par () # new :: Par (IVar a) # put :: NFData a => IVar a -> a -> Par () # put_ :: IVar a -> a -> Par () # newFull :: NFData a => a -> Par (IVar a) # newFull_ :: a -> Par (IVar a) #