more improvements
This commit is contained in:
parent
e488275523
commit
5fa4dd9683
6 changed files with 56 additions and 44 deletions
|
@ -101,6 +101,21 @@ def create_slurm_template(
|
|||
|
||||
f.write(f"export OMP_NUM_THREADS={nthreads}\n\n")
|
||||
|
||||
f.write("start=`date +%s`\n")
|
||||
f.write("%COMMAND%\n")
|
||||
f.write("end=`date +%s`\n")
|
||||
f.write("runtime=$((end-start))\n")
|
||||
f.write("\n")
|
||||
f.write("echo ''\n")
|
||||
f.write("echo ''\n")
|
||||
f.write("echo \"################## RUNTIME ##################\"\n")
|
||||
f.write("echo \"Runtime was $runtime seconds\"\n")
|
||||
#TODO: fix the two lines below
|
||||
# f.write("echo \"Runtime per task was $((${runtime}.0/${SLURM_NTASKS}.0)) seconds\"\n") # not working yet...
|
||||
# f.write("echo \"Runtime per total cpus was $((${runtime}.0/${($SLURM_NTASKS*$SLURM_CPUS_PER_TASK)}.0)) seconds\"\n")
|
||||
f.write("echo \"#############################################\"\n")
|
||||
f.write("\n")
|
||||
f.write("exit 0\n")
|
||||
|
||||
|
||||
def create_slurm_script(slurm_template:str,
|
||||
|
@ -109,6 +124,7 @@ def create_slurm_script(slurm_template:str,
|
|||
job_config_file:str,
|
||||
job_log:str,
|
||||
array:tuple|None=None,
|
||||
job_name:str|None=None,
|
||||
):
|
||||
"""
|
||||
Creates a SLURM submission script based on the provided template.
|
||||
|
@ -131,25 +147,30 @@ def create_slurm_script(slurm_template:str,
|
|||
with open(slurm_template, "r") as f:
|
||||
template = f.readlines()
|
||||
|
||||
command_line = ""
|
||||
# Add the job command
|
||||
match job:
|
||||
case "monofonic":
|
||||
command_line = f"{path_to_monofonic_binary} {job_config_file} > {job_log}"
|
||||
case "simbelmyne":
|
||||
command_line = f"{job} {job_config_file} {job_log}"
|
||||
case "scola":
|
||||
command_line = f"{job} {job_config_file} {job_log} "+"-b ${SLURM_ARRAY_TASK_ID}"
|
||||
case _:
|
||||
raise ValueError(f"Job type {job} not recognized.")
|
||||
|
||||
# Create the script file
|
||||
with open(slurm_script, "w") as f:
|
||||
for line in template:
|
||||
if job_name is not None and "--job-name" in line:
|
||||
line = f"#SBATCH --job-name={job_name}\n"
|
||||
if array is not None and "--array" in line:
|
||||
line = line.replace("%a-%b",f"{array[0]}-{array[1]}")
|
||||
line = f"#SBATCH --array={array[0]}-{array[1]}\n"
|
||||
if array is not None and ("--output" in line or "--error" in line):
|
||||
line = line.replace("%j","%a_%A")
|
||||
if "%COMMAND%" in line:
|
||||
line = command_line+"\n"
|
||||
f.write(line)
|
||||
|
||||
# Add the job command
|
||||
match job:
|
||||
case "monofonic":
|
||||
f.write(f"{path_to_monofonic_binary} {job_config_file} > {job_log}")
|
||||
case "simbelmyne":
|
||||
f.write(f"{job} {job_config_file} {job_log}")
|
||||
case "scola":
|
||||
f.write(f"{job} {job_config_file} {job_log} "+"-b ${SLURM_ARRAY_TASK_ID}")
|
||||
case _:
|
||||
raise ValueError(f"Job type {job} not recognized.")
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue