VTK  9.1.0
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{
33public:
38
43 vtkIdType GetNumElements() { return this->NumElements; }
44
49 vtkIdType GetNumProcessors() { return this->NumProcessors; }
50
56
62
68
74
80
81private:
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
A helper class that manages a block distribution of N elements of data.
vtkIdType GetGlobalIndex(vtkIdType localIndex, vtkIdType rank)
Retrieve the global index associated with the given local index on the processor with the given rank.
vtkIdType GetNumElements()
Retrieves the number of elements for which this block distribution was built.
vtkIdType GetLocalIndexOfElement(vtkIdType globalIndex)
Retrieve the local index (offset) on the processor determined by GetProcessorOfElement that refers to...
vtkIdType GetProcessorOfElement(vtkIdType globalIndex)
Retrieve the process number in [0, GetNumProcessors()) where the element with the given global index ...
vtkIdType GetNumProcessors()
Retrieves the number of processors for which this block distribution was built.
vtkIdType GetFirstGlobalIndexOnProcessor(vtkIdType rank)
Retrieve the first global index stored on the processor with the given rank.
vtkBlockDistribution(vtkIdType N, vtkIdType P)
Create a block distribution with N elements on P processors.
vtkIdType GetBlockSize(vtkIdType rank)
Get the block size for the processor with the given rank.
int vtkIdType
Definition: vtkType.h:332