30#ifdef __VRB_DIAGNOSTIC__
40recurseCoordinateVRB(
int dim,
41 const int *strides,
const int* sizes,
const int *offsets,
42 int nprocs,
int firstProc,
int *procs );
74 int *offsets =
new int[dim];
79 int *strides =
new int[dim];
81 for (i=dim-2; i>=0; --i)
82 strides[i] = strides[i+1]*sizes[i+1];
85 recurseCoordinateVRB(dim,strides,sizes,offsets,nprocs,0,procs);
108assign(
int dim,
const int *strides,
const int *sizes,
const int *offsets,
119#ifdef __VRB__DIAGNOSTIC__
120 printf(
"---------- assign ----------\n");
121 printf(
"dim=%d, sizes=",dim);
122 for (i=0; i<dim; ++i)
123 printf(
" %d",sizes[i]);
124 printf(
", offsets=");
125 for (i=0; i<dim; ++i)
126 printf(
" %d",offsets[i]);
127 printf(
", strides=");
128 for (i=0; i<dim; ++i)
129 printf(
" %d",strides[i]);
130 printf(
", procs=%lx\n",procs);
131 printf(
"----------------------------\n");
137 for (i=0; i<sizes[0]; ++i)
138 procs[offsets[0]+i] = x;
144 for (i=0; i<sizes[0]; ++i)
145 assign(dim-1,strides+1,sizes+1,offsets+1,x,procs+(offsets[0]+i)*strides[0]);
169recurseCoordinateVRB(
int dim,
170 const int* strides,
const int* sizes,
const int *offsets,
171 int nprocs,
int firstProc,
int *procs )
179 for (
int i=0; i<dim; ++i)
185#ifdef __VRB_DIAGNOSTIC__
186 printf(
"---------- RecurseCoordinateVRB ----------\n");
187 printf(
"dim= %d, sizes=",dim);
188 for (i=0; i<dim; ++i)
189 printf(
" %d",sizes[i]);
190 printf(
", offsets=");
191 for (i=0; i<dim; ++i)
192 printf(
" %d",offsets[i]);
193 printf(
", nprocs= %d, firstProc= %d\n",nprocs,firstProc);
194 printf(
"------------------------------------------\n");
202 assign(dim,strides,sizes,offsets,firstProc,procs);
214 int totalVnodes = sizes[0];
215 for (d=1; d<dim; ++d)
216 totalVnodes *= sizes[d];
220 int leftProcs = nprocs/2;
221 int rightProcs = nprocs-leftProcs;
226 for (d=1; d<dim; ++d)
227 if ( sizes[d] > sizes[splitDim] )
231 int splitSize = sizes[splitDim];
241 double outOfBalance = splitSize/(double)rightProcs;
246 for (d=0; d<dim; ++d)
248 crossSize *= sizes[d];
251 for (
int l=1; l<splitSize; ++l)
254 int r = splitSize - l;
255 double b = l/(double)leftProcs - r/(
double)rightProcs;
265 if ( (b < outOfBalance) &&
266 (l*crossSize>=leftProcs) &&
267 (r*crossSize>=rightProcs) )
282 int *newSizes =
new int[dim];
283 for (d=0; d<dim; ++d)
284 newSizes[d] = sizes[d];
287 int *newOffsets =
new int[dim];
288 for (d=0; d<dim; ++d)
289 newOffsets[d] = offsets[d];
292 newSizes[splitDim] = leftVnodes;
295 recurseCoordinateVRB(dim,strides,newSizes,newOffsets,leftProcs,firstProc,procs);
298 newSizes[splitDim] = splitSize - leftVnodes;
299 newOffsets[splitDim] += leftVnodes;
302 recurseCoordinateVRB(dim,strides,newSizes,newOffsets,rightProcs,firstProc+leftProcs,procs);
306 delete [] newOffsets;
312#ifdef __VRB_DIAGNOSTIC__
319print(
int dim,
const int *sizes,
const int *procs)
323 for (
int i=0; i<*sizes; ++i)
324 printf(
"%4d",procs[i]);
330 for (i=1; i<dim; ++i)
332 for (i=0; i<sizes[0]; ++i)
334 print(dim-1,sizes+1,procs+skip*i);
344main(
int argc,
char *argv[])
351 int nprocs = atoi(argv[1]);
355 int *sizes =
new int[dim];
357 for (
int d = 0; d<dim; ++d )
359 sizes[d] = atoi(argv[d+2]);
360 totalVnodes *= sizes[d];
362 int *procs =
new int[totalVnodes];
368 print(dim,sizes,procs);
int main(int argc, char *argv[])
void vnodeRecursiveBisection(int dim, const int *sizes, int nprocs, int *procs)
void assign(const BareField< T, Dim > &a, RHS b, OP op, ExprTag< true >)