Commit 04c6689c authored by bellotti_r's avatar bellotti_r
Browse files

Added possibility to add a pre-command for SLURM jobs (to load modules etc.)

parent de821cc7
......@@ -90,7 +90,8 @@ class Simulation:
return True
def run(self, N, baseFileName, inputfilePath, tmplFile, oinpFile,
doTest, doKeep, doNobatch, doOptimize, info, queue, hypert, quiet):
doTest, doKeep, doNobatch, doOptimize, info, queue, hypert, quiet,
preCommand=''):
'''
Run an OPAL simulation.
......@@ -138,6 +139,9 @@ class Simulation:
Defines the number of Hyper-Threads used. Default: 0
quiet: bool
suppress debug printout
preCommand: str (optional)
Shell commands to prepend to the launcher in the SLURM script.
Needed to e. g. load modules before launching the job.
'''
# make directory name indicating changed values
self.dirname = baseFileName
......@@ -258,7 +262,7 @@ class Simulation:
ram = os.getenv("SLURM_RAM", "36")
partition = os.getenv("SLURM_PARTITION", "daily")
self.WriteMerlin6(opalexe, oinpFile, CORES, time,
ram, info, runfile, partition)
ram, info, runfile, partition, preCommand)
# ANL theta.alcf.anl.gov
elif (hostname.startswith("theta")):
......@@ -349,10 +353,10 @@ class Simulation:
elif batchsys == 'COBALT':
command = 'qsub'
completed_process = subprocess.run([command, runfile],
stdout=subprocess.PIPE,
encoding='utf-8')
output = completed_process.stdout
output = subprocess.check_output(f'{command} {runfile}',
encoding='utf-8',
shell=True)
print(output)
# output format for SLURM: "Submitted batch job <ID>"
ID = output.split(' ')[-1].strip()
if not quiet:
......@@ -474,7 +478,7 @@ class Simulation:
myfile.close()
def WriteMerlin6(self, opalexe, oinpFile, cores, time,
ram, info, name, partition):
ram, info, name, partition, preCommand):
# ADA this is for the new PSI Merlin6
title = oinpFile.partition(".")[0]
myfile = open(name, 'w')
......@@ -494,6 +498,7 @@ class Simulation:
# s1 += "#SBATCH --exclude=merlin-c-001 \n"
s1 += "#SBATCH --cores-per-socket=22 \n"
s1 += "#SBATCH --sockets-per-node=2 \n"
s1 += preCommand + '\n'
s1 += f"mpirun {opalexe} {oinpFile} --info {str(info)}\n"
myfile.write(s1)
myfile.close()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment