aboutsummaryrefslogtreecommitdiffstats
path: root/app/Parallel.hs
blob: 168736428d885fe9bba1179f7fbe603b27c4f300 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
module Parallel (parMapM, parSequence) where

import Control.Concurrent.ParallelIO.Local (parallel, withPool)
import GHC.Conc (getNumProcessors)

parMapM :: (a -> IO b) -> [a] -> IO [b]
parMapM f xs = do
  n <- getNumProcessors
  withPool n $ \pool -> parallel pool (map f xs)

parSequence :: [IO a] -> IO [a]
parSequence xs = do
  n <- getNumProcessors
  withPool n $ \pool -> parallel pool xs