我必须在集群上提交大量作业,我的脚本类似于:
#!/bin/bash
for runname in bcc BNU Can CNRM GFDLG GFDLM
do
cd given_directory/$runname
cat another_directory | while read LINE ; do
qsub $LINE
done
done
该脚本中有4000行,即每个runename
都有4000个作业。
在给定时间,群集上可以提交的作业数量受到用户的限制。
因此,我想在给定的for-loop
中将每次运行之间的过程延迟到
像完成bcc
目录中的所有运行一样,完成了一批。
我该怎么做?我可以在第一个done
(?)之后放置命令,以使代码等待bcc
完成然后移至BNU
吗?
答案 0 :(得分:1)
一种选择是使用计数器来监视当前提交的作业数,并在达到限制时等待。查询作业数量对于根节点可能是一项代价高昂的操作,因此最好不要在每个提交的作业之后都执行此操作。在这里,此操作最多每SLEEP
秒执行一次。
#!/bin/bash
TARGET=4000
SLEEP=300
# Count the current jobs, pending or running
get_job_count(){
# The grep is to remove the header, there may be a better way.
qstat -u $USER | grep $USER | wc -l
}
# Wait until the number of job is under the limit, then submit.
submit_when_possible(){
while [ $COUNTER -ge $TARGET ]; do
sleep $SLEEP
COUNTER=$(get_job_count)
done
qsub $1
let "COUNTER++"
}
# Global job counter
COUNTER=$(get_job_count)
for RUNNAME in bcc BNU Can CNRM GFDLG GFDLM
do
cd given_directory/$RUNNAME
cat another_directory | while read JOB ; do
submit_when_possible $JOB
done
done
注意:该脚本未经测试,因此可能需要进行较小的修复,但该想法应该可行。