Why does my parallel code behave the same as serial code?

Bellow is my code

someFunc :: IO ()
someFunc = --print $ resultPar
    print$ runEval $ (do
        fib44<- rpar (force $fib 44) 
        fib45<- rpar (force $fib 45)
        fib46<- rpar (force $fib 46)
        fib47<- rpar (force$ fib 47)
        -- rseq fib44

        -- rseq fib45
        -- rseq fib46
        rseq fib47
        return [fib44,fib45,fib46,fib47]

        resultPlain=[fib 44,fib 45,fib 46 ,fib 47]
        resultPar= parMap rpar (force.fib)  [ 44, 45, 46 , 47]
        resultSeq= parMap rseq (force.fib)  [ 44, 45, 46 , 47]

I have add -O2 -threaded to the cabal file, and I run this program with command cabal v2-run +RTS -N4.
No matter how I modify the code, it is always as slow as running line by line.
Because I have run these code line by line.

I found the problem. The parameters+RTS -N4· of this command cabal run +RTS -N4 did not work. So how to pass parameters +RTS -N4 to cabal?

You need to do:

cabal run my-program -- +RTS -N4
1 Like

Wow, it works! Thanks !