1 -----------------------------------------------------------------------------
3 -- Module : Control.Parallel
4 -- Copyright : (c) The University of Glasgow 2001
5 -- License : BSD-style (see the file libraries/base/LICENSE)
7 -- Maintainer : libraries@haskell.org
8 -- Stability : experimental
9 -- Portability : non-portable
11 -- Parallel Constructs
13 -----------------------------------------------------------------------------
15 module Control.Parallel (
16 par, seq -- re-exported
17 #if defined(__GRANSIM__)
18 , parGlobal, parLocal, parAt, parAtAbs, parAtRel, parAtForNow
24 #ifdef __GLASGOW_HASKELL__
25 import qualified GHC.Conc ( par )
28 #if defined(__GRANSIM__)
30 import PrelErr ( parError )
31 import PrelGHC ( parGlobal#, parLocal#, parAt#, parAtAbs#, parAtRel#, parAtForNow# )
35 {-# INLINE parGlobal #-}
36 {-# INLINE parLocal #-}
38 {-# INLINE parAtAbs #-}
39 {-# INLINE parAtRel #-}
40 {-# INLINE parAtForNow #-}
41 parGlobal :: Int -> Int -> Int -> Int -> a -> b -> b
42 parLocal :: Int -> Int -> Int -> Int -> a -> b -> b
43 parAt :: Int -> Int -> Int -> Int -> a -> b -> c -> c
44 parAtAbs :: Int -> Int -> Int -> Int -> Int -> a -> b -> b
45 parAtRel :: Int -> Int -> Int -> Int -> Int -> a -> b -> b
46 parAtForNow :: Int -> Int -> Int -> Int -> a -> b -> c -> c
48 parGlobal (I# w) (I# g) (I# s) (I# p) x y = case (parGlobal# x w g s p y) of { 0# -> parError; _ -> y }
49 parLocal (I# w) (I# g) (I# s) (I# p) x y = case (parLocal# x w g s p y) of { 0# -> parError; _ -> y }
51 parAt (I# w) (I# g) (I# s) (I# p) v x y = case (parAt# x v w g s p y) of { 0# -> parError; _ -> y }
52 parAtAbs (I# w) (I# g) (I# s) (I# p) (I# q) x y = case (parAtAbs# x q w g s p y) of { 0# -> parError; _ -> y }
53 parAtRel (I# w) (I# g) (I# s) (I# p) (I# q) x y = case (parAtRel# x q w g s p y) of { 0# -> parError; _ -> y }
54 parAtForNow (I# w) (I# g) (I# s) (I# p) v x y = case (parAtForNow# x v w g s p y) of { 0# -> parError; _ -> y }
58 -- Maybe parIO and the like could be added here later.
60 -- | Indicates that it may be beneficial to evaluate the first
61 -- argument in parallel with the second. Returns the value of the
64 -- @a `par` b@ is exactly equivalent semantically to @b@.
66 -- @par@ is generally used when the value of @a@ is likely to be
67 -- required later, but not immediately. Also it is a good idea to
68 -- ensure that @a@ is not a trivial computation, otherwise the cost of
69 -- spawning it in parallel overshadows the benefits obtained by
70 -- running it in parallel.
72 -- Note that actual parallelism is only supported by certain
73 -- implementations (GHC with the @-threaded@ option, and GPH, for
74 -- now). On other implementations, @par a b = b@.
77 #ifdef __GLASGOW_HASKELL__
80 -- For now, Hugs does not support par properly.