Merge branch 'add-compute-global-point-size' into 'master'

WIP: Add ComputeGlobalPointDimensions

See merge request vtk/vtk-m!2935
This commit is contained in:
Gunther Weber 2024-07-09 17:16:19 -04:00
commit 7353e53730
2 changed files with 116 additions and 5 deletions

@ -155,6 +155,110 @@ private:
std::vector<std::string> mCLOptions;
};
void ComputeGlobalPointDimensions(vtkm::cont::PartitionedDataSet& pds)
{
// Compute GlobalPointDimensions as maximum of GlobalPointIndexStart + PointDimensions
// for each dimension across all blocks
// Compute GlobalPointDimensions for all data sets on this MPI rank
std::vector<vtkm::Id> globalPointDimensionsThisRank;
using ds_const_iterator = vtkm::cont::PartitionedDataSet::const_iterator;
for (ds_const_iterator ds_it = pds.cbegin(); ds_it != pds.cend(); ++ds_it)
{
ds_it->GetCellSet().CastAndCallForTypes<vtkm::cont::CellSetListStructured>(
[&globalPointDimensionsThisRank](const auto& css) {
globalPointDimensionsThisRank.resize(css.Dimension, -1);
for (vtkm::IdComponent d = 0; d < css.Dimension; ++d)
{
globalPointDimensionsThisRank[d] =
std::max(globalPointDimensionsThisRank[d],
css.GetGlobalPointIndexStart()[d] + css.GetPointDimensions()[d]);
}
});
}
// Perform global reduction to find GlobalPointDimensions across all ranks
std::vector<vtkm::Id> globalPointDimensions;
auto comm = vtkm::cont::EnvironmentTracker::GetCommunicator();
vtkmdiy::mpi::all_reduce(
comm, globalPointDimensionsThisRank, globalPointDimensions, vtkmdiy::mpi::maximum<vtkm::Id>{});
// Set this information in all cell sets
using ds_iterator = vtkm::cont::PartitionedDataSet::iterator;
for (ds_iterator ds_it = pds.begin(); ds_it != pds.end(); ++ds_it)
{
// This does not work, i.e., it does not really change the cell set for the DataSet
ds_it->GetCellSet().CastAndCallForTypes<vtkm::cont::CellSetListStructured>(
[&globalPointDimensions, &ds_it](auto& css) {
typename std::remove_reference_t<decltype(css)>::SchedulingRangeType gpd;
for (vtkm::IdComponent d = 0; d < css.Dimension; ++d)
{
gpd[d] = globalPointDimensions[d];
}
css.SetGlobalPointDimensions(gpd);
// Why is the following necessary? Shouldn't it be sufficient to update the
// CellSet through the reference?
ds_it->SetCellSet(css);
});
}
// Debug
pds.PrintSummary(std::cout);
}
void ShiftLogicalOriginToZero(vtkm::cont::PartitionedDataSet& pds)
{
// Shift the logical origin (minimum of LocalPointIndexStart) to zero
// along each dimension
// Compute minimum global point index start for all data sets on this MPI rank
std::vector<vtkm::Id> minimumGlobalPointIndexStartThisRank;
using ds_const_iterator = vtkm::cont::PartitionedDataSet::const_iterator;
for (ds_const_iterator ds_it = pds.cbegin(); ds_it != pds.cend(); ++ds_it)
{
ds_it->GetCellSet().CastAndCallForTypes<vtkm::cont::CellSetListStructured>(
[&minimumGlobalPointIndexStartThisRank](const auto& css) {
minimumGlobalPointIndexStartThisRank.resize(css.Dimension,
std::numeric_limits<vtkm::Id>::max());
for (vtkm::IdComponent d = 0; d < css.Dimension; ++d)
{
minimumGlobalPointIndexStartThisRank[d] =
std::min(minimumGlobalPointIndexStartThisRank[d], css.GetGlobalPointIndexStart()[d]);
}
});
}
// Perform global reduction to find GlobalPointDimensions across all ranks
std::vector<vtkm::Id> minimumGlobalPointIndexStart;
auto comm = vtkm::cont::EnvironmentTracker::GetCommunicator();
vtkmdiy::mpi::all_reduce(comm,
minimumGlobalPointIndexStartThisRank,
minimumGlobalPointIndexStart,
vtkmdiy::mpi::minimum<vtkm::Id>{});
// Shift all cell sets so that minimum global point index start
// along each dimension is zero
using ds_iterator = vtkm::cont::PartitionedDataSet::iterator;
for (ds_iterator ds_it = pds.begin(); ds_it != pds.end(); ++ds_it)
{
// This does not work, i.e., it does not really change the cell set for the DataSet
ds_it->GetCellSet().CastAndCallForTypes<vtkm::cont::CellSetListStructured>(
[&minimumGlobalPointIndexStart, &ds_it](auto& css) {
auto pointIndexStart = css.GetGlobalPointIndexStart();
typename std::remove_reference_t<decltype(css)>::SchedulingRangeType shiftedPointIndexStart;
for (vtkm::IdComponent d = 0; d < css.Dimension; ++d)
{
shiftedPointIndexStart[d] = pointIndexStart[d] - minimumGlobalPointIndexStart[d];
}
css.SetGlobalPointIndexStart(shiftedPointIndexStart);
// Why is the following necessary? Shouldn't it be sufficient to update the
// CellSet through the reference?
ds_it->SetCellSet(css);
});
}
// Debug
//pds.PrintSummary(std::cout);
}
// Compute and render an isosurface for a uniform grid example
int main(int argc, char* argv[])
@ -652,6 +756,8 @@ int main(int argc, char* argv[])
filter.SetActiveField("values");
// Execute the contour tree analysis
ShiftLogicalOriginToZero(useDataSet);
ComputeGlobalPointDimensions(useDataSet);
auto result = filter.Execute(useDataSet);
currTime = totalTime.GetElapsedTime();

@ -346,7 +346,8 @@ bool read3DHDF5File(const int& mpi_rank,
ds = dsb.Create(v_dims, v_origin, v_spacing);
vtkm::cont::CellSetStructured<3> cs;
cs.SetPointDimensions(v_dims);
cs.SetGlobalPointDimensions(globalSize);
// NOTE: Comment out for test purposes
//cs.SetGlobalPointDimensions(globalSize);
cs.SetGlobalPointIndexStart(vtkm::Id3{ v_origin[0], v_origin[1], v_origin[2] });
ds.SetCellSet(cs);
@ -587,7 +588,8 @@ bool readPreSplitFiles(const int& rank,
ds = dsb.Create(v_dims, v_origin, v_spacing);
vtkm::cont::CellSetStructured<2> cs;
cs.SetPointDimensions(v_dims);
cs.SetGlobalPointDimensions(vtkm::Id2{ globalSize[0], globalSize[1] });
// NOTE: Comment out for test purposes
//cs.SetGlobalPointDimensions(vtkm::Id2{ globalSize[0], globalSize[1] });
cs.SetGlobalPointIndexStart(vtkm::Id2{ offset[0], offset[1] });
ds.SetCellSet(cs);
}
@ -604,7 +606,8 @@ bool readPreSplitFiles(const int& rank,
ds = dsb.Create(v_dims, v_origin, v_spacing);
vtkm::cont::CellSetStructured<3> cs;
cs.SetPointDimensions(v_dims);
cs.SetGlobalPointDimensions(globalSize);
// NOTE: Comment out for test purposes
//cs.SetGlobalPointDimensions(globalSize);
cs.SetGlobalPointIndexStart(vtkm::Id3{ offset[0], offset[1], offset[2] });
ds.SetCellSet(cs);
}
@ -815,7 +818,8 @@ bool readSingleBlockFile(const int& rank,
ds = dsb.Create(vdims, origin, spacing);
vtkm::cont::CellSetStructured<2> cs;
cs.SetPointDimensions(vdims);
cs.SetGlobalPointDimensions(vtkm::Id2{ globalSize[0], globalSize[1] });
// NOTE: Comment out for test purposes
//cs.SetGlobalPointDimensions(vtkm::Id2{ globalSize[0], globalSize[1] });
cs.SetGlobalPointIndexStart(vtkm::Id2{ 0, (blockStart / blockSliceSize) });
ds.SetCellSet(cs);
localBlockIndicesPortal.Set(localBlockIndex, vtkm::Id3(0, blockIndex, 0));
@ -832,7 +836,8 @@ bool readSingleBlockFile(const int& rank,
ds = dsb.Create(vdims, origin, spacing);
vtkm::cont::CellSetStructured<3> cs;
cs.SetPointDimensions(vdims);
cs.SetGlobalPointDimensions(globalSize);
// NOTE: Comment out for test purposes
//cs.SetGlobalPointDimensions(globalSize);
cs.SetGlobalPointIndexStart(vtkm::Id3(0, 0, blockStart / blockSliceSize));
ds.SetCellSet(cs);
localBlockIndicesPortal.Set(localBlockIndex, vtkm::Id3(0, 0, blockIndex));