forked from CCQC/optavc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathingen.py
68 lines (60 loc) · 1.34 KB
/
ingen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Script to generate SLURM inputs for optmpi
import os
from subprocess import call
import sys
keywords = {
"--N": "nnode",
"--n": "nproc",
"--c": "ncore",
"--program": "program",
"--t": "time",
"--q": "queue",
"--h": "hold",
"--m": "memory"
}
settings = {
"nnode": None,
"nproc": None,
"ncore": None,
"program": None,
"time": "48:00:00",
"queue": "regular",
"hold": False,
"memory": None
}
for arg in sys.argv[1:]:
assert "=" in arg
sarg = arg.split("=")
print(sarg)
if sarg[0] in keywords:
settings[keywords[sarg[0]]] = sarg[1]
if settings["program"] is None:
print("program not set -- can't continue :(")
summ = 0
for i in settings:
if settings[i] is None:
summ += 1
if summ > 0:
print("Key information unset!")
for i in settings:
if settings[i] is None:
print(i)
settings["hold"] = True
# exit()
# if (summ <= 2) and (summ > 0):
# return
# print(summ)
template = """#!/bin/bash
#SBATCH --constraint=haswell
#SBATCH -N {nnode}
#SBATCH --qos={queue}
#SBATCH --time={time}
module load {program}
export OMP_NUM_THREADS={ncore}
srun -n {nproc} -c {ncore} python -u main.py
wait
"""
with open("submit.sh", "w") as f:
f.write(template.format(**settings))
if not settings["hold"]:
call("sbatch submit.sh", shell=True)