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