簡體   English   中英

R在HPC MPIcluster上運行foreach dopar循環

[英]R Running foreach dopar loop on HPC MPIcluster

我可以訪問帶有MPI分區的HPC群集。

我的問題是 - 無論我嘗試什么 - 我的代碼(在我的電腦上工作正常)都不能在HPC集群上運行。 代碼如下所示:

library(tm)library(qdap)library(snow)library(doSNOW)library(foreach)

> cl<- makeCluster(30, type="MPI")
> registerDoSNOW(cl)
> np<-getDoParWorkers()
> np
> Base = "./Files1a/"
> files = list.files(path=Base,pattern="\\.txt");
> 
> for(i in 1:length(files)){
...some definitions and variable generation...
+ text<-foreach(k = 1:10, .combine='c') %do%{
+   text= if (file.exists(paste("./Files", k, "a/", files[i], sep=""))) paste(tolower(readLines(paste("./Files", k, "a/", files[i], sep=""))) , collapse=" ") else ""
+ }
+ 
+ docs <- Corpus(VectorSource(text))
+ 
+ for (k in 1:10){
+ ID[k] <- paste(files[i], k, sep="_")
+ }
+ data <- as.data.frame(docs) 
+ data[["docs"]]=ID
+ rm(docs)
+ data <- sentSplit(data, "text")
+ 
+ frequency=NULL
+ cs <- ceiling(length(POLKEY$x) / getDoParWorkers()) 
+ opt <- list(chunkSize=cs) 
+ frequency<-foreach(j = 2: length(POLKEY$x), .options.mpi=opt, .combine='cbind') %dopar% ...
+ write.csv(frequency, file =paste("./Result/output", i, ".csv", sep=""))
+ rm(data, frequency)
+ }

當我運行批處理作業時,會話在時間限制內被殺死。 在MPI群集初始化后,我收到以下消息:

Loading required namespace: Rmpi
--------------------------------------------------------------------------
PMI2 initialized but returned bad values for size and rank.
This is symptomatic of either a failure to use the
"--mpi=pmi2" flag in SLURM, or a borked PMI2 installation.
If running under SLURM, try adding "-mpi=pmi2" to your
srun command line. If that doesn't work, or if you are
not running under SLURM, try removing or renaming the
pmi2.h header file so PMI2 support will not automatically
be built, reconfigure and build OMPI, and then try again
with only PMI1 support enabled.
--------------------------------------------------------------------------
--------------------------------------------------------------------------
An MPI 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 MPI 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:         ...
  MPI_COMM_WORLD rank: 0

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.
--------------------------------------------------------------------------
    30 slaves are spawned successfully. 0 failed.

不幸的是,似乎循環沒有經過一次,因為沒有返回輸出。

為了完整起見,我的批處理文件:

#!/bin/bash -l
#SBATCH --job-name MyR
#SBATCH --output MyR-%j.out
#SBATCH --nodes=5
#SBATCH --ntasks-per-node=6
#SBATCH --mem=24gb
#SBATCH --time=00:30:00

MyRProgram="$HOME/R/hpc_test2.R"

cd $HOME/R

export R_LIBS_USER=$HOME/R/Libs2

# start R with my R program
module load R

time R --vanilla -f $MyRProgram

有沒有人建議如何解決問題? 我究竟做錯了什么?

在此先感謝您的幫助!

您的腳本是MPI應用程序,因此您需要通過Slurm正確執行它。 Open MPI FAQ有一個關於如何做到這一點的特殊部分:

https://www.open-mpi.org/faq/?category=slurm

最重要的一點是你的腳本不應該直接執行R,而應該通過mpirun命令執行它,使用類似的方法:

mpirun -np 1 R --vanilla -f $MyRProgram

我的猜測是“PMI2”錯誤是由於沒有通過mpirun執行R而引起的。 我不認為“fork”消息表明存在真正的問題,有時我會發生這種情況。 我認為這是因為R在初始化時調用“fork”,但這從來沒有給我帶來過問題。 我不確定為什么我偶爾會得到這個消息。

請注意,告訴mpirun僅啟動一個進程非常重要,因為其他進程將被生成,因此您應該使用mpirun -np 1選項。 如果Open MPI是使用Slurm支持正確構建的,那么Open MPI應該知道在它們生成時啟動這些進程的位置,但是如果你不使用-np 1 ,那么通過mpirun啟動的所有30個進程將每個產生30個進程,導致一團糟。

最后,我認為你應該告訴makeCluster只生成29個進程,以避免總共運行31個MPI進程。 根據您的網絡配置,即使過多的超額訂閱也可能導致問題。

我會按如下方式創建集群對象:

library(snow)
library(Rmpi)
cl<- makeCluster(mpi.universe.size() - 1, type="MPI")

這樣更安全,可以更輕松地保持R腳本和作業腳本彼此同步。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM