Created
November 16, 2010 14:44
-
-
Save astanin/701888 to your computer and use it in GitHub Desktop.
Parallel strategy applied to Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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