11 #ifndef vtk_m_filter_flow_internal_BoundsMap_h
12 #define vtk_m_filter_flow_internal_BoundsMap_h
21 #include <vtkm/thirdparty/diy/diy.h>
23 #ifdef VTKM_ENABLE_MPI
25 #include <vtkm/thirdparty/diy/mpi-cast.h>
52 this->Init({ dataSet });
55 BoundsMap(
const std::vector<vtkm::cont::DataSet>& dataSets)
56 : LocalNumBlocks(static_cast<
vtkm::
Id>(dataSets.size()))
63 : LocalNumBlocks(pds.GetNumberOfPartitions())
71 VTKM_ASSERT(idx >= 0 && idx < this->LocalNumBlocks);
72 return this->LocalIDs[
static_cast<std::size_t
>(idx)];
77 auto it = this->BlockToRankMap.find(blockId);
78 if (it == this->BlockToRankMap.end())
83 std::vector<vtkm::Id> FindBlocks(
const vtkm::Vec3f& p)
const {
return this->FindBlocks(p, -1); }
85 std::vector<vtkm::Id> FindBlocks(
const vtkm::Vec3f& p,
86 const std::vector<vtkm::Id>& ignoreBlocks)
const
88 vtkm::Id ignoreID = (ignoreBlocks.empty() ? -1 : ignoreBlocks[0]);
89 return FindBlocks(p, ignoreID);
94 std::vector<vtkm::Id> blockIDs;
95 if (this->GlobalBounds.Contains(p))
98 for (
auto& it : this->BlockBounds)
100 if (blockId != ignoreBlock && it.Contains(p))
101 blockIDs.emplace_back(blockId);
109 vtkm::Id GetTotalNumBlocks()
const {
return this->TotalNumBlocks; }
110 vtkm::Id GetLocalNumBlocks()
const {
return this->LocalNumBlocks; }
113 void Init(
const std::vector<vtkm::cont::DataSet>& dataSets)
116 this->TotalNumBlocks = assigner.nblocks();
117 std::vector<int> ids;
120 assigner.local_gids(Comm.rank(), ids);
121 for (
const auto& i : ids)
122 this->LocalIDs.emplace_back(
static_cast<vtkm::Id>(i));
124 for (
vtkm::Id id = 0;
id < this->TotalNumBlocks;
id++)
125 this->BlockToRankMap[
id] = assigner.rank(
static_cast<int>(
id));
126 this->Build(dataSets);
129 void Build(
const std::vector<vtkm::cont::DataSet>& dataSets)
131 std::vector<vtkm::Float64> vals(
static_cast<std::size_t
>(this->TotalNumBlocks * 6), 0);
132 std::vector<vtkm::Float64> vals2(vals.size());
134 for (std::size_t i = 0; i < this->LocalIDs.size(); i++)
139 std::size_t idx =
static_cast<std::size_t
>(this->LocalIDs[i] * 6);
140 vals[idx++] = bounds.
X.
Min;
141 vals[idx++] = bounds.X.Max;
142 vals[idx++] = bounds.Y.Min;
143 vals[idx++] = bounds.Y.Max;
144 vals[idx++] = bounds.Z.Min;
145 vals[idx++] = bounds.Z.Max;
148 #ifdef VTKM_ENABLE_MPI
150 MPI_Comm mpiComm = vtkmdiy::mpi::mpi_cast(Comm.handle());
151 MPI_Allreduce(vals.data(), vals2.data(), vals.size(), MPI_DOUBLE, MPI_SUM, mpiComm);
156 this->BlockBounds.resize(
static_cast<std::size_t
>(this->TotalNumBlocks));
159 for (
auto& block : this->BlockBounds)
167 this->GlobalBounds.Include(block);
173 std::vector<vtkm::Id> LocalIDs;
174 std::map<vtkm::Id, vtkm::Int32> BlockToRankMap;
176 std::vector<vtkm::Bounds> BlockBounds;
185 #endif //vtk_m_filter_flow_internal_BoundsMap_h