This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
/
SWEETPlatform.py
368 lines (258 loc) · 6.52 KB
/
SWEETPlatform.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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
import platform
import socket
import sys
import os
from SWEET import *
from . import SWEETPlatformAutodetect
# Underscore defines symbols to be private
_job_id = None
def _whoami(depth=1):
"""
String of function name to recycle code
https://www.oreilly.com/library/view/python-cookbook/0596001673/ch14s08.html
Returns
-------
string
Return function name
"""
return sys._getframe(depth).f_code.co_name
def p_gen_script_info(j : SWEETJobGeneration):
global _job_id
return """#
# Generating function: """+_whoami(2)+"""
# Platform: """+get_platform_id()+"""
# Job id: """+_job_id+"""
#
"""
def get_platform_autodetect():
"""
Returns
-------
bool
True if current platform matches, otherwise False
"""
return SWEETPlatformAutodetect.get_platform_autodetect()
def get_platform_id():
"""
Return platform ID
Returns
-------
string
unique ID of platform
"""
return "cheyenne_intel_economy"
def get_platform_resources():
"""
Return information about hardware
"""
r = SWEETPlatformResources()
r.num_cores_per_node = 36
# Physical number of nodes, maybe the limit is different
r.num_nodes = 4032
r.num_cores_per_socket = 18
# 12h limit
r.max_wallclock_seconds = 60*60*12
return r
def jobscript_setup(j : SWEETJobGeneration):
"""
Setup data to generate job script
"""
global _job_id
_job_id = j.runtime.getUniqueID(j.compile)
return
def jobscript_get_header(j : SWEETJobGeneration):
"""
These headers typically contain the information on e.g. Job exection, number of compute nodes, etc.
Returns
-------
string
multiline text for scripts
"""
global _job_id
p = j.parallelization
time_str = p.get_max_wallclock_seconds_hh_mm_ss()
#
# See https://www.lrz.de/services/compute/linux-cluster/batch_parallel/example_jobs/
#
content = """#! /bin/bash
#
## project code
#PBS -A NCIS0002
## economy queue
#PBS -q economy
## wall-clock time (hrs:mins:secs)
#PBS -l walltime="""+time_str+"""
## select: number of nodes
## ncpus: number of CPUs per node
## mpiprocs: number of ranks per node
#PBS -l select="""+str(p.num_nodes)+""":ncpus="""+str(p.num_cores_per_node)+""":mpiprocs="""+str(p.num_ranks_per_node)+""":ompthreads="""+str(p.num_threads_per_rank)+"\n"
#"default": 2301000
#"turbo": 2301000
#"rated": 2300000
#"slow": 1200000
if p.force_turbo_off:
content += "#PBS -l select=cpufreq=2300000\n"
ld_library_path = os.getenv('LD_LIBRARY_PATH')
content += """#
#PBS -N """+_job_id[0:100]+"""
#PBS -o """+j.p_job_stdout_filepath+"""
#PBS -e """+j.p_job_stderr_filepath+"""
#source /etc/profile.d/modules.sh
#module load openmpi
"""+("module load mkl" if j.compile.mkl==True or j.compile.mkl=='enable' else "")+"""
"""+p_gen_script_info(j)+"""
# Make sure that SWEET library path is really known
export LD_LIBRARY_PATH=\""""+ld_library_path+""":$LD_LIBRARY_PATH\"
echo
echo "LD_LIBRARY_PATH"
echo "${LD_LIBRARY_PATH}"
echo
echo
echo "hostname"
hostname
echo
echo
echo "lscpu -e"
lscpu -e
echo
echo
echo "CPU Frequencies (uniquely reduced):"
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq | sort -u
echo
"""
if j.compile.threading != 'off':
content += """
export OMP_NUM_THREADS="""+str(p.num_threads_per_rank)+"""
"""
if p.core_oversubscription:
raise Exception("Not supported with this script!")
if p.core_affinity != None:
content += "\necho \"Affnity: "+str(p.core_affinity)+"\"\n"
if p.core_affinity == 'compact':
content += "\nexport OMP_PROC_BIND=close\n"
elif p.core_affinity == 'scatter':
content += "\nexport OMP_PROC_BIND=spread\n"
else:
raise Exception("Affinity '"+str(p.core_affinity)+"' not supported")
return content
def jobscript_get_exec_prefix(j : SWEETJobGeneration):
"""
Prefix before executable
Returns
-------
string
multiline text for scripts
"""
content = ""
p = j.parallelization
plan_files = []
if j.compile.plane_spectral_space == 'enable':
plan_files.append('sweet_fftw')
if j.compile.sphere_spectral_space == 'enable':
plan_files.append('shtns_cfg')
plan_files.append('shtns_cfg_fftw')
#
# Reusing plans assumes them to be stored in the folder one level up in the hierarchy
#
if j.runtime.reuse_plans == -1:
# Quick plan generation mode, nothing to do
pass
elif j.runtime.reuse_plans == 0:
# Create plans, don't load/store them
pass
elif j.runtime.reuse_plans == 1:
content += "\n"
# Reuse plans if available
for i in plan_files:
content += "cp ../"+i+" ./ 2>/dev/null\n"
elif j.runtime.reuse_plans == 2:
content += "\n"
# Reuse and trigger error if they are not available
for i in plan_files:
content += "cp ../"+i+" ./ || exit 1\n"
else:
raise Exception("Invalid reuse_plans value"+str(p.runtime.reuse_plans))
return content
def jobscript_get_exec_command(j : SWEETJobGeneration):
"""
Prefix to executable command
Returns
-------
string
multiline text for scripts
"""
p = j.parallelization
mpiexec = ""
#
# Only use MPI exec if we are allowed to do so
# We shouldn't use mpiexec for validation scripts
#
if not p.mpiexec_disabled:
# Use mpiexec_mpt for Intel MPI
#mpiexec = "mpiexec_mpt -n "+str(p.num_ranks)
# Use mpiexec for GNU
if j.compile.sweet_mpi == 'enable':
mpiexec = "mpiexec_mpt -n "+str(p.num_ranks)
mpiexec += " omplace "
mpiexec += " -nt "+str(p.num_threads_per_rank)+" "
mpiexec += " -tm intel"
mpiexec += " -vv"
if mpiexec[-1] != ' ':
mpiexec += ' '
content = """
EXEC=\"$SWEET_ROOT/build/"""+j.compile.getProgramName()+"""\"
PARAMS=\""""+j.runtime.getRuntimeOptions()+"""\"
echo
echo "ldd"
ldd $EXEC
echo
E=\""""+mpiexec+"""${EXEC} ${PARAMS}\"
echo
echo "Executing..."
echo "$E"
$E
"""
return content
def jobscript_get_exec_suffix(j : SWEETJobGeneration):
"""
Suffix before executable
Returns
-------
string
multiline text for scripts
"""
content = """
echo
echo "CPU Frequencies (uniquely reduced):"
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq | sort -u
echo
"""
return content
def jobscript_get_footer(j : SWEETJobGeneration):
"""
Footer at very end of job script
Returns
-------
string
multiline text for scripts
"""
content = ""
return content
def jobscript_get_compile_command(j : SWEETJobGeneration):
"""
Compile command(s)
This is separated here to put it either
* into the job script (handy for workstations)
or
* into a separate compile file (handy for clusters)
Returns
-------
string
multiline text with compile command to generate executable
"""
content = """
SCONS="scons """+j.compile.getSConsParams()+' -j 4"'+"""
echo "$SCONS"
$SCONS || exit 1
"""
return content