@@ -226,13 +226,47 @@ mca_spml_ucx_component_init(int* priority,
226226
227227static int mca_spml_ucx_component_fini (void )
228228{
229+ mca_spml_ucx_ctx_list_item_t * ctx_item , * next ;
230+ size_t i , j , nprocs = oshmem_num_procs ();
231+
229232 opal_progress_unregister (spml_ucx_progress );
230-
233+
234+ if (!mca_spml_ucx .enabled )
235+ return OSHMEM_SUCCESS ; /* never selected.. return success.. */
236+
237+ /* delete context objects from list */
238+ OPAL_LIST_FOREACH_SAFE (ctx_item , next , & (mca_spml_ucx .ctx_list ),
239+ mca_spml_ucx_ctx_list_item_t ) {
240+ opal_list_remove_item (& (mca_spml_ucx .ctx_list ), & ctx_item -> super );
241+
242+ opal_common_ucx_del_proc_t * del_procs ;
243+ del_procs = malloc (sizeof (* del_procs ) * nprocs );
244+
245+ for (i = 0 ; i < nprocs ; ++ i ) {
246+ for (j = 0 ; j < MCA_MEMHEAP_SEG_COUNT ; j ++ ) {
247+ if (ctx_item -> ctx .ucp_peers [i ].mkeys [j ].key .rkey != NULL ) {
248+ ucp_rkey_destroy (ctx_item -> ctx .ucp_peers [i ].mkeys [j ].key .rkey );
249+ }
250+ }
251+
252+ del_procs [i ].ep = ctx_item -> ctx .ucp_peers [i ].ucp_conn ;
253+ del_procs [i ].vpid = i ;
254+ ctx_item -> ctx .ucp_peers [i ].ucp_conn = NULL ;
255+ }
256+
257+ opal_common_ucx_del_procs (del_procs , nprocs , oshmem_my_proc_id (),
258+ mca_spml_ucx .num_disconnect ,
259+ ctx_item -> ctx .ucp_worker );
260+ free (del_procs );
261+ free (ctx_item -> ctx .ucp_peers );
262+
263+ ucp_worker_destroy (ctx_item -> ctx .ucp_worker );
264+ OBJ_RELEASE (ctx_item );
265+ }
266+
231267 if (mca_spml_ucx_ctx_default .ucp_worker ) {
232268 ucp_worker_destroy (mca_spml_ucx_ctx_default .ucp_worker );
233269 }
234- if (!mca_spml_ucx .enabled )
235- return OSHMEM_SUCCESS ; /* never selected.. return success.. */
236270
237271 mca_spml_ucx .enabled = false; /* not anymore */
238272
0 commit comments