在Compute Canada用OpenMPI运行irace失败的原因与修复方案
问题
在Compute Canada上运行irace并使用openmpi模块时,始终出现以下错误:
mpirun was unable to launch the specified application as it could not access or execute an executable:
Executable: /scratch/irace/test.R
Node: niaXXXX
while attempting to start process rank 0.
使用的bash脚本如下:
#!/bin/sh #SBATCH --nodes=5 #SBATCH --ntasks-per-node=40 #SBATCH --mem=0 #SBATCH --mail-type=ALL #SBATCH --output=/scratch/irace/irace-%j.out #SBATCH --error=/scratch/irace/irace-%j.err module load NiaEnv/2019b module load gcc module load r module load openmpi cd /scratch/irace mpirun -np 5 /scratch/irace/test.R --parallel 4
提交作业后运行失败,但将最后一行替换为:
Rscript ./test.R
后,脚本可正常运行并输出结果。
原因与解决方案
问题原因
.R文件不是可执行程序:mpirun默认直接执行传入的路径,但.R脚本本身没有可执行权限,也不属于二进制可执行文件,无法被mpirun直接调用执行。- 缺少解释器指定:即使给
.R文件加上可执行权限,系统也不知道要用R解释器来运行它,除非脚本开头添加#!/usr/bin/env Rscript这类shebang声明。
修复步骤
针对Compute Canada的环境,有两种可行的修复方式:
方式一:让mpirun调用Rscript执行脚本
修改作业脚本的最后一行,让mpirun启动Rscript进程,再由Rscript加载运行.R脚本:
mpirun -np 5 Rscript /scratch/irace/test.R --parallel 4
方式二:给.R脚本添加可执行权限与shebang声明
- 编辑
test.R脚本,在文件最顶部添加一行shebang:
#!/usr/bin/env Rscript
- 在终端给脚本添加可执行权限:
chmod +x /scratch/irace/test.R
- 保持作业脚本最后一行不变,重新提交作业即可。
额外提示:你的SBATCH参数申请了5个节点共200核心,但mpirun -np 5仅启动5个进程,可能未充分利用资源,可根据irace的并行需求调整-np的数值。
内容的提问来源于stack exchange,提问作者Phoebe
相关产品推荐
相关产品推荐

