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: ...@@ -90,7 +90,8 @@ class Simulation:
return True return True
def run(self, N, baseFileName, inputfilePath, tmplFile, oinpFile, 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. Run an OPAL simulation.
...@@ -138,6 +139,9 @@ class Simulation: ...@@ -138,6 +139,9 @@ class Simulation:
Defines the number of Hyper-Threads used. Default: 0 Defines the number of Hyper-Threads used. Default: 0
quiet: bool quiet: bool
suppress debug printout 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 # make directory name indicating changed values
self.dirname = baseFileName self.dirname = baseFileName
...@@ -258,7 +262,7 @@ class Simulation: ...@@ -258,7 +262,7 @@ class Simulation:
ram = os.getenv("SLURM_RAM", "36") ram = os.getenv("SLURM_RAM", "36")
partition = os.getenv("SLURM_PARTITION", "daily") partition = os.getenv("SLURM_PARTITION", "daily")
self.WriteMerlin6(opalexe, oinpFile, CORES, time, self.WriteMerlin6(opalexe, oinpFile, CORES, time,
ram, info, runfile, partition) ram, info, runfile, partition, preCommand)
# ANL theta.alcf.anl.gov # ANL theta.alcf.anl.gov
elif (hostname.startswith("theta")): elif (hostname.startswith("theta")):
...@@ -349,10 +353,10 @@ class Simulation: ...@@ -349,10 +353,10 @@ class Simulation:
elif batchsys == 'COBALT': elif batchsys == 'COBALT':
command = 'qsub' command = 'qsub'
completed_process = subprocess.run([command, runfile], output = subprocess.check_output(f'{command} {runfile}',
stdout=subprocess.PIPE, encoding='utf-8',
encoding='utf-8') shell=True)
output = completed_process.stdout print(output)
# output format for SLURM: "Submitted batch job <ID>" # output format for SLURM: "Submitted batch job <ID>"
ID = output.split(' ')[-1].strip() ID = output.split(' ')[-1].strip()
if not quiet: if not quiet:
...@@ -474,7 +478,7 @@ class Simulation: ...@@ -474,7 +478,7 @@ class Simulation:
myfile.close() myfile.close()
def WriteMerlin6(self, opalexe, oinpFile, cores, time, def WriteMerlin6(self, opalexe, oinpFile, cores, time,
ram, info, name, partition): ram, info, name, partition, preCommand):
# ADA this is for the new PSI Merlin6 # ADA this is for the new PSI Merlin6
title = oinpFile.partition(".")[0] title = oinpFile.partition(".")[0]
myfile = open(name, 'w') myfile = open(name, 'w')
...@@ -494,6 +498,7 @@ class Simulation: ...@@ -494,6 +498,7 @@ class Simulation:
# s1 += "#SBATCH --exclude=merlin-c-001 \n" # s1 += "#SBATCH --exclude=merlin-c-001 \n"
s1 += "#SBATCH --cores-per-socket=22 \n" s1 += "#SBATCH --cores-per-socket=22 \n"
s1 += "#SBATCH --sockets-per-node=2 \n" s1 += "#SBATCH --sockets-per-node=2 \n"
s1 += preCommand + '\n'
s1 += f"mpirun {opalexe} {oinpFile} --info {str(info)}\n" s1 += f"mpirun {opalexe} {oinpFile} --info {str(info)}\n"
myfile.write(s1) myfile.write(s1)
myfile.close() 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