[Haskell-beginners] parallel map/filter
Csaba Marosi
4bea6c869366227b879ffe4abad50c at gmail.com
Thu Jun 4 19:16:37 UTC 2015
Hi,
I'm trying to use parallelism in Haskell, parMap in particular.
My code is essentially this:
import Control.Parallel.Strategies
slow :: String -> (String, [Int])
fast x = (x, [0..255])
main :: IO ()
main = do
content <- readFile "4.txt" --a 327 lines long file
print $ parMap rpar slow $ lines content
For the full/compiling code, see:
https://github.com/csmarosi/cryptopals/blob/bf1ca794f897858f9008fb8740a1c3ef1997482b/s01p04.hs
What do I miss here? The code should be trivial to run on multiple
cores, but it seem to use only a single CPU core, i.e.
$ ghc -O2 -v0 -threaded --make s01p04.hs
slow gives:
$ time ./s01p04 +RTS -N2 | wc
1 1 64028
real 0m8.903s
user 0m7.888s
sys 0m1.792s
whereas fast is:
$ time ./s01p04 +RTS -N2 | wc
1 1 320787
real 0m0.016s
user 0m0.012s
sys 0m0.012s
Bonus question: is there a parallel filter?
I use Debian sid packages, ghc version 7.8.4
Some multi-threading seems to go on, since without -N2, the sys time
is below 0.1s.
BTW, the slow code use ~300K heap according to valgrind.
Thanks,
Csabi
More information about the Beginners
mailing list