@@ -9,12 +9,14 @@ def generate_directories():
99 '''
1010 import os
1111
12- for name in ['jobscripts' , 'slurm-out' ]:
12+ for name in ['jobscripts' , 'slurm-out' , 'nsys_profiles' ]:
1313 path = f'{ PROJECT_PATH } /etc/{ name } '
1414 os .makedirs (path , exist_ok = True )
1515
1616
17- def get_jobscript_text (sbatch_options , srun_options , command , cluster ):
17+ def get_jobscript_text (
18+ sbatch_options , srun_options , command , cluster , name = 'Coffeebreak' , nsys_profiling = False , OMP_NUM_THREADS = 1
19+ ):
1820 """
1921 Generate the text for a jobscript
2022
@@ -23,25 +25,33 @@ def get_jobscript_text(sbatch_options, srun_options, command, cluster):
2325 srun_options (list): Options for the srun command
2426 command (str): python (!) command. Will be prefaced by `python <path>/`
2527 cluster (str): Name of the cluster you want to run on
28+ name (str): Jobname
29+ nsys_profiling (bool): Whether to generate an NSIGHT Systems profile
2630
2731 Returns:
2832 str: Content of jobscript
2933 """
3034 msg = '#!/usr/bin/bash\n \n '
35+ msg += f'#SBATCH -J { name } \n '
36+
3137 for op in DEFAULT_SBATCH_OPTIONS + sbatch_options :
3238 msg += f'#SBATCH { op } \n '
3339
40+ msg += f'\n export OMP_NUM_THREADS={ OMP_NUM_THREADS } \n '
3441 msg += f'\n source { PROJECT_PATH } /etc/venv_{ cluster .lower ()} /activate.sh\n '
3542
3643 srun_cmd = 'srun'
3744 for op in DEFAULT_SRUN_OPTIONS + srun_options :
3845 srun_cmd += f' { op } '
3946
47+ if nsys_profiling :
48+ srun_cmd += f' nsys profile --trace=mpi,ucx,cuda,nvtx --output={ PROJECT_PATH } /etc/nsys_profiles/{ name } .%q{{SLURM_PROCID}}_%q{{SLURM_NTASKS}} --force-overwrite true'
49+
4050 msg += f'\n { srun_cmd } python { PROJECT_PATH } /{ command } '
4151 return msg
4252
4353
44- def write_jobscript (sbatch_options , srun_options , command , cluster , submit = True ):
54+ def write_jobscript (sbatch_options , srun_options , command , cluster , submit = True , ** kwargs ):
4555 """
4656 Generate a jobscript.
4757
@@ -54,11 +64,12 @@ def write_jobscript(sbatch_options, srun_options, command, cluster, submit=True)
5464 """
5565 generate_directories ()
5666
57- text = get_jobscript_text (sbatch_options , srun_options , command , cluster )
67+ text = get_jobscript_text (sbatch_options , srun_options , command , cluster , ** kwargs )
5868
5969 path = f'{ PROJECT_PATH } /etc/jobscripts/{ command .replace (" " , "" ).replace ("/" , "_" )} -{ cluster } .sh'
6070 with open (path , 'w' ) as file :
6171 file .write (text )
72+ print (f'Written jobscript { path !r} ' )
6273
6374 if submit :
6475 import os
0 commit comments