1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
/*
* Copyright (c) 2001-2002 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 1998-2001 University of Notre Dame.
* All rights reserved.
* Copyright (c) 1994-1998 The Ohio State University.
* All rights reserved.
*
* This file is part of the LAM/MPI software package. For license
* information, see the LICENSE file in the top level directory of the
* LAM/MPI source distribution.
*
* $HEADER$
*
* $Id: lamtest.c,v 6.16 2003/11/02 21:13:10 brbarret Exp $
*
* Function: - test if request is done
* - destructive and non-destructive modes
* Accepts: - request
* - destructive mode flag
* - flag (out)
* - status (out)
* Returns: - MPI_SUCCESS or error code
*/
#include <lam_config.h>
#include <mpi.h>
#include <mpisys.h>
#include <mpitrace.h>
#include <rpisys.h>
#include <terror.h>
#if LAM_WANT_IMPI
#include <impi.h>
#endif
/*
The new plan (27 Sep 1999):
- In request chains, there are mandatory and non-mandatory requests.
- All top-level requests should be marked as RQFMAND; need to
investigate this (I think setting it in lamsend.c should be
sufficient) -- this would make the logic below easier. Just need to
ensure that non-mandatory requests don't inadvenrtantly get RQFMAND
set (perhaps they should explicitly unset it, like we explicitly set
RQFSHADOW right now?)
- When we call lam_test, we should check each one of them
- If a request goes into a done state and has RQFACK set, do an
MPI_Isend of the ACK. Add a new request to the end of the chain, and
set RQF_MAND on it.
- If all the mandatatory requests (including any new MPI_Isends) are
in the done state, the overall request is done
- If the overall request is not done, return *flag = 0/MPI_SUCCESS
- Otherwise, go through each request:
- if it is persistent, restart it
- if it is not persistent, whack it
- We will never have persistent shadows with a non-persistent main; that
should make logic a bit easier
- Then return *flag = 1/MPI_SUCCESS
*/
/*
* global functions
*/
int lam_test_rqfmand(MPI_Request *preq);
int
lam_test(MPI_Request *preq, int destroy, int *flag, MPI_Status *stat)
{
MPI_Request req; /* request */
int errstat; /* error in status */
int err; /* error code */
int fl_trace; /* do tracing? */
double startt = 0.0; /* start time */
double finisht; /* finish time */
#if LAM_WANT_IMPI
int done; /* if all done */
int bogus_flag; /* flag for lam_test */
MPI_Request prev, cur, next; /* request */
#endif
if (preq == 0) return(lam_mkerr(MPI_ERR_REQUEST, EINVAL));
if (flag == 0) return(lam_mkerr(MPI_ERR_ARG, EINVAL));
if ((fl_trace = LAM_TRACE_TOP())) {
startt = MPI_Wtime();
_kio.ki_blktime = 0.0;
}
/*
* Advance the system.
*/
_mpi_req_blkclr_m();
err = _mpi_req_advance();
if (err != MPI_SUCCESS) return(err);
req = *preq;
/*
* Inactive requests get an empty status.
*/
if ((req == MPI_REQUEST_NULL) || (req->rq_state == LAM_RQSINIT)) {
*flag = 1;
if (stat != MPI_STATUS_IGNORE) {
lam_emptystat(stat);
}
}
/*
* If the top-level request is not done, the entire request cannot be
* done. So reset the flag.
*/
else if (req->rq_state != LAM_RQSDONE) {
*flag = 0;
}
#if LAM_WANT_IMPI
/*
* Need to check if all mandatory requests are done. See if we need
* to send out an ACK -- if we do, we have to chain it to the bottom
* of the request list, and mark it not done. Be sure to check all
* requests, regardless if we find a mandatory one that hasn't
* finished or not.
*/
else {
done = 1;
for (cur = req; cur != MPI_REQUEST_NULL; cur = cur->rq_shadow) {
/*
* If we find a newly finished request, mark it
*/
if (cur->rq_state == LAM_RQSDONE)
cur->rq_flags |= LAM_RQFMARK;
else {
if ((cur->rq_marks & LAM_RQFMAND) != 0) {
done = 0;
break;
}
}
}
/*
* Did all the mandatory requests finish?
*/
if (done == 0) {
*flag = 0;
return (MPI_SUCCESS);
}
*flag = 1;
if (destroy) {
/*
* Fill the status
*/
errstat = req->rq_status.MPI_ERROR;
if (stat != MPI_STATUS_IGNORE) {
*stat = req->rq_status;
}
/*
* Generate a run time trace except in the case of cancelled request or
* a request where the peer is MPI_PROC_NULL.
*/
if (fl_trace && (req->rq_rank != MPI_PROC_NULL) &&
!(req->rq_flags & LAM_RQFCANCEL)) {
finisht = MPI_Wtime();
lam_tr_msg( (req->rq_type == LAM_RQIRECV)
? TRTINPUT : TRTNOIO, startt,
LAM_S2US(finisht - startt - _kio.ki_blktime),
LAM_S2US(_kio.ki_blktime), req->rq_rank,
req->rq_tag, req->rq_comm, req->rq_dtype,
req->rq_count, req->rq_status.MPI_SOURCE,
req->rq_status.MPI_TAG, req->rq_seq, req->rq_type);
}
/*
* Now that all the mandatory requests are done, traverse the list
* again:
*
* 1. restart any persistent requests that have completed,
* 2. leave persistent requests that have not completed alone
* 3. destroy any non-persistent requests (completed or not),
*
* Simplifying the logic a little -- we will never have a
* non-persistent top-level request (i.e., (*preq)) with persistent
* shadow requests. So if the top-level request gets whacked, they
* will all get whacked.
*/
for (prev = MPI_REQUEST_NULL, cur = req;
cur != MPI_REQUEST_NULL; cur = next) {
next = cur->rq_shadow;
_mpi_req_rem_m(cur);
err = _mpi_req_end(cur);
if (err != MPI_SUCCESS) return(err);
/*
* If persistent and completed, restart it
*/
if (cur->rq_marks & LAM_RQFPERSIST) {
if (cur->rq_state == LAM_RQSDONE)
req->rq_state = LAM_RQSINIT;
prev = cur;
}
/*
* Otherwise, it's not persistent, so whack it. May need to cancel it
* first (if it hasn't completed). Keep the destroying here vs
* lam_test() (so that lam_test doesn't potentially whack any shadows
* of this request).
*/
else {
if (cur->rq_state != LAM_RQSDONE) {
MPI_Cancel(&cur);
lam_test(&cur, 0, &bogus_flag, MPI_STATUS_IGNORE);
}
/*
* If we're destroying the top-level request, be sure to destroy it so
* that it gets set to MPI_REQUEST_NULL
*/
if (cur == *preq)
err = _mpi_req_destroy(preq);
else
err = _mpi_req_destroy(&cur);
if (err != MPI_SUCCESS)
return err;
if (prev != MPI_REQUEST_NULL)
prev->rq_shadow = next;
}
}
if (errstat != MPI_SUCCESS)
return errstat;
}
}
#else
/*
* Finish the request if in destructive-mode.
*/
else {
*flag = 1;
if (destroy) {
_mpi_req_rem_m(req);
err = _mpi_req_end(req);
if (err != MPI_SUCCESS) return(err);
errstat = req->rq_status.MPI_ERROR;
if (stat != MPI_STATUS_IGNORE) {
*stat = req->rq_status;
}
/*
* Generate a run time trace except in the case of cancelled request or
* a request where the peer is MPI_PROC_NULL.
*/
if (fl_trace && (req->rq_rank != MPI_PROC_NULL)
&& !(req->rq_flags & LAM_RQFCANCEL)) {
finisht = MPI_Wtime();
lam_tr_msg( (req->rq_type == LAM_RQIRECV)
? TRTINPUT : TRTNOIO, startt,
LAM_S2US(finisht - startt - _kio.ki_blktime),
LAM_S2US(_kio.ki_blktime), req->rq_rank,
req->rq_tag, req->rq_comm, req->rq_dtype,
req->rq_count, req->rq_status.MPI_SOURCE,
req->rq_status.MPI_TAG, req->rq_seq, req->rq_type);
}
/*
* Reset persistent requests.
* Destroy requests that are not persistent.
*/
if (req->rq_marks & LAM_RQFPERSIST) {
req->rq_state = LAM_RQSINIT;
} else {
err = _mpi_req_destroy(preq);
if (err != MPI_SUCCESS) return(err);
}
if (errstat != MPI_SUCCESS) {
return(errstat);
}
}
}
#endif
return(MPI_SUCCESS);
}
/*
* Test to see if any shadow request in the chain has LAM_RFQMAND set
*/
int
lam_test_rqfmand(MPI_Request *preq)
{
MPI_Request p;
for (p = (*preq); p != NULL; p = p->rq_shadow)
if (((*preq)->rq_marks & LAM_RQFMAND))
return 1;
return 0;
}
|