Skip to content

Commit e5c7512

Browse files
authored
Merge pull request #1983 from hjelmn/request_cb
ompi/request: change semantics of ompi request callbacks
2 parents 6ea8ccc + 6aa658a commit e5c7512

File tree

7 files changed

+42
-72
lines changed

7 files changed

+42
-72
lines changed

ompi/mca/osc/pt2pt/osc_pt2pt.h

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,6 @@ struct ompi_osc_pt2pt_module_t {
265265
/** Lock for garbage collection lists */
266266
opal_mutex_t gc_lock;
267267

268-
/** List of requests that need to be freed */
269-
opal_list_t request_gc;
270-
271268
/** List of buffers that need to be freed */
272269
opal_list_t buffer_gc;
273270
};
@@ -658,41 +655,26 @@ static inline void osc_pt2pt_copy_for_send (void *target, size_t target_len, con
658655
}
659656

660657
/**
661-
* osc_pt2pt_request_gc_clean:
658+
* osc_pt2pt_gc_clean:
662659
*
663660
* @short Release finished PML requests and accumulate buffers.
664661
*
665-
* @long This function exists because it is not possible to free a PML request
666-
* or buffer from a request completion callback. We instead put requests
667-
* and buffers on the module's garbage collection lists and release then
668-
* at a later time.
662+
* @long This function exists because it is not possible to free a buffer from
663+
* a request completion callback. We instead put requests and buffers on the
664+
* module's garbage collection lists and release then at a later time.
669665
*/
670666
static inline void osc_pt2pt_gc_clean (ompi_osc_pt2pt_module_t *module)
671667
{
672668
ompi_request_t *request;
673669
opal_list_item_t *item;
674670

675671
OPAL_THREAD_LOCK(&module->gc_lock);
676-
677-
while (NULL != (request = (ompi_request_t *) opal_list_remove_first (&module->request_gc))) {
678-
OPAL_THREAD_UNLOCK(&module->gc_lock);
679-
ompi_request_free (&request);
680-
OPAL_THREAD_LOCK(&module->gc_lock);
681-
}
682-
683672
while (NULL != (item = opal_list_remove_first (&module->buffer_gc))) {
684673
OBJ_RELEASE(item);
685674
}
686-
687675
OPAL_THREAD_UNLOCK(&module->gc_lock);
688676
}
689677

690-
static inline void osc_pt2pt_gc_add_request (ompi_osc_pt2pt_module_t *module, ompi_request_t *request)
691-
{
692-
OPAL_THREAD_SCOPED_LOCK(&module->gc_lock,
693-
opal_list_append (&module->request_gc, (opal_list_item_t *) request));
694-
}
695-
696678
static inline void osc_pt2pt_gc_add_buffer (ompi_osc_pt2pt_module_t *module, opal_list_item_t *buffer)
697679
{
698680
OPAL_THREAD_SCOPED_LOCK(&module->gc_lock,

ompi/mca/osc/pt2pt/osc_pt2pt_comm.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ static int ompi_osc_pt2pt_comm_complete (ompi_request_t *request)
4545

4646
mark_outgoing_completion(module);
4747

48-
/* put this request on the garbage colletion list */
49-
osc_pt2pt_gc_add_request (module, request);
48+
ompi_request_free (&request);
5049

51-
return OMPI_SUCCESS;
50+
return 1;
5251
}
5352

5453
static int ompi_osc_pt2pt_req_comm_complete (ompi_request_t *request)
@@ -101,10 +100,9 @@ static int ompi_osc_pt2pt_dt_send_complete (ompi_request_t *request)
101100
OPAL_THREAD_UNLOCK(&mca_osc_pt2pt_component.lock);
102101
assert (NULL != module);
103102

104-
/* put this request on the garbage colletion list */
105-
osc_pt2pt_gc_add_request (module, request);
103+
ompi_request_free (&request);
106104

107-
return OMPI_SUCCESS;
105+
return 1;
108106
}
109107

110108
/* self communication optimizations */

ompi/mca/osc/pt2pt/osc_pt2pt_component.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
320320
OBJ_CONSTRUCT(&module->locks_pending_lock, opal_mutex_t);
321321
OBJ_CONSTRUCT(&module->outstanding_locks, opal_hash_table_t);
322322
OBJ_CONSTRUCT(&module->pending_acc, opal_list_t);
323-
OBJ_CONSTRUCT(&module->request_gc, opal_list_t);
324323
OBJ_CONSTRUCT(&module->buffer_gc, opal_list_t);
325324
OBJ_CONSTRUCT(&module->gc_lock, opal_mutex_t);
326325
OBJ_CONSTRUCT(&module->all_sync, ompi_osc_pt2pt_sync_t);

ompi/mca/osc/pt2pt/osc_pt2pt_data_move.c

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,8 @@ static int ompi_osc_pt2pt_control_send_unbuffered_cb (ompi_request_t *request)
238238
/* free the temporary buffer */
239239
free (ctx);
240240

241-
/* put this request on the garbage colletion list */
242-
osc_pt2pt_gc_add_request (module, request);
243-
244-
return OMPI_SUCCESS;
241+
ompi_request_free (&request);
242+
return 1;
245243
}
246244

247245
/**
@@ -437,10 +435,8 @@ static int osc_pt2pt_incoming_req_complete (ompi_request_t *request)
437435

438436
mark_incoming_completion (module, rank);
439437

440-
/* put this request on the garbage colletion list */
441-
osc_pt2pt_gc_add_request (module, request);
442-
443-
return OMPI_SUCCESS;
438+
ompi_request_free (&request);
439+
return 1;
444440
}
445441

446442
struct osc_pt2pt_get_post_send_cb_data_t {
@@ -460,10 +456,8 @@ static int osc_pt2pt_get_post_send_cb (ompi_request_t *request)
460456
/* mark this as a completed "incoming" request */
461457
mark_incoming_completion (module, rank);
462458

463-
/* put this request on the garbage colletion list */
464-
osc_pt2pt_gc_add_request (module, request);
465-
466-
return OMPI_SUCCESS;
459+
ompi_request_free (&request);
460+
return 1;
467461
}
468462

469463
/**
@@ -699,9 +693,7 @@ static int accumulate_cb (ompi_request_t *request)
699693
osc_pt2pt_gc_add_buffer (module, &acc_data->super);
700694
}
701695

702-
/* put this request on the garbage colletion list */
703-
osc_pt2pt_gc_add_request (module, request);
704-
696+
ompi_request_free (&request);
705697
return ret;
706698
}
707699

@@ -771,13 +763,11 @@ static int replace_cb (ompi_request_t *request)
771763

772764
mark_incoming_completion (module, rank);
773765

774-
/* put this request on the garbage colletion list */
775-
osc_pt2pt_gc_add_request (module, request);
776-
777766
/* unlock the accumulate lock */
778767
ompi_osc_pt2pt_accumulate_unlock (module);
779768

780-
return OMPI_SUCCESS;
769+
ompi_request_free (&request);
770+
return 1;
781771
}
782772

783773
/**
@@ -1435,13 +1425,11 @@ static int process_large_datatype_request_cb (ompi_request_t *request)
14351425
return OMPI_ERROR;
14361426
}
14371427

1438-
/* put this request on the garbage colletion list */
1439-
osc_pt2pt_gc_add_request (module, request);
1440-
14411428
/* free the datatype buffer */
14421429
osc_pt2pt_gc_add_buffer (module, &ddt_buffer->super);
14431430

1444-
return OMPI_SUCCESS;
1431+
ompi_request_free (&request);
1432+
return 1;
14451433
}
14461434

14471435
/**

ompi/mca/osc/pt2pt/osc_pt2pt_frag.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ static int frag_send_cb (ompi_request_t *request)
3737
mark_outgoing_completion(module);
3838
opal_free_list_return (&mca_osc_pt2pt_component.frags, &frag->super);
3939

40+
ompi_request_free (&request);
4041

41-
/* put this request on the garbage colletion list */
42-
osc_pt2pt_gc_add_request (module, request);
43-
44-
return OMPI_SUCCESS;
42+
return 1;
4543
}
4644

4745
static int frag_send (ompi_osc_pt2pt_module_t *module, ompi_osc_pt2pt_frag_t *frag)

ompi/mca/osc/pt2pt/osc_pt2pt_module.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ int ompi_osc_pt2pt_free(ompi_win_t *win)
7979
OPAL_LIST_DESTRUCT(&module->pending_acc);
8080

8181
osc_pt2pt_gc_clean (module);
82-
OPAL_LIST_DESTRUCT(&module->request_gc);
8382
OPAL_LIST_DESTRUCT(&module->buffer_gc);
8483
OBJ_DESTRUCT(&module->gc_lock);
8584

ompi/request/request.h

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ typedef int (*ompi_request_cancel_fn_t)(struct ompi_request_t* request, int flag
6767

6868
/*
6969
* Optional function called when the request is completed from the MPI
70-
* library perspective. This function is not allowed to release any
71-
* ressources related to the request.
70+
* library perspective. This function is allowed to release the request if
71+
* the request will not be used with ompi_request_wait* or ompi_request_test.
72+
* If the function reposts (using start) a request or calls ompi_request_free()
73+
* on the request it *MUST* return 1. It should return 0 otherwise.
7274
*/
7375
typedef int (*ompi_request_complete_fn_t)(struct ompi_request_t* request);
7476

@@ -412,24 +414,28 @@ static inline void ompi_request_wait_completion(ompi_request_t *req)
412414
*/
413415
static inline int ompi_request_complete(ompi_request_t* request, bool with_signal)
414416
{
417+
int rc = 0;
418+
415419
if( NULL != request->req_complete_cb) {
416-
request->req_complete_cb( request );
420+
rc = request->req_complete_cb( request );
417421
request->req_complete_cb = NULL;
418422
}
419423

420-
if( OPAL_LIKELY(with_signal) ) {
421-
if(!OPAL_ATOMIC_CMPSET_PTR(&request->req_complete, REQUEST_PENDING, REQUEST_COMPLETED)) {
422-
ompi_wait_sync_t *tmp_sync = (ompi_wait_sync_t *) OPAL_ATOMIC_SWAP_PTR(&request->req_complete,
423-
REQUEST_COMPLETED);
424-
/* In the case where another thread concurrently changed the request to REQUEST_PENDING */
425-
if( REQUEST_PENDING != tmp_sync )
426-
wait_sync_update(tmp_sync, 1, request->req_status.MPI_ERROR);
424+
if (0 == rc) {
425+
if( OPAL_LIKELY(with_signal) ) {
426+
if(!OPAL_ATOMIC_CMPSET_PTR(&request->req_complete, REQUEST_PENDING, REQUEST_COMPLETED)) {
427+
ompi_wait_sync_t *tmp_sync = (ompi_wait_sync_t *) OPAL_ATOMIC_SWAP_PTR(&request->req_complete,
428+
REQUEST_COMPLETED);
429+
/* In the case where another thread concurrently changed the request to REQUEST_PENDING */
430+
if( REQUEST_PENDING != tmp_sync )
431+
wait_sync_update(tmp_sync, 1, request->req_status.MPI_ERROR);
432+
}
433+
} else
434+
request->req_complete = REQUEST_COMPLETED;
435+
436+
if( OPAL_UNLIKELY(MPI_SUCCESS != request->req_status.MPI_ERROR) ) {
437+
ompi_request_failed++;
427438
}
428-
} else
429-
request->req_complete = REQUEST_COMPLETED;
430-
431-
if( OPAL_UNLIKELY(MPI_SUCCESS != request->req_status.MPI_ERROR) ) {
432-
ompi_request_failed++;
433439
}
434440

435441
return OMPI_SUCCESS;

0 commit comments

Comments
 (0)