-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun-parallel.py
More file actions
286 lines (231 loc) · 9.46 KB
/
run-parallel.py
File metadata and controls
286 lines (231 loc) · 9.46 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import argparse
import collections
import importlib.metadata
import numpy as np
import os
import platform as platform_
import yaml
from pathlib import Path
# Supported compute platforms and their parameters
PLATFORMS = ["dane", "lassen", "tuolumne"]
#
JOB_SUBMISSION = {}
JOB_SUBMISSION["dane"] = 'sbatch'
JOB_SUBMISSION["lassen"] = 'bsub'
JOB_SUBMISSION["tuolumne"] = 'flux batch'
#
JOB_SCHEDULER = {}
JOB_SCHEDULER["dane"] = 'slurm'
JOB_SCHEDULER["lassen"] = 'lsf'
JOB_SCHEDULER["tuolumne"] = 'flux'
#
JOB_TIME = {}
JOB_TIME['dane'] = "XX:00:00"
JOB_TIME['lassen'] = "XX:00"
JOB_TIME['tuolumne'] = "XXh"
#
MAX_TIME = {}
MAX_TIME['dane'] = 24
MAX_TIME['lassen'] = 24 # Actual max: 12
MAX_TIME['tuolumne'] = 24
#
CPU_CORES_PER_NODE = {}
CPU_CORES_PER_NODE["dane"] = 112
CPU_CORES_PER_NODE["lassen"] = 40 # 44
CPU_CORES_PER_NODE["tuolumne"] = 96
#
GPUS_PER_NODE = {}
GPUS_PER_NODE["dane"] = 0
GPUS_PER_NODE["lassen"] = 4
GPUS_PER_NODE["tuolumne"] = 4
#
MAX_NODES = {}
MAX_NODES["dane"] = 128 # Actual limit: 520
MAX_NODES["lassen"] = 128 # Actual limit: 256
MAX_NODES["tuolumne"] = 128 # No strict limit
# ======================================================================================
# Run options
# ======================================================================================
parser = argparse.ArgumentParser(description="MC/DC Performance Test Suite - Parallel")
parser.add_argument("--platform", type=str, required="True", choices=PLATFORMS)
args, unargs = parser.parse_known_args()
# Set platform parameters
platform = args.platform
job_submission = JOB_SUBMISSION[platform]
job_scheduler = JOB_SCHEDULER[platform]
job_time = JOB_TIME[platform]
cpu_cores_per_node = CPU_CORES_PER_NODE[platform]
gpus_per_node = GPUS_PER_NODE[platform]
max_nodes = MAX_NODES[platform]
max_time = MAX_TIME[platform]
# Get the PBS template
with open("pbs_templates/%s.pbs"%job_scheduler, 'r') as f:
pbs_template = f.read()
# ======================================================================================
# Preparation
# ======================================================================================
# Create version result to store the results
version = importlib.metadata.version("mcdc")
dir_version = "%s" % version
Path(dir_version).mkdir(parents=True, exist_ok=True)
# Create and get in to the folder
dir_serial = "%s/parallel/%s" % (version, platform)
Path(dir_serial).mkdir(parents=True, exist_ok=True)
os.chdir(dir_serial)
# Save the machine specification
# TODO: GPU specs
spec = {}
spec["architecture"] = str(platform_.architecture())
spec["machine"] = str(platform_.machine())
spec["node"] = str(platform_.node())
spec["platform"] = str(platform_.platform(aliased=True))
spec["processor"] = str(platform_.processor())
spec["release"] = str(platform_.release())
spec["system"] = str(platform_.system())
spec["version"] = str(platform_.version())
with open("machine_spec.yaml", "w") as f:
yaml.dump(spec, f)
# Read the tasks
os.chdir("../../../")
with open("tasks/parallel.yaml", "r") as file:
tasks = yaml.safe_load(file)
# ======================================================================================
# Run the tests
# ======================================================================================
# Loop over the test suite problems
os.chdir("test_suite")
for problem in tasks:
# Get into the problem folder
os.chdir(problem)
# ==================================================================================
# MC/DC
# ==================================================================================
os.chdir("mcdc")
# Create and get into output folder
Path("output").mkdir(parents=True, exist_ok=True)
os.chdir("output")
# Loop over methods
for method in tasks[problem]:
# Loop over modes
for mode in tasks[problem][method][platform]:
# Only-CPU platform?
if platform in ['dane'] and mode == 'gpu':
continue
# OpenMC?
if mode == 'openmc':
continue
# TODO: GPU mode
if mode == 'gpu':
continue
# Run parameter
N_base = tasks[problem][method][platform][mode]
for N_node in [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]:
N_rank = N_node * cpu_cores_per_node
# Stop if exceeding maximum
if N_node > max_nodes:
break
# Create and get into sub output folder
dir_output = "parallel-%s-%s-%s-node_%i" % (platform, method, mode, N_node)
Path(dir_output).mkdir(parents=True, exist_ok=True)
os.chdir(dir_output)
# Copy necessary files
os.system("cp ../../* . 2>/dev/null")
def submit_case(case, the_time, powers):
# Exceed the time?
if the_time > max_time:
return
# Start building the PBS file
pbs_text = pbs_template[:]
pbs_text = pbs_text.replace('<N_NODE>', '%i' % N_node)
pbs_text = pbs_text.replace('<JOB_NAME>', 'mcdc-par-%s-%s-%s-%s' % (problem, method, mode, case))
pbs_text = pbs_text.replace('<TIME>', job_time.replace('XX', str(the_time)))
pbs_text = pbs_text.replace('<CASE>', "-"+case)
# Loop over runs
commands = ""
previous_output = None
for i in range(len(powers)):
power = powers[i]
N = int(2**power * N_node * N_base)
commands += (
"srun -n %i python input.py %s --mode=numba --N_particle=%i --output=output_%i --no-progress_bar --caching --runtime_output\n"
% (N_rank, method, N, power)
)
# Delete previous output (note that runtimes are saved)
if previous_output is not None:
commands += "rm %s.h5\n" % previous_output
previous_output = "output_%i" % power
# Finalize commands and PBS file
pbs_text = pbs_text.replace('<COMMANDS>', commands)
with open(f"submit-%s.pbs"%case, 'w') as f:
f.write(pbs_text)
# Submit job
os.system("%s submit-%s.pbs" % (job_submission, case))
# Submit cases
submit_case("case1", 3, [-4, -3, -2, -1, 0])
submit_case("case2", 3, [1])
submit_case("case3", 6, [2])
submit_case("case4", 12, [3])
submit_case("case5", 24, [4])
os.chdir('..')
os.chdir("../../")
# ==================================================================================
# OpenMC
# ==================================================================================
# Only for Dane
if platform != "dane":
exit()
os.chdir("openmc")
# Create and get into output folder
Path("output").mkdir(parents=True, exist_ok=True)
os.chdir("output")
# Run parameter
N_base = tasks[problem]['analog']['dane']['openmc']
for N_node in [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]:
N_rank = N_node * cpu_cores_per_node
# Stop if exceeding maximum
if N_node > max_nodes:
break
# Create and get into sub output folder
dir_output = "parallel-%s-node_%i" % (platform, N_node)
Path(dir_output).mkdir(parents=True, exist_ok=True)
os.chdir(dir_output)
# Copy necessary files
os.system("cp ../../* . 2>/dev/null")
def submit_case(case, the_time, powers):
# Exceed the time?
if the_time > max_time:
return
# Start building the PBS file
pbs_text = pbs_template[:]
pbs_text = pbs_text.replace('<N_NODE>', '%i' % N_node)
pbs_text = pbs_text.replace('<JOB_NAME>', 'openmc-par-%s-%s' % (problem, case))
pbs_text = pbs_text.replace('<TIME>', job_time.replace('XX', str(the_time)))
pbs_text = pbs_text.replace('<CASE>', "-"+case)
# Loop over runs
commands = ""
previous_output = None
for i in range(len(powers)):
power = powers[i]
N = int(2**power * N_node * N_base)
commands += "python build-xml.py %i\n" % (N)
commands += "srun -n %i openmc -s 1\n" % (N_node)
commands += "mv statepoint.30.h5 output_%i.h5\n" % power
commands += "rm *xml\n"
# Delete previous output (note that runtimes are saved)
if previous_output is not None:
commands += "rm %s.h5\n" % previous_output
previous_output = "output_%i" % power
# Finalize commands and PBS file
pbs_text = pbs_text.replace('<COMMANDS>', commands)
with open(f"submit-%s.pbs"%case, 'w') as f:
f.write(pbs_text)
# Submit job
os.system("%s submit-%s.pbs" % (job_submission, case))
# Submit cases
submit_case("case1", 3, [-4, -3, -2, -1, 0])
submit_case("case2", 3, [1])
submit_case("case3", 6, [2])
submit_case("case4", 12, [3])
submit_case("case5", 24, [4])
os.chdir('..')
os.chdir("../../..")