@@ -549,6 +549,8 @@ categories :
549549=== END_MPI_T_CVAR_INFO_BLOCK ===
550550*/
551551
552+ static bool ofi_initialized = false;
553+
552554static int update_global_limits (struct fi_info * prov );
553555static void dump_global_settings (void );
554556static int destroy_vci_context (int vci , int nic );
@@ -799,6 +801,8 @@ int MPIDI_OFI_init_world(void)
799801 MPIR_ERR_CHECK (mpi_errno );
800802 }
801803
804+ ofi_initialized = true;
805+
802806 fn_exit :
803807 return mpi_errno ;
804808 fn_fail :
@@ -879,10 +883,14 @@ static int flush_send_queue(void)
879883{
880884 int mpi_errno = MPI_SUCCESS ;
881885
886+ if (!ofi_initialized ) {
887+ goto fn_exit ;
888+ }
889+
882890 MPIDI_OFI_dynamic_process_request_t * reqs ;
883891 /* TODO - Iterate over each NIC in addition to each VNI when multi-NIC within the same
884892 * process is implemented. */
885- int num_vcis = ( MPIDI_global . is_initialized ? MPIDI_OFI_global .num_vcis : 1 ) ;
893+ int num_vcis = MPIDI_OFI_global .num_vcis ;
886894 int num_reqs = num_vcis * 2 ;
887895 reqs = MPL_malloc (sizeof (MPIDI_OFI_dynamic_process_request_t ) * num_reqs , MPL_MEM_OTHER );
888896
@@ -937,12 +945,9 @@ int MPIDI_OFI_mpi_finalize_hook(void)
937945 MPIDI_OFI_mr_key_allocator_destroy ();
938946
939947 if (strcmp ("sockets" , MPIDI_OFI_global .prov_use [0 ]-> fabric_attr -> prov_name ) == 0 ) {
940- /* sockets provider need flush any last lightweight send. Only do it if we initialized
941- * world. Sockets provider can't even send self messages otherwise. */
942- if (MPIDI_global .is_initialized ) {
943- mpi_errno = flush_send_queue ();
944- MPIR_ERR_CHECK (mpi_errno );
945- }
948+ /* sockets provider need flush any last lightweight send. */
949+ mpi_errno = flush_send_queue ();
950+ MPIR_ERR_CHECK (mpi_errno );
946951 } else if (MPIR_CVAR_NO_COLLECTIVE_FINALIZE ) {
947952 /* skip collective work arounds */
948953 } else if (strcmp ("verbs;ofi_rxm" , MPIDI_OFI_global .prov_use [0 ]-> fabric_attr -> prov_name ) == 0
@@ -980,12 +985,10 @@ int MPIDI_OFI_mpi_finalize_hook(void)
980985 /* Tearing down endpoints in reverse order they were created */
981986 for (int nic = MPIDI_OFI_global .num_nics - 1 ; nic >= 0 ; nic -- ) {
982987 for (int vci = MPIDI_OFI_global .num_vcis - 1 ; vci >= 0 ; vci -- ) {
983- if (MPIDI_global .is_initialized || (vci == 0 && nic == 0 )) {
984- /* If the user has not freed all MPI objects, ofi might not shut down cleanly.
985- * We intentionally ignore errors to avoid crashing in finalize. Debug builds
986- * will warn about unfreed objects/memory. */
987- (void ) destroy_vci_context (vci , nic );
988- }
988+ /* If the user has not freed all MPI objects, ofi might not shut down cleanly.
989+ * We intentionally ignore errors to avoid crashing in finalize. Debug builds
990+ * will warn about unfreed objects/memory. */
991+ (void ) destroy_vci_context (vci , nic );
989992 }
990993 }
991994
0 commit comments