2016-10-19 2 views
1

multicore을 사용하는 doMC을 사용합니다. 내가 (콘솔에서) 디버깅을 할 때 옆으로 가다가 fork-bombed이 나왔다.실행중인 R 프로세스의 수를 제한하는 방법이 있습니까

R에 setrlimit() 시스템 호출이 있습니까? 이에 대한 pyhton에서 나는 R 프로세스의 수는

편집 숫자로 실행 제한하고 싶습니다 이상적 resource.RLIMIT_NPROC

사용합니다 : OS는 리눅스 CentOS는 6

+0

어떤 OS를 사용하고 있습니까? 'doMC'를 사용한다면 리눅스라고 가정합니다. – cdeterman

답변

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과 친구들로부터 제어 할 수 있습니다.

+0

매우 유망 해 보입니다. – statquant

2

당신은 registerDoMC을 사용할 수 있습니다 (다큐먼트 here는)

registerDoMC(cores=<some number>) 

또 다른 옵션은 R 스크립트를 실행하기 전에 ulimit 명령을 사용하는 것입니다 :

ulimit -u <some number> 

R이 생성 할 수있는 프로세스의 수를 제한합니다.

여러 R 프로세스가 동시에 사용하는 총 CPU 수를 제한하려면 cgroups 또는 cpusets을 사용하고 R 프로세스를 cgroup 또는 cpuset에 연결해야합니다. 그런 다음 cgroup 또는 cpuset에 정의 된 물리적 CPUS에 한정됩니다. cgroup은 더 많은 제어 (예 : 메모리)를 허용하지만 설치가 더 복잡합니다.

+0

편집 해 주셔서 감사합니다. 최대한 빨리 보겠습니다. – statquant

관련 문제