-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_qssp_bulk.py
executable file
·360 lines (341 loc) · 10.7 KB
/
create_qssp_bulk.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
import os
import platform
import shutil
import datetime
import pickle
from multiprocessing import Pool
from mpi4py import MPI
from pygrnwang.create_qssp import mt_com_list, create_inp, create_dir, call_qssp2020
from pygrnwang.utils import group
def pre_process_spec(
processes_num,
event_depth_list,
receiver_depth_list,
path_green,
path_bin,
spec_time_window,
time_window,
time_reduction,
dist_range,
delta_dist_range,
sampling_interval,
max_frequency,
max_slowness,
anti_alias,
turning_point_filter,
turning_point_d1,
turning_point_d2,
free_surface_filter,
gravity_fc,
gravity_harmonic,
cal_sph,
cal_tor,
min_harmonic,
max_harmonic,
path_nd=None,
earth_model_layer_num=None,
):
if platform.system() == 'Windows':
path_bin_call = os.path.join(path_green, "qssp2020.exe")
else:
path_bin_call = os.path.join(path_green, "qssp2020.bin")
if not os.path.exists(path_bin_call):
shutil.copy(path_bin, path_bin_call)
item_list_spec = []
for event_depth in event_depth_list:
for receiver_depth in receiver_depth_list:
create_dir(event_depth, receiver_depth, path_green)
create_inp(
"spec",
event_depth,
receiver_depth,
path_green,
spec_time_window,
time_window,
time_reduction,
dist_range,
delta_dist_range,
sampling_interval,
max_frequency,
max_slowness,
anti_alias,
turning_point_filter,
turning_point_d1,
turning_point_d2,
free_surface_filter,
gravity_fc,
gravity_harmonic,
cal_sph,
cal_tor,
min_harmonic,
max_harmonic,
1,
[0 for _ in range(11)],
path_nd,
earth_model_layer_num,
)
item_list_spec.append([event_depth, receiver_depth, "spec"])
group_list_spec = group(item_list_spec, processes_num)
with open(os.path.join(path_green, "group_list_spec.pkl"), "wb") as fw:
pickle.dump(group_list_spec, fw)
return group_list_spec
def pre_process_func(
processes_num,
event_depth_list,
receiver_depth_list,
path_green,
path_bin,
spec_time_window,
time_window,
time_reduction,
dist_range,
delta_dist_range,
sampling_interval,
max_frequency,
max_slowness,
anti_alias,
turning_point_filter,
turning_point_d1,
turning_point_d2,
free_surface_filter,
gravity_fc,
gravity_harmonic,
cal_sph,
cal_tor,
min_harmonic,
max_harmonic,
output_observables: list,
path_nd=None,
earth_model_layer_num=None,
):
if platform.system() == 'Windows':
path_bin_call = os.path.join(path_green, "qssp2020.exe")
else:
path_bin_call = os.path.join(path_green, "qssp2020.bin")
if not os.path.exists(path_bin_call):
shutil.copy(path_bin, path_bin_call)
item_list_func = []
for event_depth in event_depth_list:
for receiver_depth in receiver_depth_list:
for mt_com in mt_com_list:
create_inp(
mt_com,
event_depth,
receiver_depth,
path_green,
spec_time_window,
time_window,
time_reduction,
dist_range,
delta_dist_range,
sampling_interval,
max_frequency,
max_slowness,
anti_alias,
turning_point_filter,
turning_point_d1,
turning_point_d2,
free_surface_filter,
gravity_fc,
gravity_harmonic,
cal_sph,
cal_tor,
min_harmonic,
max_harmonic,
0,
output_observables,
path_nd,
earth_model_layer_num,
)
item_list_func.append([event_depth, receiver_depth, mt_com])
group_list_func = group(item_list_func, processes_num)
with open(os.path.join(path_green, "group_list_func.pkl"), "wb") as fw:
pickle.dump(group_list_func, fw)
return group_list_func
def pre_process(
processes_num,
event_depth_list,
receiver_depth_list,
path_green,
path_bin,
spec_time_window,
time_window,
time_reduction,
dist_range,
delta_dist_range,
sampling_interval,
max_frequency,
max_slowness,
anti_alias,
turning_point_filter,
turning_point_d1,
turning_point_d2,
free_surface_filter,
gravity_fc,
gravity_harmonic,
cal_sph,
cal_tor,
min_harmonic,
max_harmonic,
output_observables,
path_nd=None,
earth_model_layer_num=None,
):
pre_process_spec(
processes_num,
event_depth_list,
receiver_depth_list,
path_green,
path_bin,
spec_time_window,
time_window,
time_reduction,
dist_range,
delta_dist_range,
sampling_interval,
max_frequency,
max_slowness,
anti_alias,
turning_point_filter,
turning_point_d1,
turning_point_d2,
free_surface_filter,
gravity_fc,
gravity_harmonic,
cal_sph,
cal_tor,
min_harmonic,
max_harmonic,
path_nd,
earth_model_layer_num,
)
pre_process_func(
processes_num,
event_depth_list,
receiver_depth_list,
path_green,
path_bin,
spec_time_window,
time_window,
time_reduction,
dist_range,
delta_dist_range,
sampling_interval,
max_frequency,
max_slowness,
anti_alias,
turning_point_filter,
turning_point_d1,
turning_point_d2,
free_surface_filter,
gravity_fc,
gravity_harmonic,
cal_sph,
cal_tor,
min_harmonic,
max_harmonic,
output_observables,
path_nd,
earth_model_layer_num,
)
def create_grnlib_parallel_single_node(path_green):
s = datetime.datetime.now()
with open(os.path.join(path_green, "group_list_spec.pkl"), "rb") as fr:
group_list_spec = pickle.load(fr)
for item in group_list_spec:
# print(
# "computing event_dep %.1f km, receiver_dep %.1f km"
# % (item[0], item[1])
# )
print("computing spec lib " + str(item))
for i in range(len(item)):
item[i] = item[i] + [path_green]
pool = Pool()
r = pool.starmap_async(call_qssp2020, item)
r.get()
pool.close()
pool.join()
with open(os.path.join(path_green, "group_list_func.pkl"), "rb") as fr:
group_list_func = pickle.load(fr)
for item in group_list_func:
# print(
# "computing event_dep %.1f km, receiver_dep %.1f km, %s"
# % (item[0], item[1], item[2])
# )
print("computing time lib " + str(item))
for i in range(len(item)):
item[i] = item[i] + [path_green]
pool = Pool()
r = pool.starmap_async(call_qssp2020, item)
r.get()
pool.close()
pool.join()
e = datetime.datetime.now()
print("run time:" + str(e - s))
def create_grnlib_spec_parallel_multi_nodes(path_green):
with open(os.path.join(path_green, "group_list_spec.pkl"), "rb") as fr:
group_list_spec = pickle.load(fr)
N_all = 0
for ind_group in range(len(group_list_spec)):
N_all = N_all + len(group_list_spec[ind_group])
for ind_group in range(len(group_list_spec)):
comm = MPI.COMM_WORLD
processes_num = comm.Get_size()
rank = comm.Get_rank()
if processes_num < len(group_list_spec[0]):
raise ValueError(
"processes_num is %d, item num in group is %d. \n"
"Pleasse check the process num!"
% (processes_num, len(group_list_spec[0]))
)
print(
"computing spec lib ind_group:%d rank:%d event_depth:%.1f receiver_depth:%.1f"
% (
ind_group,
rank,
group_list_spec[ind_group][rank][0],
group_list_spec[ind_group][rank][1],
)
)
if ind_group * len(group_list_spec[0]) + rank < N_all:
call_qssp2020(
event_depth=group_list_spec[ind_group][rank][0],
receiver_depth=group_list_spec[ind_group][rank][1],
mt_com=group_list_spec[ind_group][rank][2],
path_green=path_green,
)
def create_grnlib_func_parallel_multi_nodes(path_green):
with open(os.path.join(path_green, "group_list_func.pkl"), "rb") as fr:
group_list_spec = pickle.load(fr)
N_all = 0
for ind_group in range(len(group_list_spec)):
N_all = N_all + len(group_list_spec[ind_group])
for ind_group in range(len(group_list_spec)):
comm = MPI.COMM_WORLD
processes_num = comm.Get_size()
rank = comm.Get_rank()
if processes_num < len(group_list_spec[0]):
raise ValueError(
"processes_num is %d, item num in group is %d. \n"
"Pleasse check the process num!"
% (processes_num, len(group_list_spec[0]))
)
print(
"computing time lib ind_group:%d rank:%d event_depth:%.1f receiver_depth:%.1f mt_com:%s"
% (
ind_group,
rank,
group_list_spec[ind_group][rank][0],
group_list_spec[ind_group][rank][1],
group_list_spec[ind_group][rank][2],
)
)
if ind_group * len(group_list_spec[0]) + rank < N_all:
call_qssp2020(
event_depth=group_list_spec[ind_group][rank][0],
receiver_depth=group_list_spec[ind_group][rank][1],
mt_com=group_list_spec[ind_group][rank][2],
path_green=path_green,
)
if __name__ == "__main__":
pass