module Data.Array.Repa.Internals.EvalChunked
( fillChunkedS
, fillChunkedP)
where
import Data.Array.Repa.Internals.Gang
import GHC.Base (remInt, quotInt)
import Prelude as P
fillChunkedS
:: Int
-> (Int -> a -> IO ())
-> (Int -> a)
-> IO ()
fillChunkedS !len !write !getElem
= fill 0
where fill !ix
| ix >= len = return ()
| otherwise
= do write ix (getElem ix)
fill (ix + 1)
fillChunkedP
:: Int
-> (Int -> a -> IO ())
-> (Int -> a)
-> IO ()
fillChunkedP !len !write !getElem
= gangIO theGang
$ \thread -> fill (splitIx thread) (splitIx (thread + 1))
where
!threads = gangSize theGang
!chunkLen = len `quotInt` threads
!chunkLeftover = len `remInt` threads
splitIx thread
| thread < chunkLeftover = thread * (chunkLen + 1)
| otherwise = thread * chunkLen + chunkLeftover
fill !ix !end
| ix >= end = return ()
| otherwise
= do write ix (getElem ix)
fill (ix + 1) end