6c169f6ade2602160df2eb64145412930b0742ed
[packages/dph.git] / dph-prim-par / Data / Array / Parallel / Unlifted / Distributed / Basics.hs
1 {-# OPTIONS -Wall -fno-warn-orphans #-}
2
3 -- | Basic operations on distributed types.
4 module Data.Array.Parallel.Unlifted.Distributed.Basics
5 (eqD, neqD, toD, fromD)
6 where
7 import Data.Array.Parallel.Unlifted.Distributed.Gang
8 import Data.Array.Parallel.Unlifted.Distributed.Types
9 import Data.Array.Parallel.Unlifted.Distributed.Combinators
10 import Data.Array.Parallel.Unlifted.Distributed.Scalars
11 import Control.Monad ( zipWithM_ )
12
13 here :: String -> String
14 here s = "Data.Array.Parallel.Unlifted.Distributed.Basics." ++ s
15
16
17 -- | Test whether to distributed values are equal.
18 -- This requires a 'Gang' and hence can't be defined in terms of 'Eq'.
19 eqD :: (Eq a, DT a) => Gang -> Dist a -> Dist a -> Bool
20 eqD g dx dy
21 = andD g (zipWithD g (==) dx dy)
22
23
24 -- | Test whether to distributed values are not equal.
25 -- This requires a 'Gang' and hence can't be defined in terms of 'Eq'.
26 neqD :: (Eq a, DT a) => Gang -> Dist a -> Dist a -> Bool
27 neqD g dx dy
28 = orD g (zipWithD g (/=) dx dy)
29
30
31 -- | Generate a distributed value from the first @p@ elements of a list.
32 --
33 -- * For debugging only, don't use in production code.
34 toD :: DT a => Gang -> [a] -> Dist a
35 toD g xs = newD g (\md -> zipWithM_ (writeMD md) [0 .. gangSize g - 1] xs)
36
37
38 -- | Yield all elements of a distributed value.
39 --
40 -- * For debugging only, don't use in production code.
41 fromD :: DT a => Gang -> Dist a -> [a]
42 fromD g dt
43 = checkGangD (here "fromDT") g dt
44 $ map (indexD (here "fromD") dt)
45 [0 .. gangSize g - 1]
46