具有堆栈runghc的多核并行性 [英] multicore parallelism with stack runghc
问题描述
我一直在研究脚本,希望在其中利用多种通过将mapM
与 Async.mapConcurrently
.
I had been working on a script in which I hoped to take advantage of multiple processors in my machine by swapping out mapM
with Async.mapConcurrently
.
在那种情况下,没有观察到速度增加,我想验证runghc
确实可以利用多个内核.
Observing no speed increase in that instance, I wanted to verify that runghc
can indeed utilize multiple cores.
提供文件Foo.hs
:
import Control.Concurrent
main = print =<< Control.Concurrent.getNumCapabilities
如果我按如下方式编译文件:
If I compile the file as follows:
stack ghc -- -threaded Foo.hs
,然后按如下所示运行它:
and then run it as follows:
./Foo
它返回结果1
.这是预期的,因为没有提供RTS选项.改为按以下方式运行它:
it returns the result 1
. This is expected, as no RTS options have been supplied. Running it instead as follows:
./Foo +RTS -N
返回数字6
,因为我的计算机中有6个处理器(同意nproc
).
returns the number 6
, as there are 6 processors in my machine (agreeing with nproc
).
但是,当我像这样在解释模式"下运行脚本时:
However, when I run the script in "interpreted mode" like so:
GHCRTS="-N" stack runghc Foo.hs
它会产生以下错误文本:
It yields the following error text:
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
是否可以使用带有堆栈脚本"的多个内核?
Is it possible to utilize multiple cores with stack "scripts"?
推荐答案
感谢提出这个问题,我认为堆栈应该专门处理GHCRTS环境变量,并打开了这个问题 https://github.com/commercialhaskell/stack/pull/3445
Thanks for asking this question, I think stack should handle the GHCRTS environment variable specially, and opened this issue https://github.com/commercialhaskell/stack/issues/3444 and made this change https://github.com/commercialhaskell/stack/pull/3445
不幸的是,它不能解决这种情况,因为runghc
本身(ghc)将处理GHCRTS
,并且它不是由线程运行时构建的.因此无法使用环境变量解决方案.
Unfortunately, it does not solve this case, because runghc
itself (ghc) will process GHCRTS
, and it is not built with the threaded runtime. So the environment variable solution cannot be used.
我认为应该为stack script --compile
提供-with-rtsopts -N
标志,但这似乎不起作用,需要进一步调查.这不适用于runghc
,因为它使用了解释器.
I think it should be possible to provide -with-rtsopts -N
flag to stack script --compile
, but that doesn't seem to be working, needs further investigation. This doesn't work with runghc
, because it uses the interpreter.
这篇关于具有堆栈runghc的多核并行性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!