VTK  9.0.1
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  */
28 #ifndef vtkBlockDistribution_h
29 #define vtkBlockDistribution_h
30 
32 {
33 public:
38 
43  vtkIdType GetNumElements() { return this->NumElements; }
44 
49  vtkIdType GetNumProcessors() { return this->NumProcessors; }
50 
56 
62 
68 
74 
79  vtkIdType GetGlobalIndex(vtkIdType localIndex, vtkIdType rank);
80 
81 private:
82  vtkIdType NumElements;
83  vtkIdType NumProcessors;
84 };
85 
86 // ----------------------------------------------------------------------
87 
89  : NumElements(N)
90  , NumProcessors(P)
91 {
92 }
93 
94 // ----------------------------------------------------------------------
95 
97 {
98  return (this->NumElements / this->NumProcessors) +
99  (rank < this->NumElements % this->NumProcessors ? 1 : 0);
100 }
101 
102 // ----------------------------------------------------------------------
103 
105 {
106  vtkIdType smallBlockSize = this->NumElements / this->NumProcessors;
107  vtkIdType cutoffProcessor = this->NumElements % this->NumProcessors;
108  vtkIdType cutoffIndex = cutoffProcessor * (smallBlockSize + 1);
109 
110  if (globalIndex < cutoffIndex)
111  {
112  return globalIndex / (smallBlockSize + 1);
113  }
114  else
115  {
116  return cutoffProcessor + (globalIndex - cutoffIndex) / smallBlockSize;
117  }
118 }
119 
120 // ----------------------------------------------------------------------
121 
123 {
124  vtkIdType rank = this->GetProcessorOfElement(globalIndex);
125  return globalIndex - this->GetFirstGlobalIndexOnProcessor(rank);
126 }
127 
128 // ----------------------------------------------------------------------
129 
131 {
132  vtkIdType estimate = rank * (this->NumElements / this->NumProcessors + 1);
133  vtkIdType cutoffProcessor = this->NumElements % this->NumProcessors;
134  if (rank < cutoffProcessor)
135  {
136  return estimate;
137  }
138  else
139  {
140  return estimate - (rank - cutoffProcessor);
141  }
142 }
143 
144 // ----------------------------------------------------------------------
145 
147 {
148  return this->GetFirstGlobalIndexOnProcessor(rank) + localIndex;
149 }
150 
151 #endif
152 // VTK-HeaderTest-Exclude: vtkBlockDistribution.h
vtkIdType
int vtkIdType
Definition: vtkType.h:338
vtkBlockDistribution::GetProcessorOfElement
vtkIdType GetProcessorOfElement(vtkIdType globalIndex)
Retrieve the process number in [0, GetNumProcessors()) where the element with the given global index ...
Definition: vtkBlockDistribution.h:104
vtkBlockDistribution::vtkBlockDistribution
vtkBlockDistribution(vtkIdType N, vtkIdType P)
Create a block distribution with N elements on P processors.
Definition: vtkBlockDistribution.h:88
vtkBlockDistribution::GetLocalIndexOfElement
vtkIdType GetLocalIndexOfElement(vtkIdType globalIndex)
Retrieve the local index (offset) on the processor determined by GetProcessorOfElement that refers to...
Definition: vtkBlockDistribution.h:122
vtkBlockDistribution
A helper class that manages a block distribution of N elements of data.
Definition: vtkBlockDistribution.h:31
vtkBlockDistribution::GetBlockSize
vtkIdType GetBlockSize(vtkIdType rank)
Get the block size for the processor with the given rank.
Definition: vtkBlockDistribution.h:96
vtkBlockDistribution::GetNumProcessors
vtkIdType GetNumProcessors()
Retrieves the number of processors for which this block distribution was built.
Definition: vtkBlockDistribution.h:49
vtkBlockDistribution::GetFirstGlobalIndexOnProcessor
vtkIdType GetFirstGlobalIndexOnProcessor(vtkIdType rank)
Retrieve the first global index stored on the processor with the given rank.
Definition: vtkBlockDistribution.h:130
vtkBlockDistribution::GetNumElements
vtkIdType GetNumElements()
Retrieves the number of elements for which this block distribution was built.
Definition: vtkBlockDistribution.h:43
vtkBlockDistribution::GetGlobalIndex
vtkIdType GetGlobalIndex(vtkIdType localIndex, vtkIdType rank)
Retrieve the global index associated with the given local index on the processor with the given rank.
Definition: vtkBlockDistribution.h:146