diff --git a/ompi/mca/io/ompio/io_ompio_file_read.c b/ompi/mca/io/ompio/io_ompio_file_read.c index e50aae1412..5ae63803cb 100644 --- a/ompi/mca/io/ompio/io_ompio_file_read.c +++ b/ompi/mca/io/ompio/io_ompio_file_read.c @@ -2,7 +2,7 @@ * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. - * Copyright (c) 2004-2005 The University of Tennessee and The University + * Copyright (c) 2004-2016 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. * 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, ompio_req->req_ompi.req_state = OMPI_REQUEST_ACTIVE; if ( 0 == count ) { - ompi_request_complete (&ompio_req->req_ompi, 0); ompio_req->req_ompi.req_status.MPI_ERROR = OMPI_SUCCESS; ompio_req->req_ompi.req_status._ucount = 0; + ompi_request_complete (&ompio_req->req_ompi, false); return OMPI_SUCCESS; } @@ -299,9 +299,9 @@ int ompio_io_ompio_file_iread (mca_io_ompio_file_t *fh, ompi_status_public_t status; ret = ompio_io_ompio_file_read (fh, buf, count, datatype, &status); - ompi_request_complete (&ompio_req->req_ompi, 0); ompio_req->req_ompi.req_status.MPI_ERROR = ret; ompio_req->req_ompi.req_status._ucount = status._ucount; + ompi_request_complete (&ompio_req->req_ompi, false); } *request = (ompi_request_t *) ompio_req; diff --git a/ompi/mca/io/ompio/io_ompio_file_write.c b/ompi/mca/io/ompio/io_ompio_file_write.c index 24f054712c..c075db5f0d 100644 --- a/ompi/mca/io/ompio/io_ompio_file_write.c +++ b/ompi/mca/io/ompio/io_ompio_file_write.c @@ -2,7 +2,7 @@ * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. - * Copyright (c) 2004-2005 The University of Tennessee and The University + * Copyright (c) 2004-2016 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. * 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, ompio_req->req_ompi.req_state = OMPI_REQUEST_ACTIVE; if ( 0 == count ) { - ompi_request_complete (&ompio_req->req_ompi, 0); ompio_req->req_ompi.req_status.MPI_ERROR = OMPI_SUCCESS; ompio_req->req_ompi.req_status._ucount = 0; + ompi_request_complete (&ompio_req->req_ompi, false); return OMPI_SUCCESS; } @@ -288,9 +288,9 @@ int ompio_io_ompio_file_iwrite (mca_io_ompio_file_t *fh, ompi_status_public_t status; ret = ompio_io_ompio_file_write(fh,buf,count,datatype, &status); - ompi_request_complete (&ompio_req->req_ompi, 0); ompio_req->req_ompi.req_status.MPI_ERROR = ret; ompio_req->req_ompi.req_status._ucount = status._ucount; + ompi_request_complete (&ompio_req->req_ompi, false); } *request = (ompi_request_t *) ompio_req; diff --git a/ompi/mca/io/ompio/io_ompio_request.c b/ompi/mca/io/ompio/io_ompio_request.c index d36bee06cd..59271a346b 100644 --- a/ompi/mca/io/ompio/io_ompio_request.c +++ b/ompi/mca/io/ompio/io_ompio_request.c @@ -85,7 +85,7 @@ int mca_io_ompio_component_progress ( void ) if ( NULL != req->req_progress_fn ) { if ( req->req_progress_fn(req) ) { completed++; - ompi_request_complete (&req->req_ompi, 1); + ompi_request_complete (&req->req_ompi, true); /* The fbtl progress function is expected to set the * status elements */ diff --git a/ompi/request/request.h b/ompi/request/request.h index d7d175425d..7285d3e6ab 100644 --- a/ompi/request/request.h +++ b/ompi/request/request.h @@ -398,12 +398,16 @@ static inline void ompi_request_wait_completion(ompi_request_t *req) #endif /** * Signal or mark a request as complete. If with_signal is true this will - * wake any thread pending on the request and ompi_request_lock should be - * held while calling this function. If with_signal is false, there will - * signal generated, and no lock required. This is a special case when - * the function is called from the critical path for small messages, where - * we know the current execution flow created the request, and is still - * in the _START macro. + * wake any thread pending on the request. If with_signal is false, the + * opposite will be true, the request will simply be marked as completed + * and no effort will be made to correctly (atomically) handle the associated + * synchronization primitive. This is a special case when the function + * is called from the critical path for small messages, where we know + * the current execution flow created the request, and no synchronized wait + * has been set. + * BEWARE: The error code should be set on the request prior to calling + * this function, or the synchronization primitive might not be correctly + * triggered. */ static inline int ompi_request_complete(ompi_request_t* request, bool with_signal) { @@ -412,13 +416,16 @@ static inline int ompi_request_complete(ompi_request_t* request, bool with_signa request->req_complete_cb = NULL; } - if(!OPAL_ATOMIC_CMPSET_PTR(&request->req_complete, REQUEST_PENDING, REQUEST_COMPLETED)) { - ompi_wait_sync_t *tmp_sync = (ompi_wait_sync_t *) OPAL_ATOMIC_SWP_PTR(&request->req_complete, - REQUEST_COMPLETED); - /* In the case where another thread concurrently changed the request to REQUEST_PENDING */ - if( REQUEST_PENDING != tmp_sync ) - wait_sync_update(tmp_sync, 1, request->req_status.MPI_ERROR); - } + if( OPAL_LIKELY(with_signal) ) { + if(!OPAL_ATOMIC_CMPSET_PTR(&request->req_complete, REQUEST_PENDING, REQUEST_COMPLETED)) { + ompi_wait_sync_t *tmp_sync = (ompi_wait_sync_t *) OPAL_ATOMIC_SWP_PTR(&request->req_complete, + REQUEST_COMPLETED); + /* In the case where another thread concurrently changed the request to REQUEST_PENDING */ + if( REQUEST_PENDING != tmp_sync ) + wait_sync_update(tmp_sync, 1, request->req_status.MPI_ERROR); + } + } else + request->req_complete = REQUEST_COMPLETED; if( OPAL_UNLIKELY(MPI_SUCCESS != request->req_status.MPI_ERROR) ) { ompi_request_failed++;