Multicore programming in Haskell - Control.Parallel

后端 未结 4 885
误落风尘
误落风尘 2021-02-08 04:25

I\'m trying to learn how to use the Control.Parallel module, but I think I didn\'t get it right.

I\'m trying to run the following code (fibs.hs).

4条回答
  •  忘了有多久
    2021-02-08 04:29

    Re (1): par allows a to be computed in another thread. I am guessing here, but I think pseq behaves much like a seq: that it forces the first result to be computed first (well, seq isn't guaranteed to do this, but in practice on GHC it does). So in this case, the computation of a is forked off as one thread, and the other thread computes b and then sums a and b.

    Re (2): This is a pretty trivial computation being forked off to other threads; it's probably just as fast for the cpu to just calculate it itself. I'm betting the overhead of threads is hurting almost as much as helping for this simple computation.

提交回复
热议问题