Skip to content

ArborX::DistributedTree::DistributedTree

Daniel Arndt edited this page Aug 30, 2022 · 3 revisions

ArborX / Spatial indexes / ArborX::DistributedTree

ArborX::DistributedTree<MemorySpace>::DistributedTree

template <typename ExecutionSpace, typename Primitives>
DistributedTree(MPI_Comm comm, ExecutionSpace const& space, Primitives const& primitives); // (1)
  1. Constructs a bounding volume hierarchy from the given data source.

Parameters

comm : the MPI communicator. space : the execution space.
primitives : geometrical objects one wishes to index.

Type requirements

  • MemorySpace must be accessible from ExecutionSpace (i.e., Kokkos::SpaceAccessibility<ExecutionSpace, MemorySpace>::accessible must be true).
  • A specialization of ArborX::AccessTraits must match Primitives as the first template argument and ArborX::PrimitivesTag as second argument.
  • The return type of ArborX::AccessTraits<Primitives,ArborX::PrimitivesTag>::get() must decay either to ArborX::Point or ArborX::Box. ArborX provides specializations for Kokkos::View objects but a user may specialize it for their types.

Complexity

O(N log N), where N is the number of primitives passed to the constructor (ArborX::AccessTraits<Primitives,ArborX::PrimitivesTag>::size(primitives)).

Exceptions

Memory allocation with Kokkos may throw.

Notes

The constructor must be called by all MPI ranks related to the given MPI communicator collectively.

Example

#include <ArborX_DistributedTree.hpp>

#include <Kokkos_Core.hpp>

#include <iostream>

int main(int argc, char *argv[])
{
  MPI_Init(&argc, &argv);
  {
    Kokkos::ScopeGuard guard(argc, argv);

    MPI_Comm const comm = MPI_COMM_WORLD;
    int comm_rank;
    MPI_Comm_rank(comm, &comm_rank);

    Kokkos::View<ArborX::Point *> cloud("point_cloud", 10);
    Kokkos::parallel_for(10, KOKKOS_LAMBDA(int i) {
      cloud[i] = {{(float)i + 10 * comm_rank, (float)i, (float)i}};
    });
    using memory_space = decltype(cloud)::memory_space; // where to store the tree
    using execution_space = decltype(cloud)::execution_space; // where to execute code
    ArborX::DistributedTree<memory_space> bvh{comm, execution_space{}, cloud};
    if (comm_rank == 0)
    {
        auto const box = bvh.bounds();
      auto min = box.minCorner();
      auto max = box.maxCorner();
      std::cout << min[0] << ',' << min[1] << ',' << min[2] << " - "
                << max[0] << ',' << max[1] << ',' << max[2] << '\n';
    }
  }
  MPI_Finalize();
  return 0;
}

Output for 4 MPI processes

(0,0,0) - (39,9,9)

See also

query : search for all primitives that meet some predicates.
bounds : returns the bounding volume that contains all leaves.

Clone this wiki locally