This source file includes following definitions.
- fence_cbfunc
- ompi_mpi_finalize
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 #include "ompi_config.h"
32
33 #ifdef HAVE_SYS_TYPES_H
34 #include <sys/types.h>
35 #endif
36 #ifdef HAVE_UNISTD_H
37 #include <unistd.h>
38 #endif
39 #ifdef HAVE_SYS_PARAM_H
40 #include <sys/param.h>
41 #endif
42 #ifdef HAVE_NETDB_H
43 #include <netdb.h>
44 #endif
45
46 #include "opal/mca/event/event.h"
47 #include "opal/util/output.h"
48 #include "opal/runtime/opal_progress.h"
49 #include "opal/mca/base/base.h"
50 #include "opal/sys/atomic.h"
51 #include "opal/runtime/opal.h"
52 #include "opal/util/show_help.h"
53 #include "opal/mca/mpool/base/base.h"
54 #include "opal/mca/mpool/base/mpool_base_tree.h"
55 #include "opal/mca/rcache/base/base.h"
56 #include "opal/mca/allocator/base/base.h"
57 #include "opal/mca/pmix/pmix.h"
58 #include "opal/util/timings.h"
59
60 #include "mpi.h"
61 #include "ompi/constants.h"
62 #include "ompi/errhandler/errcode.h"
63 #include "ompi/communicator/communicator.h"
64 #include "ompi/datatype/ompi_datatype.h"
65 #include "ompi/message/message.h"
66 #include "ompi/op/op.h"
67 #include "ompi/file/file.h"
68 #include "ompi/info/info.h"
69 #include "ompi/runtime/mpiruntime.h"
70 #include "ompi/attribute/attribute.h"
71 #include "ompi/mca/pml/pml.h"
72 #include "ompi/mca/bml/bml.h"
73 #include "ompi/mca/pml/base/base.h"
74 #include "ompi/mca/bml/base/base.h"
75 #include "ompi/mca/osc/base/base.h"
76 #include "ompi/mca/coll/base/base.h"
77 #include "ompi/mca/rte/rte.h"
78 #include "ompi/mca/rte/base/base.h"
79 #include "ompi/mca/topo/base/base.h"
80 #include "ompi/mca/io/io.h"
81 #include "ompi/mca/io/base/base.h"
82 #include "ompi/mca/pml/base/pml_base_bsend.h"
83 #include "ompi/runtime/params.h"
84 #include "ompi/dpm/dpm.h"
85 #include "ompi/mpiext/mpiext.h"
86 #include "ompi/mca/hook/base/base.h"
87
88 #if OPAL_ENABLE_FT_CR == 1
89 #include "ompi/mca/crcp/crcp.h"
90 #include "ompi/mca/crcp/base/base.h"
91 #endif
92 #include "ompi/runtime/ompi_cr.h"
93
94 extern bool ompi_enable_timing;
95
96 static void fence_cbfunc(int status, void *cbdata)
97 {
98 volatile bool *active = (volatile bool*)cbdata;
99 OPAL_ACQUIRE_OBJECT(active);
100 *active = false;
101 OPAL_POST_OBJECT(active);
102 }
103
104 int ompi_mpi_finalize(void)
105 {
106 int ret = MPI_SUCCESS;
107 opal_list_item_t *item;
108 ompi_proc_t** procs;
109 size_t nprocs;
110 volatile bool active;
111 uint32_t key;
112 ompi_datatype_t * datatype;
113
114 ompi_hook_base_mpi_finalize_top();
115
116 int32_t state = ompi_mpi_state;
117 if (state < OMPI_MPI_STATE_INIT_COMPLETED ||
118 state >= OMPI_MPI_STATE_FINALIZE_STARTED) {
119
120
121
122 char hostname[OPAL_MAXHOSTNAMELEN];
123 pid_t pid = getpid();
124 gethostname(hostname, sizeof(hostname));
125
126 if (state < OMPI_MPI_STATE_INIT_COMPLETED) {
127 opal_show_help("help-mpi-runtime.txt",
128 "mpi_finalize: not initialized",
129 true, hostname, pid);
130 } else if (state >= OMPI_MPI_STATE_FINALIZE_STARTED) {
131 opal_show_help("help-mpi-runtime.txt",
132 "mpi_finalize:invoked_multiple_times",
133 true, hostname, pid);
134 }
135 return MPI_ERR_OTHER;
136 }
137 opal_atomic_wmb();
138 opal_atomic_swap_32(&ompi_mpi_state, OMPI_MPI_STATE_FINALIZE_STARTED);
139
140 ompi_mpiext_fini();
141
142
143
144
145
146 if (NULL != ompi_mpi_comm_self.comm.c_keyhash) {
147 ompi_attr_delete_all(COMM_ATTR, &ompi_mpi_comm_self,
148 ompi_mpi_comm_self.comm.c_keyhash);
149 OBJ_RELEASE(ompi_mpi_comm_self.comm.c_keyhash);
150 ompi_mpi_comm_self.comm.c_keyhash = NULL;
151 }
152
153
154
155
156
157
158 opal_atomic_wmb();
159 opal_atomic_swap_32(&ompi_mpi_state,
160 OMPI_MPI_STATE_FINALIZE_PAST_COMM_SELF_DESTRUCT);
161
162
163
164
165 (void)mca_pml_base_bsend_detach(NULL, NULL);
166
167 #if OPAL_ENABLE_PROGRESS_THREADS == 0
168 opal_progress_set_event_flag(OPAL_EVLOOP_ONCE | OPAL_EVLOOP_NONBLOCK);
169 #endif
170
171
172
173 opal_progress_event_users_increment();
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 if (!ompi_async_mpi_finalize) {
251 if (NULL != opal_pmix.fence_nb) {
252 active = true;
253 OPAL_POST_OBJECT(&active);
254
255
256
257
258
259
260 if (OMPI_SUCCESS != (ret = opal_pmix.fence_nb(NULL, 0, fence_cbfunc,
261 (void*)&active))) {
262 OMPI_ERROR_LOG(ret);
263
264
265 active = false;
266 }
267 OMPI_LAZY_WAIT_FOR_COMPLETION(active);
268 } else {
269
270
271
272
273
274 ompi_communicator_t *comm = &ompi_mpi_comm_world.comm;
275 comm->c_coll->coll_barrier(comm, comm->c_coll->coll_barrier_module);
276
277 if (OMPI_SUCCESS != (ret = opal_pmix.fence(NULL, 0))) {
278 OMPI_ERROR_LOG(ret);
279 }
280 }
281 }
282
283
284
285
286 if (OMPI_SUCCESS != (ret = ompi_cr_finalize())) {
287 OMPI_ERROR_LOG(ret);
288 }
289
290
291
292
293
294
295
296 while (NULL != (item = opal_list_remove_first(&ompi_registered_datareps))) {
297 OBJ_RELEASE(item);
298 }
299 OBJ_DESTRUCT(&ompi_registered_datareps);
300
301
302 OPAL_HASH_TABLE_FOREACH(key, uint32, datatype, &ompi_mpi_f90_integer_hashtable)
303 OBJ_RELEASE(datatype);
304 OBJ_DESTRUCT(&ompi_mpi_f90_integer_hashtable);
305 OPAL_HASH_TABLE_FOREACH(key, uint32, datatype, &ompi_mpi_f90_real_hashtable)
306 OBJ_RELEASE(datatype);
307 OBJ_DESTRUCT(&ompi_mpi_f90_real_hashtable);
308 OPAL_HASH_TABLE_FOREACH(key, uint32, datatype, &ompi_mpi_f90_complex_hashtable)
309 OBJ_RELEASE(datatype);
310 OBJ_DESTRUCT(&ompi_mpi_f90_complex_hashtable);
311
312
313
314
315 if (OMPI_SUCCESS != (ret = ompi_file_finalize())) {
316 goto done;
317 }
318
319
320 if (OMPI_SUCCESS != (ret = ompi_win_finalize())) {
321 goto done;
322 }
323 if (OMPI_SUCCESS != (ret = ompi_osc_base_finalize())) {
324 goto done;
325 }
326
327
328
329 if (OMPI_SUCCESS != (ret = ompi_comm_finalize())) {
330 goto done;
331 }
332
333
334
335
336 nprocs = 0;
337 procs = ompi_proc_get_allocated (&nprocs);
338 MCA_PML_CALL(del_procs(procs, nprocs));
339 free(procs);
340
341
342 if(OMPI_SUCCESS != (ret = mca_pml_base_finalize())) {
343 goto done;
344 }
345
346
347 if (OMPI_SUCCESS != (ret = ompi_request_finalize())) {
348 goto done;
349 }
350
351 if (OMPI_SUCCESS != (ret = ompi_message_finalize())) {
352 goto done;
353 }
354
355
356
357 if (0 != ompi_debug_show_mpi_alloc_mem_leaks) {
358 mca_mpool_base_tree_print(ompi_debug_show_mpi_alloc_mem_leaks);
359 }
360
361
362
363 if (OMPI_SUCCESS != (ret = mca_base_framework_close(&ompi_pml_base_framework) ) ) {
364 OMPI_ERROR_LOG(ret);
365 goto done;
366 }
367
368
369 mca_pml_base_bsend_fini();
370
371 #if OPAL_ENABLE_FT_CR == 1
372
373
374
375 if (OMPI_SUCCESS != (ret = mca_base_framework_close(&ompi_crcp_base_framework) ) ) {
376 OMPI_ERROR_LOG(ret);
377 goto done;
378 }
379 #endif
380
381
382
383
384 if (OMPI_SUCCESS != (ret = ompi_attr_finalize())) {
385 goto done;
386 }
387
388
389 if (OMPI_SUCCESS != (ret = ompi_group_finalize())) {
390 goto done;
391 }
392
393
394 if ( OMPI_SUCCESS != (ret = ompi_dpm_finalize())) {
395 goto done;
396 }
397
398
399 if (OMPI_SUCCESS != (ret = ompi_errcode_intern_finalize())) {
400 goto done;
401 }
402
403
404 if (OMPI_SUCCESS != (ret = ompi_mpi_errcode_finalize())) {
405 goto done;
406 }
407
408
409 if (OMPI_SUCCESS != (ret = ompi_errhandler_finalize())) {
410 goto done;
411 }
412
413
414
415
416 if (OMPI_SUCCESS != (ret = ompi_op_finalize())) {
417 goto done;
418 }
419
420
421 if (OMPI_SUCCESS != (ret = ompi_datatype_finalize())) {
422 goto done;
423 }
424
425
426 if (OMPI_SUCCESS != (ret = ompi_mpiinfo_finalize())) {
427 goto done;
428 }
429
430
431
432
433
434 if (0 < ompi_io_base_framework.framework_refcnt) {
435
436 ompi_io_base_framework.framework_refcnt = 1;
437
438 if (OMPI_SUCCESS != mca_base_framework_close(&ompi_io_base_framework)) {
439 goto done;
440 }
441 }
442 (void) mca_base_framework_close(&ompi_topo_base_framework);
443 if (OMPI_SUCCESS != (ret = mca_base_framework_close(&ompi_osc_base_framework))) {
444 goto done;
445 }
446 if (OMPI_SUCCESS != (ret = mca_base_framework_close(&ompi_coll_base_framework))) {
447 goto done;
448 }
449 if (OMPI_SUCCESS != (ret = mca_base_framework_close(&ompi_bml_base_framework))) {
450 goto done;
451 }
452 if (OMPI_SUCCESS != (ret = mca_base_framework_close(&opal_mpool_base_framework))) {
453 goto done;
454 }
455 if (OMPI_SUCCESS != (ret = mca_base_framework_close(&opal_rcache_base_framework))) {
456 goto done;
457 }
458 if (OMPI_SUCCESS != (ret = mca_base_framework_close(&opal_allocator_base_framework))) {
459 goto done;
460 }
461
462
463 if ( OMPI_SUCCESS != (ret = ompi_proc_finalize())) {
464 goto done;
465 }
466
467 if (NULL != ompi_mpi_main_thread) {
468 OBJ_RELEASE(ompi_mpi_main_thread);
469 ompi_mpi_main_thread = NULL;
470 }
471
472
473
474 ompi_mpi_dynamics_finalize();
475
476
477
478 if (OMPI_SUCCESS != (ret = ompi_rte_finalize())) {
479 goto done;
480 }
481 ompi_rte_initialized = false;
482
483
484 if (OMPI_SUCCESS != (ret = mca_base_framework_close(&ompi_rte_base_framework) ) ) {
485 OMPI_ERROR_LOG(ret);
486 goto done;
487 }
488
489
490 if (OMPI_SUCCESS != (ret = mca_base_framework_close(&ompi_hook_base_framework) ) ) {
491 OMPI_ERROR_LOG(ret);
492 goto done;
493 }
494
495 if (OPAL_SUCCESS != (ret = opal_finalize_util())) {
496 goto done;
497 }
498
499 if (0 == opal_initialized) {
500
501
502
503 opal_class_finalize();
504 }
505
506
507 opal_unsetenv("OMPI_COMMAND", &environ);
508 opal_unsetenv("OMPI_ARGV", &environ);
509
510
511
512 done:
513 opal_atomic_wmb();
514 opal_atomic_swap_32(&ompi_mpi_state, OMPI_MPI_STATE_FINALIZE_COMPLETED);
515
516 ompi_hook_base_mpi_finalize_bottom();
517
518 return ret;
519 }