mcell_slurm_run_range.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python
  2. import sys
  3. import os
  4. import math
  5. if __name__ == '__main__':
  6. if (len(sys.argv)<4):
  7. print ('\nUsage: %s seed_list_spec seeds_per_node mdl_file\n' % (sys.argv[0]))
  8. print ('\n Example: %s "1:100:2" 8 Scene.main.mdl\n' % (sys.argv[0]))
  9. print (' This would submit mcell jobs to simulate Scene.main.mdl')
  10. print (' using seeds 1 through 100 in steps of 2,')
  11. print (' with 8 individual simulations running concurrently in each job \n\n')
  12. sys.exit()
  13. else:
  14. seed_list_spec = sys.argv[1]
  15. seeds_per_node = int(sys.argv[2])
  16. mdl_file = sys.argv[3]
  17. seed_list = []
  18. seed_list_toks = seed_list_spec.split(',')
  19. for seed_list_tok in seed_list_toks:
  20. seed_range_toks = seed_list_tok.split(':')
  21. if (len(seed_range_toks) > 1):
  22. if (len(seed_range_toks) == 2):
  23. seed_list.extend(range(int(seed_range_toks[0]),int(seed_range_toks[1])+1))
  24. else:
  25. seed_list.extend(range(int(seed_range_toks[0]),int(seed_range_toks[1])+1,int(seed_range_toks[2])))
  26. else:
  27. seed_list.append(int(seed_list_tok))
  28. # For mcell3:
  29. mcell_exec = '$HOME/bin/mcell3.5/bin/mcell'
  30. mcell_cmd = '%s -seed $seed %s' % (mcell_exec,mdl_file)
  31. # job_script_template = '%s; for seed in ${seeds[@]}; do { %s & }; done; wait;'
  32. job_script_template = 'module load python3/3.6.4; %s; for seed in ${seeds[@]}; do { %s & }; done; wait;'
  33. job_name_template = 'mcell_%04d_%04d'
  34. sbatch_option_template = '--nodes=1 --ntasks=%d --mem-per-cpu=5800 --time=48:00:00 -J %s'
  35. for start_i in range(0,len(seed_list),seeds_per_node):
  36. end_i = start_i + seeds_per_node - 1
  37. if end_i > len(seed_list)-1:
  38. end_i = len(seed_list)-1
  39. seed_chunk = 'seeds=('
  40. for seed in seed_list[start_i:end_i+1]:
  41. seed_chunk = seed_chunk + ' ' + str(seed)
  42. seed_chunk = seed_chunk + ' )'
  43. job_script = job_script_template % (seed_chunk, mcell_cmd)
  44. job_name = job_name_template % (seed_list[start_i], seed_list[end_i])
  45. sbatch_options = sbatch_option_template % (seeds_per_node, job_name)
  46. # cmd = "echo '%s' | sbatch %s" % (job_script, sbatch_options)
  47. cmd = "sbatch %s --wrap='%s'" % (sbatch_options, job_script)
  48. print(cmd)
  49. os.system(cmd)