首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >`R雪花`冻结中的`stopCluster`

`R雪花`冻结中的`stopCluster`
EN

Stack Overflow用户
提问于 2016-12-07 08:47:19
回答 1查看 891关注 0票数 0

我在使用snowR的集群计算机上运行蒙特卡洛模拟。一切都很顺利,直到R遇到了stopCluster,在那里R冻结了,最终超过了墙时间。我看不到stopCluster的问题。

以下是我的R脚本的简化版本。

代码语言:javascript
复制
simu <- function(rep_worker, n_used) {
  theta_simu <- c()
  for (i in 1 : rep_worker) {
    theta_simu[i] <- mean(rnorm(n_used))
  }
  theta_simu
}
library(Rmpi)
library(snow)
np <- mpi.universe.size() - 1
cl <- makeCluster(np, type = "MPI")
## go go go
n_used <- 1e4
rep_worker_list <- rep(1, np) # each worker do one `simu`
theta_cluster <- clusterApply(cl, rep_worker_list, simu, n_used)
theta_cluster
stopCluster(cl)
mpi.exit()

上面的脚本被保存为monte-carlo/R目录下的test_stack.R。我发送给服务器的pbs脚本如下所示。

代码语言:javascript
复制
#!/bin/bash

#PBS -N test
#PBS -l walltime=00:30:00
#PBS -l nodes=3:ppn=8
#PBS -l pvmem=8gb

module load R/3.3.1
module load openmpi/gcc/2.0.0
cd monte-carlo/R

# For snow jobs, use 'mpiexec -n 1'
mpiexec -n 1 R CMD BATCH test_stack.R

下面列出了Rout文件的一部分。它止步于stopCluster()

代码语言:javascript
复制
> simu <- function(rep_worker, n_used) {
+   theta_simu <- c()
+   for (i in 1 : rep_worker) {
+     theta_simu[i] <- mean(rnorm(n_used))
+   }
+   theta_simu
+ }
> library(Rmpi)
> library(snow)
> np <- mpi.universe.size() - 1
> cl <- makeCluster(np, type = "MPI")
    23 slaves are spawned successfully. 0 failed.
> ## go go go
> n_used <- 1e4
> rep_worker_list <- rep(1, np) # each worker do one `simu`
> theta_cluster <- clusterApply(cl, rep_worker_list, simu, n_used)
> theta_cluster
[[1]]
[1] 5.54539e-05

[[2]]
[1] 0.0009270881

... (I deleted the rest to save space)

> stopCluster(cl)
EN

回答 1

Stack Overflow用户

发布于 2017-06-02 05:51:56

昨天我得到了答案: OpenMPI的版本是关键。

如果您使用OpenMPI 1.6.5,而不是从parallel包调用stopCluster(),而是从snow调用stopCluster (),stopCluster的冻结问题就会得到解决。明白我的意思吗?将stopCluster()替换为

代码语言:javascript
复制
snow::stopCluster()

而且,为了更好地衡量,我们显式地调用

代码语言:javascript
复制
Rmpi::mpi.quit()

在最后。

据我所知,在使用MPI时,stopCluster在并行模式下会挂起,但是snow::stopCluster确实解决了这个问题,直到我们用OpenMPI >= 2重新构建了R包。如果你在OpenMPI > 2的情况下编译,那么无论你使用哪种stopCluster,stopCluster的挂起都会发生。

看起来OpenMPI 1.6.5是完全正确的版本。

如果您使用Openmpi > 1.6.5但< 2,则不会发生挂起,但是有一条关于forks的有趣的警告消息:

代码语言:javascript
复制
> library(Rmpi)
> library(parallel)
> sessionInfo()
----------------------------------------------------------------------
A process has executed an operation involving a call to the
"fork()" system call to create a child process.  Open MPI is currently
operating in a condition that could result in memory corruption or
other system errors; your job may hang, crash, or produce silent
data corruption.  The use of fork() (or system() or other calls that
create child processes) is strongly discouraged.

The process that invoked fork was:

  Local host:          [[44893,1],0] (PID 35793)

If you are *absolutely sure* that your application will successfully
and correctly survive a call to fork(), you may disable this warning
by setting the mpi_warn_on_fork MCA parameter to 0.
---------------------------------------------------------------------- 

几年前,我们遇到了这种情况,因为有人在R函数中使用GOTO BLAS,触发了一些OpenMP矩阵线程打开,作业将永远存在,不会失败,不会计算。这让我想起了这一点。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41007564

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档