Debian Codegraph @

dune/uggrid/parallel/ddd/ddd.cc

raw
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LGPL-2.1-or-later
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 /****************************************************************************/
6 /* */
7 /* File: ddd.c */
8 /* */
9 /* Purpose: distributed dynamic data module */
10 /* */
11 /* Author: Klaus Birken */
12 /* Rechenzentrum Uni Stuttgart */
13 /* Universitaet Stuttgart */
14 /* Allmandring 30 */
15 /* 70550 Stuttgart */
16 /* internet: [email protected] */
17 /* */
18 /* History: 93/11/22 kb begin */
19 /* 94/09/13 kb added DDD_Status */
20 /* 95/11/03 kb complete rewrite of StructRegister code */
21 /* 95/11/16 kb moved DDD_TYPE-definition code to typemgr.c */
22 /* */
23 /* Remarks: */
24 /* */
25 /****************************************************************************/
26
27 /****************************************************************************/
28 /* */
29 /* include files */
30 /* system include files */
31 /* application include files */
32 /* */
33 /****************************************************************************/
34
35 /* standard C library */
36 #include <config.h>
37 #include <cstdlib>
38 #include <cstdio>
39 #include <stdarg.h>
40 #include <cstring>
41
42 #include <iomanip>
43 #include <iostream>
44 #include <new>
45
46 #include "dddi.h"
47 #include <dune/uggrid/parallel/ddd/basic/lowcomm.h>
48 #include <dune/uggrid/parallel/ddd/basic/notify.h>
49
50 #include <dune/common/exceptions.hh>
51 #include <dune/common/stdstreams.hh>
52
53 #include <dune/uggrid/parallel/ddd/dddcontext.hh>
54
55 USING_UG_NAMESPACE
56 using namespace PPIF;
57
58 START_UGDIM_NAMESPACE
59
60 /****************************************************************************/
61 /* */
62 /* defines in the following order */
63 /* */
64 /* compile time constants defining static data size (i.e. arrays) */
65 /* other constants */
66 /* macros */
67 /* */
68 /****************************************************************************/
69
70 #define BUFFER_SIZE_FACTOR 3
71 #define MIN_BUFFER_SIZE 256
72
73
74 /****************************************************************************/
75 /* */
76 /* definition of static variables */
77 /* */
78 /****************************************************************************/
79
80 /**
81 * number of users of DDD.
82 * Managed by calls to `DDD_Init` and `DDD_Exit`.
83 * Resources are only freed by `DDD_Exit` when `dddUsers` is zero.
84 *
85 * This variable will be removed once no global state for DDD remains.
86 */
87 static unsigned int dddUsers = 0;
88
89
90 /****************************************************************************/
91 /* */
92 /* routines */
93 /* */
94 /****************************************************************************/
95
96 static void *LowComm_DefaultAlloc (size_t s)
97 {
98 return memmgr_AllocTMEM(s, TMEM_LOWCOMM);
99 }
100
101 static void LowComm_DefaultFree (void *buffer)
102 {
103 memmgr_FreeTMEM(buffer, TMEM_LOWCOMM);
104 }
105
106
107
108 /****************************************************************************/
109 /* */
110 /* Function: DDD_Init */
111 /* */
112 /****************************************************************************/
113
114 /**
115 Initialisation of the DDD library.
116 This function has to be called before any other function
117 of the DDD library is called. It initializes the underlying
118 PPIF-library, sets all DDD options to their default values
119 and initiates all DDD subsystems.
120
121 As some of the memory handler calls will be initiated during
122 the execution of this function, the memory manager has to be
123 initialized before calling \funk{Init}.
124 */
125
126 void DDD_Init(DDD::DDDContext& context)
127 {
128 dddUsers += 1;
129
130 /* init lineout-interface to stdout */
131 DDD_UserLineOutFunction = NULL;
132
133 /* check max. number of procs (limited by GID construction) */
134 if (context.procs() > MAX_PROCS)
135 DUNE_THROW(Dune::Exception,
136 "too many processors, cannot construct global IDs");
137
138 /* reset all global counters */
139 context.nObjs(0);
140 context.couplingContext().nCpls = 0;
141 context.couplingContext().nCplItems = 0;
142
143 /* init all DDD components */
144 NotifyInit(context);
145 LC_Init(context, LowComm_DefaultAlloc, LowComm_DefaultFree);
146 ddd_StatInit();
147 ddd_TypeMgrInit(context);
148 ddd_ObjMgrInit(context);
149 ddd_CplMgrInit(context);
150 ddd_TopoInit(context);
151 ddd_IdentInit(context);
152 ddd_IFInit(context);
153 ddd_XferInit(context);
154 ddd_PrioInit(context);
155 ddd_JoinInit(context);
156 ddd_ConsInit(context);
157
158 /* set options on default values */
159 DDD_SetOption(context, OPT_WARNING_VARSIZE_OBJ, OPT_ON);
160 DDD_SetOption(context, OPT_WARNING_SMALLSIZE, OPT_ON);
161 DDD_SetOption(context, OPT_WARNING_PRIOCHANGE, OPT_ON);
162 DDD_SetOption(context, OPT_WARNING_DESTRUCT_HDR, OPT_ON);
163 DDD_SetOption(context, OPT_DEBUG_XFERMESGS, OPT_OFF);
164 DDD_SetOption(context, OPT_QUIET_CONSCHECK, OPT_OFF);
165 DDD_SetOption(context, OPT_IDENTIFY_MODE, IDMODE_LISTS);
166 DDD_SetOption(context, OPT_WARNING_REF_COLLISION, OPT_ON);
167 DDD_SetOption(context, OPT_INFO_XFER, XFER_SHOW_NONE);
168 DDD_SetOption(context, OPT_INFO_JOIN, JOIN_SHOW_NONE);
169 DDD_SetOption(context, OPT_WARNING_OLDSTYLE, OPT_ON);
170 DDD_SetOption(context, OPT_INFO_IF_WITH_ATTR, OPT_OFF);
171 DDD_SetOption(context, OPT_XFER_PRUNE_DELETE, OPT_OFF);
172 DDD_SetOption(context, OPT_IF_REUSE_BUFFERS, OPT_OFF);
173 DDD_SetOption(context, OPT_IF_CREATE_EXPLICIT, OPT_OFF);
174 DDD_SetOption(context, OPT_CPLMGR_USE_FREELIST, OPT_ON);
175 }
176
177
178
179 /****************************************************************************/
180 /* */
181 /* Function: DDD_Exit */
182 /* */
183 /****************************************************************************/
184
185 /**
186 Clean-up of the DDD library.
187 This function frees memory previously allocated by DDD and finally
188 finishes up the PPIF library. After the call to \funk{Exit}
189 further usage of the DDD library is no longer possible during this program
190 run.
191
192 The clean-up of the memory manager should happen afterwards and is left
193 to the DDD application programmer.
194 */
195
196 void DDD_Exit(DDD::DDDContext& context)
197 {
198 dddUsers -= 1;
199 if (dddUsers > 0)
200 return;
201
202 /* close up all DDD components */
203 ddd_ConsExit(context);
204 ddd_JoinExit(context);
205 ddd_PrioExit(context);
206 ddd_XferExit(context);
207 ddd_IFExit(context);
208 ddd_IdentExit(context);
209 ddd_TopoExit(context);
210 ddd_CplMgrExit(context);
211 ddd_ObjMgrExit(context);
212 ddd_TypeMgrExit(context);
213 ddd_StatExit();
214 LC_Exit(context);
215 NotifyExit(context);
216 }
217
218
219
220 /****************************************************************************/
221 /* */
222 /* Function: DDD_Status */
223 /* */
224 /****************************************************************************/
225
226 /**
227 Show global status information.
228 This function displays information concerning both
229 the compile-time parameters of the DDD-library and some important
230 runtime-variables. Overview of compile time parameters that will
231 be displayed:
232
233 \begin{tabular}{l|l}
234 Parameter & Description\\ \hline
235 DDD-Version & current library version number\\ ##
236 #MAX_TYPEDESC# & maximum number of #DDD_TYPE# IDs\\ ##
237 #MAX_OBJ# & maximum number of DDD-objects on one processor\\ ##
238 #MAX_CPL# & maximum number of couplings on one processor\\ ##
239 \end{tabular}
240 */
241
242 void DDD_Status(const DDD::DDDContext& context)
243 {
244 using std::setw;
245 std::ostream& out = std::cout;
246
247 out << "| DDD_Status for proc=" << setw(3) << context.me()
248 << ", DDD-Version " << DDD_VERSION << "\n"
249 << "|\n"
250 << "| MAX_ELEMDESC = " << setw(4) << TYPE_DESC::MAX_ELEMDESC << "\n"
251 << "| MAX_TYPEDESC = " << setw(4) << MAX_TYPEDESC << "\n"
252 << "| MAX_PROCS = " << setw(4) << MAX_PROCS << "\n"
253 << "| MAX_PRIO = " << setw(4) << MAX_PRIO << "\n"
254 << "|\n";
255 #ifdef WithFullObjectTable
256 out << "| MAX_OBJ = " << setw(8) << context.objTable().size()
257 << " MAX_CPL = " << context.couplingContext().cplTable.size() << "\n";
258 #else
259 out << "| MAX_CPL = " << context.couplingContext().cplTable.size() << "\n";
260 #endif
261
262 out << "| nObjs = " << setw(8) << context.nObjs()
263 << " nCpls = " << setw(8) << context.couplingContext().nCpls
264 << " nCplItems = " << setw(8) << context.couplingContext().nCplItems << "\n"
265 << "|\n"
266 << "| Timeouts:\n"
267 << "| IFComm: " << setw(12) << MAX_TRIES << "\n"
268 << "|\n"
269 << "| Compile-Time Options: ";
270
271 # ifdef Statistics
272 out << "Statistics ";
273 # endif
274
275 out << "\n";
276 }
277
278
279
280
281 /****************************************************************************/
282 /* */
283 /* Function: DDD_LineOutRegister */
284 /* */
285 /****************************************************************************/
286
287 /**
288 Redirect text output.
289 This function sets the DDD-textport to a given handler function.
290 The handler should be declared as follows:
291
292 #void func(char *line_of_text)#
293
294 Instead of printing text for error, debugging and info messages
295 directly to {\em standard output}, DDD will redirect all output
296 one line at a time and send it to the handler {\em func}.
297 This can be used to send each processor's output into a separate file.
298
299 @param func handler function which should be used for text redirection
300 */
301
302 void DDD_LineOutRegister (void (*func)(const char *s))
303 {
304 DDD_UserLineOutFunction = func;
305 }
306
307
308
309
310 /****************************************************************************/
311 /* */
312 /* Function: DDD_SetOption */
313 /* */
314 /****************************************************************************/
315
316 /**
317 Set a DDD-option to a given value.
318 The current behaviour of the DDD library can be configured
319 at runtime by setting a variety of options to given values.
320 For each option, there is a default setting and a set of
321 possible values. See \Ref{DDD Options} for a description
322 of all possible options with their default settings and
323 meaning.
324
325 @param option DDD option specifier
326 @param value option value, possible values depend on option specifier
327 */
328
329 void DDD_SetOption (DDD::DDDContext& context, DDD_OPTION option, int value)
330 {
331 if (option>=OPT_END)
332 {
333 Dune::dwarn << "DDD_SetOption: invalid DDD_OPTION\n";
334 return;
335 }
336
337 context.options()[option] = value;
338 }
339
340
341
342 /****************************************************************************/
343 /* */
344 /* Function: DDD_GetOption (not exported) */
345 /* */
346 /* Purpose: get DDD runtime options */
347 /* */
348 /* Input: option: OptionType of option to get */
349 /* */
350 /* Output: value of option */
351 /* */
352 /****************************************************************************/
353
354 int DDD_GetOption(const DDD::DDDContext& context, DDD_OPTION option)
355 {
356 if (option>=OPT_END)
357 {
358 Dune::dwarn << "DDD_GetOption: invalid DDD_OPTION\n";
359 return 0;
360 }
361
362 return context.options()[option];
363 }
364
365 END_UGDIM_NAMESPACE