3baaea34069ae20f6dde70f92175e82e7f00e692
[packages/dph.git] / dph-lifted-vseg / Data / Array / Parallel / PArray / Sums.hs
1 {-# LANGUAGE CPP #-}
2 #include "fusion-phases.h"
3
4 module Data.Array.Parallel.PArray.Sums
5 ( sumPA_double, sumPA_l_double
6 , sumPA_int, sumPA_l_int)
7 where
8 import Data.Array.Parallel.PArray.PData
9 import qualified Data.Vector as V
10 import qualified Data.Array.Parallel.Unlifted as U
11
12
13 -- Double ---------------------------------------------------------------------
14 {-# INLINE_PA sumPA_double #-}
15 sumPA_double :: PArray Double -> Double
16 sumPA_double (PArray _ (PDouble xs))
17 = U.sum xs
18
19
20 -- | Lifted sum for Doubles
21 sumPA_l_double
22 :: Int
23 -> PData (PArray Double)
24 -> PData Double
25 {-# NOINLINE sumPA_l_double #-}
26 sumPA_l_double _ (PNested vsegd datas)
27 = let -- Grab all the flat source vectors.
28 pdatas = V.map toUArrayPR datas
29
30 -- Sum up each physical segment individually.
31 psegResults = U.fold_ss (+) 0 (U.takeSSegdOfVSegd vsegd) pdatas
32
33 -- Replicate the physical results according to the vsegids.
34 vsegResults = U.bpermute psegResults (U.takeVSegidsOfVSegd vsegd)
35
36 in PDouble vsegResults
37
38
39
40 -- Int ------------------------------------------------------------------------
41 {-# INLINE_PA sumPA_int #-}
42 sumPA_int :: PArray Int -> Int
43 sumPA_int (PArray _ (PInt xs))
44 = U.sum xs
45
46
47 sumPA_l_int
48 :: Int
49 -> PData (PArray Int)
50 -> PData Int
51 {-# NOINLINE sumPA_l_int #-}
52 sumPA_l_int _ (PNested vsegd datas)
53 = let -- Grab all the flat source vectors.
54 pdatas = V.map toUArrayPR datas
55
56 -- Sum up each physical segment individually.
57 psegResults = U.fold_ss (+) 0 (U.takeSSegdOfVSegd vsegd) pdatas
58
59 -- Replicate the physical results according to the vsegids.
60 vsegResults = U.bpermute psegResults (U.takeVSegidsOfVSegd vsegd)
61
62 in PInt vsegResults