| 1 |
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 2 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
/****************************************************************************/ |
| 4 |
/* */ |
| 5 |
/* File: ifstd.ct */ |
| 6 |
/* */ |
| 7 |
/* Purpose: template routines for standard interface functions */ |
| 8 |
/* */ |
| 9 |
/* Author: Klaus Birken */ |
| 10 |
/* Institut fuer Computeranwendungen III */ |
| 11 |
/* Universitaet Stuttgart */ |
| 12 |
/* Pfaffenwaldring 27 */ |
| 13 |
/* 70569 Stuttgart */ |
| 14 |
/* internet: [email protected] */ |
| 15 |
/* */ |
| 16 |
/* History: 980825 kb begin */ |
| 17 |
/* */ |
| 18 |
/* Remarks: */ |
| 19 |
/* */ |
| 20 |
/****************************************************************************/ |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
/****************************************************************************/ |
| 25 |
/* */ |
| 26 |
/* derived macros */ |
| 27 |
/* */ |
| 28 |
/****************************************************************************/ |
| 29 |
|
| 30 |
#define _CAT(a,b) a ## b |
| 31 |
#define CAT(a,b) _CAT(a,b) |
| 32 |
|
| 33 |
|
| 34 |
#define PART ifHead |
| 35 |
|
| 36 |
|
| 37 |
#ifdef IF_WITH_XARGS |
| 38 |
#define EXEC_LOOP(context, a,b,c) IFExecHdrLoopCplX(context, a,b,c) |
| 39 |
#define COMM_LOOP(context, a,b,c,d,e) IFCommHdrLoopCplX(context, a,b,c,d,e) |
| 40 |
#else |
| 41 |
#define EXEC_LOOP(context, a,b,c) IFExecHdrLoopCpl(context, a,b,c) |
| 42 |
#define COMM_LOOP(context, a,b,c,d,e) IFCommHdrLoopCpl(context, a,b,c,d,e) |
| 43 |
#endif |
| 44 |
|
| 45 |
#define D_ABA(p) (p->cpl) |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
#define IF_FUNCNAME CAT(ddd_StdIF,IF_NAME) |
| 50 |
|
| 51 |
|
| 52 |
/****************************************************************************/ |
| 53 |
/* */ |
| 54 |
/* auxiliary macros */ |
| 55 |
/* */ |
| 56 |
/****************************************************************************/ |
| 57 |
|
| 58 |
#ifndef IF_AUX_MACROS |
| 59 |
#define IF_AUX_MACROS |
| 60 |
|
| 61 |
#define CONCAT(txt,fct) txt FUNCNAME_STR(fct) |
| 62 |
#define FUNCNAME_STR(f) #f |
| 63 |
|
| 64 |
|
| 65 |
#endif |
| 66 |
|
| 67 |
|
| 68 |
/****************************************************************************/ |
| 69 |
/* */ |
| 70 |
/* routines */ |
| 71 |
/* */ |
| 72 |
/****************************************************************************/ |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
void IF_FUNCNAME ( |
| 77 |
DDD::DDDContext& context, |
| 78 |
#ifdef IF_EXECLOCAL |
| 79 |
#ifdef IF_WITH_XARGS |
| 80 |
NS_DIM_PREFIX ExecProcHdrXPtr ExecProc) |
| 81 |
#else |
| 82 |
NS_DIM_PREFIX ExecProcHdrPtr ExecProc) |
| 83 |
#endif |
| 84 |
#else |
| 85 |
size_t aSize, |
| 86 |
#ifdef IF_WITH_XARGS |
| 87 |
NS_DIM_PREFIX ComProcHdrXPtr Gather, NS_DIM_PREFIX ComProcHdrXPtr Scatter) |
| 88 |
#else |
| 89 |
NS_DIM_PREFIX ComProcHdrPtr Gather, NS_DIM_PREFIX ComProcHdrPtr Scatter) |
| 90 |
#endif |
| 91 |
#endif |
| 92 |
{ |
| 93 |
using std::setw; |
| 94 |
|
| 95 |
NS_DIM_PREFIX DDD_IF aIF = NS_DIM_PREFIX STD_INTERFACE; |
| 96 |
NS_DIM_PREFIX IF_PROC *ifHead; |
| 97 |
|
| 98 |
|
| 99 |
#ifdef IF_EXECLOCAL |
| 100 |
|
| 101 |
ForIF(context, aIF, ifHead) |
| 102 |
{ |
| 103 |
EXEC_LOOP(context, ExecProc, D_ABA(PART), PART->nItems); |
| 104 |
} |
| 105 |
|
| 106 |
#else /* ! IF_EXECLOCAL */ |
| 107 |
|
| 108 |
/* allocate storage for in and out buffers */ |
| 109 |
ForIF(context, aIF, ifHead) |
| 110 |
{ |
| 111 |
|
| 112 |
#ifdef IF_EXCHANGE |
| 113 |
NS_DIM_PREFIX IFGetMem(ifHead, aSize, PART->nItems, PART->nItems); |
| 114 |
#endif |
| 115 |
} |
| 116 |
|
| 117 |
/* init communication, initiate receives */ |
| 118 |
int recv_mesgs = NS_DIM_PREFIX IFInitComm(context, aIF); |
| 119 |
|
| 120 |
|
| 121 |
/* build messages using gather-handler and send them away */ |
| 122 |
ForIF(context, aIF, ifHead) |
| 123 |
{ |
| 124 |
char *buffer; |
| 125 |
buffer = ifHead->bufOut.data(); |
| 126 |
|
| 127 |
buffer= COMM_LOOP(context, Gather, D_ABA(PART), buffer, aSize, PART->nItems); |
| 128 |
|
| 129 |
NS_DIM_PREFIX IFInitSend(context, ifHead); |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
/* poll receives and scatter data */ |
| 135 |
unsigned long tries; |
| 136 |
for(tries=0; tries<MAX_TRIES && recv_mesgs>0; tries++) |
| 137 |
{ |
| 138 |
/* poll receive calls */ |
| 139 |
ForIF(context, aIF, ifHead) |
| 140 |
{ |
| 141 |
if (not ifHead->bufIn.empty() && ifHead->msgIn!=NO_MSGID) |
| 142 |
{ |
| 143 |
int error = InfoARecv(context.ppifContext(), ifHead->vc, ifHead->msgIn); |
| 144 |
if (error==-1) |
| 145 |
DUNE_THROW(Dune::Exception, |
| 146 |
"InfoARecv() failed for recv to proc=" << ifHead->proc); |
| 147 |
|
| 148 |
if (error==1) |
| 149 |
{ |
| 150 |
char *buffer; |
| 151 |
|
| 152 |
#ifdef CtrlTimeoutsDetailed |
| 153 |
printf("%4d: IFCTRL %02d received msg from " |
| 154 |
"%4d after %10ld, size %ld\n", |
| 155 |
context.me(), aIF, ifHead->proc, |
| 156 |
(unsigned long)tries, |
| 157 |
(unsigned long)ifHead->bufIn.size()); |
| 158 |
#endif |
| 159 |
|
| 160 |
recv_mesgs--; |
| 161 |
ifHead->msgIn=NO_MSGID; |
| 162 |
|
| 163 |
buffer = ifHead->bufIn.data(); |
| 164 |
|
| 165 |
/* get data using scatter-handler */ |
| 166 |
buffer = COMM_LOOP(context, Scatter, |
| 167 |
D_ABA(PART), buffer, aSize, PART->nItems); |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
/* finally poll send completion */ |
| 174 |
if (recv_mesgs>0) |
| 175 |
{ |
| 176 |
Dune::dwarn << FUNCNAME_STR(IF_FUNCNAME) ": receive-timeout for IF " << setw(2) << "\n"; |
| 177 |
|
| 178 |
ForIF(context, aIF, ifHead) |
| 179 |
{ |
| 180 |
if (not ifHead->bufIn.empty() && ifHead->msgIn!=NO_MSGID) |
| 181 |
{ |
| 182 |
Dune::dwarn |
| 183 |
<< " waiting for message (from proc " << ifHead->proc |
| 184 |
<< ", size " << ifHead->bufIn.size() << ")\n"; |
| 185 |
} |
| 186 |
} |
| 187 |
} |
| 188 |
else |
| 189 |
{ |
| 190 |
#ifdef CtrlTimeouts |
| 191 |
printf("%4d: IFCTRL %02d received msg all after %10ld tries\n", |
| 192 |
context.me(), aIF, (unsigned long)tries); |
| 193 |
#endif |
| 194 |
|
| 195 |
if (! NS_DIM_PREFIX IFPollSend(context, aIF)) |
| 196 |
{ |
| 197 |
Dune::dwarn << FUNCNAME_STR(IF_FUNCNAME) ": send-timeout for IF " << setw(2) << aIF << "\n"; |
| 198 |
|
| 199 |
ForIF(context, aIF, ifHead) |
| 200 |
{ |
| 201 |
if (not ifHead->bufOut.empty() && ifHead->msgOut!=NO_MSGID) |
| 202 |
{ |
| 203 |
Dune::dwarn |
| 204 |
<< " waiting for send completion (to proc " << ifHead->proc |
| 205 |
<< ", size " << ifHead->bufOut.size() << ")\n"; |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
/* free memory */ |
| 213 |
NS_DIM_PREFIX IFExitComm(context, aIF); |
| 214 |
|
| 215 |
/*STAT_TIMER1(60);*/ |
| 216 |
|
| 217 |
#endif /* IF_EXECLOCAL */ |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
/****************************************************************************/ |
| 222 |
|
| 223 |
/* undefs for all input macros and defines */ |
| 224 |
|
| 225 |
#undef IF_NAME |
| 226 |
#undef IF_FUNCNAME |
| 227 |
|
| 228 |
#ifdef IF_EXCHANGE |
| 229 |
#undef IF_EXCHANGE |
| 230 |
#endif |
| 231 |
|
| 232 |
#ifdef IF_EXECLOCAL |
| 233 |
#undef IF_EXECLOCAL |
| 234 |
#endif |
| 235 |
|
| 236 |
|
| 237 |
#ifdef IF_WITH_XARGS |
| 238 |
#undef IF_WITH_XARGS |
| 239 |
#endif |
| 240 |
|
| 241 |
#ifdef IF_CBR |
| 242 |
#undef IF_CBR |
| 243 |
#endif |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
/* undefs for derived macros */ |
| 248 |
|
| 249 |
#undef PART |
| 250 |
#undef EXEC_LOOP |
| 251 |
#undef COMM_LOOP |
| 252 |
#undef D_AB |
| 253 |
#undef D_BA |
| 254 |
#undef D_ABA |
| 255 |
|
| 256 |
|
| 257 |
#undef _CAT |
| 258 |
#undef CAT |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
/****************************************************************************/ |
| 263 |
|