因为服务器的软件编译,例如调度系统,分布式文件系统,存储系统,作业系统;都是基于Centos7进行编译,系统GCC为4.8.5,GLIBC为2.17,如何升级GLIBC,可能会导致这些软件故障,无法使用。(甚至会导致系统无法启动)所以使用容器方式提交作业是最稳定的方式。
如何使用singularity 创建镜像?(singularity build)
构建镜像:
从dockerhub上加载镜像
singularity build <自定义>.sif docker://xxxx
EX:
singularity build ubuntu.sif docker://ubuntu ##从docker上加载ubuntu基础镜像,保存为ubuntu.sif ##注意SIF格式的镜像,只为可读镜像
创建sandox可写镜像
##注意请将文件存在/tmp 下,否则安装软件时候会报错
#从Docker Hub下载Tensorflow GPU镜像,存储为本地sandbox
singularity build --sandbox /tmp/cuda102ub1804 docker://wildbrother/cuda10.2-cudnn8-runtime-ubuntu18.04 ##build镜像时,必须有 --sandbox 不然如下的步骤都是无法做的
从sandbox以可修改的方式运行容器,进行修改和定制
cd /tmp
singularity shell -f --writable cuda102ub1804
singularity> apt update -y
singularity> apt install vim -y
从修改后的sanbox生成只读的SIF格式容器,用于生产
singularity build ~/cuda102ub1804.sif cuda102ub1804
使用slurm调度系统提交作业(srun)
srun --gres=gpu:1 singularity exec --nv cuda102ub1804.sif nvidia-smi
使用slurm调度系统提交作业(sbatch) CPU
#!/bin/bash
#SBATCH --job-name=mysingularity
#SBATCH --error=opencv.%j.err
#SBATCH --output=opencv.%j.out
#SBATCH --partition=ALL
#SBATCH --ntasks=1
#SBATCH --mem=1G
#SBATCH --time=00:05:00
cd $WORKING_DIR
#your working directory
srun singularity exec my.sif python script.py
使用slurm调度系统提交作业(sbatch) GPU
#!/bin/bash
#SBATCH -J singularityGPU
#SBATCH -o output_%j.txt
#SBATCH -e errors_%j.txt
#SBATCH -t 01:30:00
#SBATCH -n 1
#SBATCH -p ALL
# requesting 1 GPU; set --gres=gpu:2 to use 2 GPUs
#SBATCH --gres=gpu:1
cd $WORKING_DIR
#your working directory
srun singularity exec --nv tensorflow.sif python script.py