VTK
vtkBlockDistribution.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkBlockDistribution.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*
16  * Copyright (C) 2008 The Trustees of Indiana University.
17  * Use, modification and distribution is subject to the Boost Software
18  * License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt)
19  */
27 #ifndef vtkBlockDistribution_h
28 #define vtkBlockDistribution_h
29 
31 {
32 public:
35 
38  vtkIdType GetNumElements() { return this->NumElements; }
39 
42  vtkIdType GetNumProcessors() { return this->NumProcessors; }
43 
47 
51 
55 
59 
62  vtkIdType GetGlobalIndex(vtkIdType localIndex, vtkIdType rank);
63 
64 private:
65  vtkIdType NumElements;
66  vtkIdType NumProcessors;
67 };
68 
69 // ----------------------------------------------------------------------
70 
72  : NumElements(N), NumProcessors(P)
73 {
74 }
75 
76 // ----------------------------------------------------------------------
77 
79 {
80  return (this->NumElements / this->NumProcessors)
81  + (rank < this->NumElements % this->NumProcessors? 1 : 0);
82 }
83 
84 // ----------------------------------------------------------------------
85 
86 inline vtkIdType
88 {
89  vtkIdType smallBlockSize = this->NumElements / this->NumProcessors;
90  vtkIdType cutoffProcessor = this->NumElements % this->NumProcessors;
91  vtkIdType cutoffIndex = cutoffProcessor * (smallBlockSize + 1);
92 
93  if (globalIndex < cutoffIndex)
94  {
95  return globalIndex / (smallBlockSize + 1);
96  }
97  else
98  {
99  return cutoffProcessor + (globalIndex - cutoffIndex) / smallBlockSize;
100  }
101 }
102 
103 // ----------------------------------------------------------------------
104 
105 inline vtkIdType
107 {
108  vtkIdType rank = this->GetProcessorOfElement(globalIndex);
109  return globalIndex - this->GetFirstGlobalIndexOnProcessor(rank);
110 }
111 
112 // ----------------------------------------------------------------------
113 
114 inline vtkIdType
116 {
117  vtkIdType estimate = rank * (this->NumElements / this->NumProcessors + 1);
118  vtkIdType cutoffProcessor = this->NumElements % this->NumProcessors;
119  if (rank < cutoffProcessor)
120  {
121  return estimate;
122  }
123  else
124  {
125  return estimate - (rank - cutoffProcessor);
126  }
127 }
128 
129 // ----------------------------------------------------------------------
130 
131 inline vtkIdType
133 {
134  return this->GetFirstGlobalIndexOnProcessor(rank) + localIndex;
135 }
136 
137 #endif
138 // VTK-HeaderTest-Exclude: vtkBlockDistribution.h
A helper class that manages a block distribution of N elements of data.
int vtkIdType
Definition: vtkType.h:275
vtkIdType GetFirstGlobalIndexOnProcessor(vtkIdType rank)
vtkBlockDistribution(vtkIdType N, vtkIdType P)
vtkIdType GetLocalIndexOfElement(vtkIdType globalIndex)
vtkIdType GetBlockSize(vtkIdType rank)
vtkIdType GetProcessorOfElement(vtkIdType globalIndex)
vtkIdType GetGlobalIndex(vtkIdType localIndex, vtkIdType rank)