#include "fusion-phases.h"
module Data.Array.Parallel.Unlifted.Parallel.Segmented (
mapSUP, filterSUP, packCUP,
zipWithSUP, foldlSUP, foldSUP, sumSUP, bpermuteSUP', enumFromThenToSUP, replicateSUP, indexedSUP, jsTest
) where
import Data.Array.Parallel.Unlifted.Sequential
import Data.Array.Parallel.Unlifted.Distributed
import Data.Array.Parallel.Unlifted.Parallel.Combinators (mapUP, packUP)
import Data.Array.Parallel.Unlifted.Parallel.Enum (enumFromToEachUP)
import Data.Array.Parallel.Base (
(:*:)(..), fstS, sndS, uncurryS)
jsTest as= joinSD theGang balanced $
(splitSD theGang unbalanced as)
mapSUP:: (UA a, UA b)
=> (a -> b) -> SUArr a -> SUArr b
mapSUP f as =
joinSD theGang balanced $
mapD theGang (mapSU f) $
(splitSD theGang unbalanced as)
zipWithSUP :: (UA a, UA b, UA c)
=> (a -> b -> c) -> SUArr a -> SUArr b -> SUArr c
zipWithSUP f as bs = joinSD theGang balanced
$ zipWithD theGang (zipWithSU f)
(splitSD theGang balanced as)
(splitSD theGang balanced bs)
filterSUP:: (UA e) => (e -> Bool) -> SUArr e -> SUArr e
filterSUP p xssArr =
joinSD theGang unbalanced $
mapD theGang (filterSU p) $
(splitSD theGang unbalanced xssArr)
packCUP:: (UA e) => UArr Bool -> SUArr e -> SUArr e
packCUP flags xssArr = segmentArrU newLengths flatData
where
repFlags = flattenSU $ replicateSUP (lengthsSU xssArr) flags
flatData = packUP (flattenSU xssArr) repFlags
newLengths = packUP (lengthsSU xssArr) flags
foldlSUP :: (UA a, UA b) => (b -> a -> b) -> b -> SUArr a -> UArr b
foldlSUP f z = joinD theGang unbalanced
. mapD theGang (foldlSU f z)
. splitSD theGang unbalanced
foldSUP :: (UA a, UA b) => (b -> a -> b) -> b -> SUArr a -> UArr b
foldSUP = foldlSUP
sumSUP :: (Num e, UA e) => SUArr e -> UArr e
sumSUP = foldSUP (+) 0
bpermuteSUP' :: UA a => UArr a -> SUArr Int -> SUArr a
bpermuteSUP' as = splitJoinSD theGang (bpermuteSD' theGang as)
enumFromThenToSUP :: (Enum e, UA e)
=> UArr e -> UArr e -> UArr e -> SUArr e
enumFromThenToSUP starts nexts ends =
joinSD theGang unbalanced $ mapD theGang (\t -> enumFromThenToSU (fstU t) (fstU $ sndU t) (sndU $ sndU t)) $
splitD theGang unbalanced $ zipU starts $ zipU nexts ends
replicateSUP :: UA e => UArr Int -> UArr e -> SUArr e
replicateSUP ns es =
joinSD theGang unbalanced $ mapD theGang ((uncurryS replicateSU) . unzipU) $
splitD theGang unbalanced $ zipU ns es
indexedSUP :: UA e => SUArr e -> SUArr (Int :*: e)
indexedSUP xss = segdSU xss >: zipU is xs
where
xs = concatSU xss
is = enumFromToEachUP (lengthU xs)
. zipU (replicateU (lengthSU xss) 0)
. mapUP (subtract 1)
$ lengthsSU xss