【问题标题】:Is there a way to limit the number of R processes running有没有办法限制正在运行的 R 进程的数量
【发布时间】:2017-03-01 08:30:49
【问题描述】:

我使用doMC,它使用包multicore。它发生了(几次),当我(在控制台中)调试时,它横着走,fork-bombed

R 是否有 setrlimit() 系统调用? 在 pyhton 中,我会使用 resource.RLIMIT_NPROC

理想情况下,我想将运行的 R 进程数限制为一个数字

编辑:操作系统是 linux CentOS 6

【问题讨论】:

  • 您使用的是什么操作系统?如果使用doMC,我假设是 Linux。

标签: r ulimit domc setrlimit


【解决方案1】:

应该有几种选择。这是来自Writing R Extensions, Section 1.2.1.1的相关部分

   Packages are not standard-alone programs, and an R process could
contain more than one OpenMP-enabled package as well as other components
(for example, an optimized BLAS) making use of OpenMP. So careful
consideration needs to be given to resource usage.  OpenMP works with
parallel regions, and for most implementations the default is to use as
many threads as 'CPUs' for such regions.  Parallel regions can be
nested, although it is common to use only a single thread below the
first level.  The correctness of the detected number of 'CPUs' and the
assumption that the R process is entitled to use them all are both
dubious assumptions.  The best way to limit resources is to limit the
overall number of threads available to OpenMP in the R process: this can
be done via environment variable 'OMP_THREAD_LIMIT', where
implemented.(4)  Alternatively, the number of threads per region can be
limited by the environment variable 'OMP_NUM_THREADS' or API call
'omp_set_num_threads', or, better, for the regions in your code as part
of their specification.  E.g. R uses
     #pragma omp parallel for num_threads(nthreads) ...
That way you only control your own code and not that of other OpenMP
users.

我最喜欢的工具之一是控制它的包:RhpcBLASctl。这是它的描述:

控制“BLAS”(又名“GotoBLAS”、“ACML”和 'MKL')。并且可以控制“OpenMP”中的线程数。得到 一些逻辑核心和物理核心(如果可行)。

毕竟,您需要控制并行会话的数量以及分配给每个并行线程的 BLAS 核心数量。并行包默认每个会话有 2 个线程是有原因的...

所有这些都应该在很大程度上独立于您正在运行的 Linux 或 Unix 的风格。好吧,除了 OS X 当然(仍然!!)不给你 OpenMP 的事实。

还有你可以通过doMC 和朋友控制的最外层。

【讨论】:

    【解决方案2】:

    您可以使用registerDoMC(参见文档here

    registerDoMC(cores=<some number>)
    

    另一种选择是在运行 R 脚本之前使用ulimit 命令:

    ulimit -u <some number>
    

    限制 R 能够生成的进程数。

    如果要限制多个 R 进程同时使用的 CPU 总数,则需要使用 cgroupscpusets 并将 R 进程附加到 cgroup 或 cpuset。然后它们将被限制在 cgroup 或 cpuset 中定义的物理 CPU。 cgroups 允许更多控制(例如内存),但设置起来更复杂。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-10
      • 1970-01-01
      • 2017-07-31
      • 2015-08-11
      相关资源
      最近更新 更多