Copyright | (c) Alexey Kuleshevich 2018 |
---|---|
License | BSD3 |
Maintainer | Alexey Kuleshevich <lehins@yandex.ru> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- data Scheduler a
- numWorkers :: Scheduler a -> Int
- scheduleWork :: Scheduler a -> IO a -> IO ()
- withScheduler :: [Int] -> (Scheduler a -> IO b) -> IO (Int, Array a)
- withScheduler' :: [Int] -> (Scheduler a -> IO b) -> IO [a]
- withScheduler_ :: [Int] -> (Scheduler a -> IO b) -> IO ()
- divideWork :: Index ix => [Int] -> ix -> (Scheduler a -> Int -> Int -> Int -> IO b) -> IO [a]
- divideWork_ :: Index ix => [Int] -> ix -> (Scheduler a -> Int -> Int -> Int -> IO b) -> IO ()
Documentation
numWorkers :: Scheduler a -> Int Source #
Helper function that allows scheduling work to be done in parallel. Use
withScheduler
to be able to get to a Scheduler
.
:: [Int] | Worker Stations, i.e. capabilities. Empty list will result in utilization of all available capabilities. |
-> (Scheduler a -> IO b) | Action that will be scheduling all the work. |
-> IO (Int, Array a) |
Run arbitrary computations in parallel. A pool of workers is initialized, unless Worker
Stations list is empty and a global worker pool is currently available. All of those workers will
be stealing work that you can schedule using scheduleWork
. The order in which work is scheduled
will be the same as the order of the resuts of those computations, stored withing the resulting
array. Size of the array, which is also the first element in the returned tuple, will match the
number of times scheduleWork
has been invoked. This function blocks until all of the submitted
jobs has finished or one of them resulted in an exception, which will be re-thrown here.
Important: In order to get work done truly in parallel, program needs to be compiled with
-threaded
GHC flag and executed with +RTS -N
.
withScheduler' :: [Int] -> (Scheduler a -> IO b) -> IO [a] Source #
Just like withScheduler
, but returns computed results in a list, instead
of an array.
withScheduler_ :: [Int] -> (Scheduler a -> IO b) -> IO () Source #
Just like withScheduler
, but discards the results.
:: Index ix | |
=> [Int] | Worker Stations (capabilities) |
-> ix | Size |
-> (Scheduler a -> Int -> Int -> Int -> IO b) | Submit function |
-> IO [a] |
Linearly (row-major first) and equally divide work among available workers. Submit function
will receive a Scheduler
, length of each chunk, total number of elements, as well as where
chunks end and slack begins. Slack work will get picked up by the first worker, that has finished
working on his chunk. Returns list with results in the same order that work was submitted