1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
|
/*@@
@file GHExtension.c
@date Thu Feb 4 10:47:14 1999
@author Tom Goodale
@desc
Pugh GH extension stuff.
@enddesc
@version $Id$
@@*/
/* #define DEBUG_PUGH 1 */
#include <stdlib.h>
#include <string.h>
#include "cctk.h"
#include "cctk_Schedule.h"
#include "cctk_Parameters.h"
#include "pugh.h"
#include "pugh_extension.h"
static const char *rcsid = "$Header$";
CCTK_FILEVERSION(CactusPUGH_pugh_GHExtension_c)
/* prototypes of routines defined in this source file */
int PUGH_PrintTimingInfo (cGH *GH);
void PUGH_RegisterCallFunc (int (* func) (void *function,
cFunctionData *fdata,
void *data));
static int (* PUGHCallFunc)(void *function, cFunctionData *fdata, void *data) = NULL;
/*@@
@routine PUGH_SetupGH
@date Wed Feb 3 23:10:19 1999
@author Tom Goodale
@desc
Sets up a new PUGH GH extension structure.
@enddesc
@calls PUGH_GFSize
PUGH_GFGhostsize
PUGH_GFPeriodic
PUGH_SetupPGH
CCTK_GroupData
CCTK_GroupSizesI
CCTK_GroupGhostsizesI
PUGH_SetupGroup
@var config
@vdesc pointer to flesh configuration structure
@vtype tFleshConfig *
@vio not used
@endvar
@var convergence_level
@vdesc convergence level of this GH
@vtype int
@vio not used
@endvar
@var GH
@vdesc pointer to CCTK grid hierarchy
@vtype cGH *
@vio out
@endvar
@returntype void *
@returndesc
pointer to new PUGH GH extension, or NULL in case of errors.
@endreturndesc
@@*/
void *PUGH_SetupGH (tFleshConfig *config,
int convergence_level,
cGH *GH)
{
int i, group, maxdim;
pGH *newGH;
cGroup pgroup;
CCTK_INT **size;
int *nsize, *ghostsize, *perme, *groupghostsize, *groupsize;
DECLARE_CCTK_PARAMETERS
/* avoid compiler warnings about unused parameters */
config = config;
convergence_level = convergence_level;
/* Set up the GH */
maxdim = CCTK_MaxDim ();
nsize = (int *) malloc (5 * maxdim * sizeof (int));
ghostsize = nsize + 1*maxdim;
perme = nsize + 2*maxdim;
PUGH_GFSize (maxdim, nsize);
PUGH_GFGhostsize (maxdim, ghostsize);
PUGH_GFPeriodic (maxdim, perme);
newGH = PUGH_SetupPGH (GH, maxdim, nsize, ghostsize,
CCTK_StaggerVars() ? PUGH_STAGGER : PUGH_NO_STAGGER,
perme);
if (!newGH)
{
CCTK_WARN (0, "Failed to allocate memory for a pGH");
}
/* Set the identity for this pGH. For now this is an empty string. */
newGH->identity_string = (char *) calloc (1, sizeof (char));
/* Set up groups on the GH */
for (group = 0; group < CCTK_NumGroups (); group++)
{
CCTK_GroupData (group, &pgroup);
groupsize = nsize + 3*maxdim;
groupghostsize = nsize + 4*maxdim;
/* Set the global size of the variables in the group */
size = CCTK_GroupSizesI (group);
if (size)
{
for (i = 0; i < pgroup.dim; i++)
{
groupsize[i] = *size[i];
/* Check distribution type */
if (pgroup.disttype == CCTK_DISTRIB_CONSTANT)
{
groupsize[i] = -groupsize[i];
}
}
}
else
{
groupsize = NULL;
}
/* Set the ghostzone size of the variables in the group */
size = CCTK_GroupGhostsizesI (group);
if (size)
{
for (i = 0; i < pgroup.dim; i++)
{
groupghostsize[i] = *size[i];
}
}
else if (pgroup.grouptype == CCTK_ARRAY)
{
memset (groupghostsize, 0, pgroup.dim * sizeof (int));
}
else
{
groupghostsize = NULL;
}
PUGH_SetupGroup (newGH, groupsize, groupghostsize, pgroup.grouptype,
pgroup.vartype, pgroup.dim, pgroup.numvars,
pgroup.stagtype, pgroup.numtimelevels,pgroup.vectorgroup);
}
/* clean up */
free (nsize);
return (newGH);
}
/*@@
@routine PUGH_InitGHBasics
@date Thu May 11 2000
@author Thomas Radke
@desc
Initializes the basic fields of a cGH structure.
@enddesc
@var GH
@vdesc pointer to CCTK grid hierarchy
@vtype cGH *
@vio out
@endvar
@@*/
static void PUGH_InitGHBasics (cGH *GH)
{
int dim, stagger;
pGH *mypGH;
pGExtras *GFExtras;
mypGH = PUGH_pGH (GH);
if (GH->cctk_dim > 0)
{
GFExtras = mypGH->GFExtras[GH->cctk_dim - 1];
}
else
{
GFExtras = NULL;
}
GH->identity = mypGH->identity_string;
GH->cctk_convlevel = 0;
for (dim = 0; dim < GH->cctk_dim; dim++)
{
GH->cctk_levfac[dim] = 1;
GH->cctk_nghostzones[dim] = GFExtras->nghostzones[dim];
GH->cctk_lsh[dim] = GFExtras->lnsize[dim];
GH->cctk_gsh[dim] = GFExtras->nsize[dim];
GH->cctk_bbox[2*dim] = GFExtras->bbox[2*dim];
GH->cctk_bbox[2*dim+1] = GFExtras->bbox[2*dim+1];
GH->cctk_lbnd[dim] = GFExtras->lb[mypGH->myproc][dim];
GH->cctk_ubnd[dim] = GFExtras->ub[mypGH->myproc][dim];
for (stagger = 0; stagger < CCTK_NSTAGGER; stagger++)
{
GH->cctk_lssh[CCTK_LSSH_IDX (stagger, dim)] = GH->cctk_lsh[dim];
if (GH->cctk_bbox[2*dim + 1] == 1 && stagger > 0)
{
GH->cctk_lssh[CCTK_LSSH_IDX (stagger, dim)]--;
}
}
}
}
/*@@
@routine PUGH_InitGHVariables
@date Thu May 11 2000
@author Thomas Radke
@desc
Initializes the variables of a cGH structure.
@enddesc
@calls CCTK_GroupTypeFromVarI
CCTK_NumTimeLevelsFromVarI
@var GH
@vdesc pointer to CCTK grid hierarchy
@vtype cGH *
@vio out
@endvar
@@*/
static void PUGH_InitGHVariables (cGH *GH)
{
int var, gtype, level, ntimelevels;
pGH *mypGH;
mypGH = PUGH_pGH (GH);
for (var = 0; var < mypGH->nvariables; var++)
{
gtype = CCTK_GroupTypeFromVarI (var);
ntimelevels = CCTK_NumTimeLevelsFromVarI (var);
for (level = 0; level < ntimelevels; level++)
{
switch (gtype)
{
case CCTK_SCALAR:
GH->data[var][level] = mypGH->variables[var][level];
break;
case CCTK_GF:
case CCTK_ARRAY:
GH->data[var][level] = ((pGA *) mypGH->variables[var][level])->data;
break;
default:
CCTK_WARN (1, "PUGH_InitGHVariables: Unknown group type");
}
}
}
}
/*@@
@routine PUGH_InitGH
@date Wed Feb 3 23:10:19 1999
@author Tom Goodale
@desc
Initialization routine for a given GH structure.
@enddesc
@calls CCTK_NumGroups
CCTK_GroupName
CCTK_EnableGroupStorage
@var GH
@vdesc pointer to CCTK grid hierarchy
@vtype cGH *
@vio out
@endvar
@returntype void *
@returndesc
always returns 0
@endreturndesc
@@*/
int PUGH_InitGH (cGH *GH)
{
int i;
DECLARE_CCTK_PARAMETERS
PUGH_InitGHBasics (GH);
/* Enable storage for all variables if required */
if (enable_all_storage)
{
for (i = 0; i < CCTK_NumGroups (); i++)
{
CCTK_EnableGroupStorage (GH, CCTK_GroupName (i));
}
}
return (0);
}
/*@@
@routine PUGH_ScheduleTraverseGH
@date Thu Jan 27 15:14:09 2000
@author Tom Goodale
@desc
Fills out the cGH and then calls schedule traverse.
@enddesc
@calls
@history
@hdate Thu Jan 27 15:15:35 2000
@hauthor Tom Goodale
@hdesc Was originally PUGH_rfrTraverse
@hdate Thu May 11 2000
@hauthor Thomas Radke
@hdesc Splitted pGH setup into PUGH_InitGHBasics() and
PUGH_InitGHVariables()
@endhistory
@var GH
@vdesc pointer to CCTK grid hierarchy
@vtype cGH *
@vio in
@endvar
@var where
@vdesc name of this scheduling bin
@vtype const char *
@vio in
@endvar
@returntype void *
@returndesc
return code of @seeroutine CCTK_ScheduleTraverse
@endreturndesc
@@*/
int PUGH_ScheduleTraverseGH (cGH *GH,
const char *where)
{
int retval;
if (strcmp ("CCTK_SHUTDOWN", where))
{
PUGH_InitGHBasics (GH);
PUGH_InitGHVariables (GH);
}
retval = CCTK_ScheduleTraverse (where, GH, PUGHCallFunc);
return (retval);
}
void PUGH_RegisterCallFunc (int (* func) (void *function,
cFunctionData *fdata,
void *data))
{
PUGHCallFunc = func;
}
/*@@
@routine PUGH_GFSize
@date Wed Feb 3 23:10:19 1999
@author Tom Goodale
@desc
Gets the size of a grid function of a given dimension.
FIXME: This cannot be made static' because it is used by
thorn BAM_Elliptic.
@enddesc
@var dim
@vdesc dimension of the grid function
@vtype int
@vio in
@endvar
@var nsize
@vdesc size in every direction
@vtype int *
@vio out
@endvar
@@*/
/* static */ void PUGH_GFSize (int dim, int *nsize)
{
int dir, size;
DECLARE_CCTK_PARAMETERS
if (global_nsize > 0 || local_nsize > 0)
{
size = global_nsize > 0 ? global_nsize : -local_nsize;
for (dir = 0; dir < dim; dir++)
{
nsize[dir] = size;
}
}
else
{
switch (dim)
{
case 3: nsize[2] = local_nz > 0 ? -local_nz : global_nz;
case 2: nsize[1] = local_ny > 0 ? -local_ny : global_ny;
case 1: nsize[0] = local_nx > 0 ? -local_nx : global_nx;
}
}
}
/*@@
@routine PUGH_GFGhostsize
@date Wed Feb 3 23:10:19 1999
@author Tom Goodale
@desc
Gets the ghostsize of a grid function of a given dimension.
FIXME: This cannot be made static' because it is used by
thorn BAM_Elliptic.
@enddesc
@var dim
@vdesc dimension of the grid function
@vtype int
@vio in
@endvar
@var ghostsize
@vdesc ghostsize in every direction
@vtype int *
@vio out
@endvar
@@*/
/* static */ void PUGH_GFGhostsize (int dim, int *ghostsize)
{
int dir;
DECLARE_CCTK_PARAMETERS
if (ghost_size >= 0)
{
for (dir = 0; dir < dim; dir++)
{
ghostsize[dir] = ghost_size;
}
}
else
{
memset (ghostsize, 0, dim);
switch (dim)
{
case 3: ghostsize[2] = ghost_size_z;
case 2: ghostsize[1] = ghost_size_y;
case 1: ghostsize[0] = ghost_size_x;
}
}
}
/*@@
@routine PUGH_GFPeriodic
@date Wed Feb 3 23:10:19 1999
@author Tom Goodale
@desc
Gets the periodic BC of a grid function of a given dimension.
FIXME: This cannot be made static' because it is used by
thorn BAM_Elliptic.
@enddesc
@var dim
@vdesc dimension of the grid function
@vtype int
@vio in
@endvar
@var perme
@vdesc periodicity in every direction
@vtype int *
@vio out
@endvar
@@*/
/* static */ void PUGH_GFPeriodic (int dim, int *perme)
{
DECLARE_CCTK_PARAMETERS
if (periodic)
{
switch (dim)
{
case 3: perme[2] = periodic_z;
case 2: perme[1] = periodic_y;
case 1: perme[0] = periodic_x;
}
}
else
{
memset (perme, 0, dim * sizeof (int));
}
}
/*@@
@routine PUGH_PrintTimingInfo
@date Wed Feb 3 23:10:19 1999
@author Tom Goodale
@desc
Prints the info from PUGH communication timers to stdout.
@enddesc
@var GH
@vdesc pointer to CCTK grid hierarchy
@vtype cGH *
@vio out
@endvar
@returntype int
@returndesc
always returns 0
@endreturndesc
@@*/
int PUGH_PrintTimingInfo (cGH *GH)
{
int i;
cTimerData *info;
pGH *pughGH = PUGH_pGH (GH);
if (pughGH->comm_time < 0)
{
return 0;
}
info = CCTK_TimerCreateData ();
if (info)
{
CCTK_INFO ("Elapsed time spent in communication:");
CCTK_TimerI (pughGH->comm_time, info);
for (i = 0; i < info->n_vals; i++)
{
switch (info->vals[i].type)
{
case val_int:
CCTK_VInfo (CCTK_THORNSTRING, " %s: %d %s", info->vals[i].heading,
info->vals[i].val.i, info->vals[i].units);
break;
case val_long:
CCTK_VInfo (CCTK_THORNSTRING, " %s: %d %s", info->vals[i].heading,
(int) info->vals[i].val.l, info->vals[i].units);
break;
case val_double:
CCTK_VInfo (CCTK_THORNSTRING, " %s: %.3f %s", info->vals[i].heading,
info->vals[i].val.d, info->vals[i].units);
break;
default:
CCTK_WARN (1, "Unknown data type for timer info");
break;
}
}
CCTK_TimerDestroyData (info);
}
else
{
CCTK_WARN (1, "Couldn't create timer info structure ! "
"No timing output available.");
}
return (0);
}
|