Commit 6938b05c authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Remove GetBounds methods from MultiBlock.

Removing GetBounds and related methods from MultiBlock. These have been
replaced by BoundsCompute and BoundsGlobalCompute.
parent c4970604
......@@ -21,7 +21,6 @@
#include <vtkm/StaticAssert.h>
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/AssignerMultiBlock.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/DynamicArrayHandle.h>
......@@ -30,54 +29,6 @@
#include <vtkm/cont/Field.h>
#include <vtkm/cont/MultiBlock.h>
// clang-format off
VTKM_THIRDPARTY_PRE_INCLUDE
#include <vtkm/thirdparty/diy/Configure.h>
#include VTKM_DIY(diy/decomposition.hpp)
#include VTKM_DIY(diy/master.hpp)
#include VTKM_DIY(diy/partners/all-reduce.hpp)
#include VTKM_DIY(diy/partners/broadcast.hpp)
#include VTKM_DIY(diy/partners/swap.hpp)
#include VTKM_DIY(diy/reduce.hpp)
VTKM_THIRDPARTY_POST_INCLUDE
// clang-format on
namespace vtkm
{
namespace cont
{
namespace detail
{
template <typename PortalType>
VTKM_CONT std::vector<typename PortalType::ValueType> CopyArrayPortalToVector(
const PortalType& portal)
{
const size_t count =
portal.GetNumberOfValues() > 0 ? static_cast<size_t>(portal.GetNumberOfValues()) : 0;
using ValueType = typename PortalType::ValueType;
std::vector<ValueType> result(count);
if (count > 0)
{
vtkm::cont::ArrayPortalToIterators<PortalType> iterators(portal);
std::copy(iterators.GetBegin(), iterators.GetEnd(), result.begin());
}
return result;
}
template <typename T>
const vtkm::cont::DataSet& GetBlock(const vtkm::cont::MultiBlock& mb, const T&);
template <>
const vtkm::cont::DataSet& GetBlock(const vtkm::cont::MultiBlock& mb,
const diy::Master::ProxyWithLink& cp)
{
const int lid = cp.master()->lid(cp.gid());
return mb.GetBlock(lid);
}
}
}
}
namespace vtkm
{
namespace cont
......@@ -187,123 +138,6 @@ void MultiBlock::ReplaceBlock(vtkm::Id index, const vtkm::cont::DataSet& ds)
}
}
VTKM_CONT vtkm::Bounds MultiBlock::GetBounds(vtkm::Id coordinate_system_index) const
{
auto world = vtkm::cont::EnvironmentTracker::GetCommunicator();
diy::Master master(world,
1,
-1,
[]() -> void* { return new vtkm::Bounds(); },
[](void* ptr) { delete static_cast<vtkm::Bounds*>(ptr); });
// create the assigner that assigns blocks to ranks.
// AssignerMultiBlock is similar to diy::ContiguousAssigner except the number
// of blocks on each rank is defermiend by the blocks in the MultiBlock on
// each rank and those can be different.
vtkm::cont::AssignerMultiBlock assigner(*this);
const int nblocks = assigner.nblocks(); // this is the total number of blocks across all ranks.
if (nblocks == 0)
{
// short circuit if there are no blocks in this multiblock globally.
return vtkm::Bounds();
}
// populate master with blocks from `this`.
diy::RegularDecomposer<diy::DiscreteBounds> decomposer(1, diy::interval(0, nblocks - 1), nblocks);
decomposer.decompose(world.rank(), assigner, master);
auto self = (*this);
master.foreach ([&](vtkm::Bounds* data, const diy::Master::ProxyWithLink& cp) {
const vtkm::cont::DataSet& block = vtkm::cont::detail::GetBlock(self, cp);
try
{
vtkm::cont::CoordinateSystem coords = block.GetCoordinateSystem(coordinate_system_index);
*data = coords.GetBounds();
}
catch (const vtkm::cont::Error&)
{
}
});
// lets do a reduction to block-0.
diy::RegularMergePartners partners(decomposer, /*k=*/2);
auto callback =
[](vtkm::Bounds* data, const diy::ReduceProxy& srp, const diy::RegularMergePartners&) {
const auto selfid = srp.gid();
// 1. dequeue.
std::vector<int> incoming;
srp.incoming(incoming);
vtkm::Bounds message;
for (const int gid : incoming)
{
if (gid != selfid)
{
srp.dequeue(gid, message);
data->Include(message);
}
}
// 2. enqueue
for (int cc = 0; cc < srp.out_link().size(); ++cc)
{
auto target = srp.out_link().target(cc);
if (target.gid != selfid)
{
srp.enqueue(target, *data);
}
}
};
// reduce and produce aggregated bounds on block(gid=0).
diy::reduce(master, assigner, partners, callback);
// now that the rank with block(gid=0) has the reduced bounds, let's ship
// them around to all ranks. Since nblocks is generally quite larger than
// nranks, we create a new assigner/decomposer.
vtkm::Bounds reduced_bounds;
if (master.local(0))
{
reduced_bounds = *static_cast<vtkm::Bounds*>(master.get(master.lid(0)));
}
master.clear();
diy::ContiguousAssigner bAssigner(world.size(), world.size());
diy::RegularDecomposer<diy::DiscreteBounds> bDecomposer(
1, diy::interval(0, world.size() - 1), world.size());
bDecomposer.decompose(world.rank(), bAssigner, master);
*master.block<vtkm::Bounds>(0) = reduced_bounds;
diy::RegularBroadcastPartners bPartners(bDecomposer, /*k=*/2);
// we can use the same `callback` as earlier since all blocks are
// initialized to empty, hence `vtkm::Bounds::Include()` should simply work
// as a copy.
diy::reduce(master, bAssigner, bPartners, callback);
assert(master.size() == 1);
return *master.block<vtkm::Bounds>(0);
}
VTKM_CONT vtkm::Bounds MultiBlock::GetBlockBounds(const std::size_t& block_index,
vtkm::Id coordinate_system_index) const
{
const vtkm::Id index = coordinate_system_index;
vtkm::cont::CoordinateSystem coords;
try
{
coords = this->Blocks[block_index].GetCoordinateSystem(index);
}
catch (const vtkm::cont::Error& error)
{
std::stringstream msg;
msg << "GetBounds call failed. vtk-m error was encountered while "
<< "attempting to get coordinate system " << index << " from "
<< "block " << block_index << ". vtkm error message: " << error.GetMessage();
throw ErrorExecution(msg.str());
}
return coords.GetBounds();
}
VTKM_CONT
void MultiBlock::PrintSummary(std::ostream& stream) const
{
......
......@@ -81,14 +81,6 @@ public:
/// append the DataSet vector "mblocks" to the end of the contained one
VTKM_CONT
void AddBlocks(const std::vector<vtkm::cont::DataSet>& mblocks);
/// get the unified bounds of the same indexed coordinate system within all contained DataSet
VTKM_CONT
vtkm::Bounds GetBounds(vtkm::Id coordinate_system_index = 0) const;
/// get the bounds of a coordinate system within a given DataSet
VTKM_CONT
vtkm::Bounds GetBlockBounds(const std::size_t& block_index,
vtkm::Id coordinate_system_index = 0) const;
VTKM_CONT
void PrintSummary(std::ostream& stream) const;
......
......@@ -23,6 +23,7 @@
#include <vtkm/Bounds.h>
#include <vtkm/VectorAnalysis.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/BoundsCompute.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DataSetFieldAdd.h>
......@@ -74,9 +75,12 @@ static void MultiBlockTest()
GlobalBound.Include(Set1Bounds);
GlobalBound.Include(Set2Bounds);
VTKM_TEST_ASSERT(multiblock.GetBounds() == GlobalBound, "Global bounds info incorrect");
VTKM_TEST_ASSERT(multiblock.GetBlockBounds(0) == Set1Bounds, "Local bounds info incorrect");
VTKM_TEST_ASSERT(multiblock.GetBlockBounds(1) == Set2Bounds, "Local bounds info incorrect");
VTKM_TEST_ASSERT(vtkm::cont::BoundsCompute(multiblock) == GlobalBound,
"Global bounds info incorrect");
VTKM_TEST_ASSERT(vtkm::cont::BoundsCompute(multiblock.GetBlock(0)) == Set1Bounds,
"Local bounds info incorrect");
VTKM_TEST_ASSERT(vtkm::cont::BoundsCompute(multiblock.GetBlock(1)) == Set2Bounds,
"Local bounds info incorrect");
vtkm::Range Set1Field1Range;
vtkm::Range Set1Field2Range;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment