| 1 |
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 2 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 4 |
// vi: set et ts=4 sw=2 sts=2: |
| 5 |
/****************************************************************************/ |
| 6 |
/* */ |
| 7 |
/* File: cmds.c */ |
| 8 |
/* */ |
| 9 |
/* Purpose: DDD-commands for Transfer Module */ |
| 10 |
/* */ |
| 11 |
/* Author: Klaus Birken */ |
| 12 |
/* Rechenzentrum Uni Stuttgart */ |
| 13 |
/* Universitaet Stuttgart */ |
| 14 |
/* Allmandring 30 */ |
| 15 |
/* 70550 Stuttgart */ |
| 16 |
/* internet: [email protected] */ |
| 17 |
/* */ |
| 18 |
/* History: 931130 kb begin (xfer.c) */ |
| 19 |
/* 950321 kb added variable sized objects (XferCopyObjX) */ |
| 20 |
/* 950405 kb V1.3: extracted from xfer.c */ |
| 21 |
/* 960703 kb split XferInfo-list into ObjXfer and CplXfer */ |
| 22 |
/* 960718 kb introduced lowcomm-layer (sets of messages) */ |
| 23 |
/* */ |
| 24 |
/* Remarks: */ |
| 25 |
/* */ |
| 26 |
/****************************************************************************/ |
| 27 |
|
| 28 |
/****************************************************************************/ |
| 29 |
/* */ |
| 30 |
/* include files */ |
| 31 |
/* system include files */ |
| 32 |
/* application include files */ |
| 33 |
/* */ |
| 34 |
/****************************************************************************/ |
| 35 |
|
| 36 |
/* standard C library */ |
| 37 |
#include <config.h> |
| 38 |
#include <cstdlib> |
| 39 |
#include <cstdio> |
| 40 |
#include <cstring> |
| 41 |
|
| 42 |
#include <iomanip> |
| 43 |
|
| 44 |
#include <dune/common/exceptions.hh> |
| 45 |
#include <dune/common/stdstreams.hh> |
| 46 |
|
| 47 |
#include <dune/uggrid/parallel/ddd/dddcontext.hh> |
| 48 |
|
| 49 |
#include <dune/uggrid/parallel/ddd/dddi.h> |
| 50 |
#include "xfer.h" |
| 51 |
|
| 52 |
|
| 53 |
USING_UG_NAMESPACE |
| 54 |
using namespace PPIF; |
| 55 |
|
| 56 |
START_UGDIM_NAMESPACE |
| 57 |
|
| 58 |
/****************************************************************************/ |
| 59 |
/* */ |
| 60 |
/* data structures */ |
| 61 |
/* */ |
| 62 |
/****************************************************************************/ |
| 63 |
|
| 64 |
|
| 65 |
/****************************************************************************/ |
| 66 |
/* */ |
| 67 |
/* definition of variables global to this source file only (static!) */ |
| 68 |
/* */ |
| 69 |
/****************************************************************************/ |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
/****************************************************************************/ |
| 75 |
/* */ |
| 76 |
/* routines */ |
| 77 |
/* */ |
| 78 |
/****************************************************************************/ |
| 79 |
|
| 80 |
|
| 81 |
static int sort_XIDelCmd (const void *e1, const void *e2) |
| 82 |
{ |
| 83 |
XIDelCmd *item1 = *((XIDelCmd **)e1); |
| 84 |
XIDelCmd *item2 = *((XIDelCmd **)e2); |
| 85 |
|
| 86 |
/* ascending GID is needed for ExecLocalXIDelCmds */ |
| 87 |
if (OBJ_GID(item1->hdr) < OBJ_GID(item2->hdr)) return(-1); |
| 88 |
if (OBJ_GID(item1->hdr) > OBJ_GID(item2->hdr)) return(1); |
| 89 |
|
| 90 |
return(0); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
static int sort_XIDelObj (const void *e1, const void *e2) |
| 95 |
{ |
| 96 |
XIDelObj *item1 = *((XIDelObj **)e1); |
| 97 |
XIDelObj *item2 = *((XIDelObj **)e2); |
| 98 |
|
| 99 |
/* ascending GID is needed for ExecLocalXIDelObjs */ |
| 100 |
if (item1->gid < item2->gid) return(-1); |
| 101 |
if (item1->gid > item2->gid) return(1); |
| 102 |
|
| 103 |
return(0); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
static int sort_XINewCpl (const void *e1, const void *e2) |
| 108 |
{ |
| 109 |
XINewCpl *item1 = *((XINewCpl **)e1); |
| 110 |
XINewCpl *item2 = *((XINewCpl **)e2); |
| 111 |
|
| 112 |
/* receiving processor */ |
| 113 |
if (item1->to < item2->to) return(-1); |
| 114 |
if (item1->to > item2->to) return(1); |
| 115 |
|
| 116 |
return(0); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
static int sort_XIOldCpl (const void *e1, const void *e2) |
| 122 |
{ |
| 123 |
XIOldCpl *item1 = *((XIOldCpl **)e1); |
| 124 |
XIOldCpl *item2 = *((XIOldCpl **)e2); |
| 125 |
DDD_GID gid1, gid2; |
| 126 |
|
| 127 |
/* receiving processor */ |
| 128 |
if (item1->to < item2->to) return(-1); |
| 129 |
if (item1->to > item2->to) return(1); |
| 130 |
|
| 131 |
/* ascending GID is needed for UnpackOldCplTab on receiver side */ |
| 132 |
gid1 = item1->te.gid; |
| 133 |
gid2 = item2->te.gid; |
| 134 |
if (gid1 < gid2) return(-1); |
| 135 |
if (gid1 > gid2) return(1); |
| 136 |
|
| 137 |
return(0); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
static int sort_XIDelCpl (const void *e1, const void *e2) |
| 143 |
{ |
| 144 |
XIDelCpl *item1 = *((XIDelCpl **)e1); |
| 145 |
XIDelCpl *item2 = *((XIDelCpl **)e2); |
| 146 |
DDD_GID gid1, gid2; |
| 147 |
|
| 148 |
/* receiving processor */ |
| 149 |
if (item1->to < item2->to) return(-1); |
| 150 |
if (item1->to > item2->to) return(1); |
| 151 |
|
| 152 |
/* ascending GID is needed by CplMsgUnpack on receiver side */ |
| 153 |
gid1 = item1->te.gid; |
| 154 |
gid2 = item2->te.gid; |
| 155 |
if (gid1 < gid2) return(-1); |
| 156 |
if (gid1 > gid2) return(1); |
| 157 |
|
| 158 |
return(0); |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
static int sort_XIModCpl (const void *e1, const void *e2) |
| 163 |
{ |
| 164 |
XIModCpl *item1 = *((XIModCpl **)e1); |
| 165 |
XIModCpl *item2 = *((XIModCpl **)e2); |
| 166 |
DDD_GID gid1, gid2; |
| 167 |
|
| 168 |
/* receiving processor */ |
| 169 |
if (item1->to < item2->to) return(-1); |
| 170 |
if (item1->to > item2->to) return(1); |
| 171 |
|
| 172 |
/* ascending GID is needed by CplMsgUnpack on receiver side */ |
| 173 |
gid1 = item1->te.gid; |
| 174 |
gid2 = item2->te.gid; |
| 175 |
if (gid1 < gid2) return(-1); |
| 176 |
if (gid1 > gid2) return(1); |
| 177 |
|
| 178 |
/* sorting according to priority is not necessary anymore, |
| 179 |
equal items with different priorities will be sorted |
| 180 |
out according to PriorityMerge(). KB 970129 |
| 181 |
if (item1->te.prio < item2->te.prio) return(-1); |
| 182 |
if (item1->te.prio > item2->te.prio) return(1); |
| 183 |
*/ |
| 184 |
|
| 185 |
return(0); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
static int sort_XIAddCpl (const void *e1, const void *e2) |
| 190 |
{ |
| 191 |
XIAddCpl *item1 = *((XIAddCpl **)e1); |
| 192 |
XIAddCpl *item2 = *((XIAddCpl **)e2); |
| 193 |
DDD_GID gid1, gid2; |
| 194 |
|
| 195 |
/* receiving processor */ |
| 196 |
if (item1->to < item2->to) return(-1); |
| 197 |
if (item1->to > item2->to) return(1); |
| 198 |
|
| 199 |
/* ascending GID is needed by CplMsgUnpack on receiver side */ |
| 200 |
gid1 = item1->te.gid; |
| 201 |
gid2 = item2->te.gid; |
| 202 |
if (gid1 < gid2) return(-1); |
| 203 |
if (gid1 > gid2) return(1); |
| 204 |
|
| 205 |
return(0); |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
/****************************************************************************/ |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
/* |
| 215 |
eliminate double XIDelCmd-items. |
| 216 |
|
| 217 |
the items have been sorted according to key |
| 218 |
(gid), all in ascending order. |
| 219 |
if gid (i.e., hdr) is equal, |
| 220 |
the item is skipped. |
| 221 |
this implements rule XFER-D1. |
| 222 |
|
| 223 |
the number of valid items is returned. |
| 224 |
*/ |
| 225 |
static int unify_XIDelCmd (const DDD::DDDContext&, XIDelCmd **i1, XIDelCmd **i2) |
| 226 |
{ |
| 227 |
return ((*i1)->hdr != (*i2)->hdr); |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
/* |
| 233 |
eliminate double XIModCpl-items. |
| 234 |
merge priorities from similar XIModCpl-items. |
| 235 |
|
| 236 |
the items have been sorted according to key (to,gid), |
| 237 |
all in ascending order. if to or gid are different, then |
| 238 |
at least the first item is relevant. if both are equal, |
| 239 |
we merge priorities and get a new priority together with |
| 240 |
the information whether first item wins over second. |
| 241 |
if first item wins, it is switched into second position and |
| 242 |
the second item (now on first position) is rejected. |
| 243 |
if second item wins, first item is rejected. |
| 244 |
in both cases, we use the new priority for next comparison. |
| 245 |
*/ |
| 246 |
static int unify_XIModCpl (const DDD::DDDContext& context, XIModCpl **i1p, XIModCpl **i2p) |
| 247 |
{ |
| 248 |
XIModCpl *i1 = *i1p, *i2 = *i2p; |
| 249 |
DDD_PRIO newprio; |
| 250 |
int ret; |
| 251 |
|
| 252 |
/* if items are different in gid or dest, take first item */ |
| 253 |
if ((i1->to != i2->to) || (i1->te.gid != i2->te.gid)) |
| 254 |
return true; |
| 255 |
|
| 256 |
/* items have equal to and gid, we must check priority */ |
| 257 |
ret = PriorityMerge(&context.typeDefs()[i1->typ], |
| 258 |
i1->te.prio, i2->te.prio, &newprio); |
| 259 |
|
| 260 |
if (ret==PRIO_FIRST || ret==PRIO_UNKNOWN) |
| 261 |
{ |
| 262 |
/* i1 is winner, take it, switch it into second position, |
| 263 |
signal rejection of i2 (now on first position). |
| 264 |
use new priority */ |
| 265 |
|
| 266 |
i1->te.prio = newprio; |
| 267 |
*i1p = i2; *i2p = i1; /* switch pointers */ |
| 268 |
} |
| 269 |
else |
| 270 |
{ |
| 271 |
/* i1 lost, i2 is winner. throw away i1, but |
| 272 |
use new priority for next comparison */ |
| 273 |
i2->te.prio = newprio; |
| 274 |
} |
| 275 |
|
| 276 |
return false; |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
/* TODO remove this */ |
| 282 |
void GetSizesXIAddData (const DDD::DDDContext& context, int *, int *, size_t *, size_t *); |
| 283 |
|
| 284 |
|
| 285 |
/* |
| 286 |
compute and display memory resources used |
| 287 |
*/ |
| 288 |
static void DisplayMemResources(const DDD::DDDContext& context) |
| 289 |
{ |
| 290 |
const auto& ctx = context.xferContext(); |
| 291 |
|
| 292 |
int nSegms=0, nItems=0, nNodes=0; |
| 293 |
size_t memAllocated=0, memUsed=0; |
| 294 |
|
| 295 |
GetSizesXIAddData(context, &nSegms, &nItems, &memAllocated, &memUsed); |
| 296 |
if (nSegms>0) |
| 297 |
printf("XferEnd, XIAddData segms=%d items=%d allocated=%ld used=%ld\n", |
| 298 |
nSegms, nItems, (long)memAllocated, (long)memUsed); |
| 299 |
|
| 300 |
|
| 301 |
XICopyObjSet_GetResources(reinterpret_cast<XICopyObjSet*>(ctx.setXICopyObj), |
| 302 |
&nSegms, &nItems, &nNodes, &memAllocated, &memUsed); |
| 303 |
if (nSegms>0) { |
| 304 |
printf("XferEnd, XICopyObj " |
| 305 |
"segms=%d items=%d nodes=%d allocated=%ld used=%ld\n", |
| 306 |
nSegms, nItems, nNodes, (long)memAllocated, (long)memUsed); |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
#ifdef XICOPYOBJ_DETAILED_RESOURCES |
| 311 |
/* this is a different version, split up into BTree and SegmList */ |
| 312 |
XICopyObjSegmList_GetResources(reinterpret_cast<XICopyObjSet*>(ctx.setXICopyObj)->list, |
| 313 |
&nSegms, &nItems, &memAllocated, &memUsed); |
| 314 |
if (nSegms>0) |
| 315 |
printf("XferEnd, XICopyObj segms=%d items=%d allocated=%ld used=%ld\n", |
| 316 |
nSegms, nItems, (long)memAllocated, (long)memUsed); |
| 317 |
|
| 318 |
XICopyObjBTree_GetResources(reinterpret_cast<XICopyObjSet*>(ctx.setXICopyObj)->tree, |
| 319 |
&nNodes, &nItems, &memAllocated, &memUsed); |
| 320 |
if (nItems>0) |
| 321 |
printf("XferEnd, XICopyObj nodes=%d items=%d allocated=%ld used=%ld\n", |
| 322 |
nNodes, nItems, (long)memAllocated, (long)memUsed); |
| 323 |
#endif |
| 324 |
|
| 325 |
|
| 326 |
XISetPrioSet_GetResources(reinterpret_cast<XISetPrioSet*>(ctx.setXISetPrio), |
| 327 |
&nSegms, &nItems, &nNodes, &memAllocated, &memUsed); |
| 328 |
if (nSegms>0) { |
| 329 |
printf("XferEnd, XISetPrio " |
| 330 |
"segms=%d items=%d nodes=%d allocated=%ld used=%ld\n", |
| 331 |
nSegms, nItems, nNodes, (long)memAllocated, (long)memUsed); |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
#define SLL_GET_SIZES(T) do { \ |
| 336 |
GetSizes##T(context, &nSegms, &nItems, &memAllocated, &memUsed); \ |
| 337 |
if (nSegms>0) \ |
| 338 |
printf("XferEnd, " #T " segms=%d items=%d allocated=%ld used=%ld\n", \ |
| 339 |
nSegms, nItems, (long)memAllocated, (long)memUsed); \ |
| 340 |
} while(false) |
| 341 |
SLL_GET_SIZES(XIDelCmd); |
| 342 |
SLL_GET_SIZES(XIDelObj); |
| 343 |
SLL_GET_SIZES(XINewCpl); |
| 344 |
SLL_GET_SIZES(XIOldCpl); |
| 345 |
SLL_GET_SIZES(XIDelCpl); |
| 346 |
SLL_GET_SIZES(XIModCpl); |
| 347 |
SLL_GET_SIZES(XIAddCpl); |
| 348 |
#undef SLL_GET_SIZES |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
/****************************************************************************/ |
| 353 |
/* */ |
| 354 |
/* Function: DDD_XferEnd */ |
| 355 |
/* */ |
| 356 |
/****************************************************************************/ |
| 357 |
|
| 358 |
/** |
| 359 |
End of transfer phase. |
| 360 |
This function starts the object transfer process. After a call to |
| 361 |
this function (on all processors) all {\bf Transfer}-commands since |
| 362 |
the last call to \funk{XferBegin} are executed. This involves |
| 363 |
a set of local communications between the processors. |
| 364 |
*/ |
| 365 |
|
| 366 |
DDD_RET DDD_XferEnd(DDD::DDDContext& context) |
| 367 |
{ |
| 368 |
auto& ctx = context.xferContext(); |
| 369 |
const auto& me = context.me(); |
| 370 |
|
| 371 |
DDD_RET ret_code = DDD_RET_OK; |
| 372 |
XICopyObj **arrayNewOwners = NULL; |
| 373 |
int nNewOwners; |
| 374 |
XIDelCmd **arrayXIDelCmd = NULL; |
| 375 |
int remXIDelCmd, prunedXIDelCmd; |
| 376 |
XIDelObj **arrayXIDelObj = NULL; |
| 377 |
std::vector<XISetPrio*> arrayXISetPrio; |
| 378 |
XINewCpl **arrayXINewCpl = NULL; |
| 379 |
XIOldCpl **arrayXIOldCpl = NULL; |
| 380 |
XIDelCpl **arrayXIDelCpl = NULL; |
| 381 |
int remXIDelCpl; |
| 382 |
XIModCpl **arrayXIModCpl = NULL; |
| 383 |
int remXIModCpl; |
| 384 |
XIAddCpl **arrayXIAddCpl = NULL; |
| 385 |
int obsolete, nRecvMsgs; |
| 386 |
XFERMSG *sendMsgs=NULL, *sm=NULL; |
| 387 |
LC_MSGHANDLE *recvMsgs = NULL; |
| 388 |
std::vector<DDD_HDR> localCplObjs; |
| 389 |
size_t sendMem=0, recvMem=0; |
| 390 |
int DelCmds_were_pruned; |
| 391 |
|
| 392 |
STAT_SET_MODULE(DDD_MODULE_XFER); |
| 393 |
STAT_ZEROALL; |
| 394 |
|
| 395 |
const auto procs = context.procs(); |
| 396 |
const auto& nCpls = context.couplingContext().nCpls; |
| 397 |
|
| 398 |
/* step mode and check whether call to XferEnd is valid */ |
| 399 |
if (!XferStepMode(context, DDD::Xfer::XferMode::XMODE_CMDS)) |
| 400 |
DUNE_THROW(Dune::Exception, "DDD_XferEnd() aborted"); |
| 401 |
|
| 402 |
|
| 403 |
/* |
| 404 |
PREPARATION PHASE |
| 405 |
*/ |
| 406 |
STAT_RESET; |
| 407 |
/* get sorted array of XICopyObj-items */ |
| 408 |
std::vector<XICopyObj*> arrayXICopyObj = XICopyObjSet_GetArray(reinterpret_cast<XICopyObjSet*>(ctx.setXICopyObj)); |
| 409 |
obsolete = XICopyObjSet_GetNDiscarded(reinterpret_cast<XICopyObjSet*>(ctx.setXICopyObj)); |
| 410 |
|
| 411 |
/* debugging output, write all XICopyObjs to file |
| 412 |
if (XICopyObjSet_GetNItems(ctx.setXICopyObj)>0) |
| 413 |
{ |
| 414 |
FILE *ff = fopen("xfer.dump","w"); |
| 415 |
XICopyObjSet_Print(ctx.setXICopyObj, 2, ff); |
| 416 |
fclose(ff); |
| 417 |
} |
| 418 |
*/ |
| 419 |
|
| 420 |
|
| 421 |
/* |
| 422 |
(OPTIONAL) COMMUNICATION PHASE 0 |
| 423 |
*/ |
| 424 |
if (DDD_GetOption(context, OPT_XFER_PRUNE_DELETE)==OPT_ON) |
| 425 |
{ |
| 426 |
/* |
| 427 |
for each XferDelete-Cmd: if there exists at least |
| 428 |
one XferCopy-cmd with destination=me, then the |
| 429 |
XferDelete-Cmd is discarded. |
| 430 |
|
| 431 |
NOTE: the priorities behave like in the specification, |
| 432 |
i.e., incoming objects with lower priority than the |
| 433 |
local (deleted) object won't be rejected. |
| 434 |
*/ |
| 435 |
/* create sorted array of XIDelCmd-items, and unify it */ |
| 436 |
/* in case of pruning set to OPT_OFF, this sorting/unifying |
| 437 |
step is done lateron. */ |
| 438 |
arrayXIDelCmd = SortedArrayXIDelCmd(context, sort_XIDelCmd); |
| 439 |
if (arrayXIDelCmd==NULL && ctx.nXIDelCmd>0) |
| 440 |
{ |
| 441 |
Dune::dwarn << "out of memory in DDD_XferEnd(), giving up.\n"; |
| 442 |
ret_code = DDD_RET_ERROR_NOMEM; |
| 443 |
LC_Abort(context, EXCEPTION_LOWCOMM_USER); |
| 444 |
goto exit; |
| 445 |
} |
| 446 |
remXIDelCmd = UnifyXIDelCmd(context, arrayXIDelCmd, unify_XIDelCmd); |
| 447 |
obsolete += (ctx.nXIDelCmd-remXIDelCmd); |
| 448 |
|
| 449 |
/* do communication and actual pruning */ |
| 450 |
prunedXIDelCmd = PruneXIDelCmd(context, arrayXIDelCmd, remXIDelCmd, arrayXICopyObj); |
| 451 |
obsolete += prunedXIDelCmd; |
| 452 |
remXIDelCmd -= prunedXIDelCmd; |
| 453 |
|
| 454 |
DelCmds_were_pruned = true; |
| 455 |
} |
| 456 |
else |
| 457 |
{ |
| 458 |
DelCmds_were_pruned = false; |
| 459 |
} |
| 460 |
|
| 461 |
/* |
| 462 |
if (nXIDelCmd>0||remXIDelCmd>0||prunedXIDelCmd>0) |
| 463 |
printf("%4d: XIDelCmd. all=%d rem=%d pruned=%d\n", me, |
| 464 |
nXIDelCmd, remXIDelCmd, prunedXIDelCmd); |
| 465 |
*/ |
| 466 |
|
| 467 |
|
| 468 |
/* |
| 469 |
COMMUNICATION PHASE 1 |
| 470 |
*/ |
| 471 |
STAT_RESET; |
| 472 |
/* send Cpl-info about new objects to owners of other local copies */ |
| 473 |
arrayNewOwners = CplClosureEstimate(context, arrayXICopyObj, &nNewOwners); |
| 474 |
if (nNewOwners>0 && arrayNewOwners==NULL) |
| 475 |
{ |
| 476 |
Dune::dwarn << "out of memory in DDD_XferEnd(), giving up.\n"; |
| 477 |
ret_code = DDD_RET_ERROR_NOMEM; |
| 478 |
LC_Abort(context, EXCEPTION_LOWCOMM_USER); |
| 479 |
goto exit; |
| 480 |
} |
| 481 |
|
| 482 |
/* create sorted array of XINewCpl- and XIOldCpl-items. |
| 483 |
TODO. if efficiency is a problem here, use b-tree or similar |
| 484 |
data structure to improve performance. */ |
| 485 |
arrayXINewCpl = SortedArrayXINewCpl(context, sort_XINewCpl); |
| 486 |
if (arrayXINewCpl==NULL && ctx.nXINewCpl>0) |
| 487 |
{ |
| 488 |
Dune::dwarn << "out of memory in DDD_XferEnd(), giving up.\n"; |
| 489 |
ret_code = DDD_RET_ERROR_NOMEM; |
| 490 |
LC_Abort(context, EXCEPTION_LOWCOMM_USER); |
| 491 |
goto exit; |
| 492 |
} |
| 493 |
|
| 494 |
arrayXIOldCpl = SortedArrayXIOldCpl(context, sort_XIOldCpl); |
| 495 |
if (arrayXIOldCpl==NULL && ctx.nXIOldCpl>0) |
| 496 |
{ |
| 497 |
Dune::dwarn << "out of memory in DDD_XferEnd(), giving up.\n"; |
| 498 |
ret_code = DDD_RET_ERROR_NOMEM; |
| 499 |
LC_Abort(context, EXCEPTION_LOWCOMM_USER); |
| 500 |
goto exit; |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
/* prepare msgs for objects and XINewCpl-items */ |
| 505 |
PrepareObjMsgs(context, |
| 506 |
arrayXICopyObj, |
| 507 |
arrayXINewCpl, ctx.nXINewCpl, |
| 508 |
arrayXIOldCpl, ctx.nXIOldCpl, |
| 509 |
&sendMsgs, &sendMem); |
| 510 |
|
| 511 |
|
| 512 |
/* |
| 513 |
DisplayMemResources(context); |
| 514 |
*/ |
| 515 |
|
| 516 |
/* init communication topology */ |
| 517 |
nRecvMsgs = LC_Connect(context, ctx.objmsg_t); |
| 518 |
STAT_TIMER(T_XFER_PREP_MSGS); |
| 519 |
if (nRecvMsgs<0) |
| 520 |
{ |
| 521 |
/* some processor raised an exception */ |
| 522 |
if (nRecvMsgs==EXCEPTION_LOWCOMM_CONNECT) |
| 523 |
{ |
| 524 |
/* the dangerous exception: it occurred only locally, |
| 525 |
the other procs doesn't know about it */ |
| 526 |
Dune::dwarn << "local exception during LC_Connect() in DDD_XferEnd(), giving up.\n"; |
| 527 |
|
| 528 |
/* in this state the local processor hasn't initiated any send |
| 529 |
or receive calls. however, there may be (and almost ever: |
| 530 |
there will be!) other processors which already initiated their |
| 531 |
receive calls. This is a tragic situation without a possibility |
| 532 |
to escape. |
| 533 |
*/ |
| 534 |
HARD_EXIT; |
| 535 |
} |
| 536 |
else |
| 537 |
{ |
| 538 |
/* all other exceptions are known globally, shutdown safely */ |
| 539 |
Dune::dwarn << "error during LC_Connect() in DDD_XferEnd(), giving up.\n"; |
| 540 |
ret_code = DDD_RET_ERROR_UNKNOWN; |
| 541 |
goto exit; |
| 542 |
} |
| 543 |
} |
| 544 |
|
| 545 |
/*** all exceptional errors which occur from here down to the |
| 546 |
point of no return (some lines below) could be cleaned up |
| 547 |
locally, but the communication situation cannot be cleaned |
| 548 |
up with the current functionality of PPIF (i.e., discarding |
| 549 |
of pending communication calls). therefore, the local processor |
| 550 |
will be able to shutdown safely, but other processors might hang. ***/ |
| 551 |
|
| 552 |
STAT_RESET; |
| 553 |
/* build obj msgs on sender side and start send */ |
| 554 |
if (! IS_OK(XferPackMsgs(context, sendMsgs))) |
| 555 |
{ |
| 556 |
Dune::dwarn << "error during message packing in DDD_XferEnd(), giving up.\n"; |
| 557 |
LC_Cleanup(context); |
| 558 |
ret_code = DDD_RET_ERROR_UNKNOWN; |
| 559 |
goto exit; |
| 560 |
} |
| 561 |
STAT_TIMER(T_XFER_PACK_SEND); |
| 562 |
|
| 563 |
/* |
| 564 |
now messages are in the net, use spare time |
| 565 |
*/ |
| 566 |
|
| 567 |
/* create sorted array of XISetPrio-items, and unify it */ |
| 568 |
STAT_RESET; |
| 569 |
arrayXISetPrio = XISetPrioSet_GetArray(reinterpret_cast<XISetPrioSet*>(ctx.setXISetPrio)); |
| 570 |
obsolete += XISetPrioSet_GetNDiscarded(reinterpret_cast<XISetPrioSet*>(ctx.setXISetPrio)); |
| 571 |
|
| 572 |
|
| 573 |
if (!DelCmds_were_pruned) |
| 574 |
{ |
| 575 |
/* create sorted array of XIDelCmd-items, and unify it */ |
| 576 |
arrayXIDelCmd = SortedArrayXIDelCmd(context, sort_XIDelCmd); |
| 577 |
if (arrayXIDelCmd==NULL && ctx.nXIDelCmd>0) |
| 578 |
{ |
| 579 |
Dune::dwarn << "out of memory in DDD_XferEnd(), giving up.\n"; |
| 580 |
LC_Cleanup(context); |
| 581 |
ret_code = DDD_RET_ERROR_NOMEM; |
| 582 |
goto exit; |
| 583 |
} |
| 584 |
remXIDelCmd = UnifyXIDelCmd(context, arrayXIDelCmd, unify_XIDelCmd); |
| 585 |
obsolete += (ctx.nXIDelCmd-remXIDelCmd); |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
/*** this is the point of no return. the next function manipulates |
| 590 |
the data structure irreversibly. ***/ |
| 591 |
|
| 592 |
/* execute local commands */ |
| 593 |
/* NOTE: messages have been build before in order to allow |
| 594 |
deletion of objects. */ |
| 595 |
ExecLocalXIDelCmd(context, arrayXIDelCmd, remXIDelCmd); |
| 596 |
|
| 597 |
/* now all XIDelObj-items have been created. these come from: |
| 598 |
1. application->DDD_XferDeleteObj->XIDelCmd->HdrDestructor-> |
| 599 |
->XferRegisterDelete |
| 600 |
2. HANDLER_DELETE->HdrDestructor (for dependent object)-> |
| 601 |
->XferRegisterDelete |
| 602 |
*/ |
| 603 |
|
| 604 |
/* create sorted array of XIDelObj-items */ |
| 605 |
arrayXIDelObj = SortedArrayXIDelObj(context, sort_XIDelObj); |
| 606 |
|
| 607 |
ExecLocalXISetPrio(context, arrayXISetPrio, |
| 608 |
arrayXIDelObj, ctx.nXIDelObj, |
| 609 |
arrayNewOwners, nNewOwners); |
| 610 |
ExecLocalXIDelObj(context, |
| 611 |
arrayXIDelObj, ctx.nXIDelObj, |
| 612 |
arrayNewOwners, nNewOwners); |
| 613 |
|
| 614 |
|
| 615 |
if (obsolete>0) |
| 616 |
{ |
| 617 |
if (DDD_GetOption(context, OPT_INFO_XFER) & XFER_SHOW_OBSOLETE) |
| 618 |
{ |
| 619 |
int all = ctx.nXIDelObj+ |
| 620 |
XISetPrioSet_GetNItems(reinterpret_cast<XISetPrioSet*>(ctx.setXISetPrio))+ |
| 621 |
XICopyObjSet_GetNItems(reinterpret_cast<XICopyObjSet*>(ctx.setXICopyObj)); |
| 622 |
|
| 623 |
using std::setw; |
| 624 |
Dune::dwarn |
| 625 |
<< "DDD MESG [" << setw(3) << me << "]: " << setw(4) << obsolete |
| 626 |
<< " from " << setw(4) << all << " xfer-cmds obsolete.\n"; |
| 627 |
} |
| 628 |
} |
| 629 |
STAT_TIMER(T_XFER_WHILE_COMM); |
| 630 |
|
| 631 |
/* |
| 632 |
nothing more to do until incoming messages arrive |
| 633 |
*/ |
| 634 |
|
| 635 |
/* display information about send-messages on lowcomm-level */ |
| 636 |
if (DDD_GetOption(context, OPT_INFO_XFER) & XFER_SHOW_MSGSALL) |
| 637 |
{ |
| 638 |
DDD_SyncAll(context); |
| 639 |
if (context.isMaster()) |
| 640 |
Dune::dwarn << "DDD XFER_SHOW_MSGSALL: ObjMsg.Send\n"; |
| 641 |
LC_PrintSendMsgs(context); |
| 642 |
} |
| 643 |
|
| 644 |
|
| 645 |
/* wait for communication-completion (send AND receive) */ |
| 646 |
STAT_RESET; |
| 647 |
recvMsgs = LC_Communicate(context); |
| 648 |
STAT_TIMER(T_XFER_WAIT_RECV); |
| 649 |
|
| 650 |
|
| 651 |
/* display information about message buffer sizes */ |
| 652 |
if (DDD_GetOption(context, OPT_INFO_XFER) & XFER_SHOW_MEMUSAGE) |
| 653 |
{ |
| 654 |
int k; |
| 655 |
|
| 656 |
/* sum up sizes of receive mesg buffers */ |
| 657 |
for(k=0; k<nRecvMsgs; k++) |
| 658 |
{ |
| 659 |
recvMem += LC_GetBufferSize(recvMsgs[k]); |
| 660 |
} |
| 661 |
|
| 662 |
using std::setw; |
| 663 |
Dune::dwarn |
| 664 |
<< "DDD MESG [" << setw(3) << me << "]: SHOW_MEM msgs " |
| 665 |
<< " send=" << setw(10) << sendMem |
| 666 |
<< " recv=" << setw(10) << recvMem |
| 667 |
<< " all=" << setw(10) << (sendMem+recvMem) << "\n"; |
| 668 |
} |
| 669 |
|
| 670 |
/* display information about recv-messages on lowcomm-level */ |
| 671 |
if (DDD_GetOption(context, OPT_INFO_XFER) & XFER_SHOW_MSGSALL) |
| 672 |
{ |
| 673 |
DDD_SyncAll(context); |
| 674 |
if (context.isMaster()) |
| 675 |
Dune::dwarn << "DDD XFER_SHOW_MSGSALL: ObjMsg.Recv\n"; |
| 676 |
LC_PrintRecvMsgs(context); |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
/* get sorted list of local objects with couplings */ |
| 681 |
localCplObjs = LocalCoupledObjectsList(context); |
| 682 |
|
| 683 |
|
| 684 |
/* unpack messages */ |
| 685 |
STAT_RESET; |
| 686 |
XferUnpack(context, recvMsgs, nRecvMsgs, |
| 687 |
localCplObjs.data(), nCpls, |
| 688 |
arrayXISetPrio, |
| 689 |
arrayXIDelObj, ctx.nXIDelObj, |
| 690 |
arrayXICopyObj, |
| 691 |
arrayNewOwners, nNewOwners); |
| 692 |
LC_Cleanup(context); |
| 693 |
STAT_TIMER(T_XFER_UNPACK); |
| 694 |
|
| 695 |
/* recreate sorted list of local coupled objects, |
| 696 |
old list might be corrupt due to creation of new objects */ |
| 697 |
STAT_RESET; |
| 698 |
localCplObjs = LocalCoupledObjectsList(context); |
| 699 |
|
| 700 |
|
| 701 |
/* create sorted array of XIDelCpl-, XIModCpl- and XIAddCpl-items. |
| 702 |
TODO. if efficiency is a problem here, use b-tree or similar |
| 703 |
data structure to improve performance. */ |
| 704 |
arrayXIDelCpl = SortedArrayXIDelCpl(context, sort_XIDelCpl); |
| 705 |
arrayXIModCpl = SortedArrayXIModCpl(context, sort_XIModCpl); |
| 706 |
arrayXIAddCpl = SortedArrayXIAddCpl(context, sort_XIAddCpl); |
| 707 |
|
| 708 |
|
| 709 |
/* some XIDelCpls have been invalidated by UpdateCoupling(), |
| 710 |
decrease list size to avoid sending them */ |
| 711 |
remXIDelCpl = ctx.nXIDelCpl; |
| 712 |
while (remXIDelCpl>0 && arrayXIDelCpl[remXIDelCpl-1]->to == procs) |
| 713 |
remXIDelCpl--; |
| 714 |
|
| 715 |
remXIModCpl = UnifyXIModCpl(context, arrayXIModCpl, unify_XIModCpl); |
| 716 |
STAT_TIMER(T_XFER_PREP_CPL); |
| 717 |
|
| 718 |
/* |
| 719 |
printf("%4d: %d XIDelCpls obsolete\n", me, nXIDelCpl-remXIDelCpl); |
| 720 |
*/ |
| 721 |
|
| 722 |
|
| 723 |
/* |
| 724 |
COMMUNICATION PHASE 2 |
| 725 |
*/ |
| 726 |
|
| 727 |
STAT_RESET; |
| 728 |
CommunicateCplMsgs(context, |
| 729 |
arrayXIDelCpl, remXIDelCpl, |
| 730 |
arrayXIModCpl, remXIModCpl, |
| 731 |
arrayXIAddCpl, ctx.nXIAddCpl, |
| 732 |
localCplObjs.data(), nCpls); |
| 733 |
STAT_TIMER(T_XFER_CPLMSG); |
| 734 |
|
| 735 |
|
| 736 |
/* |
| 737 |
CLEAN-UP PHASE 2 |
| 738 |
*/ |
| 739 |
exit: |
| 740 |
|
| 741 |
/* free temporary storage */ |
| 742 |
XICopyObjSet_Reset(reinterpret_cast<XICopyObjSet*>(ctx.setXICopyObj)); |
| 743 |
|
| 744 |
if (arrayNewOwners!=NULL) OO_Free (arrayNewOwners /*,0*/); |
| 745 |
FreeAllXIAddData(context); |
| 746 |
|
| 747 |
XISetPrioSet_Reset(reinterpret_cast<XISetPrioSet*>(ctx.setXISetPrio)); |
| 748 |
|
| 749 |
if (arrayXIDelCmd!=NULL) OO_Free (arrayXIDelCmd /*,0*/); |
| 750 |
FreeAllXIDelCmd(context); |
| 751 |
|
| 752 |
if (arrayXIDelObj!=NULL) OO_Free (arrayXIDelObj /*,0*/); |
| 753 |
FreeAllXIDelObj(context); |
| 754 |
|
| 755 |
if (arrayXINewCpl!=NULL) OO_Free (arrayXINewCpl /*,0*/); |
| 756 |
FreeAllXINewCpl(context); |
| 757 |
|
| 758 |
if (arrayXIOldCpl!=NULL) OO_Free (arrayXIOldCpl /*,0*/); |
| 759 |
FreeAllXIOldCpl(context); |
| 760 |
|
| 761 |
if (arrayXIDelCpl!=NULL) OO_Free (arrayXIDelCpl /*,0*/); |
| 762 |
FreeAllXIDelCpl(context); |
| 763 |
|
| 764 |
if (arrayXIModCpl!=NULL) OO_Free (arrayXIModCpl /*,0*/); |
| 765 |
FreeAllXIModCpl(context); |
| 766 |
|
| 767 |
if (arrayXIAddCpl!=NULL) OO_Free (arrayXIAddCpl /*,0*/); |
| 768 |
FreeAllXIAddCpl(context); |
| 769 |
|
| 770 |
for(; sendMsgs!=NULL; sendMsgs=sm) |
| 771 |
{ |
| 772 |
sm = sendMsgs->next; |
| 773 |
OO_Free (sendMsgs /*,0*/); |
| 774 |
} |
| 775 |
|
| 776 |
# if DebugXfer<=4 |
| 777 |
Dune::dverb << "XferEnd, before IFAllFromScratch().\n"; |
| 778 |
# endif |
| 779 |
|
| 780 |
if (ret_code==DDD_RET_OK) |
| 781 |
{ |
| 782 |
/* re-create all interfaces and step XMODE */ |
| 783 |
STAT_RESET; |
| 784 |
IFAllFromScratch(context); |
| 785 |
STAT_TIMER(T_XFER_BUILD_IF); |
| 786 |
} |
| 787 |
|
| 788 |
XferStepMode(context, DDD::Xfer::XferMode::XMODE_BUSY); |
| 789 |
return(ret_code); |
| 790 |
} |
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
/* ablage fuer debug-ausgabe |
| 796 |
|
| 797 |
# if DebugXfer<=4 |
| 798 |
sprintf(cBuffer,"%4d: XferEnd, after XferDeleteObjects(): " |
| 799 |
"send=%d recv=%d\n", me, nSendMsgs, nRecvMsgs); |
| 800 |
DDD_PrintDebug(cBuffer); |
| 801 |
# endif |
| 802 |
*/ |
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
/****************************************************************************/ |
| 807 |
/* */ |
| 808 |
/* Function: DDD_XferPrioChange */ |
| 809 |
/* */ |
| 810 |
/****************************************************************************/ |
| 811 |
|
| 812 |
/** |
| 813 |
Consistent change of a local object's priority during DDD Transfer. |
| 814 |
Local objects which are part of a distributed object must notify |
| 815 |
other copies about local priority changes. This is accomplished |
| 816 |
by issuing \funk{XferPrioChange}-commands during the transfer phase; |
| 817 |
DDD will send appropriate messages to the owner processors of |
| 818 |
the other copies. |
| 819 |
|
| 820 |
This function is regarded as a {\bf Transfer}-operation due |
| 821 |
to its influence on DDD management information on neighbouring |
| 822 |
processors. Therefore the function has to be issued between |
| 823 |
a starting \funk{XferBegin} and a final \funk{XferEnd} call. |
| 824 |
|
| 825 |
@param hdr DDD local object whose priority should be changed. |
| 826 |
@param prio new priority of that local object. |
| 827 |
*/ |
| 828 |
|
| 829 |
void DDD_XferPrioChange (DDD::DDDContext& context, DDD_HDR hdr, DDD_PRIO prio) |
| 830 |
{ |
| 831 |
auto& ctx = context.xferContext(); |
| 832 |
|
| 833 |
XISetPrio *xi = XISetPrioSet_NewItem(reinterpret_cast<XISetPrioSet*>(ctx.setXISetPrio)); |
| 834 |
xi->hdr = hdr; |
| 835 |
xi->gid = OBJ_GID(hdr); |
| 836 |
xi->prio = prio; |
| 837 |
|
| 838 |
if (! XISetPrioSet_ItemOK(reinterpret_cast<XISetPrioSet*>(ctx.setXISetPrio))) |
| 839 |
return; |
| 840 |
|
| 841 |
# if DebugXfer<=2 |
| 842 |
Dune::dvverb << "DDD_XferPrioChange " << OBJ_GID(hdr) << ", prio=" << prio << "\n"; |
| 843 |
# endif |
| 844 |
} |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
static void XferInitCopyInfo (DDD::DDDContext& context, |
| 849 |
DDD_HDR hdr, |
| 850 |
TYPE_DESC *desc, |
| 851 |
size_t size, |
| 852 |
DDD_PROC dest, |
| 853 |
DDD_PRIO prio) |
| 854 |
{ |
| 855 |
auto& ctx = context.xferContext(); |
| 856 |
|
| 857 |
if (!ddd_XferActive(context)) |
| 858 |
DUNE_THROW(Dune::Exception, "Missing DDD_XferBegin()"); |
| 859 |
|
| 860 |
if (dest >= context.procs()) |
| 861 |
DUNE_THROW(Dune::Exception, |
| 862 |
"cannot transfer " << OBJ_GID(hdr) << " to processor " << dest |
| 863 |
<< " (procs=" << context.procs() << ")"); |
| 864 |
|
| 865 |
if (prio>=MAX_PRIO) |
| 866 |
DUNE_THROW(Dune::Exception, |
| 867 |
"priority must be less than " << MAX_PRIO |
| 868 |
<< " (prio=" << prio << ")"); |
| 869 |
|
| 870 |
if (dest==context.me()) |
| 871 |
{ |
| 872 |
/* XFER-C4: XferCopyObj degrades to SetPrio command */ |
| 873 |
XISetPrio *xi = XISetPrioSet_NewItem(reinterpret_cast<XISetPrioSet*>(ctx.setXISetPrio)); |
| 874 |
xi->hdr = hdr; |
| 875 |
xi->gid = OBJ_GID(hdr); |
| 876 |
xi->prio = prio; |
| 877 |
|
| 878 |
if (! XISetPrioSet_ItemOK(reinterpret_cast<XISetPrioSet*>(ctx.setXISetPrio))) |
| 879 |
{ |
| 880 |
/* item has been inserted already, don't store it twice. */ |
| 881 |
/* even don't call XFERCOPY-handler, this is a real API change! */ |
| 882 |
|
| 883 |
/* xi->prio will be set to PRIO_INVALID if the priority of |
| 884 |
the previously existing XICopyObj-item wins the PriorityMerge |
| 885 |
in the corresponding Compare function (see supp.c). Then, |
| 886 |
we in fact won't need calling the XFERCOPY-handler here, |
| 887 |
because it doesn't give new information. If xi->prio is |
| 888 |
not PRIO_INVALID, then the XICopyObj-item xi wins the merge |
| 889 |
and the XFERCOPY-handler has to be called a second time, now |
| 890 |
with a higher priority. */ |
| 891 |
if (xi->prio==PRIO_INVALID) |
| 892 |
return; |
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
/* although XferCopyObj degrades to SetPrio, call XFERCOPY-handler! */ |
| 897 |
|
| 898 |
/* reset for eventual AddData-calls during handler execution */ |
| 899 |
ctx.theXIAddData = nullptr; |
| 900 |
|
| 901 |
/* call application handler for xfer of dependent objects */ |
| 902 |
if (desc->handlerXFERCOPY) |
| 903 |
{ |
| 904 |
DDD_OBJ obj = HDR2OBJ(hdr,desc); |
| 905 |
|
| 906 |
desc->handlerXFERCOPY(context, obj, dest, prio); |
| 907 |
} |
| 908 |
|
| 909 |
/* theXIAddData might be changed during handler execution */ |
| 910 |
ctx.theXIAddData = nullptr; |
| 911 |
} |
| 912 |
else |
| 913 |
{ |
| 914 |
/* this is a real transfer to remote proc */ |
| 915 |
XICopyObj *xi = XICopyObjSet_NewItem(reinterpret_cast<XICopyObjSet*>(ctx.setXICopyObj)); |
| 916 |
xi->hdr = hdr; |
| 917 |
xi->gid = OBJ_GID(hdr); |
| 918 |
xi->dest = dest; |
| 919 |
xi->prio = prio; |
| 920 |
|
| 921 |
if (! XICopyObjSet_ItemOK(reinterpret_cast<XICopyObjSet*>(ctx.setXICopyObj))) |
| 922 |
{ |
| 923 |
/* item has been inserted already, don't store it twice. */ |
| 924 |
/* even don't call XFERCOPY-handler, this is a real API change! */ |
| 925 |
|
| 926 |
/* xi->prio will be set to PRIO_INVALID if the priority of |
| 927 |
the previously existing XICopyObj-item wins the PriorityMerge |
| 928 |
in the corresponding Compare function (see supp.c). Then, |
| 929 |
we in fact won't need calling the XFERCOPY-handler here, |
| 930 |
because it doesn't give new information. If xi->prio is |
| 931 |
not PRIO_INVALID, then the XICopyObj-item xi wins the merge |
| 932 |
and the XFERCOPY-handler has to be called a second time, now |
| 933 |
with a higher priority. */ |
| 934 |
if (xi->prio==PRIO_INVALID) |
| 935 |
return; |
| 936 |
} |
| 937 |
|
| 938 |
xi->size = size; |
| 939 |
xi->add = NULL; |
| 940 |
xi->addLen = 0; |
| 941 |
|
| 942 |
/* set XferAddInfo for evtl AddData-calls during handler execution */ |
| 943 |
ctx.theXIAddData = xi; |
| 944 |
|
| 945 |
/* call application handler for xfer of dependent objects */ |
| 946 |
if (desc->handlerXFERCOPY) |
| 947 |
{ |
| 948 |
DDD_OBJ obj = HDR2OBJ(hdr,desc); |
| 949 |
|
| 950 |
desc->handlerXFERCOPY(context, obj, dest, prio); |
| 951 |
} |
| 952 |
|
| 953 |
/* theXIAddData might be changed during handler execution */ |
| 954 |
ctx.theXIAddData = xi; |
| 955 |
} |
| 956 |
} |
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
/****************************************************************************/ |
| 961 |
/* */ |
| 962 |
/* Function: DDD_XferCopyObj */ |
| 963 |
/* */ |
| 964 |
/****************************************************************************/ |
| 965 |
|
| 966 |
/** |
| 967 |
Transfer-command for copying a local DDD object to another processor. |
| 968 |
After an initial call to \funk{XferBegin}, this function |
| 969 |
creates a copy of one local DDD object on another processor with a certain |
| 970 |
priority. The necessary actions (packing/unpacking of object data, message |
| 971 |
transfer) are executed via the final call to \funk{XferEnd}; therefore |
| 972 |
a whole set of {\bf Transfer}-operations is accumulated. |
| 973 |
|
| 974 |
Caution: As the original object data is not copied throughout this |
| 975 |
call due to efficiency reasons (transferring a large number of objects |
| 976 |
would result in a huge amount of memory copy operations), |
| 977 |
the object may not be changed or deleted until the actual transfer |
| 978 |
has happened. Otherwise the changes will be sent, too. |
| 979 |
|
| 980 |
Two different mechanisms allow the transfer of data depending on the |
| 981 |
stated object: |
| 982 |
|
| 983 |
\begin{itemize} |
| 984 |
\item Right after the function \funk{XferCopyObj} has been called, |
| 985 |
the optional handler #HANDLER_XFERCOPY# is executed by DDD. |
| 986 |
Basically this mechanism allows the transfer of dependent DDD objects |
| 987 |
(or: hierarchies of objects), although arbitrary actions may occur |
| 988 |
inside the handler. |
| 989 |
No relationship between the {\em primary} object and the additional |
| 990 |
objects can be expressed, as many different destination processors |
| 991 |
might be involved. |
| 992 |
% |
| 993 |
\item Via an arbitrary number of additional calls to \funk{XferAddData} |
| 994 |
arrays of {\em data objects} (i.e.~without the usual DDD object header) |
| 995 |
may be sent. |
| 996 |
Using this mechanism the data objects are strongly linked to the |
| 997 |
{\em primary} object; all data objects are transferred to the same |
| 998 |
destination processor. |
| 999 |
\end{itemize} |
| 1000 |
|
| 1001 |
After the object copy has been established on the destination processor, |
| 1002 |
first the optional handler #HANDLER_LDATACONSTRUCTOR# is called to |
| 1003 |
update the LDATA parts of that object (e.g.~locally linked lists). |
| 1004 |
Afterwards the optional handler #HANDLER_OBJMKCONS# is called |
| 1005 |
to establish consistency for that object (e.g.~backward references on |
| 1006 |
the new object copy). For handlers related to function |
| 1007 |
\funk{XferAddData} refer to its description. |
| 1008 |
|
| 1009 |
@param hdr DDD local object which has to be copied. |
| 1010 |
@param proc destination processor which will receive the object copy. |
| 1011 |
@param prio DDD priority of new object copy. |
| 1012 |
*/ |
| 1013 |
|
| 1014 |
void DDD_XferCopyObj (DDD::DDDContext& context, DDD_HDR hdr, DDD_PROC proc, DDD_PRIO prio) |
| 1015 |
{ |
| 1016 |
TYPE_DESC *desc = &context.typeDefs()[OBJ_TYPE(hdr)]; |
| 1017 |
|
| 1018 |
# if DebugXfer<=2 |
| 1019 |
Dune::dvverb << "DDD_XferCopyObj " << OBJ_GID(hdr) |
| 1020 |
<< ", proc=" << proc << " prio=" << prio << "\n"; |
| 1021 |
# endif |
| 1022 |
|
| 1023 |
XferInitCopyInfo(context, hdr, desc, desc->size, proc, prio); |
| 1024 |
} |
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
/****************************************************************************/ |
| 1031 |
/* */ |
| 1032 |
/* Function: DDD_XferCopyObjX */ |
| 1033 |
/* */ |
| 1034 |
/****************************************************************************/ |
| 1035 |
|
| 1036 |
/** |
| 1037 |
Transfer-command for objects of varying sizes. |
| 1038 |
This function is an extension of \funk{XferCopyObj}. |
| 1039 |
For objects with same DDD type but with variable size in memory, |
| 1040 |
one can give the real size as forth parameter to \funk{XferCopyObjX}. |
| 1041 |
The DDD Transfer module will use that size value instead of using |
| 1042 |
the size computed in \funk{TypeDefine} after the definition of |
| 1043 |
the object's DDD type. |
| 1044 |
|
| 1045 |
@param hdr DDD local object which has to be copied. |
| 1046 |
@param proc destination processor which will receive the object copy. |
| 1047 |
@param prio DDD priority of new object copy. |
| 1048 |
@param size real size of local object. |
| 1049 |
*/ |
| 1050 |
void DDD_XferCopyObjX (DDD::DDDContext& context, DDD_HDR hdr, DDD_PROC proc, DDD_PRIO prio, size_t size) |
| 1051 |
{ |
| 1052 |
TYPE_DESC *desc = &context.typeDefs()[OBJ_TYPE(hdr)]; |
| 1053 |
|
| 1054 |
# if DebugXfer<=2 |
| 1055 |
Dune::dvverb |
| 1056 |
<< "DDD_XferCopyObjX " << OBJ_GID(hdr) << ", proc=" << proc |
| 1057 |
<< " prio=" << prio << " size=" << size << "\n"; |
| 1058 |
# endif |
| 1059 |
|
| 1060 |
if ((desc->size!=size) && (DDD_GetOption(context, OPT_WARNING_VARSIZE_OBJ)==OPT_ON)) |
| 1061 |
Dune::dwarn << "object size differs from declared size in DDD_XferCopyObjX\n"; |
| 1062 |
|
| 1063 |
if ((desc->size>size) && (DDD_GetOption(context, OPT_WARNING_SMALLSIZE)==OPT_ON)) |
| 1064 |
Dune::dwarn << "object size smaller than declared size in DDD_XferCopyObjX\n"; |
| 1065 |
|
| 1066 |
XferInitCopyInfo(context, hdr, desc, size, proc, prio); |
| 1067 |
} |
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
/****************************************************************************/ |
| 1073 |
/* */ |
| 1074 |
/* Function: DDD_XferAddData */ |
| 1075 |
/* */ |
| 1076 |
/****************************************************************************/ |
| 1077 |
|
| 1078 |
/** |
| 1079 |
Transfer array of additional data objects with a DDD local object. |
| 1080 |
This function transfers an array of additional data objects |
| 1081 |
corresponding to one DDD object to the same destination processor. |
| 1082 |
Therefore the latest call to \funk{XferCopyObj} defines the |
| 1083 |
{\em primary} object and the destination. An arbitrary number of |
| 1084 |
\funk{XferAddData}-calls may be issued to transfer various |
| 1085 |
data object arrays at once. This serves as a mechanism to send |
| 1086 |
object references which cannot be handled by the native DDD |
| 1087 |
pointer conversion technique. |
| 1088 |
|
| 1089 |
Just before the actual {\bf Transfer}-operation is executed, the (optional) |
| 1090 |
handler #HANDLER_XFERGATHER# will be called to fill the data |
| 1091 |
object array into some reserved storage space. |
| 1092 |
After the {\bf Xfer}-operation the handler #HANDLER_XFERSCATTER# is |
| 1093 |
called on the receiving processor to rebuild the data objects. |
| 1094 |
|
| 1095 |
As the data objects had to be registered and equipped with a |
| 1096 |
usual {\em type\_id} (as with the DDD objects), the |
| 1097 |
standard DDD pointer conversion will also take place for the data objects. |
| 1098 |
|
| 1099 |
@param cnt number of data objects in array (i.e.~array length). |
| 1100 |
@param typ DDD type of data objects. All data objects inside one array |
| 1101 |
should have the same object type. This object type is defined by |
| 1102 |
registering the object structure via \funk{TypeDefine} as usual, |
| 1103 |
but without including the DDD object header. |
| 1104 |
*/ |
| 1105 |
|
| 1106 |
void DDD_XferAddData (DDD::DDDContext& context, int cnt, DDD_TYPE typ) |
| 1107 |
{ |
| 1108 |
auto& ctx = context.xferContext(); |
| 1109 |
XFERADDDATA *xa; |
| 1110 |
|
| 1111 |
# if DebugXfer<=2 |
| 1112 |
Dune::dvverb << "DDD_XferAddData cnt=" << cnt << " typ=" << typ << "\n"; |
| 1113 |
# endif |
| 1114 |
|
| 1115 |
if (not ctx.theXIAddData) |
| 1116 |
return; |
| 1117 |
|
| 1118 |
xa = NewXIAddData(context); |
| 1119 |
if (xa==NULL) |
| 1120 |
throw std::bad_alloc(); |
| 1121 |
|
| 1122 |
xa->addCnt = cnt; |
| 1123 |
xa->addTyp = typ; |
| 1124 |
xa->sizes = NULL; |
| 1125 |
|
| 1126 |
if (typ<DDD_USER_DATA || typ>DDD_USER_DATA_MAX) |
| 1127 |
{ |
| 1128 |
/* normal dependent object */ |
| 1129 |
const TYPE_DESC& descDepTyp = context.typeDefs()[typ]; |
| 1130 |
|
| 1131 |
xa->addLen = CEIL(descDepTyp.size) * cnt; |
| 1132 |
xa->addNPointers = (descDepTyp.nPointers) * cnt; |
| 1133 |
} |
| 1134 |
else |
| 1135 |
{ |
| 1136 |
/* stream of bytes, since V1.2 */ |
| 1137 |
/* many streams, since V1.7.8 */ |
| 1138 |
xa->addLen = CEIL(cnt); |
| 1139 |
xa->addNPointers = 0; |
| 1140 |
} |
| 1141 |
|
| 1142 |
ctx.theXIAddData->addLen += xa->addLen; |
| 1143 |
} |
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
/****************************************************************************/ |
| 1148 |
/* */ |
| 1149 |
/* Function: DDD_XferAddDataX */ |
| 1150 |
/* */ |
| 1151 |
/****************************************************************************/ |
| 1152 |
|
| 1153 |
/** |
| 1154 |
Transfer array of additional, variable-sized data objects. |
| 1155 |
\todo{not documented yet.} |
| 1156 |
*/ |
| 1157 |
|
| 1158 |
void DDD_XferAddDataX (DDD::DDDContext& context, int cnt, DDD_TYPE typ, size_t *sizes) |
| 1159 |
{ |
| 1160 |
auto& ctx = context.xferContext(); |
| 1161 |
XFERADDDATA *xa; |
| 1162 |
|
| 1163 |
# if DebugXfer<=2 |
| 1164 |
Dune::dvverb << "DDD_XferAddData cnt=" << cnt << " typ=" << typ << "\n"; |
| 1165 |
# endif |
| 1166 |
|
| 1167 |
if (not ctx.theXIAddData) |
| 1168 |
return; |
| 1169 |
|
| 1170 |
xa = NewXIAddData(context); |
| 1171 |
if (xa==NULL) |
| 1172 |
HARD_EXIT; |
| 1173 |
|
| 1174 |
xa->addCnt = cnt; |
| 1175 |
xa->addTyp = typ; |
| 1176 |
|
| 1177 |
if (typ<DDD_USER_DATA || typ>DDD_USER_DATA_MAX) |
| 1178 |
{ |
| 1179 |
/* copy sizes array */ |
| 1180 |
xa->sizes = AddDataAllocSizes(context, cnt); |
| 1181 |
memcpy(xa->sizes, sizes, sizeof(int)*cnt); |
| 1182 |
|
| 1183 |
/* normal dependent object */ |
| 1184 |
const TYPE_DESC& descDepTyp = context.typeDefs()[typ]; |
| 1185 |
|
| 1186 |
xa->addLen = 0; |
| 1187 |
for (int i = 0; i < cnt; i++) |
| 1188 |
{ |
| 1189 |
xa->addLen += CEIL(sizes[i]); |
| 1190 |
} |
| 1191 |
xa->addNPointers = descDepTyp.nPointers * cnt; |
| 1192 |
} |
| 1193 |
else |
| 1194 |
{ |
| 1195 |
/* stream of bytes, since V1.2 */ |
| 1196 |
/* many streams, since V1.7.8 */ |
| 1197 |
xa->addLen = CEIL(cnt); |
| 1198 |
xa->addNPointers = 0; |
| 1199 |
} |
| 1200 |
|
| 1201 |
ctx.theXIAddData->addLen += xa->addLen; |
| 1202 |
} |
| 1203 |
|
| 1204 |
|
| 1205 |
/** |
| 1206 |
Tell application if additional data will be sent. |
| 1207 |
If the application issues a \funk{XferCopyObj} command |
| 1208 |
with the local processor as the destination processor, |
| 1209 |
no object copy will be created. Therefore, also additional |
| 1210 |
data objects will not be sent and the corresponding |
| 1211 |
#XFER_GATHER#/#XFER_SCATTER# handlers will not be called. |
| 1212 |
This function returns a boolean value indicating whether |
| 1213 |
the last \funk{XferCopyObj}-command will need the specification |
| 1214 |
of additional data objects. |
| 1215 |
|
| 1216 |
The application program may use this function in order to |
| 1217 |
avoid unnecessary work, \eg, for counting the number of |
| 1218 |
additional data objects. |
| 1219 |
|
| 1220 |
@return #true# if additional data objects will be gathered, sent |
| 1221 |
and scattered; #false# otherwise. |
| 1222 |
*/ |
| 1223 |
bool DDD_XferWithAddData(const DDD::DDDContext& context) |
| 1224 |
{ |
| 1225 |
/* if theXIAddData==NULL, the XferAddData-functions will |
| 1226 |
do nothing -> the Gather/Scatter-handlers will not be |
| 1227 |
called. */ |
| 1228 |
return context.xferContext().theXIAddData != nullptr; |
| 1229 |
} |
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
/****************************************************************************/ |
| 1234 |
/* */ |
| 1235 |
/* Function: DDD_XferDeleteObj */ |
| 1236 |
/* */ |
| 1237 |
/****************************************************************************/ |
| 1238 |
|
| 1239 |
/** |
| 1240 |
Transfer-command for deleting a local DDD object. |
| 1241 |
This function is regarded as a {\bf Transfer}-operation due |
| 1242 |
to its influence on DDD management information on neighbouring |
| 1243 |
processors. Therefore the function has to be issued between |
| 1244 |
a starting \funk{XferBegin} and a final \funk{XferEnd} call. |
| 1245 |
|
| 1246 |
During the actual {\bf Transfer}-operation all data corresponding |
| 1247 |
to that object and the object memory itself will be deleted. |
| 1248 |
|
| 1249 |
@param hdr DDD local object which has to be deleted. |
| 1250 |
*/ |
| 1251 |
|
| 1252 |
void DDD_XferDeleteObj (DDD::DDDContext& context, DDD_HDR hdr) |
| 1253 |
{ |
| 1254 |
TYPE_DESC *desc = &context.typeDefs()[OBJ_TYPE(hdr)]; |
| 1255 |
XIDelCmd *dc = NewXIDelCmd(context); |
| 1256 |
|
| 1257 |
if (dc==NULL) |
| 1258 |
HARD_EXIT; |
| 1259 |
|
| 1260 |
dc->hdr = hdr; |
| 1261 |
|
| 1262 |
# if DebugXfer<=2 |
| 1263 |
Dune::dvverb << "DDD_XferDeleteObj " << OBJ_GID(hdr) << "\n"; |
| 1264 |
# endif |
| 1265 |
|
| 1266 |
|
| 1267 |
/* call application handler for deletion of dependent objects */ |
| 1268 |
if (desc->handlerXFERDELETE!=NULL) |
| 1269 |
{ |
| 1270 |
desc->handlerXFERDELETE(context, HDR2OBJ(hdr,desc)); |
| 1271 |
} |
| 1272 |
} |
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
/****************************************************************************/ |
| 1277 |
/* */ |
| 1278 |
/* Function: DDD_XferBegin */ |
| 1279 |
/* */ |
| 1280 |
/****************************************************************************/ |
| 1281 |
|
| 1282 |
/** |
| 1283 |
Starts transfer phase. |
| 1284 |
A call to this function establishes a global transfer operation. |
| 1285 |
It should be issued on all processors. After this call an arbitrary |
| 1286 |
series of {\bf Xfer}-commands may be issued. The global transfer operation |
| 1287 |
is carried out via a \funk{XferEnd} call on each processor. |
| 1288 |
*/ |
| 1289 |
|
| 1290 |
void DDD_XferBegin(DDD::DDDContext& context) |
| 1291 |
{ |
| 1292 |
auto& ctx = context.xferContext(); |
| 1293 |
ctx.theXIAddData = nullptr; |
| 1294 |
|
| 1295 |
|
| 1296 |
/* step mode and check whether call to XferBegin is valid */ |
| 1297 |
if (!XferStepMode(context, DDD::Xfer::XferMode::XMODE_IDLE)) |
| 1298 |
DUNE_THROW(Dune::Exception, "DDD_XferBegin() aborted"); |
| 1299 |
} |
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
/****************************************************************************/ |
| 1304 |
/* */ |
| 1305 |
/* Function: DDD_XferIsPrunedDelete */ |
| 1306 |
/* */ |
| 1307 |
/****************************************************************************/ |
| 1308 |
|
| 1309 |
/** |
| 1310 |
Returns information about pruned \funk{XferDeleteObj} command. |
| 1311 |
If a \funk{XferDeleteObj} command has been pruned (i.e., option |
| 1312 |
#OPT_XFER_PRUNE_DELETE# is set to #OPT_ON# and another processor issued |
| 1313 |
a \funk{XferCopyObj}, command which sends an object copy to the |
| 1314 |
local processor), then this function will return #XFER_PRUNED_TRUE#, |
| 1315 |
otherwise it returns #XFER_PRUNED_FALSE#. If an error condition |
| 1316 |
occurs (e.g., when it is called at the wrong time), the function |
| 1317 |
returns #XFER_PRUNED_ERROR#. |
| 1318 |
|
| 1319 |
@param hdr DDD local object which has to be deleted. |
| 1320 |
@return one of #XFER_PRUNED_xxx# |
| 1321 |
*/ |
| 1322 |
|
| 1323 |
|
| 1324 |
int DDD_XferIsPrunedDelete(const DDD::DDDContext& context, DDD_HDR hdr) |
| 1325 |
{ |
| 1326 |
if (XferMode(context) != DDD::Xfer::XferMode::XMODE_BUSY) |
| 1327 |
{ |
| 1328 |
return(XFER_PRUNED_ERROR); |
| 1329 |
} |
| 1330 |
|
| 1331 |
if (OBJ_PRUNED(hdr)) |
| 1332 |
return(XFER_PRUNED_TRUE); |
| 1333 |
|
| 1334 |
return(XFER_PRUNED_FALSE); |
| 1335 |
} |
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
/****************************************************************************/ |
| 1340 |
/* */ |
| 1341 |
/* Function: DDD_XferObjIsResent */ |
| 1342 |
/* */ |
| 1343 |
/****************************************************************************/ |
| 1344 |
|
| 1345 |
#ifdef SUPPORT_RESENT_FLAG |
| 1346 |
|
| 1347 |
/** |
| 1348 |
Returns if an object will receive an additional copy. |
| 1349 |
If another processor issued a \funk{XferCopyObj} in order |
| 1350 |
to send a further copy of the given local object to the local |
| 1351 |
processor, this function will return #XFER_RESENT_TRUE#. |
| 1352 |
Otherwise this function will return #XFER_RESENT_FALSE#. |
| 1353 |
If an error condition occurs (e.g., when it is called at the |
| 1354 |
wrong time), the function returns #XFER_RESENT_ERROR#. |
| 1355 |
|
| 1356 |
This function will only work with option #OPT_XFER_PRUNE_DELETE# |
| 1357 |
set to #OPT_ON#. Otherwise, there will be no kind of communication |
| 1358 |
to supply this information. |
| 1359 |
|
| 1360 |
@param hdr DDD local object which has to be deleted. |
| 1361 |
@return one of #XFER_RESENT_xxx# |
| 1362 |
*/ |
| 1363 |
|
| 1364 |
int DDD_XferObjIsResent(const DDD::DDDContext& context, DDD_HDR hdr) |
| 1365 |
{ |
| 1366 |
if (XferMode(context) != DDD::Xfer::XferMode::XMODE_BUSY) |
| 1367 |
{ |
| 1368 |
return(XFER_RESENT_ERROR); |
| 1369 |
} |
| 1370 |
|
| 1371 |
if (DDD_GetOption(context, OPT_XFER_PRUNE_DELETE)==OPT_OFF) |
| 1372 |
{ |
| 1373 |
return(XFER_RESENT_ERROR); |
| 1374 |
} |
| 1375 |
|
| 1376 |
if (OBJ_RESENT(hdr)) |
| 1377 |
return(XFER_RESENT_TRUE); |
| 1378 |
|
| 1379 |
return(XFER_RESENT_FALSE); |
| 1380 |
} |
| 1381 |
|
| 1382 |
#endif /* SUPPORT_RESENT_FLAG */ |
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
END_UGDIM_NAMESPACE |