You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用mpirun运行Rmpi测试代码时无法生成Slave进程的问题

关于HPC集群上Rmpi包运行报错的问题分析

一、Rmpi包安装命令

成功安装Rmpi的命令如下:

R CMD INSTALL -l /storage/home/***/.R Rmpi_0.6-7.tar.gz --configure-args="--with-Rmpi-type=OPENMPI --disable-dlopen --with-Rmpi-include=/gpfs/group/RISE/sw7/openmpi_4.1.4_gcc-9.3.1/include --with-Rmpi-libpath=/gpfs/group/RISE/sw7/openmpi_4.1.4_gcc-9.3.1/lib"

二、测试代码

使用的测试代码:

# Load the R MPI package if it is not already loaded.
if (!is.loaded("mpi_initialize")) {
  library("Rmpi")
}

ns <- mpi.universe.size() - 1
mpi.spawn.Rslaves(nslaves=ns)
#
# In case R exits unexpectedly, have it automatically clean up
# resources taken up by Rmpi (slaves, memory, etc...)
.Last <- function(){
  if (is.loaded("mpi_initialize")){
    if (mpi.comm.size(1) > 0){
      print("Please use mpi.close.Rslaves() to close slaves.")
      mpi.close.Rslaves()
    }
    print("Please use mpi.quit() to quit R")
    .Call("mpi_finalize")
  }
}
# Tell all slaves to return a message identifying themselves
mpi.bcast.cmd( id <- mpi.comm.rank() )
mpi.bcast.cmd( ns <- mpi.comm.size() )
mpi.bcast.cmd( host <- mpi.get.processor.name() )
mpi.remote.exec(paste("I am",mpi.comm.rank(),"of",mpi.comm.size()))

# Test computations
x <- 5
x <- mpi.remote.exec(rnorm, x)
length(x)
x

# Tell all slaves to close down, and exit the program
mpi.close.Rslaves(dellog = FALSE)
mpi.quit()

三、集群执行流程

在HPC集群上执行的命令:

qsub -A open -l walltime=6:00:00 -l nodes=4:ppn=4:stmem -I
module use /gpfs/group/RISE/sw7/modules
module load openmpi/4.1.4-gcc.9.3.1 r/4.0.3
mpirun -np 4 Rscript "codes/test/test4.R" 

四、问题及原因分析

1. 初始错误:需选择正整数的Slave数量

加载r/4.0.3模块时,系统自动加载了intel/19.1.2和mkl/2020.3,这两个模块与OpenMPI存在环境冲突,导致mpi.universe.size()返回值小于等于1,计算ns = mpi.universe.size() - 1后得到非正整数,触发mpi.spawn.Rslaves的参数校验报错。

2. 卸载intel/mkl后:libiomp5.so依赖缺失

r/4.0.3版本编译时依赖了intel提供的libiomp5.so库,卸载intel模块后,系统的动态链接库路径中不再包含该库的位置,导致运行时出现依赖缺失错误。

3. 更换R版本(r/4.0.5-gcc-9.3.1)后:节点已被占满无法生成进程

  • 资源冲突:mpirun -np 4启动了4个R主进程,而测试代码中又通过mpi.spawn.Rslaves尝试生成额外的slave进程,超出了qsub申请的nodes=4:ppn=4的总资源配额,导致节点资源耗尽无法创建新进程。
  • 调度兼容性问题:在PBS调度的HPC集群环境下,Rmpi的mpi.spawn.Rslaves机制与OpenMPI的进程管理方式存在兼容性问题,更合适的做法是直接通过mpirun启动所有需要的进程,而非在主进程中动态spawn slave。

内容的提问来源于stack exchange,提问作者knkn1711

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 22:09:37