为什么必须同时使用编译器标志和运行时标志才能在 Haskell 中获得多核支持?

发布于 2024-09-18 19:49:14 字数 500 浏览 3 评论 0原文

Haskell wiki 显示您需要同时设置编译标志和运行时标志才能获得多核支持。为什么使用该库不足以在编译时获得正确的行为?为什么运行时可执行文件无法检测到它是使用 -threaded 编译的并使用系统上的所有内核,除非另有指定?我认为默认打开这些会更好。然后可能会有关闭或修改这些功能的标志。

http://www.haskell.org/haskellwiki/GHC/Concurrency#Multicore_GHC说:

  • 使用 -threaded 开关编译您的程序。
  • 例如,使用 +RTS -N2 运行程序以使用 2 个线程。您应该使用等于计算机上 CPU 核心数量的 -N 值(不包括超线程核心)。


    必须在编译时和运行时再次设置标志似乎有点麻烦。这些标志是为 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:

  • Compile your program using the -threaded switch.
  • Run the program with +RTS -N2 to use 2 threads, for example. You should use a -N value equal to the number of CPU cores on your machine (not including Hyper-threading cores).


    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 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(3

    落在眉间の轻吻 2024-09-25 19:49:15

    当你开发程序时,额外的 +RTS ... 应该不是什么大问题(尽管我承认当我第一次拿起 Haskell 时这让我感到很奇怪)。对于最终(已发布)的二进制文件,您可以将其与静态 RTS 选项链接(GHC 手册),方法是提供包含 char *ghc_rts_opts = "-N"; 的 C 文件。

    编辑:更新 GHC 7.x 的这个问题,现在有一种在编译时指定 RTS 选项的方法:

    ghc -threaded -rtsopts -with-rtsopts=-N
    

    这 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 containing char *ghc_rts_opts = "-N";.

    EDIT: Updating this question for GHC 7.x, there is now a way to specify RTS options at compile time:

    ghc -threaded -rtsopts -with-rtsopts=-N
    

    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 where x is a number to manually control the number of OS threads).

    荆棘i 2024-09-25 19:49:15

    为什么运行时可执行文件无法检测到它是使用 -threaded 编译的并使用系统上的所有内核,除非另有指定?

    这是一个有趣的功能请求!

    您可以在 GHC 功能跟踪器上请求:http://hackage.haskell.org/ trac/ghc/wiki/ReportABug

    Why can't the run-time executable detect it was compiled with -threaded and use all cores on the system unless otherwise specified?

    That's an interesting feature request!

    You could ask for it on the GHC feature tracker: http://hackage.haskell.org/trac/ghc/wiki/ReportABug

    隐诗 2024-09-25 19:49:15

    来自 GHC 用户指南(版本 6.12.1):

    省略x,即+RTS -N -RTS,让运行时根据处理器数量选择x本身的值在你的机器上。

    我想除了作者对默认值应该是什么的看法之外,没有什么具体的理由不能将其设为默认值。 (请注意,这也会启用并行 GC,但有时这可能不是您所希望的默认情况。)

    From GHC User guide (version 6.12.1):

    Omitting x, i.e. +RTS -N -RTS, lets the runtime choose the value of x itself based on how many processors are in your machine.

    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.)

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文