| 1 |
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 2 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
#ifndef DUNE_UGGRID_PARALLEL_DDD_DDDTYPES_IMPL_HH |
| 4 |
#define DUNE_UGGRID_PARALLEL_DDD_DDDTYPES_IMPL_HH 1 |
| 5 |
|
| 6 |
#include <memory> |
| 7 |
#include <vector> |
| 8 |
|
| 9 |
#include <dune/uggrid/parallel/ppif/ppiftypes.hh> |
| 10 |
|
| 11 |
#include "dddconstants.hh" |
| 12 |
#include "dddtypes.hh" |
| 13 |
|
| 14 |
namespace DDD { |
| 15 |
|
| 16 |
/** options for DDD_SetOption */ |
| 17 |
enum DDD_OPTION { |
| 18 |
OPT_IDENTIFY_MODE=0, ///< one of the IDMODE_xxx constants |
| 19 |
|
| 20 |
OPT_WARNING_VARSIZE_OBJ=8, ///< warning on differing obj sizes |
| 21 |
OPT_WARNING_SMALLSIZE, ///< warning on obj sizes smaller than declared |
| 22 |
OPT_WARNING_PRIOCHANGE, ///< warning on inconsistency in prio-change |
| 23 |
OPT_WARNING_DESTRUCT_HDR, ///< warning on inconsistency in HdrDestructor |
| 24 |
OPT_WARNING_REF_COLLISION, ///< warning on collision in reference-localize |
| 25 |
OPT_WARNING_OLDSTYLE, ///< warning on usage of old-style ddd-funcs |
| 26 |
|
| 27 |
OPT_QUIET_CONSCHECK=16, ///< do ConsCheck in a quiet manner |
| 28 |
OPT_DEBUG_XFERMESGS, ///< print debug info for xfer messages |
| 29 |
OPT_INFO_XFER, ///< display some statistical info during xfer |
| 30 |
OPT_INFO_JOIN, ///< display some statistical info during join |
| 31 |
OPT_INFO_IF_WITH_ATTR, ///< display interfaces detailed (with attrs) |
| 32 |
|
| 33 |
OPT_XFER_PRUNE_DELETE, ///< prune del-cmd in del/xfercopy-combination |
| 34 |
|
| 35 |
OPT_IF_REUSE_BUFFERS, ///< reuse interface buffs as long as possible |
| 36 |
OPT_IF_CREATE_EXPLICIT, ///< dont (re-)create interfaces automatically |
| 37 |
|
| 38 |
OPT_CPLMGR_USE_FREELIST, ///< use freelist for coupling-memory (default) |
| 39 |
|
| 40 |
OPT_END |
| 41 |
}; |
| 42 |
|
| 43 |
/** |
| 44 |
* \brief DDD object header, include this into all parallel object structures |
| 45 |
* |
| 46 |
* Some remarks: |
| 47 |
* |
| 48 |
* - don't touch the member elements of DDD_HEADER in the |
| 49 |
* application program, they will be changed in further |
| 50 |
* DDD versions! |
| 51 |
* |
| 52 |
* - use DDD functional interface for accessing the header fields; |
| 53 |
* elements which are not accessible via the DDD functional interface |
| 54 |
* should not be accessed by the application program anyway, |
| 55 |
*/ |
| 56 |
struct DDD_HEADER |
| 57 |
{ |
| 58 |
/* control word elements */ |
| 59 |
unsigned char typ; |
| 60 |
unsigned char prio; |
| 61 |
unsigned char attr; |
| 62 |
unsigned char flags; |
| 63 |
|
| 64 |
/** global object array index */ |
| 65 |
unsigned int myIndex; |
| 66 |
|
| 67 |
/** global id */ |
| 68 |
DDD_GID gid; |
| 69 |
|
| 70 |
/* 4 unused bytes in current impl. */ |
| 71 |
char empty[4]; |
| 72 |
}; |
| 73 |
|
| 74 |
|
| 75 |
/** |
| 76 |
* \brief record for coupling of local object with foreign objects |
| 77 |
*/ |
| 78 |
struct COUPLING |
| 79 |
{ |
| 80 |
COUPLING* _next; |
| 81 |
unsigned short _proc; |
| 82 |
unsigned char prio; |
| 83 |
unsigned char _flags; |
| 84 |
DDD_HDR obj; |
| 85 |
}; |
| 86 |
|
| 87 |
/** |
| 88 |
* \brief description of one element in DDD object structure description |
| 89 |
* |
| 90 |
* \todo in CPP_FRONTEND only one of the versions for C_FRONTEND and |
| 91 |
* F_FRONTEND is needed, depending on setting of desc->storage. |
| 92 |
* this should be a union for memory efficiency reasons. |
| 93 |
*/ |
| 94 |
struct ELEM_DESC |
| 95 |
{ |
| 96 |
/** element offset from object address */ |
| 97 |
int offset; |
| 98 |
|
| 99 |
/** gbits array, if type==EL_GBITS */ |
| 100 |
std::unique_ptr<unsigned char[]> gbits; |
| 101 |
|
| 102 |
/** size of this element */ |
| 103 |
std::size_t size; |
| 104 |
|
| 105 |
/** type of element, one of EL_xxx */ |
| 106 |
int type; |
| 107 |
|
| 108 |
/* if type==EL_OBJPTR, the following entries will be used: */ |
| 109 |
|
| 110 |
/** DDD_TYPE of ref. destination */ |
| 111 |
DDD_TYPE _reftype; |
| 112 |
|
| 113 |
/* if reftype==DDD_TYPE_BY_HANDLER, we must use a handler for |
| 114 |
* determining the reftype on-the-fly (additional parameter during |
| 115 |
* TypeDefine with EL_OBJPTR) |
| 116 |
*/ |
| 117 |
HandlerGetRefType reftypeHandler; |
| 118 |
}; |
| 119 |
|
| 120 |
|
| 121 |
/** |
| 122 |
* \brief single DDD object structure description |
| 123 |
*/ |
| 124 |
struct TYPE_DESC |
| 125 |
{ |
| 126 |
/** current TypeMode (DECLARE/DEFINE) */ |
| 127 |
int mode; |
| 128 |
|
| 129 |
/** textual object description */ |
| 130 |
const char* name; |
| 131 |
|
| 132 |
/** number of current call to TypeDefine */ |
| 133 |
int currTypeDefCall; |
| 134 |
|
| 135 |
/* if C_FRONTEND or (CPP_FRONTEND and storage==STORAGE_STRUCT): */ |
| 136 |
|
| 137 |
/** flag: real ddd type (with header)? */ |
| 138 |
bool hasHeader; |
| 139 |
|
| 140 |
/** offset of header from begin of obj */ |
| 141 |
int offsetHeader; |
| 142 |
|
| 143 |
/** max. number of elements per TYPE_DESC */ |
| 144 |
static const int MAX_ELEMDESC = 64; |
| 145 |
|
| 146 |
/** element description array */ |
| 147 |
ELEM_DESC element[MAX_ELEMDESC]; |
| 148 |
|
| 149 |
/** number of elements in object */ |
| 150 |
int nElements; |
| 151 |
|
| 152 |
/** size of object, correctly aligned */ |
| 153 |
std::size_t size; |
| 154 |
|
| 155 |
/* pointer to handler functions: */ |
| 156 |
|
| 157 |
HandlerLDATACONSTRUCTOR handlerLDATACONSTRUCTOR; |
| 158 |
HandlerDESTRUCTOR handlerDESTRUCTOR; |
| 159 |
HandlerDELETE handlerDELETE; |
| 160 |
HandlerUPDATE handlerUPDATE; |
| 161 |
HandlerOBJMKCONS handlerOBJMKCONS; |
| 162 |
HandlerSETPRIORITY handlerSETPRIORITY; |
| 163 |
HandlerXFERCOPY handlerXFERCOPY; |
| 164 |
HandlerXFERDELETE handlerXFERDELETE; |
| 165 |
HandlerXFERGATHER handlerXFERGATHER; |
| 166 |
HandlerXFERSCATTER handlerXFERSCATTER; |
| 167 |
HandlerXFERGATHERX handlerXFERGATHERX; |
| 168 |
HandlerXFERSCATTERX handlerXFERSCATTERX; |
| 169 |
HandlerXFERCOPYMANIP handlerXFERCOPYMANIP; |
| 170 |
|
| 171 |
|
| 172 |
/** 2D matrix for comparing priorities */ |
| 173 |
std::unique_ptr<DDD_PRIO[]> prioMatrix; |
| 174 |
|
| 175 |
/** default mode for PrioMerge */ |
| 176 |
int prioDefault; |
| 177 |
|
| 178 |
/* redundancy for efficiency: */ |
| 179 |
|
| 180 |
/** number of outside references */ |
| 181 |
int nPointers; |
| 182 |
|
| 183 |
/** mask for fast type-dependent copy */ |
| 184 |
std::unique_ptr<unsigned char[]> cmask; |
| 185 |
}; |
| 186 |
|
| 187 |
namespace Basic { |
| 188 |
|
| 189 |
struct NOTIFY_DESC |
| 190 |
{ |
| 191 |
DDD_PROC proc; |
| 192 |
size_t size; |
| 193 |
}; |
| 194 |
|
| 195 |
enum class NotifyTypes : unsigned short |
| 196 |
{ |
| 197 |
MYSELF, |
| 198 |
KNOWN, |
| 199 |
DUMMY, |
| 200 |
UNKNOWN |
| 201 |
}; |
| 202 |
|
| 203 |
struct NOTIFY_INFO { |
| 204 |
short from, to; /* source and destination processor */ |
| 205 |
NotifyTypes flag; /* one of NotifyTypes */ |
| 206 |
size_t size; /* message size */ |
| 207 |
}; |
| 208 |
|
| 209 |
} /* namespace Basic */ |
| 210 |
|
| 211 |
namespace If { |
| 212 |
|
| 213 |
using IFObjPtr = DDD_OBJ; |
| 214 |
|
| 215 |
/** |
| 216 |
* single part of interface, all couplings have same attr |
| 217 |
*/ |
| 218 |
struct IF_ATTR |
| 219 |
{ |
| 220 |
IF_ATTR* next = nullptr; |
| 221 |
|
| 222 |
/* note: the cplXX resp. objXX arrays are NOT contiguous in memory */ |
| 223 |
COUPLING **cplAB = nullptr, **cplBA = nullptr, **cplABA = nullptr; |
| 224 |
/* object shortcut */ |
| 225 |
IFObjPtr *objAB, *objBA, *objABA; |
| 226 |
int nItems = 0; |
| 227 |
int nAB = 0; |
| 228 |
int nBA = 0; |
| 229 |
int nABA = 0; |
| 230 |
DDD_ATTR attr; |
| 231 |
|
| 232 |
explicit IF_ATTR(DDD_ATTR attr) |
| 233 |
: attr(attr) |
| 234 |
{ /* Nothing */ } |
| 235 |
}; |
| 236 |
|
| 237 |
/** |
| 238 |
* descriptor of message and its contents/buffers for IF-communic. |
| 239 |
*/ |
| 240 |
struct IF_PROC |
| 241 |
{ |
| 242 |
IF_PROC* next; |
| 243 |
IF_ATTR *ifAttr; |
| 244 |
int nAttrs; |
| 245 |
|
| 246 |
/* note: the cplXX resp. objXX arrays ARE contiguous in memory */ |
| 247 |
COUPLING **cpl, **cplAB = nullptr, **cplBA = nullptr, **cplABA = nullptr; |
| 248 |
/* object shortcut */ |
| 249 |
IFObjPtr *obj = nullptr, *objAB, *objBA, *objABA; |
| 250 |
int nItems = 0, nAB = 0, nBA = 0, nABA = 0; |
| 251 |
DDD_PROC proc; |
| 252 |
|
| 253 |
PPIF::VChannelPtr vc; |
| 254 |
PPIF::msgid msgIn; |
| 255 |
PPIF::msgid msgOut; |
| 256 |
std::vector<char> bufIn; |
| 257 |
std::vector<char> bufOut; |
| 258 |
}; |
| 259 |
|
| 260 |
/** |
| 261 |
* descriptor for one single interface |
| 262 |
*/ |
| 263 |
struct IF_DEF |
| 264 |
{ |
| 265 |
IF_PROC *ifHead = nullptr; |
| 266 |
|
| 267 |
/** list of couplings belonging to interface */ |
| 268 |
COUPLING **cpl = nullptr; |
| 269 |
|
| 270 |
/** overall number of items in this interface */ |
| 271 |
int nItems = 0; |
| 272 |
|
| 273 |
/** shortcut: list of object addresses in interf */ |
| 274 |
IFObjPtr *obj = nullptr; |
| 275 |
|
| 276 |
/* flag: is obj-table valid? */ |
| 277 |
bool objValid = false; |
| 278 |
|
| 279 |
int nIfHeads = 0; |
| 280 |
|
| 281 |
int nObjStruct; |
| 282 |
int nPrioA; |
| 283 |
int nPrioB; |
| 284 |
DDD_TYPE O[16]; |
| 285 |
DDD_PRIO A[16]; |
| 286 |
DDD_PRIO B[16]; |
| 287 |
|
| 288 |
/* data for efficiency tuning */ |
| 289 |
int maskO; |
| 290 |
|
| 291 |
/* data for nice user interaction */ |
| 292 |
/** string for interface identification */ |
| 293 |
char name[IF_NAMELEN+1]; |
| 294 |
}; |
| 295 |
|
| 296 |
} /* namespace If */ |
| 297 |
|
| 298 |
namespace Mgr { |
| 299 |
|
| 300 |
/** segment of Cpls */ |
| 301 |
struct CplSegm |
| 302 |
{ |
| 303 |
CplSegm *next; |
| 304 |
int nItems; |
| 305 |
|
| 306 |
COUPLING item[CPLSEGM_SIZE]; |
| 307 |
}; |
| 308 |
|
| 309 |
} /* namespace Mgr */ |
| 310 |
|
| 311 |
} /* namespace DDD */ |
| 312 |
|
| 313 |
#endif |