Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-Core Haskell on Windows

I've been reading a number of tutorials on Haskell. However, I have not been able to get the compiled application to run on a multicore (I have an Intel Quad Core) on windows (32 bit).

I have tried a number of things:

  • ghc -O2 --make A.hs -threaded
  • ./real-par +RTS -N2
  • ./real-par +RTS -N4

But no luck.

The compiled application runs 100% on one core only.

Any ideas?

Code:

import Control.Parallel
import Control.Monad
import Text.Printf

fib :: Int -> Int
fib 0 = 0
fib 1 = 1
fib n = l `pseq` r `pseq` l+r
    where
    l = fib (n-1)
    r = fib (n-2)

main = forM_ [0..350] $ \i ->
        printf "n=%d => %d\n" i (fib i)
like image 837
cbrulak Avatar asked Mar 08 '09 05:03

cbrulak


People also ask

Why is Haskell good for concurrency?

Parallel and concurrent programming is much easier in Haskell: it's pure, which means that there are no mutations to observe and all data can be shared between threads freely; it supports modern techniques like STM (among many other options for parallel and concurrent programming);

Does Haskell support concurrency?

GHC implements some major extensions to Haskell to support concurrent and parallel programming. Let us first establish terminology: Parallelism means running a Haskell program on multiple processors, with the goal of improving performance.

Is Haskell multi threaded?

Thread primitives For explicit concurrency and/or parallelism, Haskell implementations have a light-weight thread system that schedules logical threads on the available operating system threads. These light and cheap threads can be created with forkIO.

Is Haskell single threaded?

Without -threaded , the Haskell process uses a single OS thread only, and multithreaded foreign calls are not supported.


1 Answers

Using par instead of pseq seems to fix it.

like image 109
vili Avatar answered Sep 28 '22 00:09

vili