#!/usr/bin/env stack-- stack --resolver lts-8.12 script --optimize{-# OPTIONS_GHC -Wall -Werror #-}
module Main ( main ) where
import qualified Data.Array.Repa as Rimport Data.Array.Repa (Array, DIM1, (+^), D, Z(..), (:.)(..), (!))import Data.Timeimport Prelude hiding (sum)import qualified System.Random as Random
n :: Intn = round (1e6 :: Double)
addLargeRandomArrays :: Array D DIM1 Int -> Array D DIM1 IntaddLargeRandomArrays array = array +^ array' where i = array ! (Z :. 0) -- use the first element in the array as the random seed array' = R.fromListUnboxed (Z :. n) . take n $ Random.randoms (Random.mkStdGen i) -- random array
main :: IO ()main = do start <- getCurrentTime loop start zeros where zeros = R.fromFunction (Z :. n) $ const 0 -- all zeros loop prev array = do let array' = addLargeRandomArrays array sum <- (! Z) <$> R.sumP array' now <- getCurrentTime print (diffUTCTime now prev, sum) loop now array'
(1.032166806s,2800541561548865196)(1.179660843s,-2028702759150123772)(1.270479104s,4490058364035702598)(1.438625015s,3665177830385523617)(1.608387404s,7642130176018406570)(1.708253711s,4711939266492313927)(1.857334362s,-6870409763904305554)(2.05369752s,-2099373253931113423)(2.101834085s,-1376969400381574539)(2.334134717s,2918951703665812958)(2.530702978s,-1577758356363651853)(2.606746963s,7608490931496987974)(2.841643195s,3672299153820034522)(2.988611585s,1029404858630974257)(2.884691073s,-331399684382111615)(3.240190308s,-8742327991973025592)
...
--
You received this message because you are subscribed to the Google Groups "Haskell Repa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-repa+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
instance Source D a where data Array D sh a = ADelayed !sh (sh -> a)
i.e., it is just a shape and a function which can return a value of type a for each index in that shape, so in your example you're building up a function whose complexity grows linearly. To fix it, you need to force the result into some form of manifest representation, such as Unboxed. You can do this by using:
addLargeRandomArrays :: Array D DIM1 Int -> Array U DIM1 IntaddLargeRandomArrays array = computeUnboxedS (array +^ array')-- or computeUnboxedP if you find parallelism helps at this array size...
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-repa...@googlegroups.com.