From fe4efd0d06527d0cc5867aa1ad3c130603c3bf1e Mon Sep 17 00:00:00 2001 From: cpenadep Date: Thu, 1 Sep 2022 15:30:31 +0200 Subject: [PATCH 1/2] Initial Torque manager added --- Job_Creator.py | 40 +++++++++++++++++++++++++++++++++++++++- script.sh | 27 +++++++++++++++++++-------- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/Job_Creator.py b/Job_Creator.py index 15330c8..4d9f46e 100644 --- a/Job_Creator.py +++ b/Job_Creator.py @@ -117,6 +117,41 @@ def create_job_lsf(args): lsf_job.write(line) +def create_job_torque(args): + file_name = args.file_name + time = args.set_time + cores = args.set_core + name = args.job_name + cores_per_node = args.set_core_per_node + queue = args.set_queue + workload = args.set_workload + nodes = (cores//cores_per_node)+1 + hours = time // 60 + minutes = time % 60 + file = ["#!/bin/bash \n", + "############################################################################### \n", + "#PBS -o "+str(name)+".out \n#PBS -e "+str(name)+".err \n" + "#PBS --constraint=perfparanoid \n"] + + if cores is not None: + file.append("#PBS -l nodes"+str(nodes)":ppn=" + str(cores) + "\n") + if time is not None and not 0: + file.append("#PBS -l cput=" + str(hours)+":"+str(minutes)+ ":00\n") + if name is not None: + file.append("#PBS -N " + name + "\n") + if queue is not None and not len(queue) == 0: + file.append("#PBS -q " + queue + "\n") + + if workload is not None: + file.append("\n") + for work in workload: + file.append(str(work) + "") + + with open(file_name, "w") as torque_job: + for line in file: + torque_job.write(line) + + def modify_job(args): file_name = args.file_name time = args.set_time @@ -148,6 +183,8 @@ if __name__ == "__main__": args.file_name = args.file_name if args.file_name.count(".slurm") else args.file_name + ".slurm" elif args.scheduler == "lsf": args.file_name = args.file_name if args.file_name.count(".lsf") else args.file_name + ".lsf" + elif args.scheduler == "torque": + args.file_name = args.file_name if args.file_name.count(".torque") else args.file_name + ".torque" if os.path.exists(str(args.file_name)): os.remove(str(args.file_name)) @@ -156,4 +193,5 @@ if __name__ == "__main__": create_job_slurm(args) elif args.scheduler == "lsf": create_job_lsf(args) - + elif args.scheduler == "torque": + create_job_torque(args) diff --git a/script.sh b/script.sh index 82a4254..9a4911f 100755 --- a/script.sh +++ b/script.sh @@ -32,22 +32,31 @@ Job_completed() { if [ "$Jobs_scheduler" == "slurm" ]; then local id1=${1##* } - sleep .5 + sleep 5 if ! scontrol show job $id1 | grep -q 'JobState=COMPLETED'; then Completed=false else Completed=true fi - else - local id1=${head -n1 1 | cut -d'<' -f2 | cut -d'>' -f1} - sleep .5 + elif [ "$Jobs_scheduler" == "lsf" ]; then + local id1=$(head -n1 1 | cut -d'<' -f2 | cut -d'>' -f1) + sleep 5 if ! bjobs -l $id | grep -q 'Status '; then Completed=false else Completed=true fi - fi + elif [ "$Jobs_scheduler" == "torque" ]; then + local id1=$(head -n1 $1 | awk '{ print $3 }') + sleep 5 + if ! qstat f $id | grep -q 'exit_status = 0'; then + Completed=false + else + Completed=true + fi + + } @@ -98,7 +107,7 @@ Test_arguments() exit 1 fi # scheduler correct? - if [ "$Jobs_scheduler" != "slurm" ] && [ "$Jobs_scheduler" != "lsf" ]; then + if [ "$Jobs_scheduler" != "slurm" ] && [ "$Jobs_scheduler" != "lsf" ] && [ "$Jobs_scheduler" != "torque" ]; then echo "$Jobs_scheduler is not a valid scheduler" echo exit 1 @@ -133,8 +142,10 @@ Test_arguments() # Creating auxiliar vars for submiting jobs if [ "$Jobs_scheduler" == "slurm" ]; then job="sbatch" - else - job="bsub" + elif [ "$Jobs_scheduler" == "lsf" ] + job="qsub" + elif [ "$Jobs_scheduler" == "torque" ] + job="" fi -- GitLab From a313905c0cd2c3a98660e2753450b3feba9620ff Mon Sep 17 00:00:00 2001 From: cpenadep Date: Thu, 1 Sep 2022 15:52:03 +0200 Subject: [PATCH 2/2] Fixed mistakes in principal files --- Job_Creator.py | 6 +++--- script.sh | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Job_Creator.py b/Job_Creator.py index 4d9f46e..dc70f90 100644 --- a/Job_Creator.py +++ b/Job_Creator.py @@ -134,9 +134,9 @@ def create_job_torque(args): "#PBS --constraint=perfparanoid \n"] if cores is not None: - file.append("#PBS -l nodes"+str(nodes)":ppn=" + str(cores) + "\n") + file.append("#PBS -l nodes" + str(nodes) + ":ppn=" + str(cores) + "\n") if time is not None and not 0: - file.append("#PBS -l cput=" + str(hours)+":"+str(minutes)+ ":00\n") + file.append("#PBS -l cput=" + str(hours) + ":"+str(minutes)+ ":00\n") if name is not None: file.append("#PBS -N " + name + "\n") if queue is not None and not len(queue) == 0: @@ -194,4 +194,4 @@ if __name__ == "__main__": elif args.scheduler == "lsf": create_job_lsf(args) elif args.scheduler == "torque": - create_job_torque(args) + create_job_torque(args) diff --git a/script.sh b/script.sh index 9a4911f..65193fd 100755 --- a/script.sh +++ b/script.sh @@ -55,7 +55,7 @@ Job_completed() else Completed=true fi - + fi } @@ -142,10 +142,10 @@ Test_arguments() # Creating auxiliar vars for submiting jobs if [ "$Jobs_scheduler" == "slurm" ]; then job="sbatch" - elif [ "$Jobs_scheduler" == "lsf" ] + elif [ "$Jobs_scheduler" == "lsf" ]; then + job="bsub" + elif [ "$Jobs_scheduler" == "torque" ]; then job="qsub" - elif [ "$Jobs_scheduler" == "torque" ] - job="" fi -- GitLab