1 #ifndef DUNE_UGGRID_PARALLEL_DDD_DDDCONTEXT_HH
2 #define DUNE_UGGRID_PARALLEL_DDD_DDDCONTEXT_HH 1
3 
4 #include <memory>
5 #include <vector>
6 #include <array>
7 
8 #include <dune/uggrid/parallel/ddd/dddconstants.hh>
9 #include <dune/uggrid/parallel/ddd/dddtypes.hh>
10 #include <dune/uggrid/parallel/ddd/dddtypes_impl.hh>
11 #include <dune/uggrid/parallel/ppif/ppiftypes.hh>
12 
13 namespace DDD {
14 
15 namespace Basic {
16 
17 struct LowCommContext
18 {
19   MSG_TYPE *MsgTypes = nullptr;
20   MSG_DESC *SendQueue = nullptr;
21   MSG_DESC *RecvQueue = nullptr;
22   int nSends = 0;
23   int nRecvs = 0;
24   char *theRecvBuffer;
25   LC_MSGHANDLE *theRecvArray = nullptr;
26   MSG_DESC *FreeMsgDescs = nullptr;
27 
28   AllocFunc DefaultAlloc, SendAlloc, RecvAlloc;
29   FreeFunc DefaultFree, SendFree, RecvFree;
30 };
31 
32 struct NotifyContext
33 {
34   std::vector<NOTIFY_INFO> allInfoBuffer;
35   std::vector<NOTIFY_DESC> theDescs;
36   std::vector<int> theRouting;
37   int maxInfos;
38   int lastInfo;
39   int nSendDescs;
40 };
41 
42 struct TopoContext
43 {
44   std::vector<PPIF::VChannelPtr> theTopology;
45   std::vector<DDD_PROC> theProcArray;
46 };
47 
48 } /* namespace Basic */
49 
50 namespace Ctrl {
51 
52 struct ConsContext
53 {
54   Basic::LC_MSGTYPE consmsg_t;
55   Basic::LC_MSGCOMP constab_id;
56 };
57 
58 } /* namespace Ctrl */
59 
60 namespace Ident {
61 
62 struct IdentContext
63 {
64   ID_PLIST* thePLists;
65   int cntIdents;
66   int nPLists;
67   IdentMode identMode;
68 };
69 
70 } /* namespace Ident */
71 
72 namespace If {
73 
74 struct IfCreateContext
75 {
76   IF_DEF theIf[MAX_IF];
77   int nIfs;
78 };
79 
80 struct IfUseContext
81 {
82   int send_mesgs;
83 };
84 
85 } /* namespace If */
86 
87 namespace Join {
88 
89 struct JoinContext
90 {
91   /** mode of join module */
92   JoinMode joinMode;
93 
94   /* description for phase1 message */
95   Basic::LC_MSGTYPE phase1msg_t;
96   Basic::LC_MSGCOMP jointab_id;
97 
98   /* description for phase2 message */
99   Basic::LC_MSGTYPE phase2msg_t;
100   Basic::LC_MSGCOMP addtab_id;
101 
102   /* description for phase3 message */
103   Basic::LC_MSGTYPE phase3msg_t;
104   Basic::LC_MSGCOMP cpltab_id;
105 
106   /* entry points for global sets */
107   JIJoinSet   *setJIJoin;
108   JIAddCplSet *setJIAddCpl2;
109   JIAddCplSet *setJIAddCpl3;
110 };
111 
112 } /* namespace Join */
113 
114 namespace Mgr {
115 
116 struct CplmgrContext
117 {
118   CplSegm *segmCpl = nullptr;
119   COUPLING *memlistCpl = nullptr;
120   int *localIBuffer;
121   int nCplSegms;
122 };
123 
124 struct ObjmgrContext
125 {
126   DDD_GID theIdCount;
127 };
128 
129 struct TypemgrContext
130 {
131   int nDescr;
132 };
133 
134 } /* namespace Mgr */
135 
136 namespace Prio {
137 
138 struct PrioContext
139 {
140   PrioMode prioMode;
141 };
142 
143 } /* namespace Prio */
144 
145 namespace Xfer {
146 
147 struct CmdmsgContext
148 {
149   Basic::LC_MSGTYPE cmdmsg_t;
150   Basic::LC_MSGCOMP undelete_id;
151 };
152 
153 struct CplmsgContext
154 {
155   Basic::LC_MSGTYPE cplmsg_t;
156   Basic::LC_MSGCOMP delcpl_id;
157   Basic::LC_MSGCOMP modcpl_id;
158   Basic::LC_MSGCOMP addcpl_id;
159 };
160 
161 /**
162  * global data for xfer module
163  */
164 struct XferContext
165 {
166   /** mode of xfer module */
167   XferMode xferMode;
168 
169   /* description for object message */
170   Basic::LC_MSGTYPE objmsg_t;
171   Basic::LC_MSGCOMP symtab_id, objtab_id;
172   Basic::LC_MSGCOMP newcpl_id, oldcpl_id;
173   Basic::LC_MSGCOMP objmem_id;
174 
175 
176   /* entry points for global sets */
177   XICopyObjSet *setXICopyObj;
178   XISetPrioSet *setXISetPrio;
179 
180   XICopyObj* theXIAddData;
181 
182   AddDataSegm* segmAddData = nullptr;
183   SizesSegm* segmSizes = nullptr;
184 
185 #define SLL_MEMBERS(T) Segm##T* segms##T; T* list##T; int n##T;
186   SLL_MEMBERS(XIDelCmd)
187   SLL_MEMBERS(XIDelObj)
188   SLL_MEMBERS(XINewCpl)
189   SLL_MEMBERS(XIOldCpl)
190   SLL_MEMBERS(XIAddCpl)
191   SLL_MEMBERS(XIDelCpl)
192   SLL_MEMBERS(XIModCpl)
193 #undef SLL_MEMBERS
194 };
195 
196 } /* namespace Xfer */
197 
198 struct CouplingContext
199 {
200   std::vector<COUPLING*> cplTable;
201   std::vector<short> nCplTable;
202 
203   /** number of coupling lists */
204   int nCpls;
205 
206   /* number of couplings */
207   int nCplItems;
208 };
209 
210 class DDDContext {
211 public:
212   DDDContext(const std::shared_ptr<PPIF::PPIFContext>& ppifContext, const std::shared_ptr<void>& data);
213 
ppifContext() const214   const PPIF::PPIFContext& ppifContext() const
215     { return *ppifContext_; }
216 
ppifContext()217   PPIF::PPIFContext& ppifContext()
218     { return *ppifContext_; }
219 
220   /**
221    * \see PPIF::PPIFContext::me()
222    */
223   int me() const;
224 
225   /**
226    * \see PPIF::PPIFContext::procs()
227    */
228   int procs() const;
229 
230   /**
231    * \see PPIF::PPIFContext::isMaster()
232    */
233   bool isMaster() const;
234 
235   /**
236    * return pointer to user data
237    */
data()238   void* data()
239     { return data_.get(); }
240 
241   /**
242    * return const pointer to user data
243    */
data() const244   const void* data() const
245     { return data_.get(); }
246 
lowCommContext()247   Basic::LowCommContext& lowCommContext()
248     { return lowCommContext_; }
249 
lowCommContext() const250   const Basic::LowCommContext& lowCommContext() const
251     { return lowCommContext_; }
252 
notifyContext()253   Basic::NotifyContext& notifyContext()
254     { return notifyContext_; }
255 
topoContext()256   Basic::TopoContext& topoContext()
257     { return topoContext_; }
258 
topoContext() const259   const Basic::TopoContext& topoContext() const
260     { return topoContext_; }
261 
consContext()262   Ctrl::ConsContext& consContext()
263     { return consContext_; }
264 
identContext()265   Ident::IdentContext& identContext()
266     { return identContext_; }
267 
identContext() const268   const Ident::IdentContext& identContext() const
269     { return identContext_; }
270 
ifCreateContext()271   If::IfCreateContext& ifCreateContext()
272     { return ifCreateContext_; }
273 
ifCreateContext() const274   const If::IfCreateContext& ifCreateContext() const
275     { return ifCreateContext_; }
276 
ifUseContext()277   If::IfUseContext& ifUseContext()
278     { return ifUseContext_; }
279 
joinContext()280   Join::JoinContext& joinContext()
281     { return joinContext_; }
282 
joinContext() const283   const Join::JoinContext& joinContext() const
284     { return joinContext_; }
285 
cplmgrContext()286   Mgr::CplmgrContext& cplmgrContext()
287     { return cplmgrContext_; }
288 
cplmgrContext() const289   const Mgr::CplmgrContext& cplmgrContext() const
290     { return cplmgrContext_; }
291 
objmgrContext()292   Mgr::ObjmgrContext& objmgrContext()
293     { return objmgrContext_; }
294 
typemgrContext()295   Mgr::TypemgrContext& typemgrContext()
296     { return typemgrContext_; }
297 
typemgrContext() const298   const Mgr::TypemgrContext& typemgrContext() const
299     { return typemgrContext_; }
300 
prioContext()301   Prio::PrioContext& prioContext()
302     { return prioContext_; }
303 
prioContext() const304   const Prio::PrioContext& prioContext() const
305     { return prioContext_; }
306 
cmdmsgContext()307   Xfer::CmdmsgContext& cmdmsgContext()
308     { return cmdmsgContext_; }
309 
cmdmsgContext() const310   const Xfer::CmdmsgContext& cmdmsgContext() const
311     { return cmdmsgContext_; }
312 
cplmsgContext()313   Xfer::CplmsgContext& cplmsgContext()
314     { return cplmsgContext_; }
315 
cplmsgContext() const316   const Xfer::CplmsgContext& cplmsgContext() const
317     { return cplmsgContext_; }
318 
xferContext()319   Xfer::XferContext& xferContext()
320     { return xferContext_; }
321 
xferContext() const322   const Xfer::XferContext& xferContext() const
323     { return xferContext_; }
324 
couplingContext()325   CouplingContext& couplingContext()
326     { return couplingContext_; }
327 
couplingContext() const328   const CouplingContext& couplingContext() const
329     { return couplingContext_; }
330 
objTable() const331   const std::vector<DDD_HDR>& objTable() const
332     { return objTable_; }
333 
objTable()334   std::vector<DDD_HDR>& objTable()
335     { return objTable_; }
336 
nObjs() const337   int nObjs() const
338     { return nObjs_; }
339 
nObjs(int n)340   void nObjs(int n)
341     { nObjs_ = n; }
342 
typeDefs()343   std::array<TYPE_DESC, MAX_TYPEDESC>& typeDefs()
344     { return typeDefs_; }
345 
typeDefs() const346   const std::array<TYPE_DESC, MAX_TYPEDESC>& typeDefs() const
347     { return typeDefs_; }
348 
options()349   std::array<int, OPT_END>& options()
350     { return options_; }
351 
options() const352   const std::array<int, OPT_END>& options() const
353     { return options_; }
354 
355 protected:
356   std::shared_ptr<PPIF::PPIFContext> ppifContext_;
357   std::shared_ptr<void> data_;
358   Basic::LowCommContext lowCommContext_;
359   Basic::NotifyContext notifyContext_;
360   Basic::TopoContext topoContext_;
361   Ctrl::ConsContext consContext_;
362   Ident::IdentContext identContext_;
363   If::IfCreateContext ifCreateContext_;
364   If::IfUseContext ifUseContext_;
365   Join::JoinContext joinContext_;
366   Mgr::CplmgrContext cplmgrContext_;
367   Mgr::ObjmgrContext objmgrContext_;
368   Mgr::TypemgrContext typemgrContext_;
369   Prio::PrioContext prioContext_;
370   CouplingContext couplingContext_;
371   Xfer::CmdmsgContext cmdmsgContext_;
372   Xfer::CplmsgContext cplmsgContext_;
373   Xfer::XferContext xferContext_;
374 
375   std::vector<DDD_HDR> objTable_;
376   int nObjs_;
377 
378   std::array<TYPE_DESC, MAX_TYPEDESC> typeDefs_;
379 
380   std::array<int, OPT_END> options_;
381 };
382 
383 } /* namespace DDD */
384 
385 #endif
386