Hoogle Search

Within LTS Haskell 24.6 (ghc-9.10.2)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. iforWS :: forall r ix b r' a s m . (Source r' a, Manifest r b, Index ix, MonadUnliftIO m, PrimMonad m) => WorkerStates s -> Array r' ix a -> (ix -> a -> s -> m b) -> m (Array r ix b)

    massiv Data.Massiv.Array

    Same as imapWS, but with source array and mapping action arguments flipped.

  2. generateArrayLinearWS :: forall r ix e s m . (Manifest r e, Index ix, MonadUnliftIO m, PrimMonad m) => WorkerStates s -> Sz ix -> (Int -> s -> m e) -> m (Array r ix e)

    massiv Data.Massiv.Array.Manifest

    Same as generateArrayWS, but use linear indexing instead.

  3. generateArrayLinearWS :: forall r ix e s m . (Manifest r e, Index ix, MonadUnliftIO m, PrimMonad m) => WorkerStates s -> Sz ix -> (Int -> s -> m e) -> m (Array r ix e)

    massiv Data.Massiv.Array.Mutable

    Same as generateArrayWS, but use linear indexing instead.

  4. data SchedulerWS ws a

    massiv Data.Massiv.Core

    This is a wrapper around Scheduler, but it also keeps a separate state for each individual worker. See withSchedulerWS or withSchedulerWS_ for ways to construct and use this data type.

  5. data SchedulerWS ws a

    scheduler Control.Scheduler

    This is a wrapper around Scheduler, but it also keeps a separate state for each individual worker. See withSchedulerWS or withSchedulerWS_ for ways to construct and use this data type.

  6. unwrapSchedulerWS :: SchedulerWS ws a -> Scheduler RealWorld a

    scheduler Control.Scheduler

    Get the underlying Scheduler, which cannot access WorkerStates.

  7. withSchedulerWS :: MonadUnliftIO m => WorkerStates ws -> (SchedulerWS ws a -> m b) -> m [a]

    scheduler Control.Scheduler

    Run a scheduler with stateful workers. Throws MutexException if an attempt is made to concurrently use the same WorkerStates with another SchedulerWS.

    Examples

    A good example of using stateful workers would be generation of random number in parallel. A lof of times random number generators are not thread safe, so we can work around this problem with a separate stateful generator for each of the workers.
    >>> import Control.Monad as M ((>=>), replicateM)
    
    >>> import Control.Concurrent (yield, threadDelay)
    
    >>> import Data.List (sort)
    
    >>> -- ^ Above imports are used to make sure output is deterministic, which is needed for doctest
    
    >>> import System.Random.MWC as MWC
    
    >>> import Data.Vector.Unboxed as V (singleton)
    
    >>> states <- initWorkerStates (ParN 4) (MWC.initialize . V.singleton . fromIntegral . getWorkerId)
    
    >>> let scheduleGen scheduler = scheduleWorkState scheduler (MWC.uniform >=> \r -> yield >> threadDelay 200000 >> pure r)
    
    >>> sort <$> withSchedulerWS states (M.replicateM 4 . scheduleGen) :: IO [Double]
    [0.21734983682025255,0.5000843862105709,0.5759825622603018,0.8587171114177893]
    
    >>> sort <$> withSchedulerWS states (M.replicateM 4 . scheduleGen) :: IO [Double]
    [2.3598617298033475e-2,9.949679290089553e-2,0.38223134248645885,0.7408640677124702]
    
    In the above example we use four different random number generators from `mwc-random` in order to generate 4 numbers, all in separate threads. The subsequent call to the withSchedulerWS function with the same states is allowed to reuse the same generators, thus avoiding expensive initialization. Side note - The example presented was crafted with slight trickery in order to guarantee that the output is deterministic, so if you run instructions exactly the same way in GHCI you will get the exact same output. Non-determinism comes from thread scheduling, rather than from random number generator, because we use exactly the same seed for each worker, but workers run concurrently. Exact output is not really needed, except for the doctests to pass.

  8. withSchedulerWSR :: MonadUnliftIO m => WorkerStates ws -> (SchedulerWS ws a -> m b) -> m (Results a)

    scheduler Control.Scheduler

    Same as withSchedulerWS, except instead of a list it produces Results, which allows for distinguishing between the ways computation was terminated.

  9. withSchedulerWS_ :: MonadUnliftIO m => WorkerStates ws -> (SchedulerWS ws () -> m b) -> m ()

    scheduler Control.Scheduler

    Run a scheduler with stateful workers, while discarding computation results.

  10. evalRWS :: RWS r w s a -> r -> s -> (a, w)

    automaton Data.Automaton.Trans.RWS

    Evaluate a computation with the given initial state and environment, returning the final value and output, discarding the final state.

Page 16 of many | Previous | Next