// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root // SPDX-License-Identifier: LGPL-2.1-or-later /****************************************************************************/ /* */ /* File: ifstd.ct */ /* */ /* Purpose: template routines for standard interface functions */ /* */ /* Author: Klaus Birken */ /* Institut fuer Computeranwendungen III */ /* Universitaet Stuttgart */ /* Pfaffenwaldring 27 */ /* 70569 Stuttgart */ /* internet: birken@ica3.uni-stuttgart.de */ /* */ /* History: 980825 kb begin */ /* */ /* Remarks: */ /* */ /****************************************************************************/ /****************************************************************************/ /* */ /* derived macros */ /* */ /****************************************************************************/ #define _CAT(a,b) a ## b #define CAT(a,b) _CAT(a,b) #define PART ifHead #ifdef IF_WITH_XARGS #define EXEC_LOOP(context, a,b,c) IFExecHdrLoopCplX(context, a,b,c) #define COMM_LOOP(context, a,b,c,d,e) IFCommHdrLoopCplX(context, a,b,c,d,e) #else #define EXEC_LOOP(context, a,b,c) IFExecHdrLoopCpl(context, a,b,c) #define COMM_LOOP(context, a,b,c,d,e) IFCommHdrLoopCpl(context, a,b,c,d,e) #endif #define D_ABA(p) (p->cpl) #define IF_FUNCNAME CAT(ddd_StdIF,IF_NAME) /****************************************************************************/ /* */ /* auxiliary macros */ /* */ /****************************************************************************/ #ifndef IF_AUX_MACROS #define IF_AUX_MACROS #define CONCAT(txt,fct) txt FUNCNAME_STR(fct) #define FUNCNAME_STR(f) #f #endif /****************************************************************************/ /* */ /* routines */ /* */ /****************************************************************************/ void IF_FUNCNAME ( DDD::DDDContext& context, #ifdef IF_EXECLOCAL #ifdef IF_WITH_XARGS NS_DIM_PREFIX ExecProcHdrXPtr ExecProc) #else NS_DIM_PREFIX ExecProcHdrPtr ExecProc) #endif #else size_t aSize, #ifdef IF_WITH_XARGS NS_DIM_PREFIX ComProcHdrXPtr Gather, NS_DIM_PREFIX ComProcHdrXPtr Scatter) #else NS_DIM_PREFIX ComProcHdrPtr Gather, NS_DIM_PREFIX ComProcHdrPtr Scatter) #endif #endif { using std::setw; NS_DIM_PREFIX DDD_IF aIF = NS_DIM_PREFIX STD_INTERFACE; NS_DIM_PREFIX IF_PROC *ifHead; #ifdef IF_EXECLOCAL ForIF(context, aIF, ifHead) { EXEC_LOOP(context, ExecProc, D_ABA(PART), PART->nItems); } #else /* ! IF_EXECLOCAL */ /* allocate storage for in and out buffers */ ForIF(context, aIF, ifHead) { #ifdef IF_EXCHANGE NS_DIM_PREFIX IFGetMem(ifHead, aSize, PART->nItems, PART->nItems); #endif } /* init communication, initiate receives */ int recv_mesgs = NS_DIM_PREFIX IFInitComm(context, aIF); /* build messages using gather-handler and send them away */ ForIF(context, aIF, ifHead) { char *buffer; buffer = ifHead->bufOut.data(); buffer= COMM_LOOP(context, Gather, D_ABA(PART), buffer, aSize, PART->nItems); NS_DIM_PREFIX IFInitSend(context, ifHead); } /* poll receives and scatter data */ unsigned long tries; for(tries=0; tries0; tries++) { /* poll receive calls */ ForIF(context, aIF, ifHead) { if (not ifHead->bufIn.empty() && ifHead->msgIn!=NO_MSGID) { int error = InfoARecv(context.ppifContext(), ifHead->vc, ifHead->msgIn); if (error==-1) DUNE_THROW(Dune::Exception, "InfoARecv() failed for recv to proc=" << ifHead->proc); if (error==1) { char *buffer; #ifdef CtrlTimeoutsDetailed printf("%4d: IFCTRL %02d received msg from " "%4d after %10ld, size %ld\n", context.me(), aIF, ifHead->proc, (unsigned long)tries, (unsigned long)ifHead->bufIn.size()); #endif recv_mesgs--; ifHead->msgIn=NO_MSGID; buffer = ifHead->bufIn.data(); /* get data using scatter-handler */ buffer = COMM_LOOP(context, Scatter, D_ABA(PART), buffer, aSize, PART->nItems); } } } } /* finally poll send completion */ if (recv_mesgs>0) { Dune::dwarn << FUNCNAME_STR(IF_FUNCNAME) ": receive-timeout for IF " << setw(2) << "\n"; ForIF(context, aIF, ifHead) { if (not ifHead->bufIn.empty() && ifHead->msgIn!=NO_MSGID) { Dune::dwarn << " waiting for message (from proc " << ifHead->proc << ", size " << ifHead->bufIn.size() << ")\n"; } } } else { #ifdef CtrlTimeouts printf("%4d: IFCTRL %02d received msg all after %10ld tries\n", context.me(), aIF, (unsigned long)tries); #endif if (! NS_DIM_PREFIX IFPollSend(context, aIF)) { Dune::dwarn << FUNCNAME_STR(IF_FUNCNAME) ": send-timeout for IF " << setw(2) << aIF << "\n"; ForIF(context, aIF, ifHead) { if (not ifHead->bufOut.empty() && ifHead->msgOut!=NO_MSGID) { Dune::dwarn << " waiting for send completion (to proc " << ifHead->proc << ", size " << ifHead->bufOut.size() << ")\n"; } } } } /* free memory */ NS_DIM_PREFIX IFExitComm(context, aIF); /*STAT_TIMER1(60);*/ #endif /* IF_EXECLOCAL */ } /****************************************************************************/ /* undefs for all input macros and defines */ #undef IF_NAME #undef IF_FUNCNAME #ifdef IF_EXCHANGE #undef IF_EXCHANGE #endif #ifdef IF_EXECLOCAL #undef IF_EXECLOCAL #endif #ifdef IF_WITH_XARGS #undef IF_WITH_XARGS #endif #ifdef IF_CBR #undef IF_CBR #endif /* undefs for derived macros */ #undef PART #undef EXEC_LOOP #undef COMM_LOOP #undef D_AB #undef D_BA #undef D_ABA #undef _CAT #undef CAT /****************************************************************************/