#!/bin/bash
# SLURM_NODELIST=n[03495-03498]
# SLURM_JOB_CPUS_PER_NODE=4,56(x2),50
# 把这两个环境变量转换一下,转成
# mp_host_list=[['n03485',4],['n03496',56],['n03497',56],['n03498',50]]
SLURM_JOB_CPUS_PER_NODE="4,56(x3),50(x2)"
SLURM_NODELIST="n[03495-03500]"
min=`echo "$SLURM_NODELIST" | sed -r "s/n\[([0-9]+)\-[0-9]+\]/\1/"`
max=`echo "$SLURM_NODELIST" | sed -r "s/n\[[0-9]+\-([0-9]+)\]/\1/"`
array1=()
for i in `seq $min $max`;do
i=`printf "%05d\n" $i`
array1[${#array1[*]}]=$i
done
array2=( ${SLURM_JOB_CPUS_PER_NODE//,/ } )
array3=()
for i in ${array2[@]};do
if [[ "$i" =~ "x" ]];then
num=`echo $i | sed -r "s/[0-9]+\(x([0-9]+)\)/\1/"`
ele=`echo $i | sed -r "s/([0-9]+)\(x[0-9]+\)/\1/"`
for j in `seq 1 $num`;do
array3[${#array3[*]}]=$ele
done
else
array3[${#array3[*]}]=$i
fi
done
(( len=${#array1[@]}-1 ))
array4=()
for i in `seq 0 $len `;do
res="['n${array1[$i]}',${array3[$i]}]"
array4[${#array4[*]}]=$res
done
str="["$(IFS=,; echo "${array4[*]}")"]"
echo $str
字符串拼接
最新推荐文章于 2024-09-11 15:16:48 发布