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

使用PBS脚本启动Singularity容器时出现execvp错误求助

PBS提交Singularity+MPI任务报错找不到singularity的解决方法

问题详情

尝试通过PBS脚本启动Singularity容器运行MPI程序,遇到execvp error on file singularity (No such file or directory)错误,直接运行脚本正常,但PBS提交任务失败。相关文件及报错如下:

现有文件内容

PBS脚本(ph.sh)

#!/bin/bash
# ph.sh
export MPI_DIR=/opt/mpich
module load singularity/3.7.5
mpirun -n $num_cores -hostfile ./hostlist singularity exec --bind "MPI_DIR" ./bind.sif /usr/local/bin/PHengLEIv3d0-5720-tianhe > cfd.log

Singularity定义文件

Bootstrap: docker
From: centos:7

%files
      /usr/local/bin/PHengLEIv3d0-5720-tianhe /usr/local/bin/PHengLEIv3d0-5720-tianhe

%environment
      export PATH="$MPI_DIR/bin:$PATH"
      export LD_LIBRARY_PATH="$MPI_DIR/lib:$LD_LIBRARY_PATH"

%post
     export DEBIAN_FRONTEND=noninteractive
     yum update -y && yum install -y gcc-c++ && yum install -y gcc-gfortran

报错信息

[proxy:0:0@phdev1] HYDU_create_process (utils/launch/launch.c:74): execvp error on file singularity (No such file or directory)

对比验证

直接执行以下脚本可正常运行:

export MPI_DIR="/opt/mpich"
mpirun -n 1 singularity exec --bind "$MPI_DIR" bind.sif /usr/local/bin/PHengLEIv3d0-5720-tianhe

但通过PBS提交时失败:

qsub -N Pro325_Job281 -W sandbox=PRIVATE -q workq  -l nodes=1:ppn=1 ph_ys144.sh

问题根源与修复步骤

1. 初始化PBS环境的module系统

PBS非交互式环境默认不加载用户shell配置,module load命令可能无法在所有节点生效。需先初始化module环境:

# 根据集群实际路径调整,常见路径为/etc/profile.d/modules.sh
source /etc/profile.d/modules.sh
module load singularity/3.7.5

也可直接使用singularity绝对路径(先在交互式环境用which singularity获取路径):

SINGULARITY=$(which singularity)

2. 让MPIRun传递环境变量到远程节点

MPIRun启动多节点任务时,远程节点不会继承提交节点的环境变量,需显式传递关键变量:

mpirun -n $num_cores -x PATH -x LD_LIBRARY_PATH ...

3. 正确定义核心数变量

脚本中$num_cores未赋值,直接使用PBS内置环境变量获取资源:

num_cores=$PBS_NP  # 获取任务总核心数
# 或单节点核心数:num_cores=$PBS_NUM_PPN

4. 修复Bind参数错误

原脚本--bind "MPI_DIR"是绑定字符串而非环境变量值,需改为:

--bind "$MPI_DIR"

5. 移除不必要的Hostfile参数

PBS会自动分配节点并配置MPI环境,手动指定-hostfile ./hostlist可能导致节点不匹配,建议删除该参数。


修改后的完整PBS脚本

#!/bin/bash
# ph.sh

# 初始化module环境(根据集群实际路径调整)
source /etc/profile.d/modules.sh

# 加载Singularity模块
module load singularity/3.7.5

# 定义MPI路径
export MPI_DIR=/opt/mpich

# 从PBS环境变量获取核心数
num_cores=$PBS_NP

# 执行MPI容器任务
mpirun -n $num_cores -x PATH -x LD_LIBRARY_PATH singularity exec --bind "$MPI_DIR" ./bind.sif /usr/local/bin/PHengLEIv3d0-5720-tianhe > cfd.log

镜像轻量化优化建议

  • 删除%post中无效的export DEBIAN_FRONTEND=noninteractive(该变量仅适用于Debian/Ubuntu系统,CentOS无需设置)
  • 改用centos:7-slim作为基础镜像,减少冗余系统包

内容的提问来源于stack exchange,提问作者jason-lin

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 02:10:18