Add locked zipwith code
[packages/dph.git] / dph-prim-par / Data / Array / Parallel / Unlifted / Parallel / Locked.hs
1 {-# LANGUAGE CPP #-}
2 #include "fusion-phases.h"
3
4 -- | Locked zips and zipWiths
5 module Data.Array.Parallel.Unlifted.Parallel.Locked
6 ( lockedZipWithUP
7 , lockedZipWith3UP
8 , lockedZipWith4UP
9 , lockedZipWith5UP
10 , lockedZipWith6UP
11 , lockedZipWith7UP
12 , lockedZipWith8UP)
13 where
14 import Data.Array.Parallel.Unlifted.Sequential
15 import Data.Array.Parallel.Unlifted.Distributed
16 import Data.Array.Parallel.Unlifted.Distributed.What
17 import Data.Array.Parallel.Unlifted.Sequential.Vector as Seq
18
19
20 -- Locked ZipWiths ------------------------------------------------------------
21 lockedZipWithUP
22 :: (Unbox a, Unbox b, Unbox c)
23 => (a -> b -> c)
24 -> Vector a -> Vector b
25 -> Vector c
26
27 lockedZipWithUP f as bs
28 = joinD theGang balanced
29 $ mapD (What "lockedZipWithP") theGang
30 (\(a, b) -> lockedZipWithSU f a b)
31 $ zipD (splitD theGang balanced as)
32 (splitD theGang balanced bs)
33 {-# INLINE_UP lockedZipWithUP #-}
34
35
36 lockedZipWith3UP
37 :: (Unbox a, Unbox b, Unbox c, Unbox d)
38 => (a -> b -> c -> d)
39 -> Vector a -> Vector b -> Vector c
40 -> Vector d
41
42 lockedZipWith3UP f as bs cs
43 = joinD theGang balanced
44 $ mapD (What "lockedWith3P") theGang
45 (\(a, b, c) -> lockedZipWith3SU f a b c)
46 $ zip3D (splitD theGang balanced as)
47 (splitD theGang balanced bs)
48 (splitD theGang balanced cs)
49 {-# INLINE_UP lockedZipWith3UP #-}
50
51
52 lockedZipWith4UP
53 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e)
54 => (a -> b -> c -> d -> e)
55 -> Vector a -> Vector b -> Vector c -> Vector d
56 -> Vector e
57
58 lockedZipWith4UP f as bs cs ds
59 = joinD theGang balanced
60 $ mapD (What "lockedWith4P") theGang
61 (\((a, b), c, d) -> lockedZipWith4SU f a b c d)
62 $ zip3D (zipD (splitD theGang balanced as)
63 (splitD theGang balanced bs))
64 (splitD theGang balanced cs)
65 (splitD theGang balanced ds)
66 {-# INLINE_UP lockedZipWith4UP #-}
67
68
69 lockedZipWith5UP
70 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f)
71 => (a -> b -> c -> d -> e -> f)
72 -> Vector a -> Vector b -> Vector c -> Vector d
73 -> Vector e
74 -> Vector f
75
76 lockedZipWith5UP fn as bs cs ds es
77 = joinD theGang balanced
78 $ mapD (What "lockedWith5P") theGang
79 (\((a, b), (c, d), e) -> lockedZipWith5SU fn a b c d e)
80 $ zip3D (zipD (splitD theGang balanced as)
81 (splitD theGang balanced bs))
82 (zipD (splitD theGang balanced cs)
83 (splitD theGang balanced ds))
84 (splitD theGang balanced es)
85 {-# INLINE_UP lockedZipWith5UP #-}
86
87
88 lockedZipWith6UP
89 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f, Unbox g)
90 => (a -> b -> c -> d -> e -> f -> g)
91 -> Vector a -> Vector b -> Vector c -> Vector d
92 -> Vector e -> Vector f
93 -> Vector g
94
95 lockedZipWith6UP fn as bs cs ds es fs
96 = joinD theGang balanced
97 $ mapD (What "lockedWith6P") theGang
98 (\as bs cs ds es fs -> lockedZip6SU fn)
99 $ splitD theGang balanced
100 (lockedZip6SU as bs cs ds es fs)
101 {-# INLINE_UP lockedZipWith6UP #-}
102
103 zipWith6D
104
105
106
107 lockedZipWith7UP
108 :: ( Unbox a, Unbox b, Unbox c, Unbox d
109 , Unbox e, Unbox f, Unbox g, Unbox h)
110 => (a -> b -> c -> d -> e -> f -> g -> h)
111 -> Vector a -> Vector b -> Vector c -> Vector d
112 -> Vector e -> Vector f -> Vector g
113 -> Vector h
114
115 lockedZipWith7UP fn as bs cs ds es fs gs
116 = joinD theGang balanced
117 $ mapD (What "lockedWith7P") theGang
118 (\((a, b, c), (d, e), (f, g)) -> lockedZipWith7SU fn a b c d e f g)
119 $ zip3D (zip3D (splitD theGang balanced as)
120 (splitD theGang balanced bs)
121 (splitD theGang balanced cs))
122 (zipD (splitD theGang balanced ds)
123 (splitD theGang balanced es))
124 (zipD (splitD theGang balanced fs)
125 (splitD theGang balanced gs))
126 {-# INLINE_UP lockedZipWith7UP #-}
127
128
129 lockedZipWith8UP
130 :: ( Unbox a, Unbox b, Unbox c, Unbox d
131 , Unbox e, Unbox f, Unbox g, Unbox h, Unbox i)
132 => (a -> b -> c -> d -> e -> f -> g -> h -> i)
133 -> Vector a -> Vector b -> Vector c -> Vector d
134 -> Vector e -> Vector f -> Vector g -> Vector h
135 -> Vector i
136
137 lockedZipWith8UP fn as bs cs ds es fs gs hs
138 = joinD theGang balanced
139 $ mapD (What "lockedWith8P") theGang
140 (\((a, b, c), (d, e), (f, g, h)) -> lockedZipWith8SU fn a b c d e f g h)
141 $ zip3D (zip3D (splitD theGang balanced as)
142 (splitD theGang balanced bs)
143 (splitD theGang balanced cs))
144 (zipD (splitD theGang balanced ds)
145 (splitD theGang balanced es))
146 (zip3D (splitD theGang balanced fs)
147 (splitD theGang balanced gs)
148 (splitD theGang balanced hs))
149 {-# INLINE_UP lockedZipWith8UP #-}
150