Skip to content

@astanin /parr.hs
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Parallel strategy applied to Array
import qualified Data.Array as A
import Control.Parallel.Strategies
ack 0 n = n+1
ack m 0 = ack (m-1) 1
ack m n = ack (m-1) (ack m (n-1))
main = do
let arr = A.listArray (0,999) [1..] :: A.Array Int Int
let res = (fmap (ack 2) arr) `using` parTraversable rdeepseq
print res
{-
Speed-up ≈ 1.9. Works also with Data.Array.Unboxed.
$ ghc --make -threaded -O2 parr.hs
[1 of 1] Compiling Main ( parr.hs, parr.o )
Linking parr ...
$ time ./parr +RTS -N1 >/dev/null
real 0m7.058s
user 0m6.870s
sys 0m0.030s
$ time ./parr +RTS -N2 >/dev/null
real 0m3.649s
user 0m7.140s
sys 0m0.000s
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.