root/oshmem/runtime/oshmem_shmem_finalize.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. oshmem_shmem_finalize
  2. _shmem_finalize

   1 /*
   2  * Copyright (c) 2013-2018 Mellanox Technologies, Inc.
   3  *                         All rights reserved.
   4  * Copyright (c) 2015-2019 Research Organization for Information Science
   5  *                         and Technology (RIST).  All rights reserved.
   6  * Copyright (c) 2018      Cisco Systems, Inc.  All rights reserved
   7  * $COPYRIGHT$
   8  *
   9  * Additional copyrights may follow
  10  *
  11  * $HEADER$
  12  */
  13 
  14 #include "oshmem_config.h"
  15 
  16 #ifdef HAVE_SYS_TYPES_H
  17 #include <sys/types.h>
  18 #endif
  19 #ifdef HAVE_UNISTD_H
  20 #include <unistd.h>
  21 #endif
  22 #ifdef HAVE_SYS_PARAM_H
  23 #include <sys/param.h>
  24 #endif
  25 #ifdef HAVE_NETDB_H
  26 #include <netdb.h>
  27 #endif
  28 
  29 #include "opal/util/output.h"
  30 #include "opal/runtime/opal_progress.h"
  31 #include "opal/mca/base/base.h"
  32 #include "opal/sys/atomic.h"
  33 #include "opal/runtime/opal.h"
  34 
  35 #include "opal/mca/rcache/base/base.h"
  36 #include "opal/mca/mpool/base/base.h"
  37 #include "opal/mca/allocator/base/base.h"
  38 #include "ompi/runtime/mpiruntime.h"
  39 
  40 #include "oshmem/constants.h"
  41 #include "oshmem/runtime/runtime.h"
  42 #include "oshmem/runtime/params.h"
  43 #include "oshmem/mca/spml/base/base.h"
  44 #include "oshmem/mca/scoll/base/base.h"
  45 #include "oshmem/mca/atomic/base/base.h"
  46 #include "oshmem/mca/memheap/base/base.h"
  47 #include "oshmem/mca/sshmem/base/base.h"
  48 #include "oshmem/info/info.h"
  49 #include "oshmem/proc/proc.h"
  50 #include "oshmem/proc/proc_group_cache.h"
  51 #include "oshmem/op/op.h"
  52 #include "oshmem/request/request.h"
  53 #include "oshmem/shmem/shmem_lock.h"
  54 #include "oshmem/runtime/oshmem_shmem_preconnect.h"
  55 
  56 extern int oshmem_shmem_globalexit_status;
  57 
  58 static int _shmem_finalize(void);
  59 
  60 int oshmem_shmem_finalize(void)
  61 {
  62     int ret = OSHMEM_SUCCESS;
  63 
  64     if (oshmem_shmem_initialized && !oshmem_shmem_aborted) {
  65         /* Should be called first because ompi_mpi_finalize makes orte and opal finalization */
  66         ret = _shmem_finalize();
  67 
  68         if (OSHMEM_SUCCESS == ret) {
  69             oshmem_shmem_initialized = false;
  70         }
  71 
  72         SHMEM_MUTEX_DESTROY(shmem_internal_mutex_alloc);
  73     }
  74 
  75     /* Note: ompi_mpi_state is set atomically in ompi_mpi_init() and
  76        ompi_mpi_finalize().  Those 2 functions have the appropriate
  77        memory barriers such that we don't need one here. */
  78     int32_t state = ompi_mpi_state;
  79     if ((OSHMEM_SUCCESS == ret) &&
  80         (state >= OMPI_MPI_STATE_INIT_COMPLETED &&
  81          state < OMPI_MPI_STATE_FINALIZE_PAST_COMM_SELF_DESTRUCT) &&
  82         oshmem_shmem_globalexit_status == 0) {
  83         PMPI_Comm_free(&oshmem_comm_world);
  84         ret = ompi_mpi_finalize();
  85     }
  86 
  87     return ret;
  88 }
  89 
  90 static int _shmem_finalize(void)
  91 {
  92     int ret = OSHMEM_SUCCESS;
  93 
  94     shmem_barrier_all();
  95 
  96     shmem_lock_finalize();
  97 
  98     /* Finalize preconnect framework */
  99     if (OSHMEM_SUCCESS != (ret = oshmem_shmem_preconnect_all_finalize())) {
 100         return ret;
 101     }
 102 
 103     /* free requests */
 104     if (OSHMEM_SUCCESS != (ret = oshmem_request_finalize())) {
 105         return ret;
 106     }
 107 
 108     oshmem_proc_group_finalize_scoll();
 109 
 110     /* Close down MCA modules */
 111     if (OSHMEM_SUCCESS != (ret = mca_base_framework_close(&oshmem_atomic_base_framework) ) ) {
 112         return ret;
 113     }
 114 
 115     if (OSHMEM_SUCCESS != (ret = mca_base_framework_close(&oshmem_scoll_base_framework) ) ) {
 116         return ret;
 117     }
 118 
 119     if (OSHMEM_SUCCESS != (ret = mca_base_framework_close(&oshmem_memheap_base_framework) ) ) {
 120         return ret;
 121     }
 122 
 123     if (OSHMEM_SUCCESS != (ret = mca_base_framework_close(&oshmem_sshmem_base_framework) ) ) {
 124         return ret;
 125     }
 126 
 127     if (OSHMEM_SUCCESS
 128             != (ret =
 129                     MCA_SPML_CALL(del_procs(oshmem_group_all->proc_array, oshmem_group_all->proc_count)))) {
 130         return ret;
 131     }
 132 
 133     oshmem_shmem_barrier();
 134 
 135     /* free spml resource */
 136     if (OSHMEM_SUCCESS != (ret = mca_spml_base_finalize())) {
 137         return ret;
 138     }
 139 
 140     if (OSHMEM_SUCCESS != (ret = mca_base_framework_close(&oshmem_spml_base_framework) ) ) {
 141         return ret;
 142     }
 143 
 144     /* free op resources */
 145     if (OSHMEM_SUCCESS != (ret = oshmem_op_finalize())) {
 146         return ret;
 147     }
 148 
 149     /* free proc_group resources */
 150     if (OSHMEM_SUCCESS != (ret = oshmem_proc_group_finalize())) {
 151         return ret;
 152     }
 153 
 154     /* free proc resources */
 155     if (OSHMEM_SUCCESS != (ret = oshmem_proc_finalize())) {
 156         return ret;
 157     }
 158 
 159     /* free info resources */
 160     if (OSHMEM_SUCCESS != (ret = oshmem_info_finalize())) {
 161         return ret;
 162     }
 163 
 164     return ret;
 165 }
 166 

/* [<][>][^][v][top][bottom][index][help] */