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
|
/*@@
@file LoadAware.c
@date Fri Feb 21 10:21:36 2000
@author Matei Ripeanu
@desc
@enddesc
@version $Id$
@@*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "pugh.h"
#include "cctk.h"
#include "cctk_Parameters.h"
static const char *rcsid="$Header$";
CCTK_FILEVERSION(CactusPUGH_PUGH_LoadAware_c);
/* prototypes of routines defined in this source file */
int PUGH_SetPartitionInfo (int dim, const char *partition_info[]);
static void PUGH_GetSliceSizes (int np,
int grid_points,
const char *slicesS,
int **slices,
int manual);
/* static pointers to strings which contain partition information if set */
static char *partition_1D[1] = {NULL};
static char *partition_2D[2] = {NULL, NULL};
static char *partition_3D[3] = {NULL, NULL, NULL};
/*@@
@routine PUGH_SetPartitionInfo
@date Tue 13 Feb 2001
@author Thomas Radke
@desc
Set/reset the static partition info string variables.
Note that using such static variables here instead of the
partition_[123]d_[xyz] parameters is just a hack because
we don't want to make those steerable (this could make
people think they can change the processor topology at
runtime).
But eg. BAM wants to set up a new topology when creating
new grids.
@enddesc
@var dim
@vdesc number of dimensions of processor topology
@vtype int
@vio in
@endvar
@var partition_info
@vdesc list of strings with partition information
@vtype const char *[dim]
@vio in
@endvar
@returntype int
@returndesc
0: OK
-1: invalid dimension
@endreturndesc
@@*/
int PUGH_SetPartitionInfo (int dim, const char *partition_info[])
{
int retval;
retval = 0;
if (dim == 1)
{
if (partition_1D[0])
{
free (partition_1D[0]);
}
partition_1D[0] = strdup (partition_info[0]);
}
else if (dim == 2)
{
if (partition_2D[0])
{
free (partition_2D[0]);
}
if (partition_2D[1])
{
free (partition_2D[1]);
}
partition_2D[0] = strdup (partition_info[0]);
partition_2D[1] = strdup (partition_info[1]);
}
else if (dim == 3)
{
if (partition_3D[0])
{
free (partition_3D[0]);
}
if (partition_3D[1])
{
free (partition_3D[1]);
}
if (partition_3D[2])
{
free (partition_3D[2]);
}
partition_3D[0] = strdup (partition_info[0]);
partition_3D[1] = strdup (partition_info[1]);
partition_3D[2] = strdup (partition_info[2]);
}
else
{
CCTK_WARN (1, "Only 1D, 2D, and 3D supported");
retval = -1;
}
return (retval);
}
/*@@
@routine PUGH_GetBounds
@date Fri Feb 21 10:21:36 2000
@author Matei Ripeanu
@desc
@enddesc
@calls PUGH_GetSliceSizes
@var is_gf
@vdesc flag indicating that bounds are to be set up for a grid function
@vtype int
@vio in
@endvar
@var dim
@vdesc dimension to set up bounds for
@vtype int
@vio in
@endvar
@var bounds
@vdesc bounds to be allocated and set up
@vtype *int [dim-1]
@vio out
@endvar
@var dim
@vdesc processors in every direction
@vtype int [dim-1]
@vio in
@endvar
@var nsize
@vdesc points in every direction
@vtype int [dim-1]
@vio in
@endvar
@returntype int
@returndesc
0: OK
-1: invalid dimension
@endreturndesc
@@*/
int PUGH_GetBounds (int is_gf, int dim, int *bounds[], int nprocs[], int nsize[])
{
DECLARE_CCTK_PARAMETERS
int i, retval, manual, external_manual;
const char *partition_info;
retval = 0;
manual = CCTK_Equals (partition, "manual");
if (dim == 1)
{
external_manual = partition_1D[0] != NULL;
partition_info = external_manual ? (const char *) partition_1D[0] :
partition_1d_x;
PUGH_GetSliceSizes (nprocs[0], nsize[0], partition_info, &bounds[0],
is_gf && (manual || external_manual));
}
else if (dim == 2)
{
external_manual = partition_2D[0] != NULL;
partition_info = external_manual ? (const char *) partition_2D[0] :
partition_2d_x;
PUGH_GetSliceSizes (nprocs[0], nsize[0], partition_info, &bounds[0],
is_gf && (manual || external_manual));
external_manual = partition_2D[1] != NULL;
partition_info = external_manual ? (const char *) partition_2D[1] :
partition_2d_y;
PUGH_GetSliceSizes (nprocs[1], nsize[1], partition_info, &bounds[1],
is_gf && (manual || external_manual));
}
else if (dim == 3)
{
external_manual = partition_3D[0] != NULL;
partition_info = external_manual ? (const char *) partition_3D[0] :
partition_3d_x;
PUGH_GetSliceSizes (nprocs[0], nsize[0], partition_info, &bounds[0],
is_gf && (manual || external_manual));
external_manual = partition_3D[1] != NULL;
partition_info = external_manual ? (const char *) partition_3D[1] :
partition_3d_y;
PUGH_GetSliceSizes (nprocs[1], nsize[1], partition_info, &bounds[1],
is_gf && (manual || external_manual));
external_manual = partition_3D[2] != NULL;
partition_info = external_manual ? (const char *) partition_3D[2] :
partition_3d_z;
PUGH_GetSliceSizes (nprocs[2], nsize[2], partition_info, &bounds[2],
is_gf && (manual || external_manual));
}
else
{
if (is_gf && manual)
{
CCTK_WARN (1, "Only 1D, 2D, and 3D supported in manual topology setup");
retval = -1;
}
else
{
for (i = 0; i < dim; i++)
{
PUGH_GetSliceSizes (nprocs[i], nsize[i], NULL, &bounds[i], 0);
}
}
}
return (retval);
}
/*@@
@routine PUGH_GetSliceSizes
@date Fri Feb 21 10:21:36 2000
@author Matei Ripeanu
@desc
Computes partition based on parameter information
@enddesc
@var np
@vdesc number of processors in this direction
@vtype int
@vio in
@endvar
@var grid_points
@vdesc number of grid points in this direction
@vtype int
@vio in
@endvar
@var slicesS
@vdesc line in parameter file, format "10:10:10"
@vtype char *
@vio in
@endvar
@var slices
@vdesc grid points foe each processor, int array
@vtype int **
@vio inout
@endvar
@var manual
@vdesc manual or automatic partition
@vtype int
@vio in
@endvar
@@*/
static void PUGH_GetSliceSizes (int np,
int grid_points,
const char *slicesS,
int **slices,
int manual)
{
int tmp, i=0, rt=0;
*slices = malloc (np * sizeof (int));
if (! *slices)
{
CCTK_WARN (0, "Not enough memory");
}
if (manual && *slicesS)
{
while (*slicesS)
{
if (i >= np)
{
CCTK_WARN (0, "Wrong partition parameters: "
"expect data for fewer processors");
}
sscanf (slicesS, "%d", &tmp);
(*slices)[i] = i ? rt - 1 : 0;
rt += tmp;
i++;
while (isdigit ((int) *slicesS))
{
slicesS++;
}
while (*slicesS && ! isdigit ((int) *slicesS))
{
slicesS++;
}
}
if (i != np)
{
CCTK_WARN (0, "Wrong partition parameters: "
"expect data for more processors");
}
if (rt != grid_points)
{
CCTK_WARN (0, "Wrong partition parameters: "
"total number of grid points doesnt match");
}
}
else
{
for (i = 0; i < np; i++)
{
(*slices)[i] = rt;
rt += (grid_points - rt -1) / (np - i);
}
}
}
|