{-# LANGUAGE MagicHash #-}-- | Evaluate an array in parallel in an interleaved fashion,-- with each by having each processor computing alternate elements.moduleData.Array.Repa.Eval.Interleaved(fillInterleavedP)whereimportData.Array.Repa.Eval.GangimportGHC.ExtsimportPreludeasP-- | Fill something in parallel.-- -- * The array is split into linear chunks and each thread fills one chunk.-- fillInterleavedP::Int-- ^ Number of elements.->(Int->a->IO())-- ^ Update function to write into result buffer.->(Int->a)-- ^ Fn to get the value at a given index.->IO(){-# INLINE [0] fillInterleavedP #-}fillInterleavedP!(I#len)writegetElem=gangIOtheGang$\(I#thread)->let!step=threads!start=thread!count=elemsForThreadthreadinfillstepstartcountwhere-- Decide now to split the work across the threads.!(I#threads)=gangSizetheGang-- All threads get this many elements.!chunkLenBase=len`quotInt#`threads-- Leftover elements to divide between first few threads.!chunkLenSlack=len`remInt#`threads-- How many elements to compute with this thread.elemsForThreadthread|thread<#chunkLenSlack=chunkLenBase+#1#|otherwise=chunkLenBase{-# INLINE elemsForThread #-}-- Evaluate the elements of a single chunk.fill!step!ix0!count0=goix0count0wherego!ix!count|count<=#0#=return()|otherwise=dowrite(I#ix)(getElem(I#ix))go(ix+#step)(count-#1#){-# INLINE fill #-}