2004-10-12 19:50:01 +04:00
|
|
|
/*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
#include "include/constants.h"
|
|
|
|
#include "request/request.h"
|
|
|
|
|
|
|
|
|
2004-10-12 22:01:39 +04:00
|
|
|
int ompi_request_wait_any(
|
2004-10-12 19:50:01 +04:00
|
|
|
size_t count,
|
|
|
|
ompi_request_t ** requests,
|
|
|
|
int *index,
|
|
|
|
ompi_status_public_t * status)
|
|
|
|
{
|
|
|
|
#if OMPI_HAVE_THREADS
|
|
|
|
int c;
|
|
|
|
#endif
|
2004-10-20 03:31:03 +04:00
|
|
|
unsigned int i, null_requests;
|
|
|
|
int rc, completed = -1;
|
2004-10-12 19:50:01 +04:00
|
|
|
ompi_request_t **rptr;
|
|
|
|
ompi_request_t *request;
|
|
|
|
|
|
|
|
#if OMPI_HAVE_THREADS
|
|
|
|
/* poll for completion */
|
|
|
|
ompi_atomic_mb();
|
|
|
|
for (c = 0; completed < 0 && c < ompi_request_poll_iterations; c++) {
|
|
|
|
rptr = requests;
|
2004-10-12 22:01:39 +04:00
|
|
|
null_requests = 0;
|
2004-10-12 19:50:01 +04:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
request = *rptr;
|
2004-10-12 22:01:39 +04:00
|
|
|
if (MPI_REQUEST_NULL == request) {
|
|
|
|
if(++null_requests == count)
|
|
|
|
goto finished;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (true == request->req_complete) {
|
2004-10-12 19:50:01 +04:00
|
|
|
completed = i;
|
2004-10-12 22:01:39 +04:00
|
|
|
goto finished;
|
2004-10-12 19:50:01 +04:00
|
|
|
}
|
|
|
|
rptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-10-12 22:01:39 +04:00
|
|
|
/* give up and sleep until completion */
|
|
|
|
OMPI_THREAD_LOCK(&ompi_request_lock);
|
|
|
|
do {
|
|
|
|
ompi_request_waiting++;
|
|
|
|
rptr = requests;
|
|
|
|
null_requests = 0;
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
request = *rptr;
|
|
|
|
if (MPI_REQUEST_NULL == request) {
|
|
|
|
null_requests++;
|
|
|
|
continue;
|
2004-10-12 19:50:01 +04:00
|
|
|
}
|
2004-10-12 22:01:39 +04:00
|
|
|
if (request->req_complete == true) {
|
|
|
|
completed = i;
|
|
|
|
break;
|
2004-10-12 19:50:01 +04:00
|
|
|
}
|
2004-10-12 22:01:39 +04:00
|
|
|
rptr++;
|
|
|
|
}
|
|
|
|
if(null_requests == count)
|
|
|
|
break;
|
|
|
|
if (completed < 0) {
|
|
|
|
ompi_condition_wait(&ompi_request_cond, &ompi_request_lock);
|
|
|
|
}
|
|
|
|
} while (completed < 0);
|
|
|
|
ompi_request_waiting--;
|
|
|
|
OMPI_THREAD_UNLOCK(&ompi_request_lock);
|
2004-10-12 19:50:01 +04:00
|
|
|
|
2004-10-12 22:01:39 +04:00
|
|
|
finished:
|
|
|
|
|
|
|
|
if(null_requests == count) {
|
|
|
|
*index = MPI_UNDEFINED;
|
|
|
|
*status = ompi_request_null.req_status;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* return status */
|
|
|
|
if (MPI_STATUS_IGNORE != status) {
|
|
|
|
*status = request->req_status;
|
|
|
|
}
|
2004-10-12 19:50:01 +04:00
|
|
|
|
2004-10-12 22:01:39 +04:00
|
|
|
/* return request to pool */
|
2004-10-20 02:00:19 +04:00
|
|
|
rc = request->req_fini(rptr);
|
2004-10-12 22:01:39 +04:00
|
|
|
*index = completed;
|
|
|
|
}
|
2004-10-12 19:50:01 +04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ompi_request_wait_all(
|
|
|
|
size_t count,
|
|
|
|
ompi_request_t ** requests,
|
|
|
|
ompi_status_public_t * statuses)
|
|
|
|
{
|
|
|
|
size_t completed = 0, i;
|
|
|
|
ompi_request_t **rptr;
|
|
|
|
ompi_request_t *request;
|
|
|
|
|
|
|
|
rptr = requests;
|
|
|
|
for (i = 0; i < count; i++) {
|
2004-10-14 23:17:16 +04:00
|
|
|
request = *rptr++;
|
2004-10-12 22:01:39 +04:00
|
|
|
if (request->req_complete == true) {
|
2004-10-12 19:50:01 +04:00
|
|
|
completed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if all requests have not completed -- defer acquiring lock
|
|
|
|
* unless required
|
|
|
|
*/
|
|
|
|
if (completed != count) {
|
|
|
|
/*
|
|
|
|
* acquire lock and test for completion - if all requests are
|
|
|
|
* not completed pend on condition variable until a request
|
|
|
|
* completes
|
|
|
|
*/
|
|
|
|
OMPI_THREAD_LOCK(&ompi_request_lock);
|
|
|
|
ompi_request_waiting++;
|
|
|
|
do {
|
|
|
|
completed = 0;
|
|
|
|
rptr = requests;
|
|
|
|
for (i = 0; i < count; i++) {
|
2004-10-14 23:17:16 +04:00
|
|
|
request = *rptr++;
|
2004-10-14 02:56:42 +04:00
|
|
|
if (request->req_complete == true) {
|
2004-10-12 19:50:01 +04:00
|
|
|
completed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (completed != count) {
|
|
|
|
ompi_condition_wait(&ompi_request_cond, &ompi_request_lock);
|
|
|
|
}
|
|
|
|
} while (completed != count);
|
|
|
|
ompi_request_waiting--;
|
|
|
|
OMPI_THREAD_UNLOCK(&ompi_request_lock);
|
|
|
|
}
|
|
|
|
|
2004-10-12 22:01:39 +04:00
|
|
|
if (MPI_STATUS_IGNORE != statuses) {
|
2004-10-12 19:50:01 +04:00
|
|
|
/* fill out status and free request if required */
|
|
|
|
rptr = requests;
|
|
|
|
for (i = 0; i < count; i++) {
|
2004-10-12 22:01:39 +04:00
|
|
|
int rc;
|
2004-10-12 19:50:01 +04:00
|
|
|
request = *rptr;
|
2004-10-12 22:01:39 +04:00
|
|
|
statuses[i] = request->req_status;
|
2004-10-20 02:00:19 +04:00
|
|
|
rc = request->req_fini(rptr);
|
2004-10-12 19:50:01 +04:00
|
|
|
rptr++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* free request if required */
|
|
|
|
rptr = requests;
|
|
|
|
for (i = 0; i < count; i++) {
|
2004-10-12 22:01:39 +04:00
|
|
|
int rc;
|
2004-10-12 19:50:01 +04:00
|
|
|
request = *rptr;
|
2004-10-20 02:00:19 +04:00
|
|
|
rc = request->req_fini(rptr);
|
2004-10-12 19:50:01 +04:00
|
|
|
rptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
2004-10-12 22:01:39 +04:00
|
|
|
|