为什么必须同时使用编译器标志和运行时标志才能在 Haskell 中获得多核支持?
Haskell wiki 显示您需要同时设置编译标志和运行时标志才能获得多核支持。为什么使用该库不足以在编译时获得正确的行为?为什么运行时可执行文件无法检测到它是使用 -threaded 编译的并使用系统上的所有内核,除非另有指定?我认为默认打开这些会更好。然后可能会有关闭或修改这些功能的标志。
http://www.haskell.org/haskellwiki/GHC/Concurrency#Multicore_GHC说:
必须在编译时和运行时再次设置标志似乎有点麻烦。这些标志是为 GHC 添加并发性所做努力的残余吗?
The Haskell wiki shows that you need to both set a compilation flag and a run-time flag to get multi-core support. Why isn't using the library enough to get the correct behavior at compile time? Why can't the run-time executable detect it was compiled with -threaded and use all cores on the system unless otherwise specified? I think turning these on by default would be better. Then there could be flags to turn off or modify these features.
http://www.haskell.org/haskellwiki/GHC/Concurrency#Multicore_GHC says:
It seems somewhat onerous to have flags one must set both at compile time and again at run time. Are these flags vestigial remains of the effort to add concurrency to GHC?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当你开发程序时,额外的
+RTS ...
应该不是什么大问题(尽管我承认当我第一次拿起 Haskell 时这让我感到很奇怪)。对于最终(已发布)的二进制文件,您可以将其与静态 RTS 选项链接(GHC 手册),方法是提供包含 char *ghc_rts_opts = "-N"; 的 C 文件。编辑:更新 GHC 7.x 的这个问题,现在有一种在编译时指定 RTS 选项的方法:
这 1) 使用线程运行时系统 2) 启用 RTS 选项 3) 设置 RTS 选项以使用尽可能多的线程有可用的核心(使用
-Nx
,其中x
是手动控制操作系统线程数量的数字)。While you're developing the program the extra
+RTS ...
shouldn't be a big deal (though I admit it struck me as odd when I first picked up Haskell). For the final (shipped) binary you can link it with static RTS options (GHC manual) by providing a C file containingchar *ghc_rts_opts = "-N";
.EDIT: Updating this question for GHC 7.x, there is now a way to specify RTS options at compile time:
This 1) uses the threaded runtime system 2) Enables the RTS options 3) Sets the RTS option to use as many threads as there are cores available (use
-Nx
wherex
is a number to manually control the number of OS threads).这是一个有趣的功能请求!
您可以在 GHC 功能跟踪器上请求:http://hackage.haskell.org/ trac/ghc/wiki/ReportABug
That's an interesting feature request!
You could ask for it on the GHC feature tracker: http://hackage.haskell.org/trac/ghc/wiki/ReportABug
来自 GHC 用户指南(版本 6.12.1):
我想除了作者对默认值应该是什么的看法之外,没有什么具体的理由不能将其设为默认值。 (请注意,这也会启用并行 GC,但有时这可能不是您所希望的默认情况。)
From GHC User guide (version 6.12.1):
I suppose there's no specific reason for this not to be the default, apart from authors' vision of what should defaults be. (Note that this also enables parallel GC, which maybe sometimes isn't what you wish to be by default.)