【发布时间】:2017-09-20 00:47:39
【问题描述】:
我一直在研究script,我希望通过将mapM 换成Async.mapConcurrently 来利用我机器中的多个处理器。
观察到在这种情况下速度没有增加,我想验证runghc 确实可以利用多个内核。
给定一个文件Foo.hs:
import Control.Concurrent
main = print =<< Control.Concurrent.getNumCapabilities
如果我按如下方式编译文件:
stack ghc -- -threaded Foo.hs
然后运行如下:
./Foo
它返回结果1。这是意料之中的,因为没有提供 RTS 选项。改为按如下方式运行:
./Foo +RTS -N
返回数字6,因为我的机器中有6个处理器(同意nproc)。
但是,当我像这样以“解释模式”运行脚本时:
GHCRTS="-N" stack runghc Foo.hs
它会产生以下错误文本:
Running /home/kostmo/.stack/programs/x86_64-linux/ghc-nopie-8.0.2/bin/ghc-pkg --no-user-package-db list --global exited with ExitFailure 1
ghc-pkg: the flag -N requires the program to be built with -threaded
是否可以通过堆栈“脚本”利用多个内核?
【问题讨论】:
标签: haskell parallel-processing haskell-stack