70 fprintf(stderr,
"To be compatible with multigrid level %d, this\n"
71 "must be a multiple of %d.\n",
80 for (
int i=0;
i<3;
i++) {
81 if (ret[
i]<0) ret[
i]=0;
100 for (
unsigned int c=0;c<
BCs[f].size();c++) {
116 fprintf(stderr,
"Asked to split block into %d pieces!\n",
120 else if (nPieces==1) {
123 dest.push_back(
this);
131 for (
int a=0;a<3;a++)
132 if (
dim[a]>splitLen) {
137 int splitLen=
dim[splitAxis];
140 int loPieces=(int)floor(nPieces/2.0);
141 int hiPieces=nPieces-loPieces;
144 loSize=(int)(splitLen/2);
146 loSize=splitLen*loPieces/nPieces;
152 fprintf(stderr,
"Couldn't split block %d any further-- you must:\n"
153 " -increase the input grid resolution\n"
154 " -decrease the number of requested output blocks\n"
164 blockDim hiStart=origin; hiStart[splitAxis]=loSize;
173 lo->
split(loPieces,dest);
174 hi->
split(hiPieces,dest);
208 if ((
int)blocks.size()>=nPieces)
215 unsigned int b,nBlocks=blocks.size();
217 int *nSplit=
new int[nBlocks];
221 for (b=0;b<nBlocks;b++) {
227 vector<bRec> heap(nBlocks);
228 for (b=0;b<nBlocks;b++) {
233 std::make_heap(heap.begin(),heap.end(),
bRec::less);
236 int nRemaining=nPieces-nBlocks;
237 while (nRemaining-->0) {
238 std::pop_heap(heap.begin(),heap.end(),
bRec::less);
239 bRec &r=heap[nBlocks-1];
241 std::push_heap(heap.begin(),heap.end(),
bRec::less);
246 vector<block *> split;
247 for (b=0;b<nBlocks;b++) {
248 printf(
"Input block %d splits into %d pieces (%d-%d)\n",
249 b+1,nSplit[b],(
int)(1+split.size()),(
int)(1+split.size()+nSplit[b]-1));
250 blocks[b]->split(nSplit[b],split);
255 double maxVol=-1e100,minVol=1e100,sumVol=0;
256 for (b=0;b<split.size();b++) {
257 double vol=
volume(split[b]);
259 if (maxVol<vol) maxVol=vol;
260 if (minVol>vol) minVol=vol;
262 double avgVol=sumVol/split.size();
263 printf(
"Static load balance results:\n"
264 " %.2f blocks per processor, %.0f nodes per block\n"
265 " Heaviest block is %.02f times the average\n"
266 " Lightest block is %.02f times the average\n",
267 ((
double)split.size())/nPieces,avgVol,
268 maxVol/avgVol,minVol/avgVol);
int getOriginalNumber(void) const
void addBC(const blockSpan &span, int bcNo)
vector< externalBCpatch > BCs[nFaces]
block * subBlock(const blockSpan &span) const
void multigridError(void)
blockDim getDim(void) const
#define BLOCKSPAN_FOR(i, span)
int volume(const block *b)
const blockDim & getDim(void) const
const char * splitBlocks(vector< block * > &blocks, int nPieces)
blockLoc pin(const blockLoc &l) const
static bool less(const bRec &a, const bRec &b)
bool blocks
Input data is block-structured grid.
block(const blockDim &dim_, int originalNo_, int blockNo_, vector3d *nodeLocs_)
void split(int nPieces, vector< block * > &dest)