Skip to content

Commit 50cec45

Browse files
committed
ompi_request_complete with signal
Rewrite the ompi_request_complete function to take in account the with_signal argument. Change the comment to explain the expected behavior. Alter all the ompi_request_complete uses to make sure the status of the request is set before calling ompi_request_complete. bot:label:enhancement
1 parent 223d755 commit 50cec45

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

ompi/mca/io/ompio/io_ompio_file_read.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
33
* University Research and Technology
44
* Corporation. All rights reserved.
5-
* Copyright (c) 2004-2005 The University of Tennessee and The University
5+
* Copyright (c) 2004-2016 The University of Tennessee and The University
66
* of Tennessee Research Foundation. All rights
77
* reserved.
88
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@@ -233,9 +233,9 @@ int ompio_io_ompio_file_iread (mca_io_ompio_file_t *fh,
233233
ompio_req->req_ompi.req_state = OMPI_REQUEST_ACTIVE;
234234

235235
if ( 0 == count ) {
236-
ompi_request_complete (&ompio_req->req_ompi, 0);
237236
ompio_req->req_ompi.req_status.MPI_ERROR = OMPI_SUCCESS;
238237
ompio_req->req_ompi.req_status._ucount = 0;
238+
ompi_request_complete (&ompio_req->req_ompi, false);
239239
return OMPI_SUCCESS;
240240
}
241241

@@ -299,9 +299,9 @@ int ompio_io_ompio_file_iread (mca_io_ompio_file_t *fh,
299299
ompi_status_public_t status;
300300
ret = ompio_io_ompio_file_read (fh, buf, count, datatype, &status);
301301

302-
ompi_request_complete (&ompio_req->req_ompi, 0);
303302
ompio_req->req_ompi.req_status.MPI_ERROR = ret;
304303
ompio_req->req_ompi.req_status._ucount = status._ucount;
304+
ompi_request_complete (&ompio_req->req_ompi, false);
305305
}
306306

307307
*request = (ompi_request_t *) ompio_req;

ompi/mca/io/ompio/io_ompio_file_write.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
33
* University Research and Technology
44
* Corporation. All rights reserved.
5-
* Copyright (c) 2004-2005 The University of Tennessee and The University
5+
* Copyright (c) 2004-2016 The University of Tennessee and The University
66
* of Tennessee Research Foundation. All rights
77
* reserved.
88
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@@ -225,9 +225,9 @@ int ompio_io_ompio_file_iwrite (mca_io_ompio_file_t *fh,
225225
ompio_req->req_ompi.req_state = OMPI_REQUEST_ACTIVE;
226226

227227
if ( 0 == count ) {
228-
ompi_request_complete (&ompio_req->req_ompi, 0);
229228
ompio_req->req_ompi.req_status.MPI_ERROR = OMPI_SUCCESS;
230229
ompio_req->req_ompi.req_status._ucount = 0;
230+
ompi_request_complete (&ompio_req->req_ompi, false);
231231
return OMPI_SUCCESS;
232232
}
233233

@@ -288,9 +288,9 @@ int ompio_io_ompio_file_iwrite (mca_io_ompio_file_t *fh,
288288
ompi_status_public_t status;
289289
ret = ompio_io_ompio_file_write(fh,buf,count,datatype, &status);
290290

291-
ompi_request_complete (&ompio_req->req_ompi, 0);
292291
ompio_req->req_ompi.req_status.MPI_ERROR = ret;
293292
ompio_req->req_ompi.req_status._ucount = status._ucount;
293+
ompi_request_complete (&ompio_req->req_ompi, false);
294294
}
295295

296296
*request = (ompi_request_t *) ompio_req;

ompi/mca/io/ompio/io_ompio_request.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int mca_io_ompio_component_progress ( void )
8585
if ( NULL != req->req_progress_fn ) {
8686
if ( req->req_progress_fn(req) ) {
8787
completed++;
88-
ompi_request_complete (&req->req_ompi, 1);
88+
ompi_request_complete (&req->req_ompi, true);
8989
/* The fbtl progress function is expected to set the
9090
* status elements
9191
*/

ompi/request/request.h

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,16 @@ static inline void ompi_request_wait_completion(ompi_request_t *req)
398398
#endif
399399
/**
400400
* Signal or mark a request as complete. If with_signal is true this will
401-
* wake any thread pending on the request and ompi_request_lock should be
402-
* held while calling this function. If with_signal is false, there will
403-
* signal generated, and no lock required. This is a special case when
404-
* the function is called from the critical path for small messages, where
405-
* we know the current execution flow created the request, and is still
406-
* in the _START macro.
401+
* wake any thread pending on the request. If with_signal is false, the
402+
* opposite will be true, the request will simply be marked as completed
403+
* and no effort will be made to correctly (atomically) handle the associated
404+
* synchronization primitive. This is a special case when the function
405+
* is called from the critical path for small messages, where we know
406+
* the current execution flow created the request, and no synchronized wait
407+
* has been set.
408+
* BEWARE: The error code should be set on the request prior to calling
409+
* this function, or the synchronization primitive might not be correctly
410+
* triggered.
407411
*/
408412
static inline int ompi_request_complete(ompi_request_t* request, bool with_signal)
409413
{
@@ -412,13 +416,16 @@ static inline int ompi_request_complete(ompi_request_t* request, bool with_signa
412416
request->req_complete_cb = NULL;
413417
}
414418

415-
if(!OPAL_ATOMIC_CMPSET_PTR(&request->req_complete, REQUEST_PENDING, REQUEST_COMPLETED)) {
416-
ompi_wait_sync_t *tmp_sync = (ompi_wait_sync_t *) OPAL_ATOMIC_SWP_PTR(&request->req_complete,
417-
REQUEST_COMPLETED);
418-
/* In the case where another thread concurrently changed the request to REQUEST_PENDING */
419-
if( REQUEST_PENDING != tmp_sync )
420-
wait_sync_update(tmp_sync, 1, request->req_status.MPI_ERROR);
421-
}
419+
if( OPAL_LIKELY(with_signal) ) {
420+
if(!OPAL_ATOMIC_CMPSET_PTR(&request->req_complete, REQUEST_PENDING, REQUEST_COMPLETED)) {
421+
ompi_wait_sync_t *tmp_sync = (ompi_wait_sync_t *) OPAL_ATOMIC_SWP_PTR(&request->req_complete,
422+
REQUEST_COMPLETED);
423+
/* In the case where another thread concurrently changed the request to REQUEST_PENDING */
424+
if( REQUEST_PENDING != tmp_sync )
425+
wait_sync_update(tmp_sync, 1, request->req_status.MPI_ERROR);
426+
}
427+
} else
428+
request->req_complete = REQUEST_COMPLETED;
422429

423430
if( OPAL_UNLIKELY(MPI_SUCCESS != request->req_status.MPI_ERROR) ) {
424431
ompi_request_failed++;

0 commit comments

Comments
 (0)