Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
split.cpp File Reference
#include <math.h>
#include "face.h"
#include "makeflo.h"
#include <algorithm>
Include dependency graph for split.cpp:

Go to the source code of this file.

Classes

class  bRec
 

Functions

int volume (const block *b)
 
const char * splitBlocks (vector< block * > &blocks, int nPieces)
 

Function Documentation

const char* splitBlocks ( vector< block * > &  blocks,
int  nPieces 
)

Definition at line 205 of file split.cpp.

References bRec::less(), parameters, makefloParam::splithalf, and volume().

Referenced by main().

207 {
208  if ((int)blocks.size()>=nPieces)
209  return NULL;//Already have enough blocks
210 
211 
212 //We try to split so that the resulting blocks
213 // have about the same volume-- distribute pieces
214 // to blocks by volume
215  unsigned int b,nBlocks=blocks.size();
216 
217  int *nSplit=new int[nBlocks];
218 
219  if (parameters.splithalf == 1) {
220  // split every block in half
221  for (b=0;b<nBlocks;b++) {
222  nSplit[b]=2;
223  }
224  }
225  else { // regular split
226  //Create max-heap of blocks, ordered by output volume
227  vector<bRec> heap(nBlocks);
228  for (b=0;b<nBlocks;b++) {
229  heap[b]=bRec(b,volume(blocks[b]));
230  nSplit[b]=1;
231  }
232 
233  std::make_heap(heap.begin(),heap.end(),bRec::less);
234 
235  //Allocate remaining output blocks to the most needy
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];
240  r.n=++(nSplit[r.b]);
241  std::push_heap(heap.begin(),heap.end(),bRec::less);
242  }
243  } // end of parameters.splithalf
244 
245  //Split the blocks
246  vector<block *> split;//Accumulates split blocks
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);
251  }
252  delete[] nSplit;
253 
254 //Check the load balance
255  double maxVol=-1e100,minVol=1e100,sumVol=0;
256  for (b=0;b<split.size();b++) {
257  double vol=volume(split[b]);
258  sumVol+=vol;
259  if (maxVol<vol) maxVol=vol;
260  if (minVol>vol) minVol=vol;
261  }
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);
269 
270 //Return split blocks to caller
271  blocks=split;
272  return NULL;
273 }
int splithalf
Definition: makeflo.h:97
int volume(const block *b)
Definition: split.cpp:181
static bool less(const bRec &a, const bRec &b)
Definition: split.cpp:198
Definition: split.cpp:186
makefloParam parameters
Definition: makeflo.cpp:101
int n
Definition: split.cpp:190

Here is the call graph for this function:

Here is the caller graph for this function:

int volume ( const block b)

Definition at line 181 of file split.cpp.

References block::getDim(), and blockDim::getSize().

Referenced by checkQuality(), Rocsurf::compute_bounded_volumes(), Rocsurf::compute_swept_volumes(), get_face_volume(), lass(), splitBlocks(), and volumehexa().

181  {
182  return b->getDim().getSize();
183 }
const blockDim & getDim(void) const
Definition: adj.h:222
int getSize(void) const
Definition: gridutil.h:126

Here is the call graph for this function:

Here is the caller graph for this function: