VTK  9.7.20260727
vtkBlockDistribution.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-FileCopyrightText: Copyright (C) 2008 The Trustees of Indiana University.
3// SPDX-License-Identifier: BSD-3-Clause AND BSL-1.0
11
12#ifndef vtkBlockDistribution_h
13#define vtkBlockDistribution_h
14
15#include "vtkABINamespace.h"
16#include "vtkType.h" // for vtkIdType
17
18VTK_ABI_NAMESPACE_BEGIN
20{
21public:
26
31 vtkIdType GetNumElements() { return this->NumElements; }
32
37 vtkIdType GetNumProcessors() { return this->NumProcessors; }
38
44
50
56
62
68
69private:
70 vtkIdType NumElements;
71 vtkIdType NumProcessors;
72};
73
74// ----------------------------------------------------------------------
75
77 : NumElements(N)
78 , NumProcessors(P)
79{
80}
81
82// ----------------------------------------------------------------------
83
85{
86 return (this->NumElements / this->NumProcessors) +
87 (rank < this->NumElements % this->NumProcessors ? 1 : 0);
88}
89
90// ----------------------------------------------------------------------
91
93{
94 vtkIdType smallBlockSize = this->NumElements / this->NumProcessors;
95 vtkIdType cutoffProcessor = this->NumElements % this->NumProcessors;
96 vtkIdType cutoffIndex = cutoffProcessor * (smallBlockSize + 1);
97
98 if (globalIndex < cutoffIndex)
99 {
100 return globalIndex / (smallBlockSize + 1);
101 }
102 else
103 {
104 return cutoffProcessor + (globalIndex - cutoffIndex) / smallBlockSize;
105 }
106}
107
108// ----------------------------------------------------------------------
109
111{
112 vtkIdType rank = this->GetProcessorOfElement(globalIndex);
113 return globalIndex - this->GetFirstGlobalIndexOnProcessor(rank);
114}
115
116// ----------------------------------------------------------------------
117
119{
120 vtkIdType estimate = rank * (this->NumElements / this->NumProcessors + 1);
121 vtkIdType cutoffProcessor = this->NumElements % this->NumProcessors;
122 if (rank < cutoffProcessor)
123 {
124 return estimate;
125 }
126 else
127 {
128 return estimate - (rank - cutoffProcessor);
129 }
130}
131
132// ----------------------------------------------------------------------
133
135{
136 return this->GetFirstGlobalIndexOnProcessor(rank) + localIndex;
137}
138
139VTK_ABI_NAMESPACE_END
140#endif
141// VTK-HeaderTest-Exclude: vtkBlockDistribution.h
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:363