Haskell 并行程序启动参数
Haskell parallel program launch arguments
我编写了一个 Haskell 程序,它以 Unix 实用程序的方式工作 - 你启动程序,它完成工作,然后退出。
我在该程序中使用了并发,但要使其真正并发,必须分别对其进行编译,此外,让我感到惊讶的是,启动带有一些附加参数的已编译程序。
我编译它:
ghc -O2 -threaded --make Main.hs -o Main.parallel
当我这样 运行 时,它似乎可以并行工作:
./Main.parallel ds_houses/task.txt 8 500000 1:+1 +RTS -N8
./Main.parallel ds_houses/task.txt 8 500000 +RTS -N8
./Main.parallel ds_houses/task.txt 8 +RTS -N8
./Main.parallel ds_houses/task.txt +RTS -N8
我使用参数 8
、500000
和 1:+1
因为我在 shell 脚本中看到它们 here。
我理解第一个参数是CPU的核心,但其他的是什么? /usr/bin/time
程序似乎没有使用这些参数,因为如果将 %C
添加到其格式,这些参数将显示为基准程序的参数。
有人可以解释或指出这些参数的作用吗?
我的假设是否正确,一个人的 Haskell 编译程序不仅接受程序员期望的参数,还接受转发给 Haskell 运行time 的其他参数?
+RTS ... -RTS
之间的参数被运行时拦截,不会传递给您的程序(如果参数在调用结束时,-RTS
是可选的)。其他一切都将被您的程序消耗。
所以您的问题的答案在程序的代码中 - 特别是用法消息显示为:usage: zeta <nthreads> <boundary> <s>
,如果您使用 ghc -O2 -threaded --make Main.hs -o zeta
编译则更有意义。查看函数以了解如何使用这些函数。
另一个答案解决了你所问的问题,但我想解决这个临时评论:
for it to be really concurrent, one has to... launch compiled program with some additional arguments.
(我将此理解为您想解决的问题。)即使没有使用 Control.Concurrent
API. In particular, getNumCapabilities
and setNumCapabilities
read and write the number of OS threads dedicated to evaluating Haskell code. You may also like rtsSupportsBoundThreads
to check whether the program was compiled with the right threading flags and getNumProcessors
检查的 RTS 选项,也可以将程序设计为使用额外的 OS 线程有多少 CPU 可用于 运行 个线程。
我编写了一个 Haskell 程序,它以 Unix 实用程序的方式工作 - 你启动程序,它完成工作,然后退出。 我在该程序中使用了并发,但要使其真正并发,必须分别对其进行编译,此外,让我感到惊讶的是,启动带有一些附加参数的已编译程序。 我编译它:
ghc -O2 -threaded --make Main.hs -o Main.parallel
当我这样 运行 时,它似乎可以并行工作:
./Main.parallel ds_houses/task.txt 8 500000 1:+1 +RTS -N8
./Main.parallel ds_houses/task.txt 8 500000 +RTS -N8
./Main.parallel ds_houses/task.txt 8 +RTS -N8
./Main.parallel ds_houses/task.txt +RTS -N8
我使用参数 8
、500000
和 1:+1
因为我在 shell 脚本中看到它们 here。
我理解第一个参数是CPU的核心,但其他的是什么? /usr/bin/time
程序似乎没有使用这些参数,因为如果将 %C
添加到其格式,这些参数将显示为基准程序的参数。
有人可以解释或指出这些参数的作用吗? 我的假设是否正确,一个人的 Haskell 编译程序不仅接受程序员期望的参数,还接受转发给 Haskell 运行time 的其他参数?
+RTS ... -RTS
之间的参数被运行时拦截,不会传递给您的程序(如果参数在调用结束时,-RTS
是可选的)。其他一切都将被您的程序消耗。
所以您的问题的答案在程序的代码中 - 特别是用法消息显示为:usage: zeta <nthreads> <boundary> <s>
,如果您使用 ghc -O2 -threaded --make Main.hs -o zeta
编译则更有意义。查看函数以了解如何使用这些函数。
另一个答案解决了你所问的问题,但我想解决这个临时评论:
for it to be really concurrent, one has to... launch compiled program with some additional arguments.
(我将此理解为您想解决的问题。)即使没有使用 Control.Concurrent
API. In particular, getNumCapabilities
and setNumCapabilities
read and write the number of OS threads dedicated to evaluating Haskell code. You may also like rtsSupportsBoundThreads
to check whether the program was compiled with the right threading flags and getNumProcessors
检查的 RTS 选项,也可以将程序设计为使用额外的 OS 线程有多少 CPU 可用于 运行 个线程。