00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00042 #ifndef __vtkPKdTree_h
00043 #define __vtkPKdTree_h
00044
00045 #include "vtkKdTree.h"
00046
00047 class vtkMultiProcessController;
00048 class vtkCommunicator;
00049 class vtkSubGroup;
00050 class vtkIntArray;
00051 class vtkKdNode;
00052
00053 class VTK_PARALLEL_EXPORT vtkPKdTree : public vtkKdTree
00054 {
00055 public:
00056 vtkTypeRevisionMacro(vtkPKdTree, vtkKdTree);
00057
00058
00059 void PrintSelf(ostream& os, vtkIndent indent);
00060 void PrintTiming(ostream& os, vtkIndent indent);
00061 void PrintTables(ostream& os, vtkIndent indent);
00062
00063 static vtkPKdTree *New();
00064
00069 void BuildLocator();
00070
00075 int GetTotalNumberOfCells(){return this->TotalNumCells;}
00076
00083 int CreateProcessCellCountData();
00084
00091 int CreateGlobalDataArrayBounds();
00092
00095 void SetController(vtkMultiProcessController *c);
00096 vtkGetObjectMacro(Controller, vtkMultiProcessController);
00097
00106 vtkGetMacro(RegionAssignment, int);
00107
00108 static const int NoRegionAssignment;
00109 static const int ContiguousAssignment;
00110 static const int UserDefinedAssignment;
00111 static const int RoundRobinAssignment;
00112
00117 int AssignRegions(int *map, int numRegions);
00118
00123 int AssignRegionsRoundRobin();
00124
00131 int AssignRegionsContiguous();
00132
00137 int GetRegionAssignmentList(int procId, vtkIntArray *list);
00138
00145 void GetAllProcessesBorderingOnPoint(float x, float y, float z,
00146 vtkIntArray *list);
00147
00150 int GetProcessAssignedToRegion(int regionId);
00151
00154 int HasData(int processId, int regionId);
00155
00159 int GetProcessCellCountForRegion(int processId, int regionId);
00160
00164 int GetTotalProcessesInRegion(int regionId);
00165
00169 int GetProcessListForRegion(int regionId, vtkIntArray *processes);
00170
00176 int GetProcessesCellCountForRegion(int regionId, int *count, int len);
00177
00181 int GetTotalRegionsForProcess(int processId);
00182
00186 int GetRegionListForProcess(int processId, vtkIntArray *regions);
00187
00193 int GetRegionsCellCountForProcess(int ProcessId, int *count, int len);
00194
00213 vtkIdType GetCellListsForProcessRegions(int ProcessId, int set,
00214 vtkIdList *inRegionCells, vtkIdList *onBoundaryCells);
00215 vtkIdType GetCellListsForProcessRegions(int ProcessId, vtkDataSet *set,
00216 vtkIdList *inRegionCells, vtkIdList *onBoundaryCells);
00217 vtkIdType GetCellListsForProcessRegions(int ProcessId, vtkIdList *inRegionCells,
00218 vtkIdList *onBoundaryCells);
00219
00223 int DepthOrderAllProcesses(double *directionOfProjection,
00224 vtkIntArray *orderedList);
00225
00231 int GetCellArrayGlobalRange(const char *name, float range[2]);
00232 int GetPointArrayGlobalRange(const char *name, float range[2]);
00233 int GetCellArrayGlobalRange(const char *name, double range[2]);
00234 int GetPointArrayGlobalRange(const char *name, double range[2]);
00235
00236 int GetCellArrayGlobalRange(int arrayIndex, double range[2]);
00237 int GetPointArrayGlobalRange(int arrayIndex, double range[2]);
00238 int GetCellArrayGlobalRange(int arrayIndex, float range[2]);
00239 int GetPointArrayGlobalRange(int arrayIndex, float range[2]);
00240
00241 protected:
00242
00243 vtkPKdTree();
00244 ~vtkPKdTree();
00245
00246 void SingleProcessBuildLocator();
00247 int MultiProcessBuildLocator(double *bounds);
00248
00249 private:
00250
00251 int RegionAssignment;
00252
00253 vtkMultiProcessController *Controller;
00254
00255 vtkSubGroup *SubGroup;
00256
00257 static char *StrDupWithNew(const char *s);
00258
00259 int NumProcesses;
00260 int MyId;
00261
00262
00263
00264
00265 int *RegionAssignmentMap;
00266 int RegionAssignmentMapLength;
00267 int **ProcessAssignmentMap;
00268 int *NumRegionsAssigned;
00269
00270 int UpdateRegionAssignment();
00271
00272
00273
00274
00275 char *DataLocationMap;
00276
00277 int *NumProcessesInRegion;
00278 int **ProcessList;
00279
00280 int *NumRegionsInProcess;
00281 int **RegionList;
00282
00283 int **CellCountList;
00284
00285 double *CellDataMin;
00286 double *CellDataMax;
00287 double *PointDataMin;
00288 double *PointDataMax;
00289 char **CellDataName;
00290 char **PointDataName;
00291 int NumCellArrays;
00292 int NumPointArrays;
00293
00294
00295
00296 int BuildGlobalIndexLists(int ncells);
00297
00298 int *StartVal;
00299 int *EndVal;
00300 int *NumCells;
00301 int TotalNumCells;
00302
00303
00304
00305 int WhoHas(int pos);
00306 int _whoHas(int L, int R, int pos);
00307 float *GetLocalVal(int pos);
00308 float *GetLocalValNext(int pos);
00309 void SetLocalVal(int pos, float *val);
00310 void ExchangeVals(int pos1, int pos2);
00311 void ExchangeLocalVals(int pos1, int pos2);
00312
00313 float *PtArray;
00314 float *PtArray2;
00315 float *CurrentPtArray;
00316 float *NextPtArray;
00317 int PtArraySize;
00318
00319 int *SelectBuffer;
00320
00321
00322
00323 int AllCheckForFailure(int rc, const char *where, const char *how);
00324 void AllCheckParameters();
00325 double *VolumeBounds();
00326 int DivideRegion(vtkKdNode *kd, int L, int level, int tag);
00327 int BreadthFirstDivide(double *bounds);
00328 void enQueueNode(vtkKdNode *kd, int L, int level, int tag);
00329
00330 int Select(int dim, int L, int R);
00331 void _select(int L, int R, int K, int dim);
00332 void DoTransfer(int from, int to, int fromIndex, int toIndex, int count);
00333
00334 int *PartitionAboutMyValue(int L, int R, int K, int dim);
00335 int *PartitionAboutOtherValue(int L, int R, float T, int dim);
00336 int *PartitionSubArray(int L, int R, int K, int dim, int p1, int p2);
00337
00338 int CompleteTree();
00339 #ifdef YIELDS_INCONSISTENT_REGION_BOUNDARIES
00340 void RetrieveData(vtkKdNode *kd, int *buf);
00341 #else
00342 void ReduceData(vtkKdNode *kd, int *sources);
00343 void BroadcastData(vtkKdNode *kd);
00344 #endif
00345
00346 float *DataBounds(int L, int K, int R);
00347 void GetLocalMinMax(int L, int R, int me, float *min, float *max);
00348
00349 static int FillOutTree(vtkKdNode *kd, int level);
00350 static int ComputeDepth(vtkKdNode *kd);
00351 static void PackData(vtkKdNode *kd, double *data);
00352 static void UnpackData(vtkKdNode *kd, double *data);
00353 static void CheckFixRegionBoundaries(vtkKdNode *tree);
00354
00355
00356
00357 int AllocateDoubleBuffer();
00358 void FreeDoubleBuffer();
00359 void SwitchDoubleBuffer();
00360 int AllocateSelectBuffer();
00361 void FreeSelectBuffer();
00362
00363 void InitializeGlobalIndexLists();
00364 int AllocateAndZeroGlobalIndexLists();
00365 void FreeGlobalIndexLists();
00366 void InitializeRegionAssignmentLists();
00367 int AllocateAndZeroRegionAssignmentLists();
00368 void FreeRegionAssignmentLists();
00369 void InitializeProcessDataLists();
00370 int AllocateAndZeroProcessDataLists();
00371 void FreeProcessDataLists();
00372 void InitializeFieldArrayMinMax();
00373 int AllocateAndZeroFieldArrayMinMax();
00374 void FreeFieldArrayMinMax();
00375
00376 void ReleaseTables();
00377
00378
00379
00380 void AddProcessRegions(int procId, vtkKdNode *kd);
00381 void BuildRegionListsForProcesses();
00382
00383
00384
00385 int *CollectLocalRegionProcessData();
00386 int BuildRegionProcessTables();
00387 int BuildFieldArrayMinMax();
00388 void AddEntry(int *list, int len, int id);
00389 static int BinarySearch(int *list, int len, int which);
00390
00391 static int FindNextLocalArrayIndex(const char *n, const char **names, int len, int start=0);
00392
00393 vtkPKdTree(const vtkPKdTree&);
00394 void operator=(const vtkPKdTree&);
00395 };
00396
00397 #endif