@@ -110,10 +110,7 @@ static int component_register(void) {
110
110
}
111
111
112
112
static int progress_callback (void ) {
113
- if ((mca_osc_ucx_component .ucp_worker != NULL ) &&
114
- mca_osc_ucx_component .num_modules ) {
115
- ucp_worker_progress (mca_osc_ucx_component .ucp_worker );
116
- }
113
+ ucp_worker_progress (mca_osc_ucx_component .ucp_worker );
117
114
return 0 ;
118
115
}
119
116
@@ -140,7 +137,6 @@ static int component_finalize(void) {
140
137
assert (mca_osc_ucx_component .num_incomplete_req_ops == 0 );
141
138
if (mca_osc_ucx_component .env_initialized == true) {
142
139
OBJ_DESTRUCT (& mca_osc_ucx_component .requests );
143
- opal_progress_unregister (progress_callback );
144
140
ucp_cleanup (mca_osc_ucx_component .ucp_context );
145
141
mca_osc_ucx_component .env_initialized = false;
146
142
}
@@ -250,7 +246,7 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
250
246
ucs_status_t status ;
251
247
int i , comm_size = ompi_comm_size (comm );
252
248
int is_eps_ready ;
253
- bool progress_registered = false, eps_created = false, env_initialized = false;
249
+ bool eps_created = false, env_initialized = false;
254
250
ucp_address_t * my_addr = NULL ;
255
251
size_t my_addr_len ;
256
252
char * recv_buf = NULL ;
@@ -327,13 +323,6 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
327
323
goto error_nomem ;
328
324
}
329
325
330
- ret = opal_progress_register (progress_callback );
331
- progress_registered = true;
332
- if (OMPI_SUCCESS != ret ) {
333
- OSC_UCX_VERBOSE (1 , "opal_progress_register failed: %d" , ret );
334
- goto error ;
335
- }
336
-
337
326
/* query UCP worker attributes */
338
327
worker_attr .field_mask = UCP_WORKER_ATTR_FIELD_THREAD_MODE ;
339
328
status = ucp_worker_query (mca_osc_ucx_component .ucp_worker , & worker_attr );
@@ -617,6 +606,14 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
617
606
goto error ;
618
607
}
619
608
609
+ OSC_UCX_ASSERT (mca_osc_ucx_component .num_modules > 0 );
610
+ if (1 == mca_osc_ucx_component .num_modules ) {
611
+ ret = opal_progress_register (progress_callback );
612
+ if (OMPI_SUCCESS != ret ) {
613
+ OSC_UCX_VERBOSE (1 , "opal_progress_register failed: %d" , ret );
614
+ goto error ;
615
+ }
616
+ }
620
617
return ret ;
621
618
622
619
error :
@@ -644,9 +641,17 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
644
641
ucp_ep_destroy (ep );
645
642
}
646
643
}
647
- if (progress_registered ) opal_progress_unregister (progress_callback );
648
- if (module ) free (module );
649
- mca_osc_ucx_component .num_modules -- ;
644
+ if (module ) {
645
+ free (module );
646
+ mca_osc_ucx_component .num_modules -- ;
647
+ OSC_UCX_ASSERT (mca_osc_ucx_component .num_modules >= 0 );
648
+ if (0 == mca_osc_ucx_component .num_modules ) {
649
+ ret = opal_progress_unregister (progress_callback );
650
+ if (OMPI_SUCCESS != ret ) {
651
+ OSC_UCX_VERBOSE (1 , "opal_progress_unregister failed: %d" , ret );
652
+ }
653
+ }
654
+ }
650
655
651
656
error_nomem :
652
657
if (env_initialized == true) {
@@ -815,6 +820,13 @@ int ompi_osc_ucx_free(struct ompi_win_t *win) {
815
820
816
821
free (module );
817
822
mca_osc_ucx_component .num_modules -- ;
823
+ OSC_UCX_ASSERT (mca_osc_ucx_component .num_modules >= 0 );
824
+ if (0 == mca_osc_ucx_component .num_modules ) {
825
+ ret = opal_progress_unregister (progress_callback );
826
+ if (OMPI_SUCCESS != ret ) {
827
+ OSC_UCX_VERBOSE (1 , "opal_progress_unregister failed: %d" , ret );
828
+ }
829
+ }
818
830
819
831
return ret ;
820
832
}
0 commit comments