-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Concurrent utilities
--
-- Release notes for version 0.4.5.0:
--
--
-- - The countA operation on .DataParallel didn't fuse very well. It
-- has been replaced by a more general countA that generates a list of
-- indices.
-- - Removed most code for Channel library; it now passes through to
-- Chan.
--
@package ConcurrentUtils
@version 0.4.5.0
-- | Implements rudimentary thread pools.
module Control.CUtils.ThreadPool
-- | Thread pools support some standard operations...
class ThreadPool pool
addToPool :: ThreadPool pool => pool -> IO () -> IO ()
class Interruptible pool
stopPool :: Interruptible pool => pool -> IO ()
data NoPool
NoPool :: NoPool
data BoxedThreadPool
[BoxedThreadPool] :: (ThreadPool pool) => pool -> BoxedThreadPool
instance Control.CUtils.ThreadPool.ThreadPool Control.CUtils.ThreadPool.Pool
instance Control.CUtils.ThreadPool.Interruptible Control.CUtils.ThreadPool.Pool
instance Control.CUtils.ThreadPool.ThreadPool Control.CUtils.ThreadPool.NoPool
instance Control.CUtils.ThreadPool.ThreadPool Control.CUtils.ThreadPool.BoxedThreadPool
module Control.CUtils.StrictArrow
-- | Arrows that have a strictness effect.
class Strict a
force :: Strict a => a t u -> a t u
instance Control.CUtils.StrictArrow.Strict (->)
instance GHC.Base.Monad m => Control.CUtils.StrictArrow.Strict (Control.Arrow.Kleisli m)
-- | Functional channels | A channel data type which allows consumers to
-- hold references to different points in a stream at the same time.
-- Elements of a channel are kept alive only so long as there are
-- references pointing before those elements; producers on a channel are
-- kept alive only so long as there are consumers.
module Control.CUtils.FChan
data Chan t
-- | Construct a channel from a list.
listToChan :: [t] -> Chan t
chanContents :: Chan t -> IO [t]
-- | Thrown by the writer function.
data DoneReadingException
DoneReadingException :: DoneReadingException
-- | Take the first element from a channel, and a channel representing the
-- remainder of the output.
takeChan :: Chan t -> IO (t, Chan t)
tryTakeChan :: Chan t -> IO (Maybe (t, Chan t))
-- | Create a new channel. The first return value is a function that can be
-- used to add values to the channel. The second return value is the
-- channel itself.
newChan :: IO (t -> IO (), Chan t)
-- | The first return value is a procedure that returns values from the
-- channel successively, starting from the position of the parameter
-- channel. The second thunk can be used to retrieve the position of the
-- channel after all the reads made using the first thunk.
makeConsumer :: Chan b -> IO (IO b, IO (Chan b))
-- | Create a channel which is initially empty, but accumulates new
-- elements.
dupChan :: Chan a -> IO (Chan a)
instance GHC.Show.Show Control.CUtils.FChan.DoneReadingException
instance GHC.Exception.Exception Control.CUtils.FChan.DoneReadingException
module Control.CUtils.Dyn
data Dyn
value :: (Typeable t) => Dyn -> Maybe t
makeDyn :: (Eq t, Show t, Typeable t) => t -> Dyn
determineType :: Dyn -> TypeRep
instance GHC.Classes.Eq Control.CUtils.Dyn.Dyn
instance GHC.Show.Show Control.CUtils.Dyn.Dyn
-- | A module of concurrent higher order functions.
module Control.CUtils.Conc
-- | For exceptions caused by caller code.
data ExceptionList
ExceptionList :: [SomeException] -> ExceptionList
-- | For internal errors. If a procedure throws this, some threads it
-- created may still be running. It is thrown separately from
-- ExceptionList.
data ConcException
ConcException :: ConcException
assocFold :: (?pool :: BoxedThreadPool, Concurrent (Kleisli m)) => (b -> b -> m b) -> (c -> b) -> (b, Array Int c) -> m b
-- | A type class of arrows that support some form of concurrency.
class Concurrent a
-- | Runs an associative folding function on the given array. Note: this
-- function only spawns enough threads to make effective use of the
-- capabilities. Any two list elements may be processed
-- sequentially or concurrently. To get parallelism, you have to set the
-- numCapabilities value, e.g. using GHC's +RTS -N flag.
arr_assocFold :: (Concurrent a, ?pool :: BoxedThreadPool) => a (b, b) b -> (c -> b) -> a (b, Array Int c) b
-- | The first parameter is the number of computations which are indexed
-- from 0 to n - 1.
arr_concF_ :: (Concurrent a, ?seq :: Bool, ?pool :: BoxedThreadPool) => a (t, Int) () -> a (t, Int) ()
arr_concF :: (Concurrent a, ?seq :: Bool, ?pool :: BoxedThreadPool) => a (u, Int) t -> a (u, Int) (Array Int t)
arr_oneOfF :: Concurrent a => a (u, Int) b -> a (u, Int) b
concF_ :: (?seq :: Bool, ?pool :: BoxedThreadPool, Concurrent (Kleisli m)) => Int -> (Int -> m ()) -> m ()
concF :: (?seq :: Bool, ?pool :: BoxedThreadPool, Concurrent (Kleisli m)) => Int -> (Int -> m t) -> m (Array Int t)
conc_ :: (?seq :: Bool, ?pool :: BoxedThreadPool, Concurrent (Kleisli m)) => Array Int (m ()) -> m ()
-- | The next function takes an implicit parameter ?seq. Set it to True if
-- you want to only spawn threads for the capabilities (same as
-- assocFold; good for speed). If you need all the actions to be
-- executed concurrently, set it to False.
conc :: (?seq :: Bool, ?pool :: BoxedThreadPool) => Array Int (IO e) -> IO (Array Int e)
-- | Version of concF specialized for two computations.
concP :: (Concurrent (Kleisli m), ?pool :: BoxedThreadPool, Monad m) => m t1 -> m t -> m (t1, t)
progressConcF :: (?seq :: Bool, ?pool :: BoxedThreadPool) => Int -> (Int -> IO t) -> IO (Array Int t)
oneOfF :: Concurrent (Kleisli m) => Int -> (Int -> m b) -> m b
-- | Runs several computations in parallel, and returns one of their
-- results (terminating the other computations).
oneOf :: Array Int (IO a) -> IO a
instance GHC.Show.Show Control.CUtils.Conc.ConcException
instance GHC.Show.Show Control.CUtils.Conc.ExceptionList
instance GHC.Exception.Exception Control.CUtils.Conc.ExceptionList
instance GHC.Exception.Exception Control.CUtils.Conc.ConcException
instance Control.CUtils.Conc.Concurrent (Control.Arrow.Kleisli GHC.Types.IO)
instance Control.CUtils.Conc.Concurrent (->)
-- | An implementation of nested data parallelism (due to Simon Peyton
-- Jones et al)
module Control.CUtils.DataParallel
data Equal t u
[Equal] :: Equal t t
data ArrC t
newArray :: [e] -> Array Int e
inject :: Array Int e -> ArrC e
project :: ArrC t -> Array Int t
data Structural a t u
-- | The A arrow includes a set of primitives that may be executed
-- concurrently. Programs are incrementally optimized as they are put
-- together. A program may be optimized once, and the result saved for
-- repeated use.
--
-- Notes:
--
--
-- - The exact output of the optimizer is subject to change.
-- - The program must be a finite data structure, or optimization may
-- diverge. Therefore recursive definitions do not work, unless something
-- is done to limit the depth.
--
data A a t u
-- | Obtain a Structural program from an A program.
unA :: Category * t2 => A t2 t1 t -> Structural t2 t1 t
mapA' :: (ArrowChoice a) => A a t u -> A a (ArrC t) (ArrC u)
liftA :: (Category a) => a t u -> A a t u
-- | Supplies an array of a repeated value paired with the index of each
-- element. Arguably adjacent countAs should fuse; however this is
-- hard to implement, so I have opted to provide a more powerful
-- countA that works on arrays of indices; it generates arrays of
-- indices lexicographically ordered.
countA :: (ArrowChoice a) => A a (t, [Int]) (ArrC (t, [Int]))
countA' :: (ArrowChoice a) => A a (t, Int) (ArrC (t, Int))
splitOff :: (ArrowChoice a) => A a ((t1, t2), u) ((t1, u), (t2, u))
assoc :: (ArrowChoice a) => A a ((t, u), v) (t, (u, v))
-- | Access one index of an array.
indexA :: (ArrowChoice a) => A a (ArrC t, Int) t
-- | An operation analogous to zip, zipA combines two packed
-- arrays into a single array element by element.
zipA :: (ArrowChoice a) => A a (ArrC t, ArrC u) (ArrC (t, u))
-- | unzipA and zipA are inverses.
unzipA :: (ArrowChoice a) => A a (ArrC (t, u)) (ArrC t, ArrC u)
-- | Concatenation flattens out nested layers of arrays. The key operation
-- used to implement is erasing marks; erasing marks throws away the
-- structure that would delineate the edges of arrays; effectively
-- flattening them into one array. The operation is divided into packing
-- and erasing marks, in the hope that the packing stage will fuse with
-- an adjacent unpack.
concatA :: (Category a) => A a (ArrC (ArrC t)) (ArrC t)
-- | Replacements for common arrow functions make fusing work better.
dupA :: (Category a) => A a t (t, t)
fstA :: (Category a) => A a (t, u) t
sndA :: (Category a) => A a (t, u) u
-- | Evaluates arrows.
eval :: (?pool :: BoxedThreadPool, ArrowChoice a, Strict a, Concurrent a) => Structural a t u -> a t u
nQueens :: Int -> A (->) () (ArrC [Int])
sorting :: (Ord t) => Int -> A (->) (ArrC t) (ArrC t)
permute :: A (->) (ArrC Int) (ArrC Int)
dotProduct :: (Num t) => A (->) (ArrC t, ArrC t) t
transpose' :: A (->) (ArrC (ArrC t)) (ArrC (ArrC t))
instance GHC.Base.Functor Control.CUtils.DataParallel.ArrC
instance GHC.Base.Functor Control.CUtils.DataParallel.Tree
instance GHC.Show.Show (t -> u)
instance Control.Category.Category a => Control.Category.Category (Control.CUtils.DataParallel.A a)
instance Control.Arrow.ArrowChoice a => Control.Arrow.Arrow (Control.CUtils.DataParallel.A a)
instance Control.Arrow.ArrowChoice a => Control.Arrow.ArrowChoice (Control.CUtils.DataParallel.A a)
instance GHC.Show.Show (Control.CUtils.DataParallel.Structural a t u)
instance Control.Category.Category a => Control.Category.Category (Control.CUtils.DataParallel.Structural a)
instance (Control.CUtils.Conc.Concurrent a, Control.CUtils.StrictArrow.Strict a, Control.Arrow.ArrowChoice a, Control.Arrow.ArrowApply a) => Control.Arrow.ArrowApply (Control.CUtils.DataParallel.A a)
module Data.BellmanFord
keys :: [(a, b)] -> [a]
mapWithKey :: (t -> u -> v) -> Array Int (t, u) -> Array Int (t, v)
-- | Edge relaxation.
relaxEdge :: (Eq t, Eq a1, Fractional b, Ord b) => Array i (a1, (a, b)) -> [((a1, t), b)] -> t -> (a1, b) -> (a1, b)
-- | The Bellman-Ford shortest path algorithm.
bellmanFord :: (Eq a) => [((a, a), Double)] -> a -> [(a, (a, Double))]
retrievePath :: (Eq a) => [(a, (a, Double))] -> a -> a -> [a]
-- | Cycle finding
cycles :: (Eq a) => [((a, a), ())] -> a -> Maybe a
-- | Automatic deadlock avoidance.
module Control.CUtils.Deadlock
class AbstractLock l
lock :: AbstractLock l => l -> IO ()
unlock :: AbstractLock l => l -> IO ()
data BoxedAbstractLock
[BoxedAbstractLock] :: (AbstractLock l, Eq l, Hashable l, Typeable l) => l -> BoxedAbstractLock
data LockSafetyException
LockTakenTwice :: LockSafetyException
LockNotDeclared :: LockSafetyException
-- | Acquire a lock. In order to implement deadlock avoidance, the function
-- acquire requires that all locks a thread may take while holding
-- the given lock are annotated in parameter possiblyAcq.
--
-- While programs with locks have rare deadlock conditions, they have
-- common lock use patterns in-thread. If we throw an exception whenever
-- lock use patterns are not properly declared, all lock use patterns
-- will show up in testing and can be annotated.
--
-- Complexity overview:
--
-- Let N = the number of locks.
--
-- Let K = the size of the largest directed component of the ownership
-- graph.
--
-- Let C = the number of capabilities.
--
-- acquire runs in O(K log N + K^3/C) time [provided C <= K].
acquire :: BoxedAbstractLock -> [BoxedAbstractLock] -> IO ()
-- | Release a lock so acquired.
--
-- release runs in O(log N) time.
release :: BoxedAbstractLock -> IO ()
-- | Test: The dining philosophers problem
test :: IO ()
instance GHC.Show.Show Control.CUtils.Deadlock.LockSafetyException
instance Control.CUtils.Deadlock.AbstractLock (GHC.MVar.MVar ())
instance GHC.Classes.Eq Control.CUtils.Deadlock.BoxedAbstractLock
instance Control.CUtils.Deadlock.AbstractLock Control.CUtils.Deadlock.BoxedAbstractLock
instance GHC.Show.Show Control.CUtils.Deadlock.BoxedAbstractLock
instance Data.Hashable.Class.Hashable Control.CUtils.Deadlock.BoxedAbstractLock
instance GHC.Show.Show (GHC.MVar.MVar t)
instance Data.Hashable.Class.Hashable (GHC.MVar.MVar t)
instance GHC.Exception.Exception Control.CUtils.Deadlock.LockSafetyException
module Control.CUtils.Channel
type Channel = Chan
-- | Lists suitable for parallel execution (taken from Hackage's monad-par
-- package). (For converting to regular lists, there is the toList
-- function in Data.Foldable.)
module Control.CUtils.AList
data AList t
Append :: (AList t) -> (AList t) -> AList t
List :: [t] -> AList t
-- | Filters the AList using a predicate.
filterAList :: (b -> Bool) -> AList b -> AList b
-- | Folds the AList with a function, that must be associative. This allows
-- parallelism to be introduced.
assocFold :: (c -> c -> c) -> AList c -> c
-- | Combine monoid elements to get a result.
monoid :: (Monoid t, Eq t) => AList t -> t
-- | Length of an AList.
lenAList :: (Num t, Eq b) => AList b -> t
-- | Find the first element satisfying a predicate.
findAList :: Eq a => (a -> Bool) -> AList a -> Maybe a
-- | Concatenate an AList of ALists.
concatAList :: Monad m => m (m b) -> m b
instance Data.Data.Data t => Data.Data.Data (Control.CUtils.AList.AList t)
instance GHC.Show.Show t => GHC.Show.Show (Control.CUtils.AList.AList t)
instance GHC.Classes.Ord t => GHC.Classes.Ord (Control.CUtils.AList.AList t)
instance GHC.Classes.Eq t => GHC.Classes.Eq (Control.CUtils.AList.AList t)
instance GHC.Base.Monad Control.CUtils.AList.AList
instance GHC.Base.MonadPlus Control.CUtils.AList.AList
instance GHC.Base.Applicative Control.CUtils.AList.AList
instance GHC.Base.Alternative Control.CUtils.AList.AList
instance GHC.Base.Functor Control.CUtils.AList.AList
instance Data.Traversable.Traversable Control.CUtils.AList.AList
instance Data.Foldable.Foldable Control.CUtils.AList.AList