2014-03-07 56 views
0

我一直在關注RWH中的concurrency chapter。我一直在嘗試本書中提到的示例程序。以下是代碼:numCapabilities不顯示正確的核心數

test.hs:

import GHC.Conc (numCapabilities) 

main = do 
    putStrLn $ "number of cores: " ++ show numCapabilities 

這是我如何執行它們:

$ ghc -c test.hs 
$ ghc -threaded -o test test.o 
$ ./test -RTS -N4 
number of cores: 1 

但我似乎有四個核心:

$ nproc 
4 
$ cat /proc/cpuinfo 
Produces a big output. But shows four processors. (0..3). 

任何我做錯了什麼想法?

+2

是不是應該是'./test + RTS -N4 -RTS'? – bheklilr

+0

@bheklilr啊是的。捂臉。 – Sibi

+1

它發生在我們所有人身上,很高興這是一個簡單的修復 – bheklilr

回答

4

Runtime system options+RTS-RTS之間支架(儘管後者可以省略)。這也是正確的RWH

$ ./NumCapabilities +RTS -N4 -RTS foo 

使用+RTS而不是-RTS

./test +RTS -N4 
+3

請注意,設置沒有具體的編號會自動檢測處理器的可用數量,例如'./test + RTS -N'。我個人覺得更合適。 –