parallel-tasks-4.0.1.0

Safe HaskellNone

Control.Concurrent.ParallelTasks.Base

Description

Module with the internal workhorse for the library, parallelTasks. You only need to use this module if you want to alter ExtendedParTaskOpts, which allows you to redirect the logging output or store information about task timing.

Synopsis

Documentation

data ExtendedParTaskOpts m a Source

Advanced options controlling the behaviour of parallel tasks. The m parameter is the monad that the tasks execute in, the a parameter is the output value of the tasks, and the b parameter is the type that is stored in the results array. It is common that either b = a or b = Maybe a.

Constructors

ExtendedParTaskOpts 

Fields

coreOpts :: ParTaskOpts m a

Core options

printTo :: forall r. (Handle -> IO r) -> IO r

Function that supplies a handle to an inner block to write messages to. To use stdout or stderr, you can just supply ($ stdout). To write to a file, use withFile "blah" WriteMode.

afterFinish :: Double -> Int -> TaskOutcome -> IO (Maybe String)

Function used to store the outcome of the task. Arguments are (in order):

  • Time that the task took to complete (in seconds)
  • Index at which to store the result (same as index of the task in the original tasks list)
  • The outcome of the task

If a String is returned, it is logged

data ParTaskOpts m a Source

Options controlling the general running of parallel tasks. The m parameter is the monad (which must be an instance of MonadIO) in which the tasks will be run, and the a parameter is the return value of the tasks.

Constructors

ParTaskOpts 

Fields

simpleOpts :: SimpleParTaskOpts

The simple options.

wrapWorker :: forall r. m (m r -> IO r)

Function to use to run the m monad on top of IO. The returned function is run at least once per worker, so should support being run multiple times in parallel, and should clean up after itself. Suitable instance for IO is simply return id.

timeLimit :: Maybe (Integer, a)

When Just, the number of microseconds to let each task run for, before assuming it will not complete, and killing it off. In the case that the task is killed off, the second part of the pair is the value that will be stored in the vector.

data SimpleParTaskOpts Source

Constructors

SimpleParTaskOpts 

Fields

numberWorkers :: Maybe Int

Number of worker threads to use. When this is Nothing, defaults to number of capabilities (see numCapabilities)

printProgress :: Maybe Int

How often to print the progress of the tasks. E.g. when Just 100, print a message roughly after the completion of every 100 tasks.

printEstimate :: Maybe Int

How often to print an estimate of the estimated completion time. E.g. when Just 100, print an estimate after the completion of every 100 tasks.

data TaskOutcome Source

Value indicating whether a task successfully completed, or was killed off for taking too long

Constructors

Success 
TookTooLong 

defaultExtendedParTaskOpts :: MonadIO m => ParTaskOpts m a -> ExtendedParTaskOpts m aSource

Default extended options. Prints messages to stderr, and writes a message when a task is killed

defaultParTaskOpts :: ParTaskOpts IO aSource

Default parallel task options. The number of workers defaults to the number of capabilities, with no time limit, and printing progress every 50 tasks and an estimated time every 200

parallelTasks :: MonadIO m => ExtendedParTaskOpts m a -> [m a] -> m (IOVector a)Source

Runs the given set of computations in parallel, and once they are all finished, returns their results. Note that they won't all be run in parallel from the start; rather, a set of workers will be spawned that work their way through the (potentially large) set of jobs.