You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently there was a request on dataHaskell gitter about creating an array in parallel, where generation of an array element depends on some of its neighbors. Here is a solution for 2D matrices:
waterfallCreate::MutablerIx2a=>Sz2-> (Maybea->Maybea->a) -> (a->a->a) ->ArrayrIx2a
waterfallCreate sz@(Sz2 m n) g f =
unsafePerformIO $
createArray_ Par sz $\scheduler marr ->do
void $ write marr (0:.0) $ g NothingNothing
forM_ (1..: m) $\i ->
unsafeWrite marr (i :.0) . g Nothing.Just=<< unsafeRead marr (i -1:.0)
forM_ (1..: n) $\j ->do
unsafeWrite marr (0:. j) . (`g`Nothing) .Just=<< unsafeRead marr (0:. j -1)
let jIter = rangeStepSize Seq j (-1) (Sz (min (m -1) j))
iforSchedulerM_ scheduler jIter $\i' -> writeF marr (i' +1)
forM_ (2..: m) $\i ->dolet jIter = rangeStepSize Seq (n -1) (-1) (Sz (min (n -1) (m - i)))
iforSchedulerM_ scheduler jIter $\i' -> writeF marr (i' + i)
where
writeF marr i j =do
left <- unsafeRead marr (i :. j -1)
top <- unsafeRead marr (i -1:. j)
unsafeWrite marr (i :. j) $ f left top
{-# INLINE writeF #-}
{-# INLINE waterfallCreate #-}
Above solution is a good demonstration of the problem, but the full solution will require:
support for arbitrary dimensions
ability to select which neighbors there is a dependency on
implemented as a stencil, not only for creation of new arrays
use same optimizations as in DW array
block wise parallelization along the diagonal, instead of single element diagonal.
The text was updated successfully, but these errors were encountered:
Recently there was a request on dataHaskell gitter about creating an array in parallel, where generation of an array element depends on some of its neighbors. Here is a solution for 2D matrices:
Above solution is a good demonstration of the problem, but the full solution will require:
DW
arrayThe text was updated successfully, but these errors were encountered: