[Haskell-cafe] Repa: traverse delayed array multiple times

Dominic Steinitz dominic at steinitz.org
Mon Jan 14 09:08:24 CET 2013


Andrey Yankin <yankin013 <at> gmail.com> writes:

> 
> 
> Greetings to all!
> 
repa?I wrote this rough sketch that shows what I am into. Apparently, program 
is severely slow. I think reason is:"Every time an element is requested from a 
delayed array it is calculated
>  anew, which means that delayed arrays are inefficient when the data is 
> needed multiple 
times"(http://www.haskell.org/haskellwiki/Numeric_Haskell:_A_Repa_Tutorial).I 
started diving into Guiding Parallel Array Fusion with Indexed Types mentioned 
there. Is it a right place to find any answer to my question?
> 

It's certainly possible to do this in repa. As I understand it, that is pretty 
much what repa is for. I'm not sure about your explanation for the slowdown 
although it sounds plausible.

I amended your code slightly and it runs pretty quickly for me using my 2 
processors!

updater :: Source r Int => Array r DIM2 Int -> Array D DIM2 Int
updater a = traverse a id step

updaterM :: Monad m => Int -> Array U DIM2 Int -> m (Array U DIM2 Int)
updaterM n = foldr (>=>) return (replicate n (computeP . updater))

and replace

  g <- computeP $ accumulate n grid :: IO (Array U DIM2 Int)

by

  g <- updaterM n grid

BTW I think you can use stencils for what you are doing (I assume it is some 
sort of relaxation method) as the coefficients are constant. I think this 
should speed things up further as you won't be testing the boundary conditions 
on every loop.

Dominic.






More information about the Haskell-Cafe mailing list