From ff41a23165b8b5aeb2870c1c158c9f342a1339b6 Mon Sep 17 00:00:00 2001 From: Ansgar Burchardt <Ansgar.Burchardt@tu-dresden.de> Date: Thu, 19 Apr 2018 12:28:15 +0200 Subject: [PATCH] DDD: xfer: use exceptions and DUNE's debug streams --- parallel/ddd/xfer/cmdmsg.cc | 55 +++++++--------- parallel/ddd/xfer/cmds.cc | 119 ++++++++++++++--------------------- parallel/ddd/xfer/cplmsg.cc | 68 ++++++++++---------- parallel/ddd/xfer/ctrl.cc | 122 +++++++++++++++++------------------- parallel/ddd/xfer/pack.cc | 21 +++---- parallel/ddd/xfer/supp.cc | 12 ++-- parallel/ddd/xfer/unpack.cc | 73 +++++++++------------ parallel/ddd/xfer/xfer.cc | 110 +++++++++++++++----------------- 8 files changed, 254 insertions(+), 326 deletions(-) diff --git a/parallel/ddd/xfer/cmdmsg.cc b/parallel/ddd/xfer/cmdmsg.cc index 5419e3936..ccee5efd6 100644 --- a/parallel/ddd/xfer/cmdmsg.cc +++ b/parallel/ddd/xfer/cmdmsg.cc @@ -40,8 +40,13 @@ #include <cassert> #include <algorithm> +#include <iomanip> +#include <iostream> +#include <sstream> #include <vector> +#include <dune/common/stdstreams.hh> + #include "dddi.h" #include "xfer.h" @@ -117,10 +122,7 @@ static CMDMSG *CreateCmdMsg (DDD_PROC dest, CMDMSG *lastxm) xm = (CMDMSG *) AllocTmp(sizeof(CMDMSG)); if (xm==NULL) - { - DDD_PrintError('E', 6500, STR_NOMEM " in PrepareCmdMsgs"); - HARD_EXIT; - } + throw std::bad_alloc(); xm->aUnDelete = NULL; xm->nUnDelete = 0; @@ -147,8 +149,7 @@ static int PrepareCmdMsgs (DDD::DDDContext& context, XICopyObj **itemsCO, int nC return(0); # if DebugCmdMsg<=3 - sprintf(cBuffer,"%4d: PreparePrune, nCopyObj=%d\n", me, nCO); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "PreparePrune, nCopyObj=" << nCO << "\n"; # endif @@ -189,10 +190,7 @@ static int PrepareCmdMsgs (DDD::DDDContext& context, XICopyObj **itemsCO, int nC gids = (DDD_GID *) AllocTmp(sizeof(DDD_GID) * markedCO); if (gids==NULL) - { - DDD_PrintError('E', 6501, STR_NOMEM " in PrepareCmdMsgs"); - HARD_EXIT; - } + throw std::bad_alloc(); /* @@ -321,8 +319,7 @@ static int CmdMsgUnpack (DDD::DDDContext& context, SET_OBJ_RESENT(localCplObjs[iLCO], 0); # if DebugCmdMsg<=0 - sprintf(cBuffer,"%4d: PruneDelCmds. %08x without resent1.\n", me, OBJ_GID(localCplObjs[iLCO])); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "PruneDelCmds. " << OBJ_GID(localCplObjs[iLCO]) << " without resent1.\n"; # endif iLCO++; @@ -333,8 +330,7 @@ static int CmdMsgUnpack (DDD::DDDContext& context, SET_OBJ_RESENT(localCplObjs[iLCO], 1); # if DebugCmdMsg<=1 - sprintf(cBuffer,"%4d: PruneDelCmds. %08x will be resent.\n", me, OBJ_GID(localCplObjs[iLCO])); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "PruneDelCmds. " << OBJ_GID(localCplObjs[iLCO]) << " will be resent.\n"; # endif iLCO++; @@ -347,8 +343,7 @@ static int CmdMsgUnpack (DDD::DDDContext& context, SET_OBJ_RESENT(localCplObjs[iLCO], 0); # if DebugCmdMsg<=0 - sprintf(cBuffer,"%4d: PruneDelCmds. %08x without resent2.\n", me, OBJ_GID(localCplObjs[iLCO])); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "PruneDelCmds. " << OBJ_GID(localCplObjs[iLCO]) << " without resent2.\n"; # endif iLCO++; @@ -371,8 +366,7 @@ static int CmdMsgUnpack (DDD::DDDContext& context, SET_OBJ_PRUNED(itemsDC[iDC]->hdr, 1); # if DebugCmdMsg<=1 - sprintf(cBuffer,"%4d: PruneDelCmds. pruned %08x\n", me, gidDC); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "PruneDelCmds. pruned " << gidDC << "\n"; # endif } else @@ -384,8 +378,7 @@ static int CmdMsgUnpack (DDD::DDDContext& context, nPruned = nDC-jDC; # if DebugCmdMsg<=3 - sprintf(cBuffer,"%4d: PruneDelCmds. nPruned=%d/%d\n", me, nPruned, nDC); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "PruneDelCmds. nPruned=" << nPruned << "/" << nDC << "\n"; # endif return(nPruned); @@ -397,26 +390,26 @@ static int CmdMsgUnpack (DDD::DDDContext& context, static void CmdMsgDisplay (const char *comment, LC_MSGHANDLE xm) { + using std::setw; + std::ostream& out = std::cout; + DDD_GID *theGid; char buf[30]; - int i, proc = LC_MsgGetProc(xm); + int proc = LC_MsgGetProc(xm); int lenGid = (int) LC_GetTableLen(xm, undelete_id); - sprintf(buf, " %03d-%s-%03d ", me, comment, proc); + std::ostringstream prefixStream; + prefixStream << setw(3) << me << "-" << comment << setw(3) << proc << " "; + const std::string& prefix = prefixStream.str(); /* get table addresses inside message */ theGid = (DDD_GID *) LC_GetPtr(xm, undelete_id); + out << prefix << " 04 Gid.size=" << setw(5) << lenGid << "\n"; - sprintf(cBuffer, "%s 04 Gid.size=%05d\n", buf, lenGid); - DDD_PrintDebug(cBuffer); - - for(i=0; i<lenGid; i++) - { - sprintf(cBuffer, "%s 14 gid %04d - " DDD_GID_FMT "\n", - buf, i, DDD_GID_TO_INT(theGid[i])); - DDD_PrintDebug(cBuffer); - } + for(int i=0; i<lenGid; i++) + out << prefix << " 14 gid " << setw(4) << i << " - " + << DDD_GID_TO_INT(theGid[i]) << "\n"; } diff --git a/parallel/ddd/xfer/cmds.cc b/parallel/ddd/xfer/cmds.cc index 7b1f19dca..c859796b4 100644 --- a/parallel/ddd/xfer/cmds.cc +++ b/parallel/ddd/xfer/cmds.cc @@ -37,6 +37,11 @@ #include <cstdio> #include <cstring> +#include <iomanip> + +#include <dune/common/exceptions.hh> +#include <dune/common/stdstreams.hh> + #include <dune/uggrid/parallel/ddd/dddcontext.hh> #include "dddi.h" @@ -426,10 +431,7 @@ DDD_RET DDD_XferEnd(DDD::DDDContext& context) /* step mode and check whether call to XferEnd is valid */ if (!XferStepMode(XMODE_CMDS)) - { - DDD_PrintError('E', 6011, "DDD_XferEnd() aborted"); - HARD_EXIT; - } + DUNE_THROW(Dune::Exception, "DDD_XferEnd() aborted"); /* @@ -470,7 +472,7 @@ DDD_RET DDD_XferEnd(DDD::DDDContext& context) arrayXIDelCmd = SortedArrayXIDelCmd(sort_XIDelCmd); if (arrayXIDelCmd==NULL && nXIDelCmd>0) { - DDD_PrintError('W', 6081, "out of memory in DDD_XferEnd(), giving up."); + Dune::dwarn << "out of memory in DDD_XferEnd(), giving up.\n"; ret_code = DDD_RET_ERROR_NOMEM; LC_Abort(context, EXCEPTION_LOWCOMM_USER); goto exit; @@ -505,7 +507,7 @@ DDD_RET DDD_XferEnd(DDD::DDDContext& context) arrayNewOwners = CplClosureEstimate(context, arrayXICopyObj, &nNewOwners); if (nNewOwners>0 && arrayNewOwners==NULL) { - DDD_PrintError('W', 6082, "out of memory in DDD_XferEnd(), giving up."); + Dune::dwarn << "out of memory in DDD_XferEnd(), giving up.\n"; ret_code = DDD_RET_ERROR_NOMEM; LC_Abort(context, EXCEPTION_LOWCOMM_USER); goto exit; @@ -517,7 +519,7 @@ DDD_RET DDD_XferEnd(DDD::DDDContext& context) arrayXINewCpl = SortedArrayXINewCpl(sort_XINewCpl); if (arrayXINewCpl==NULL && nXINewCpl>0) { - DDD_PrintError('W', 6083, "out of memory in DDD_XferEnd(), giving up."); + Dune::dwarn << "out of memory in DDD_XferEnd(), giving up.\n"; ret_code = DDD_RET_ERROR_NOMEM; LC_Abort(context, EXCEPTION_LOWCOMM_USER); goto exit; @@ -526,7 +528,7 @@ DDD_RET DDD_XferEnd(DDD::DDDContext& context) arrayXIOldCpl = SortedArrayXIOldCpl(sort_XIOldCpl); if (arrayXIOldCpl==NULL && nXIOldCpl>0) { - DDD_PrintError('W', 6084, "out of memory in DDD_XferEnd(), giving up."); + Dune::dwarn << "out of memory in DDD_XferEnd(), giving up.\n"; ret_code = DDD_RET_ERROR_NOMEM; LC_Abort(context, EXCEPTION_LOWCOMM_USER); goto exit; @@ -555,8 +557,7 @@ DDD_RET DDD_XferEnd(DDD::DDDContext& context) { /* the dangerous exception: it occured only locally, the other procs doesn't know about it */ - DDD_PrintError('W', 6089, - "local exception during LC_Connect() in DDD_XferEnd(), giving up."); + Dune::dwarn << "local exception during LC_Connect() in DDD_XferEnd(), giving up.\n"; /* in this state the local processor hasn't initiated any send or receive calls. however, there may be (and almost ever: @@ -569,8 +570,7 @@ DDD_RET DDD_XferEnd(DDD::DDDContext& context) else { /* all other exceptions are known globally, shutdown safely */ - DDD_PrintError('W', 6085, - "error during LC_Connect() in DDD_XferEnd(), giving up."); + Dune::dwarn << "error during LC_Connect() in DDD_XferEnd(), giving up.\n"; ret_code = DDD_RET_ERROR_UNKNOWN; goto exit; } @@ -587,8 +587,7 @@ DDD_RET DDD_XferEnd(DDD::DDDContext& context) /* build obj msgs on sender side and start send */ if (! IS_OK(XferPackMsgs(context, sendMsgs))) { - DDD_PrintError('W', 6086, - "error during message packing in DDD_XferEnd(), giving up."); + Dune::dwarn << "error during message packing in DDD_XferEnd(), giving up.\n"; LC_Cleanup(context); ret_code = DDD_RET_ERROR_UNKNOWN; goto exit; @@ -611,7 +610,7 @@ DDD_RET DDD_XferEnd(DDD::DDDContext& context) arrayXIDelCmd = SortedArrayXIDelCmd(sort_XIDelCmd); if (arrayXIDelCmd==NULL && nXIDelCmd>0) { - DDD_PrintError('W', 6088, "out of memory in DDD_XferEnd(), giving up."); + Dune::dwarn << "out of memory in DDD_XferEnd(), giving up.\n"; LC_Cleanup(context); ret_code = DDD_RET_ERROR_NOMEM; goto exit; @@ -654,9 +653,10 @@ DDD_RET DDD_XferEnd(DDD::DDDContext& context) XISetPrioSet_GetNItems(xferGlobals.setXISetPrio)+ XICopyObjSet_GetNItems(xferGlobals.setXICopyObj); - sprintf(cBuffer, "DDD MESG [%03d]: %4d from %4d xfer-cmds obsolete.\n", - me, obsolete, all); - DDD_PrintLine(cBuffer); + using std::setw; + Dune::dwarn + << "DDD MESG [" << setw(3) << me << "]: " << setw(4) << obsolete + << " from " << setw(4) << all << " xfer-cmds obsolete.\n"; } } STAT_TIMER(T_XFER_WHILE_COMM); @@ -670,7 +670,7 @@ DDD_RET DDD_XferEnd(DDD::DDDContext& context) { DDD_SyncAll(context); if (context.isMaster()) - DDD_PrintLine("DDD XFER_SHOW_MSGSALL: ObjMsg.Send\n"); + Dune::dwarn << "DDD XFER_SHOW_MSGSALL: ObjMsg.Send\n"; LC_PrintSendMsgs(context); } @@ -692,11 +692,12 @@ DDD_RET DDD_XferEnd(DDD::DDDContext& context) recvMem += LC_GetBufferSize(recvMsgs[k]); } - sprintf(cBuffer, - "DDD MESG [%03d]: SHOW_MEM " - "msgs send=%010ld recv=%010ld all=%010ld\n", - me, (long)sendMem, (long)recvMem, (long)(sendMem+recvMem)); - DDD_PrintLine(cBuffer); + using std::setw; + Dune::dwarn + << "DDD MESG [" << setw(3) << me << "]: SHOW_MEM msgs " + << " send=" << setw(10) << sendMem + << " recv=" << setw(10) << recvMem + << " all=" << setw(10) << (sendMem+recvMem) << "\n"; } /* display information about recv-messages on lowcomm-level */ @@ -704,7 +705,7 @@ DDD_RET DDD_XferEnd(DDD::DDDContext& context) { DDD_SyncAll(context); if (context.isMaster()) - DDD_PrintLine("DDD XFER_SHOW_MSGSALL: ObjMsg.Recv\n"); + Dune::dwarn << "DDD XFER_SHOW_MSGSALL: ObjMsg.Recv\n"; LC_PrintRecvMsgs(context); } @@ -812,8 +813,7 @@ exit: #endif # if DebugXfer<=4 - sprintf(cBuffer,"%4d: XferEnd, before IFAllFromScratch().\n", me); - DDD_PrintDebug(cBuffer); + Dune::dverb << "XferEnd, before IFAllFromScratch().\n"; # endif if (ret_code==DDD_RET_OK) @@ -876,9 +876,7 @@ void DDD_XferPrioChange (DDD_HDR hdr, DDD_PRIO prio) return; # if DebugXfer<=2 - sprintf(cBuffer, "%4d: DDD_XferPrioChange %08x, prio=%d\n", - me, OBJ_GID(hdr), prio); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "DDD_XferPrioChange " << OBJ_GID(hdr) << ", prio=" << prio << "\n"; # endif } @@ -892,26 +890,17 @@ static void XferInitCopyInfo (DDD::DDDContext& context, DDD_PRIO prio) { if (!ddd_XferActive(context)) - { - DDD_PrintError('E', 6012, "Missing DDD_XferBegin(). aborted"); - HARD_EXIT; - } + DUNE_THROW(Dune::Exception, "Missing DDD_XferBegin()"); if (dest>=procs) - { - sprintf(cBuffer, "cannot transfer " OBJ_GID_FMT " to processor %d (procs=%d)", - OBJ_GID(hdr), dest, procs); - DDD_PrintError('E', 6003, cBuffer); - HARD_EXIT; - } + DUNE_THROW(Dune::Exception, + "cannot transfer " << OBJ_GID(hdr) << " to processor " << dest + << " (procs=" << procs << ")"); if (prio>=MAX_PRIO) - { - sprintf(cBuffer, "priority must be less than %d (prio=%d) in xfer-cmd", - MAX_PRIO, prio); - DDD_PrintError('E', 6004, cBuffer); - HARD_EXIT; - } + DUNE_THROW(Dune::Exception, + "priority must be less than " << MAX_PRIO + << " (prio=" << prio << ")"); if (dest==me) { @@ -1062,9 +1051,8 @@ void DDD_XferCopyObj (DDD::DDDContext& context, DDD_HDR hdr, DDD_PROC proc, DDD_ TYPE_DESC *desc = &context.typeDefs()[OBJ_TYPE(hdr)]; # if DebugXfer<=2 -sprintf(cBuffer, "%4d: DDD_XferCopyObj %08x, proc=%d prio=%d\n", - me, OBJ_GID(hdr), proc, prio); -DDD_PrintDebug(cBuffer); + Dune::dvverb << "DDD_XferCopyObj " << OBJ_GID(hdr) + << ", proc=" << proc << " prio=" << prio << "\n"; # endif XferInitCopyInfo(context, hdr, desc, desc->size, proc, prio); @@ -1099,22 +1087,16 @@ void DDD_XferCopyObjX (DDD::DDDContext& context, DDD_HDR hdr, DDD_PROC proc, DDD TYPE_DESC *desc = &context.typeDefs()[OBJ_TYPE(hdr)]; # if DebugXfer<=2 - sprintf(cBuffer, "%4d: DDD_XferCopyObjX %08x, proc=%d prio=%d size=%d\n", - me, OBJ_GID(hdr), proc, prio, size); - DDD_PrintDebug(cBuffer); + Dune::dvverb + << "DDD_XferCopyObjX " << OBJ_GID(hdr) << ", proc=" << proc + << " prio=" << prio << " size=" << size << "\n"; # endif if ((desc->size!=size) && (DDD_GetOption(context, OPT_WARNING_VARSIZE_OBJ)==OPT_ON)) - { - DDD_PrintError('W', 6001, - "object size differs from declared size in DDD_XferCopyObjX"); - } + Dune::dwarn << "object size differs from declared size in DDD_XferCopyObjX\n"; if ((desc->size>size) && (DDD_GetOption(context, OPT_WARNING_SMALLSIZE)==OPT_ON)) - { - DDD_PrintError('W', 6002, - "object size smaller than declared size in DDD_XferCopyObjX"); - } + Dune::dwarn << "object size smaller than declared size in DDD_XferCopyObjX\n"; XferInitCopyInfo(context, hdr, desc, size, proc, prio); } @@ -1161,15 +1143,14 @@ void DDD_XferAddData (DDD::DDDContext& context, int cnt, DDD_TYPE typ) XFERADDDATA *xa; # if DebugXfer<=2 - sprintf(cBuffer, "%4d: DDD_XferAddData cnt=%d typ=%d\n", me, cnt, typ); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "DDD_XferAddData cnt=" << cnt << " typ=" << typ << "\n"; # endif if (theXIAddData==NULL) return; xa = NewXIAddData(); if (xa==NULL) - HARD_EXIT; + throw std::bad_alloc(); xa->addCnt = cnt; xa->addTyp = typ; @@ -1214,8 +1195,7 @@ void DDD_XferAddDataX (DDD::DDDContext& context, int cnt, DDD_TYPE typ, size_t * int i; # if DebugXfer<=2 - sprintf(cBuffer,"%4d: DDD_XferAddData cnt=%d typ=%d\n", me, cnt, typ); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "DDD_XferAddData cnt=" << cnt << " typ=" << typ << "\n"; # endif if (theXIAddData==NULL) return; @@ -1313,9 +1293,7 @@ void DDD_XferDeleteObj (DDD::DDDContext& context, DDD_HDR hdr) dc->hdr = hdr; # if DebugXfer<=2 - sprintf(cBuffer,"%4d: DDD_XferDeleteObj %08x\n", - me, OBJ_GID(hdr)); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "DDD_XferDeleteObj " << OBJ_GID(hdr) << "\n"; # endif @@ -1349,10 +1327,7 @@ void DDD_XferBegin(DDD::DDDContext& context) /* step mode and check whether call to XferBegin is valid */ if (!XferStepMode(XMODE_IDLE)) - { - DDD_PrintError('E', 6010, "DDD_XferBegin() aborted"); - HARD_EXIT; - } + DUNE_THROW(Dune::Exception, "DDD_XferBegin() aborted"); /* set kind of TMEM alloc/free requests */ diff --git a/parallel/ddd/xfer/cplmsg.cc b/parallel/ddd/xfer/cplmsg.cc index fed0556f7..ed6df30fc 100644 --- a/parallel/ddd/xfer/cplmsg.cc +++ b/parallel/ddd/xfer/cplmsg.cc @@ -34,6 +34,12 @@ #include <cstdlib> #include <cstdio> +#include <iomanip> +#include <iostream> +#include <sstream> + +#include <dune/common/stdstreams.hh> + #include <dune/uggrid/parallel/ddd/dddcontext.hh> #include "dddi.h" @@ -118,10 +124,7 @@ static CPLMSG *CreateCplMsg (DDD_PROC dest, CPLMSG *lastxm) xm = (CPLMSG *) AllocTmpReq(sizeof(CPLMSG), TMEM_XFER); if (xm==NULL) - { - DDD_PrintError('E', 6400, STR_NOMEM " in PrepareCplMsgs"); - HARD_EXIT; - } + throw std::bad_alloc(); xm->nDelCpl = 0; xm->xferDelCpl = NULL; @@ -149,9 +152,8 @@ static int PrepareCplMsgs ( const auto procs = context.procs(); # if DebugCplMsg<=3 - sprintf(cBuffer,"%4d: PrepareCplMsgs, nXIDelCpl=%d nXIModCpl=%d nXIAddCpl=%d\n", - me, nDC, nMC, nAC); - DDD_PrintDebug(cBuffer); + Dune::dverb << "PrepareCplMsgs, nXIDelCpl=" << nDC << " nXIModCpl=" << nMC + << " nXIAddCpl=" << nAC << "\n"; # endif @@ -278,10 +280,10 @@ static void CplMsgSend(DDD::DDDContext& context, CPLMSG *theMsgs) { XIModCpl *mc = m->xferModCpl[i]; - sprintf(cBuffer, "%4d: send modcpl to %d (%08x, %3d) %s:%d\n", - me, m->proc, - mc->te.gid, mc->te.prio, mc->sll_file, mc->sll_line); - DDD_PrintDebug(cBuffer); + Dune::dwarn + << "send modcpl to " << m->proc << " (" << mc->te.gid + << ", " << mc->te.prio << ") " + << mc->sll_file << ":" << mc->sll_line << "\n"; } # endif } @@ -363,6 +365,9 @@ static void CplMsgUnpackSingle (DDD::DDDContext& context, LC_MSGHANDLE xm, static void CplMsgDisplay (const char *comment, LC_MSGHANDLE xm) { + using std::setw; + + std::ostream& out = std::cout; TEDelCpl *theDelCpl; TEModCpl *theModCpl; TEAddCpl *theAddCpl; @@ -372,7 +377,10 @@ static void CplMsgDisplay (const char *comment, LC_MSGHANDLE xm) int lenModCpl = (int) LC_GetTableLen(xm, modcpl_id); int lenAddCpl = (int) LC_GetTableLen(xm, addcpl_id); - sprintf(buf, " %03d-%s-%03d ", me, comment, proc); + std::ostringstream prefixStream; + prefixStream + << " " << setw(3) << me << "-" << comment << "-" << setw(3) << proc << " "; + const std::string& prefix = prefixStream.str(); /* get table addresses inside message */ theDelCpl = (TEDelCpl *) LC_GetPtr(xm, delcpl_id); @@ -380,34 +388,22 @@ static void CplMsgDisplay (const char *comment, LC_MSGHANDLE xm) theAddCpl = (TEAddCpl *) LC_GetPtr(xm, addcpl_id); - sprintf(cBuffer, "%s 04 DelCpl.size=%05d\n", buf, lenDelCpl); - DDD_PrintDebug(cBuffer); - sprintf(cBuffer, "%s 05 ModCpl.size=%05d\n", buf, lenModCpl); - DDD_PrintDebug(cBuffer); - sprintf(cBuffer, "%s 06 AddCpl.size=%05d\n", buf, lenAddCpl); - DDD_PrintDebug(cBuffer); - + out << prefix << " 04 DelCpl.size=" << setw(5) << lenDelCpl << "\n"; + out << prefix << " 05 ModCpl.size=" << setw(5) << lenModCpl << "\n"; + out << prefix << " 06 AddCpl.size=" << setw(5) << lenAddCpl << "\n"; for(i=0; i<lenDelCpl; i++) - { - sprintf(cBuffer, "%s 14 delcpl %04d - " DDD_GID_FMT "\n", - buf, i, theDelCpl[i].gid); - DDD_PrintDebug(cBuffer); - } + out << prefix << " 14 delcpl " << setw(4) << i << " - " + << theDelCpl[i].gid << "\n"; for(i=0; i<lenModCpl; i++) - { - sprintf(cBuffer, "%s 15 modcpl %04d - " DDD_GID_FMT " %3d\n", - buf, i, theModCpl[i].gid, theModCpl[i].prio); - DDD_PrintDebug(cBuffer); - } + out << prefix << " 15 modcpl " << setw(4) << i << " - " + << theModCpl[i].gid << " " << setw(3) << theModCpl[i].prio << "\n"; for(i=0; i<lenAddCpl; i++) - { - sprintf(cBuffer, "%s 16 addcpl %04d - " DDD_GID_FMT " %4d %3d\n", - buf, i, theAddCpl[i].gid, theAddCpl[i].proc, theAddCpl[i].prio); - DDD_PrintDebug(cBuffer); - } + out << prefix << " 16 addcpl " << setw(4) << i << " - " + << theAddCpl[i].gid << " " << setw(4) << theAddCpl[i].proc + << " " << setw(3) << theAddCpl[i].prio << "\n"; } @@ -462,7 +458,7 @@ void CommunicateCplMsgs ( { DDD_SyncAll(context); if (context.isMaster()) - DDD_PrintLine("DDD XFER_SHOW_MSGSALL: CplMsg.Send\n"); + Dune::dwarn << "DDD XFER_SHOW_MSGSALL: CplMsg.Send\n"; LC_PrintSendMsgs(context); } @@ -476,7 +472,7 @@ void CommunicateCplMsgs ( { DDD_SyncAll(context); if (context.isMaster()) - DDD_PrintLine("DDD XFER_SHOW_MSGSALL: CplMsg.Recv\n"); + Dune::dwarn << "DDD XFER_SHOW_MSGSALL: CplMsg.Recv\n"; LC_PrintRecvMsgs(context); } diff --git a/parallel/ddd/xfer/ctrl.cc b/parallel/ddd/xfer/ctrl.cc index 899826f6b..350170cf8 100644 --- a/parallel/ddd/xfer/ctrl.cc +++ b/parallel/ddd/xfer/ctrl.cc @@ -33,6 +33,9 @@ #include <cstdlib> #include <cstdio> +#include <iomanip> +#include <iostream> + #include "dddi.h" #include "xfer.h" @@ -61,7 +64,7 @@ START_UGDIM_NAMESPACE #ifdef DebugAllPointers -static void XferPtr (DDD::DDDContext& context, LC_MSGHANDLE xm, char *buf) +static void XferPtr (DDD::DDDContext& context, LC_MSGHANDLE xm, const std::string& prefix, std::ostream& out) { SYMTAB_ENTRY *theSymTab; OBJTAB_ENTRY *theObjTab; @@ -88,30 +91,33 @@ static void XferPtr (DDD::DDDContext& context, LC_MSGHANDLE xm, char *buf) /* loop over all pointers inside of object with DDD_HEADER hdr */ for(int e=0; e < desc.nElements; ++e, ++theElem) { - if (theElem->type==EL_OBJPTR) + if (theElem->type != EL_OBJPTR) + continue; + + for(int l=0; l<theElem->size; l+=sizeof(void *)) { - int l; - - for(l=0; l<theElem->size; l+=sizeof(void *)) - { - /* ref points to a reference inside objmem */ - DDD_OBJ *ref = (DDD_OBJ *)(((char *)obj)+theElem->offset+l); - - /* reference had been replaced by SymTab-index */ - INT stIdx = ((int)*ref)-1; - - if (stIdx>=0) - { - /* get corresponding symtab entry */ - SYMTAB_ENTRY *st = &(theSymTab[stIdx]); - - sprintf(cBuffer, "%s 20 obj=%03d %03d st=%08x" - " gid=%08x (%08x==%08x)\n", - buf, theObjTab[i].offset, stIdx, - st, st->gid, st->adr.hdr, st->adr.ref); - DDD_PrintDebug(cBuffer); - } - } + /* ref points to a reference inside objmem */ + DDD_OBJ *ref = (DDD_OBJ *)(((char *)obj)+theElem->offset+l); + + /* reference had been replaced by SymTab-index */ + INT stIdx = ((int)*ref)-1; + + if (stIdx < 0) + continue; + + /* get corresponding symtab entry */ + const SYMTAB_ENTRY *st = &(theSymTab[stIdx]); + + using std::dec; + using std::hex; + using std::setw; + out << prefix << " 20 " + << " obj=" << setw(3) << theObjTab[i].offset << " " << setw(3) << stIdx + << hex + << " st=" << setw(8) << st << " gid=" << setw(8) << st->gid + << "(" << setw(x) << st->adr.hdr << "==" + << setw(8) << st->adr.ref << ")\n" + << dec; } } } @@ -121,20 +127,24 @@ static void XferPtr (DDD::DDDContext& context, LC_MSGHANDLE xm, char *buf) void XferDisplayMsg (DDD::DDDContext& context, const char *comment, LC_MSGHANDLE xm) { + using std::setw; + + std::ostream& out = std::cout; SYMTAB_ENTRY *theSymTab; OBJTAB_ENTRY *theObjTab; TENewCpl *theNewCpl; TEOldCpl *theOldCpl; char *theObjects; - char buf[30]; int i, proc = LC_MsgGetProc(xm); int lenSymTab = (int) LC_GetTableLen(xm, xferGlobals.symtab_id); int lenObjTab = (int) LC_GetTableLen(xm, xferGlobals.objtab_id); int lenNewCpl = (int) LC_GetTableLen(xm, xferGlobals.newcpl_id); int lenOldCpl = (int) LC_GetTableLen(xm, xferGlobals.oldcpl_id); - - sprintf(buf, " %03d-%s-%03d ", me, comment, proc); + std::ostringstream prefixStream; + prefixStream << " " << setw(3) << me << "-" << comment + << "-" << setw(3) << proc << " "; + const std::string& prefix = prefixStream.str(); /* get table addresses inside message */ theSymTab = (SYMTAB_ENTRY *)LC_GetPtr(xm, xferGlobals.symtab_id); @@ -160,57 +170,41 @@ void XferDisplayMsg (DDD::DDDContext& context, const char *comment, LC_MSGHANDLE */ - sprintf(cBuffer, "%s 05 ObjTab.size=%05d\n", buf, lenObjTab); - DDD_PrintDebug(cBuffer); - sprintf(cBuffer, "%s 06 SymTab.size=%05d\n", buf, lenSymTab); - DDD_PrintDebug(cBuffer); - sprintf(cBuffer, "%s 07 NewCpl.size=%05d\n", buf, lenNewCpl); - DDD_PrintDebug(cBuffer); - sprintf(cBuffer, "%s 08 OldCpl.size=%05d\n", buf, lenOldCpl); - DDD_PrintDebug(cBuffer); + out << prefix << " 05 ObjTab.size=" << setw(5) << lenObjTab << "\n"; + out << prefix << " 06 SymTab.size=" << setw(5) << lenSymTab << "\n"; + out << prefix << " 07 NewCpl.size=" << setw(5) << lenNewCpl << "\n"; + out << prefix << " 08 OldCpl.size=" << setw(5) << lenOldCpl << "\n"; for(i=0; i<lenObjTab; i++) { - DDD_OBJ obj = OTE_OBJ(context, theObjects, &(theObjTab[i])); - sprintf(cBuffer, "%s 10 objtab %06d typ=%1d gid=" OTE_GID_FMT - " hdr=%p size=%05d add=%05d\n", - buf, (((char *)obj)-theObjects), OTE_TYPE(theObjects,&(theObjTab[i])), - OTE_GID(theObjects,&(theObjTab[i])), - theObjTab[i].hdr, theObjTab[i].size, theObjTab[i].addLen); - - DDD_PrintDebug(cBuffer); + out << prefix << " 10 objtab " << setw(6) << (((char *)obj)-theObjects) + << " typ=" << OTE_TYPE(theObjects,&(theObjTab[i])) + << " gid=" << OTE_GID(theObjects,&(theObjTab[i])) + << " hdr=" << theObjTab[i].hdr << " size=" << setw(5) << theObjTab[i].size + << " add=" << setw(5) << theObjTab[i].addLen << "\n"; } for(i=0; i<lenSymTab; i++) - { - sprintf(cBuffer, "%s 11 symtab %04d - " DDD_GID_FMT " (%08x==%08x)\n", - buf, i, - theSymTab[i].gid, theSymTab[i].adr.hdr, theSymTab[i].adr.ref); - DDD_PrintDebug(cBuffer); - } + out << prefix << " 11 symtab " << setw(4) << i << " - " << theSymTab[i].gid + << " (" << setw(8) << theSymTab[i].adr.hdr << "==" + << theSymTab[i].adr.ref << ")\n"; for(i=0; i<lenNewCpl; i++) - { - sprintf(cBuffer, "%s 12 newcpl %04d - " DDD_GID_FMT " %4d %4d\n", - buf, i, - NewCpl_GetGid(theNewCpl[i]), - NewCpl_GetDest(theNewCpl[i]), - NewCpl_GetPrio(theNewCpl[i])); - DDD_PrintDebug(cBuffer); - } + out << prefix << " 12 newcpl " << setw(4) << i << " - " + << NewCpl_GetGid(theNewCpl[i]) + << " " << setw(4) << NewCpl_GetDest(theNewCpl[i]) + << " " << setw(4) << NewCpl_GetPrio(theNewCpl[i]) << "\n"; for(i=0; i<lenOldCpl; i++) - { - sprintf(cBuffer, "%s 13 oldcpl %04d - " DDD_GID_FMT " %4d %4d\n", - buf, i, - theOldCpl[i].gid, theOldCpl[i].proc, theOldCpl[i].prio); - DDD_PrintDebug(cBuffer); - } + out << prefix << " 13 oldcpl " << setw(4) << i << " - " + << theOldCpl[i].gid + << " " << setw(4) << theOldCpl[i].proc + << " " << setw(4) << theOldCpl[i].prio << "\n"; # ifdef DebugAllPointers - XferPtr(xm, buf); + XferPtr(context, xm, prefix, out); # endif } diff --git a/parallel/ddd/xfer/pack.cc b/parallel/ddd/xfer/pack.cc index 58d8aeb65..5c65eadee 100644 --- a/parallel/ddd/xfer/pack.cc +++ b/parallel/ddd/xfer/pack.cc @@ -37,6 +37,9 @@ #include <algorithm> +#include <dune/common/exceptions.hh> +#include <dune/common/stdstreams.hh> + #include "dddi.h" #include "xfer.h" @@ -174,12 +177,9 @@ static int BuildSymTab (DDD::DDDContext& context, rt = theElem->reftypeHandler(context, obj, *ref); if (rt>=MAX_TYPEDESC) - { - DDD_PrintError('E', 6520, - "invalid referenced DDD_TYPE " - "returned by handler"); - HARD_EXIT; - } + DUNE_THROW(Dune::Exception, + "invalid referenced DDD_TYPE returned by handler"); + refdesc = &context.typeDefs()[rt]; } @@ -548,9 +548,7 @@ RETCODE XferPackMsgs (DDD::DDDContext& context, XFERMSG *theMsgs) XFERMSG *xm; #if DebugPack<=3 - sprintf(cBuffer, "%d: XferPackMsgs\n", me); - DDD_PrintDebug(cBuffer); - fflush(stdout); + Dune::dverb << "XferPackMsgs" << std::endl; #endif /* sort messages according to decreasing size. i.e., send @@ -596,9 +594,8 @@ RETCODE XferPackMsgs (DDD::DDDContext& context, XFERMSG *theMsgs) { if (! LC_MsgAlloc(context, xm->msg_h)) { - sprintf(cBuffer, STR_NOMEM " in XferPackMsgs (size=%ld)", - (unsigned long) LC_GetBufferSize(xm->msg_h)); - DDD_PrintError('E', 6522, cBuffer); + Dune::dwarn << STR_NOMEM " in XferPackMsgs (size=" + << LC_GetBufferSize(xm->msg_h) << ")\n"; RET_ON_ERROR; } XferPackSingleMsg(context, xm); diff --git a/parallel/ddd/xfer/supp.cc b/parallel/ddd/xfer/supp.cc index df82e13b3..265d26faa 100644 --- a/parallel/ddd/xfer/supp.cc +++ b/parallel/ddd/xfer/supp.cc @@ -35,6 +35,8 @@ #include <cstdio> #include <cassert> +#include <new> + #include "dddi.h" USING_UG_NAMESPACE @@ -351,10 +353,7 @@ static AddDataSegm *NewAddDataSegm (void) segm = (AddDataSegm *) OO_Allocate(sizeof(AddDataSegm)); if (segm==NULL) - { - DDD_PrintError('F', 9999, STR_NOMEM " during XferEnd()"); - HARD_EXIT; - } + throw std::bad_alloc(); segm->next = segmAddData; segmAddData = segm; @@ -390,10 +389,7 @@ static SizesSegm *NewSizesSegm (void) segm = (SizesSegm *) OO_Allocate (sizeof(SizesSegm)); if (segm==NULL) - { - DDD_PrintError('F', 9999, STR_NOMEM " during XferEnd()"); - HARD_EXIT; - } + throw std::bad_alloc(); segm->next = segmSizes; segmSizes = segm; diff --git a/parallel/ddd/xfer/unpack.cc b/parallel/ddd/xfer/unpack.cc index 5be5d275a..8511e8f63 100644 --- a/parallel/ddd/xfer/unpack.cc +++ b/parallel/ddd/xfer/unpack.cc @@ -36,8 +36,12 @@ #include <cassert> #include <algorithm> +#include <iomanip> #include <tuple> +#include <dune/common/exceptions.hh> +#include <dune/common/stdstreams.hh> + #include "dddi.h" #include "xfer.h" @@ -169,12 +173,8 @@ static void LocalizeObject (DDD::DDDContext& context, bool merge_mode, TYPE_DESC rt = theElem->reftypeHandler(context, obj, *ref); if (rt>=MAX_TYPEDESC) - { - DDD_PrintError('E', 6570, - "invalid referenced DDD_TYPE " - "returned by handler"); - HARD_EXIT; - } + DUNE_THROW(Dune::Exception, + "invalid referenced DDD_TYPE returned by handler"); refdesc = &context.typeDefs()[rt]; } @@ -199,13 +199,11 @@ static void LocalizeObject (DDD::DDDContext& context, bool merge_mode, TYPE_DESC /* get corresponding symtab entry */ if (theSymTab[stIdx].adr.hdr!=OBJ2HDR(*ref,refdesc)) { - sprintf(cBuffer, - "reference collision in " OBJ_GID_FMT " " - "(old=" OBJ_GID_FMT ", inc=" OBJ_GID_FMT ") in LocalizeObject\n", - OBJ_GID(OBJ2HDR(obj,desc)), - OBJ_GID(OBJ2HDR(*ref,refdesc)), - OBJ_GID(theSymTab[stIdx].adr.hdr)); - DDD_PrintError('W', 6540, cBuffer); + Dune::dwarn + << "LocalizeObject: " + << "reference collision in " << OBJ_GID(OBJ2HDR(obj,desc)) + << " (old=" << OBJ_GID(OBJ2HDR(*ref,refdesc)) + << ", inc=" << OBJ_GID(theSymTab[stIdx].adr.hdr) << ")\n"; /* assert(0); ??? */ } } @@ -456,9 +454,8 @@ static void AcceptObjFromMsg ( if (OBJ_PRUNED(localCplObjs[j])) { # if DebugUnpack<=1 - sprintf(cBuffer, "%4d: NewPrio wins due to PruneDel. " - "%08x\n", me, OBJ_GID(ote->hdr)); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "NewPrio wins due to PruneDel. " + << OBJ_GID(ote->hdr) << "\n"; # endif /* reset flag */ @@ -479,9 +476,7 @@ static void AcceptObjFromMsg ( DDD_OBJ copy; # if DebugUnpack<=1 - sprintf(cBuffer, "%4d: NewPrio wins. %07x\n",me, - OBJ_GID(ote->hdr)); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "NewPrio wins. " << OBJ_GID(ote->hdr) << "\n"; # endif /* new priority wins -> recreate */ @@ -495,9 +490,7 @@ static void AcceptObjFromMsg ( else /* existing is higher than incoming */ { # if DebugUnpack<=1 - sprintf(cBuffer, "%4d: OldPrio wins. %07x\n",me, - OBJ_GID(ote->hdr)); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "OldPrio wins. " << OBJ_GID(ote->hdr) << "\n"; # endif /* new priority loses -> keep existing obj */ @@ -533,9 +526,8 @@ static void AcceptObjFromMsg ( DDD_PRIO new_prio = OBJ_PRIO(ote->hdr); # if DebugUnpack<=1 - sprintf(cBuffer, "%4d: NewObject %08x, prio=%d\n",me, - OBJ_GID(ote->hdr), new_prio); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "NewObject " << OBJ_GID(ote->hdr) + << ", prio=" << new_prio << "\n"; # endif /* new object, create local copy */ @@ -988,7 +980,7 @@ static void PropagateIncomings ( { XIModCpl *xc = NewXIModCpl(SLLNewArgs); if (xc==NULL) - HARD_EXIT; + throw std::bad_alloc(); xc->to = arrayNO[iNO]->dest; /* receiver of XIModCpl*/ xc->te.gid = OBJ_GID(ote->hdr); /* the object's gid */ @@ -1008,7 +1000,7 @@ static void PropagateIncomings ( */ XIModCpl *xc = NewXIModCpl(SLLNewArgs); if (xc==NULL) - HARD_EXIT; + throw std::bad_alloc(); xc->to = CPL_PROC(cpl); /* receiver of XIModCpl*/ xc->te.gid = OBJ_GID(ote->hdr); /* the object's gid */ @@ -1494,9 +1486,11 @@ void XferUnpack (DDD::DDDContext& context, LC_MSGHANDLE *theMsgs, int nRecvMsgs, } # if DebugUnpack<=4 - sprintf(cBuffer, "%4d: SUM OF OBJ=%3d SYM=%3d NEW=%3d FROM %2d MSGS\n", - me, lenObjTab, lenSymTab, nNewCpl, nRecvMsgs); - DDD_PrintDebug(cBuffer); + Dune::dverb << "SUM OF" + << " OBJ=" << std::setw(3) << lenObjTab + << " SYM=" << std::setw(3) << lenSymTab + << " NEW=" << std::setw(3) << nNewCpl + << " FROM " << std::setw(2) << nRecvMsgs << " MSGS\n"; # endif /*STAT_RESET3;*/ @@ -1504,10 +1498,8 @@ void XferUnpack (DDD::DDDContext& context, LC_MSGHANDLE *theMsgs, int nRecvMsgs, if (nNewCpl>0) { allNewCpl = (TENewCpl *) OO_Allocate (sizeof(TENewCpl)*nNewCpl); - if (allNewCpl==NULL) { - DDD_PrintError('E', 6560, STR_NOMEM " in XferUnpack"); - return; - } + if (allNewCpl == nullptr) + throw std::bad_alloc(); } else { allNewCpl = NULL; } @@ -1516,11 +1508,8 @@ void XferUnpack (DDD::DDDContext& context, LC_MSGHANDLE *theMsgs, int nRecvMsgs, if (lenObjTab>0) { unionObjTab = (OBJTAB_ENTRY **) OO_Allocate (sizeof(OBJTAB_ENTRY *)*lenObjTab); - - if (unionObjTab==NULL) { - DDD_PrintError('E', 6562, STR_NOMEM " in XferUnpack"); - return; - } + if (unionObjTab == nullptr) + throw std::bad_alloc(); } else { unionObjTab = NULL; } @@ -1576,9 +1565,9 @@ void XferUnpack (DDD::DDDContext& context, LC_MSGHANDLE *theMsgs, int nRecvMsgs, # if DebugUnpack<=2 for(i=0; i<nNewCpl; i++) { - sprintf(cBuffer, "%4d: TAB allNewCpl %08x on %4d/%d\n",me, - NewCpl_GetGid(allNewCpl[i]),NewCpl_GetDest(allNewCpl[i]),NewCpl_GetPrio(allNewCpl[i])); - DDD_PrintDebug(cBuffer); + Dune::dvverb << " TAB allNewCpl " << NewCpl_GetGid(allNewCpl[i]) + << " on " << std::setw(4) NewCpl_GetDest(allNewCpl[i]) + << "/" << NewCpl_GetPrio(allNewCpl[i]) << "\n"; } # endif diff --git a/parallel/ddd/xfer/xfer.cc b/parallel/ddd/xfer/xfer.cc index e6bd6ae5a..182e9fc85 100644 --- a/parallel/ddd/xfer/xfer.cc +++ b/parallel/ddd/xfer/xfer.cc @@ -39,8 +39,11 @@ #include <cstring> #include <algorithm> +#include <iomanip> #include <tuple> +#include <dune/common/stdstreams.hh> + #include "dddi.h" #include "xfer.h" @@ -165,7 +168,7 @@ XICopyObj **CplClosureEstimate (DDD::DDDContext& context, const std::vector<XICo { XINewCpl *xc = NewXINewCpl(SLLNewArgs); if (xc==NULL) - HARD_EXIT; + throw std::bad_alloc(); xc->to = CPL_PROC(cpl); /* receiver of XINewCpl */ NewCpl_SetDest(xc->te,dest); /* destination of XICopyObj*/ @@ -182,7 +185,7 @@ XICopyObj **CplClosureEstimate (DDD::DDDContext& context, const std::vector<XICo { XIOldCpl *xc = NewXIOldCpl(SLLNewArgs); if (xc==NULL) - HARD_EXIT; + throw std::bad_alloc(); xc->to = dest; /* receiver of XIOldCpl */ xc->te.gid = xigid; /* the object's gid */ @@ -194,7 +197,7 @@ XICopyObj **CplClosureEstimate (DDD::DDDContext& context, const std::vector<XICo { XIOldCpl *xc = NewXIOldCpl(SLLNewArgs); if (xc==NULL) - HARD_EXIT; + throw std::bad_alloc(); xc->to = dest; /* receiver of XIOldCpl */ xc->te.gid = xigid; /* the object's gid */ @@ -259,7 +262,7 @@ XICopyObj **CplClosureEstimate (DDD::DDDContext& context, const std::vector<XICo { XINewCpl *xc = NewXINewCpl(SLLNewArgs); if (xc==NULL) - HARD_EXIT; + throw std::bad_alloc(); xc->to = no1->dest; /* receiver of XINewCpl */ NewCpl_SetDest(xc->te,no2->dest); /* dest of XICopyObj */ @@ -271,7 +274,7 @@ XICopyObj **CplClosureEstimate (DDD::DDDContext& context, const std::vector<XICo { XINewCpl *xc = NewXINewCpl(SLLNewArgs); if (xc==NULL) - HARD_EXIT; + throw std::bad_alloc(); xc->to = no2->dest; /* receiver of XINewCpl */ NewCpl_SetDest(xc->te,no1->dest); /* dest of XICopyObj */ @@ -373,9 +376,8 @@ static XFERMSG *AccumXICopyObj (const DDD::DDDContext& context, } # if DebugXfer<=2 - sprintf(cBuffer, "%4d: PrepareObjMsgs, XferMsg proc=%d" - " nmax=%d\n", me, dest, nmax); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "PrepareObjMsgs, XferMsg" + << " proc=" << dest << " nmax=" << nmax << "\n"; # endif @@ -386,10 +388,9 @@ static XFERMSG *AccumXICopyObj (const DDD::DDDContext& context, const TYPE_DESC& desc = context.typeDefs()[OBJ_TYPE(hdr)]; # if DebugXfer<=0 - sprintf(cBuffer, "%4d: PrepareObjMsgs, proc=%d" - " i=%d/%d (%08x)\n", - me, dest, i, nmax, xi->gid); - DDD_PrintDebug(cBuffer); + Dune::dvverb + << "PrepareObjMsgs, proc=" << dest + << " i=" i << "/" << nmax << " (" << xi->gid << ")\n"; # endif /* accumulate xfer-items in message-info */ @@ -429,24 +430,20 @@ static XFERMSG *AccumXINewCpl (XFERMSG *currxm, int *nMsgs, int *nItems, } # if DebugXfer<=2 - sprintf(cBuffer, "%4d: PrepareObjMsgs, XferMsg proc=%d" - " nmax=%d\n", me, dest, nmax); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "PrepareObjMsgs, XferMsg" + << " proc=" << dest << " nmax=" << nmax << "\n"; # endif for (i=0; i<nmax && items[i]->to==dest; i++) -# if DebugXfer<=0 { +# if DebugXfer<=0 XINewCpl *xi = items[i]; - sprintf(cBuffer, "%4d: PrepareObjMsgs, proc=%d" - " i=%d/%d (%08x)\n", - me, dest, i, nmax, NewCpl_GetGid(xi->te)); - DDD_PrintDebug(cBuffer); - } -# else - ; + Dune::dvverb + << "PrepareObjMsgs, proc=" << dest + << " i=" i << "/" << nmax << " (" << NewCpl_GetGid(xi->te) << ")\n"; # endif + } *nItems = i; return xm; @@ -473,24 +470,20 @@ static XFERMSG *AccumXIOldCpl (XFERMSG *currxm, int *nMsgs, int *nItems, } # if DebugXfer<=2 - sprintf(cBuffer, "%4d: PrepareObjMsgs, XferMsg proc=%d" - " nmax=%d\n", me, dest, nmax); - DDD_PrintDebug(cBuffer); + Dune::dvverb << "PrepareObjMsgs, XferMsg" + << " proc=" << dest << " nmax=" << nmax << "\n"; # endif for (i=0; i<nmax && items[i]->to==dest; i++) -# if DebugXfer<=0 { +# if DebugXfer<=0 XIOldCpl *xi = items[i]; - sprintf(cBuffer, "%4d: PrepareObjMsgs, proc=%d" - " i=%d/%d (%08x)\n", - me, dest, i, nmax, xi->te.gid); - DDD_PrintDebug(cBuffer); - } -# else - ; + Dune::dvverb + << "PrepareObjMsgs, proc=" << dest + << " i=" i << "/" << nmax << " (" << xi->te.gid << ")\n"; # endif + } *nItems = i; return xm; @@ -521,9 +514,10 @@ int PrepareObjMsgs (DDD::DDDContext& context, # if DebugXfer<=3 - sprintf(cBuffer,"%4d: PrepareObjMsgs, nXICopyObj=%d nXINewCpl=%d nXIOldCpl=%d\n", - me, nO, nNC, nOC); - DDD_PrintDebug(cBuffer); + Dune::dverb << "PrepareObjMsgs," + << " nXICopyObj=" << nO + << " nXINewCpl=" << nNC + << " nXIOldCpl=" << nOC << "\n"; # endif @@ -590,18 +584,17 @@ int PrepareObjMsgs (DDD::DDDContext& context, if (DDD_GetOption(context, OPT_INFO_XFER) & XFER_SHOW_MEMUSAGE) { - sprintf(cBuffer, - "DDD MESG [%03d]: SHOW_MEM " - "send msg dest=%04d size=%010ld\n", - me, xm->proc, (long)bufSize); - DDD_PrintLine(cBuffer); + using std::setw; + Dune::dwarn + << "DDD MESG [" << setw(3) << "]: SHOW_MEM send msg " + << " dest=" << setw(4) << xm->proc + << " size=" << setw(10) << bufSize << "\n"; } } # if DebugXfer<=3 - sprintf(cBuffer,"%4d: PrepareObjMsgs, nMsgs=%d\n", me, nMsgs); - DDD_PrintDebug(cBuffer); + Dune::dverb << "PrepareObjMsgs, nMsgs=" << nMsgs << "\n"; # endif return(nMsgs); @@ -672,7 +665,7 @@ void ExecLocalXISetPrio ( { XIModCpl *xc = NewXIModCpl(SLLNewArgs); if (xc==NULL) - HARD_EXIT; + throw std::bad_alloc(); xc->to = CPL_PROC(cpl); /* receiver of XIModCpl */ xc->te.gid = gid; /* the object's gid */ @@ -684,7 +677,7 @@ void ExecLocalXISetPrio ( { XIModCpl *xc = NewXIModCpl(SLLNewArgs); if (xc==NULL) - HARD_EXIT; + throw std::bad_alloc(); xc->to = itemsNO[iNO]->dest; /* receiver of XIModCpl */ xc->te.gid = gid; /* the object's gid */ @@ -723,10 +716,7 @@ void ExecLocalXIDelCmd (DDD::DDDContext& context, XIDelCmd **itemsD, int nD) /* reconstruct original order of DelObj commands */ origD = (XIDelCmd **) OO_Allocate (sizeof(XIDelCmd *) * nD); if (origD==NULL) - { - DDD_PrintError('E', 6101, STR_NOMEM " in XferEnd()"); - HARD_EXIT; - } + throw std::bad_alloc(); /* copy pointer array and resort it */ memcpy(origD, itemsD, sizeof(XIDelCmd *) * nD); @@ -792,7 +782,7 @@ void ExecLocalXIDelObj ( { XIDelCpl *xc = NewXIDelCpl(SLLNewArgs); if (xc==NULL) - HARD_EXIT; + throw std::bad_alloc(); xc->to = itemsNO[iNO]->dest; /* receiver of XIDelCpl */ xc->prio = PRIO_INVALID; /* dont remember priority */ @@ -849,7 +839,7 @@ void PropagateCplInfos ( { XIModCpl *xc = NewXIModCpl(SLLNewArgs); if (xc==NULL) - HARD_EXIT; + throw std::bad_alloc(); /* receiver of XIModCpl */ xc->to = NewCpl_GetDest(arrayNC[iNC]); @@ -880,7 +870,7 @@ void PropagateCplInfos ( { XIDelCpl *xc = NewXIDelCpl(SLLNewArgs); if (xc==NULL) - HARD_EXIT; + throw std::bad_alloc(); xc->to = NewCpl_GetDest(arrayNC[iNC]); /* receiver of XIDelCpl */ xc->prio = PRIO_INVALID; @@ -912,7 +902,7 @@ void ddd_XferRegisterDelete (DDD::DDDContext& context, DDD_HDR hdr) /* create new XIDelObj */ xi = NewXIDelObj(SLLNewArgs); if (xi==NULL) - HARD_EXIT; + throw std::bad_alloc(); xi->gid = OBJ_GID(hdr); xi->delcpls = NULL; @@ -929,7 +919,7 @@ void ddd_XferRegisterDelete (DDD::DDDContext& context, DDD_HDR hdr) { XIDelCpl *xc = NewXIDelCpl(SLLNewArgs); if (xc==NULL) - HARD_EXIT; + throw std::bad_alloc(); xc->to = CPL_PROC(cpl); /* receiver of XIDelCpl */ xc->prio = cpl->prio; /* remember priority */ @@ -972,9 +962,7 @@ static void XferSetMode (enum XferMode mode) xferGlobals.xferMode = mode; # if DebugXfer<=8 - sprintf(cBuffer, "%4d: XferMode=%s.\n", - me, XferModeName(xferGlobals.xferMode)); - DDD_PrintDebug(cBuffer); + Dune::dwarn << "XferMode=" << XferModeName(xferGlobals.xferMode) << "\n"; # endif } @@ -1008,9 +996,9 @@ int XferStepMode (enum XferMode old) { if (xferGlobals.xferMode!=old) { - sprintf(cBuffer, "wrong xfer-mode (currently in %s, expected %s)", - XferModeName(xferGlobals.xferMode), XferModeName(old)); - DDD_PrintError('E', 6200, cBuffer); + Dune::dwarn + << "wrong xfer-mode (currently in " << XferModeName(xferGlobals.xferMode) + << ", expected " << XferModeName(old) << ")\n"; return false; } -- GitLab