如何使用远程提交给使用Loadleveler的群集的作业的状态作为BASH脚本中的循环控制参数?

时间:2018-09-10 12:22:45

标签: bash parallel-processing batch-processing jobs job-scheduling

集群使用Loadleveler调度作业。我希望循环仅在当前迭代中提交的作业完成后才开始下一个迭代。 我知道可以使用wait来做到这一点,但我不知道如何做。任何帮助表示赞赏。

#!/bin/bash

for i in 1 2 3
do

    submit job 

    retrieve job id

    check if the submitted job is over so the next iteration of for can start

done

1 个答案:

答案 0 :(得分:0)

这是一小段代码,可以为您提供帮助。

#!/bin/bash

total_attempts=0

for attempt in 1 2 3;
do
  echo attempt $attempt      #Use your submit job here

  # initialise stuff 
  counter=0                  #Use your retrieve_job_id here

  # since the next step is to check, we first need to retrieve state.
  rand=$((RANDOM))           #Use your get_job_state here

  # Check we didn't reach completion
  while [ $rand -gt 2000 ];  #Use your criterium here
  do  
    # You probably want to change the following lines...
    echo $rand;              #You don't want this line, but it'll help you understand what's going on
    # get new state
    rand=$((RANDOM));        #Use your get_job_state here
    counter=$((counter+1))
  done

  #At this line, the criterium has been met for the attempt.       
  echo attempt $attempt got $rand ! #You don't want this line, but it'll help you understand what's going on

  # A job has been completed, so maybe we need to clean stuff up.
  total_attempts=$((total_attempts+counter)) #Use your imagination here :)
done

echo $total_attempts attempts required to finish 3 jobs.