From 0a72225d5f47832ea056b5435d17ee84009b5a91 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Wed, 31 Aug 2022 15:58:22 -0400 Subject: [PATCH 1/7] Add DistributedTree nearest example --- examples/CMakeLists.txt | 4 + examples/distributed_tree/CMakeLists.txt | 3 + examples/distributed_tree/distributed_knn.cpp | 106 ++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 examples/distributed_tree/CMakeLists.txt create mode 100644 examples/distributed_tree/distributed_knn.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 4fe135477..39b6e1f34 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -13,6 +13,10 @@ add_subdirectory(simple_intersection) add_subdirectory(molecular_dynamics) +if(ARBORX_ENABLE_MPI) + add_subdirectory(distributed_tree) +endif() + find_package(Boost COMPONENTS program_options) if(Boost_FOUND) add_subdirectory(viz) diff --git a/examples/distributed_tree/CMakeLists.txt b/examples/distributed_tree/CMakeLists.txt new file mode 100644 index 000000000..6bcc3d396 --- /dev/null +++ b/examples/distributed_tree/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(ArborX_DistributedTree_KNN.exe distributed_knn.cpp) +target_link_libraries(ArborX_DistributedTree_KNN.exe ArborX::ArborX) +add_test(NAME ArborX_DistributedTree_KNN_Example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} ./ArborX_DistributedTree_KNN.exe ${MPIEXEC_POSTFLAGS}) diff --git a/examples/distributed_tree/distributed_knn.cpp b/examples/distributed_tree/distributed_knn.cpp new file mode 100644 index 000000000..565915db1 --- /dev/null +++ b/examples/distributed_tree/distributed_knn.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** + * Copyright (c) 2017-2022 by the ArborX authors * + * All rights reserved. * + * * + * This file is part of the ArborX library. ArborX is * + * distributed under a BSD 3-clause license. For the licensing terms see * + * the LICENSE file in the top-level directory. * + * * + * SPDX-License-Identifier: BSD-3-Clause * + ****************************************************************************/ + +#include + +#include + +#include +#include +#include +#include +#include + +#include + +using ExecutionSpace = Kokkos::DefaultExecutionSpace; +using MemorySpace = ExecutionSpace::memory_space; + +namespace Example +{ +template +struct Nearest +{ + Points points; + int k; +}; +template +Nearest(Points const &, int) -> Nearest; + +struct IndexAndRank +{ + int index; + int rank; +}; + +} // namespace Example + +template +struct ArborX::AccessTraits, ArborX::PredicatesTag> +{ + static KOKKOS_FUNCTION std::size_t size(Example::Nearest const &x) + { + return x.points.extent(0); + } + static KOKKOS_FUNCTION auto get(Example::Nearest const &x, + std::size_t i) + { + return ArborX::nearest(x.points(i), x.k); + } + using memory_space = MemorySpace; +}; + +int main(int argc, char *argv[]) +{ + MPI_Init(&argc, &argv); + Kokkos::initialize(argc, argv); + { + MPI_Comm comm = MPI_COMM_WORLD; + int comm_rank; + MPI_Comm_rank(comm, &comm_rank); + int comm_size; + MPI_Comm_size(comm, &comm_size); + ArborX::Point lower_left_corner = {static_cast(comm_rank), + static_cast(comm_rank), + static_cast(comm_rank)}; + ArborX::Point center = {static_cast(comm_rank) + .5f, + static_cast(comm_rank) + .5f, + static_cast(comm_rank) + .5f}; + std::vector points = {lower_left_corner, center}; + auto points_device = Kokkos::create_mirror_view_and_copy( + MemorySpace{}, + Kokkos::View(points.data(), points.size())); + + ExecutionSpace exec; + ArborX::DistributedTree tree(comm, exec, points_device); + + Kokkos::View values("values", 0); + Kokkos::View offsets("offsets", 0); + tree.query(exec, Example::Nearest{points_device, 3}, values, offsets); + + auto host_values = + Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, values); + auto host_offsets = + Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, offsets); + for (unsigned int i = 0; i + 1 < host_offsets.size(); ++i) + { + std::cout << "Results for query " << i << " on MPI rank " << comm_rank + << '\n'; + for (unsigned int j = host_offsets(i); j < host_offsets(i + 1); ++j) + std::cout << "point " << host_values(j).index << ", rank " + << host_values(j).rank << std::endl; + } + } + Kokkos::finalize(); + MPI_Finalize(); + return 0; +} From 0768edb0d0be1adb4dcaee37066953e043f5084e Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Wed, 31 Aug 2022 15:59:16 -0400 Subject: [PATCH 2/7] Add DistributedTree intersects example --- examples/distributed_tree/CMakeLists.txt | 4 + .../distributed_intersects.cpp | 106 ++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 examples/distributed_tree/distributed_intersects.cpp diff --git a/examples/distributed_tree/CMakeLists.txt b/examples/distributed_tree/CMakeLists.txt index 6bcc3d396..47e358f2d 100644 --- a/examples/distributed_tree/CMakeLists.txt +++ b/examples/distributed_tree/CMakeLists.txt @@ -1,3 +1,7 @@ add_executable(ArborX_DistributedTree_KNN.exe distributed_knn.cpp) target_link_libraries(ArborX_DistributedTree_KNN.exe ArborX::ArborX) add_test(NAME ArborX_DistributedTree_KNN_Example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} ./ArborX_DistributedTree_KNN.exe ${MPIEXEC_POSTFLAGS}) + +add_executable(ArborX_DistributedTree_Intersects.exe distributed_intersects.cpp) +target_link_libraries(ArborX_DistributedTree_Intersects.exe ArborX::ArborX) +add_test(NAME ArborX_DistributedTree_Intersects_Example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} ./ArborX_DistributedTree_Intersects.exe ${MPIEXEC_POSTFLAGS}) diff --git a/examples/distributed_tree/distributed_intersects.cpp b/examples/distributed_tree/distributed_intersects.cpp new file mode 100644 index 000000000..8d6a7658a --- /dev/null +++ b/examples/distributed_tree/distributed_intersects.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** + * Copyright (c) 2017-2022 by the ArborX authors * + * All rights reserved. * + * * + * This file is part of the ArborX library. ArborX is * + * distributed under a BSD 3-clause license. For the licensing terms see * + * the LICENSE file in the top-level directory. * + * * + * SPDX-License-Identifier: BSD-3-Clause * + ****************************************************************************/ + +#include + +#include + +#include +#include +#include +#include +#include + +#include + +using ExecutionSpace = Kokkos::DefaultExecutionSpace; +using MemorySpace = ExecutionSpace::memory_space; + +namespace Example +{ +template +struct Intersects +{ + Points points; + float radius; +}; +template +Intersects(Points const &, int) -> Intersects; + +struct IndexAndRank +{ + int index; + int rank; +}; + +} // namespace Example + +template +struct ArborX::AccessTraits, ArborX::PredicatesTag> +{ + static KOKKOS_FUNCTION std::size_t size(Example::Intersects const &x) + { + return x.points.extent(0); + } + static KOKKOS_FUNCTION auto get(Example::Intersects const &x, + std::size_t i) + { + return ArborX::intersects(ArborX::Sphere(x.points(i), x.radius)); + } + using memory_space = MemorySpace; +}; + +int main(int argc, char *argv[]) +{ + MPI_Init(&argc, &argv); + Kokkos::initialize(argc, argv); + { + MPI_Comm comm = MPI_COMM_WORLD; + int comm_rank; + MPI_Comm_rank(comm, &comm_rank); + int comm_size; + MPI_Comm_size(comm, &comm_size); + ArborX::Point lower_left_corner = {static_cast(comm_rank), + static_cast(comm_rank), + static_cast(comm_rank)}; + ArborX::Point center = {static_cast(comm_rank) + .5f, + static_cast(comm_rank) + .5f, + static_cast(comm_rank) + .5f}; + std::vector points = {lower_left_corner, center}; + auto points_device = Kokkos::create_mirror_view_and_copy( + MemorySpace{}, + Kokkos::View(points.data(), points.size())); + + ExecutionSpace exec; + ArborX::DistributedTree tree(comm, exec, points_device); + + Kokkos::View values("values", 0); + Kokkos::View offsets("offsets", 0); + tree.query(exec, Example::Intersects{points_device, 1.}, values, offsets); + + auto host_values = + Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, values); + auto host_offsets = + Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, offsets); + for (unsigned int i = 0; i + 1 < host_offsets.size(); ++i) + { + std::cout << "Results for query " << i << " on MPI rank " << comm_rank + << '\n'; + for (unsigned int j = host_offsets(i); j < host_offsets(i + 1); ++j) + std::cout << "point " << host_values(j).index << ", rank " + << host_values(j).rank << std::endl; + } + } + Kokkos::finalize(); + MPI_Finalize(); + return 0; +} From 3e6b3e313703070a6891e4f663e9a9694d4bc2c1 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Wed, 31 Aug 2022 15:59:32 -0400 Subject: [PATCH 3/7] Add DistributedTree intersects with callback example --- examples/distributed_tree/CMakeLists.txt | 4 + .../distributed_intersects_callback.cpp | 140 ++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 examples/distributed_tree/distributed_intersects_callback.cpp diff --git a/examples/distributed_tree/CMakeLists.txt b/examples/distributed_tree/CMakeLists.txt index 47e358f2d..8ecad2be9 100644 --- a/examples/distributed_tree/CMakeLists.txt +++ b/examples/distributed_tree/CMakeLists.txt @@ -5,3 +5,7 @@ add_test(NAME ArborX_DistributedTree_KNN_Example COMMAND ${MPIEXEC_EXECUTABLE} $ add_executable(ArborX_DistributedTree_Intersects.exe distributed_intersects.cpp) target_link_libraries(ArborX_DistributedTree_Intersects.exe ArborX::ArborX) add_test(NAME ArborX_DistributedTree_Intersects_Example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} ./ArborX_DistributedTree_Intersects.exe ${MPIEXEC_POSTFLAGS}) + +add_executable(ArborX_DistributedTree_IntersectsCallback.exe distributed_intersects_callback.cpp) +target_link_libraries(ArborX_DistributedTree_IntersectsCallback.exe ArborX::ArborX) +add_test(NAME ArborX_DistributedTree_IntersectsCallback_Example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} ./ArborX_DistributedTree_IntersectsCallback.exe ${MPIEXEC_POSTFLAGS}) diff --git a/examples/distributed_tree/distributed_intersects_callback.cpp b/examples/distributed_tree/distributed_intersects_callback.cpp new file mode 100644 index 000000000..128bb9a2e --- /dev/null +++ b/examples/distributed_tree/distributed_intersects_callback.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** + * Copyright (c) 2017-2022 by the ArborX authors * + * All rights reserved. * + * * + * This file is part of the ArborX library. ArborX is * + * distributed under a BSD 3-clause license. For the licensing terms see * + * the LICENSE file in the top-level directory. * + * * + * SPDX-License-Identifier: BSD-3-Clause * + ****************************************************************************/ + +#include + +#include + +#include +#include +#include +#include +#include + +#include + +using ExecutionSpace = Kokkos::DefaultExecutionSpace; +using MemorySpace = ExecutionSpace::memory_space; + +int global_mpi_rank; + +namespace Example +{ +template +struct Intersects +{ + Points points; + float radius; +}; +template +Intersects(Points const &, int) -> Intersects; + +struct IndexAndRank +{ + int index; + int rank; +}; + +template +struct InlinePrintCallback +{ + Kokkos::View points; + int mpi_rank; + + InlinePrintCallback(Kokkos::View const &points_, + int mpi_rank_) + : points(points_) + , mpi_rank(mpi_rank_) + {} + + template + KOKKOS_FUNCTION void operator()(Predicate const &predicate, + int primitive_index, + OutputFunctor const &out) const + { + auto data = ArborX::getData(predicate); + auto const &point = points(primitive_index); + printf("Intersection for query %d from MPI rank %d on MPI rank %d for " + "point %f,%f,%f with index %d\n", + data.index, data.rank, mpi_rank, point[0], point[1], point[2], + primitive_index); + + out({primitive_index, mpi_rank}); + } +}; + +} // namespace Example + +template +struct ArborX::AccessTraits, ArborX::PredicatesTag> +{ + static KOKKOS_FUNCTION std::size_t size(Example::Intersects const &x) + { + return x.points.extent(0); + } + static KOKKOS_FUNCTION auto get(Example::Intersects const &x, int i) + { + return attach(ArborX::intersects(ArborX::Sphere(x.points(i), x.radius)), + Example::IndexAndRank{i, global_mpi_rank}); + } + using memory_space = MemorySpace; +}; + +int main(int argc, char *argv[]) +{ + MPI_Init(&argc, &argv); + Kokkos::initialize(argc, argv); + { + MPI_Comm comm = MPI_COMM_WORLD; + int comm_rank; + MPI_Comm_rank(comm, &comm_rank); + global_mpi_rank = comm_rank; + int comm_size; + MPI_Comm_size(comm, &comm_size); + ArborX::Point lower_left_corner = {static_cast(comm_rank), + static_cast(comm_rank), + static_cast(comm_rank)}; + ArborX::Point center = {static_cast(comm_rank) + .5f, + static_cast(comm_rank) + .5f, + static_cast(comm_rank) + .5f}; + std::vector points = {lower_left_corner, center}; + auto points_device = Kokkos::create_mirror_view_and_copy( + MemorySpace{}, + Kokkos::View(points.data(), points.size())); + + ExecutionSpace exec; + ArborX::DistributedTree tree(comm, exec, points_device); + + Kokkos::View values("values", 0); + Kokkos::View offsets("offsets", 0); + tree.query( + exec, Example::Intersects{points_device, 1.}, + Example::InlinePrintCallback(points_device, comm_rank), + values, offsets); + + auto host_values = + Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, values); + auto host_offsets = + Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, offsets); + for (unsigned int i = 0; i + 1 < host_offsets.size(); ++i) + { + std::cout << "Results for query " << i << " on MPI rank " << comm_rank + << '\n'; + for (unsigned int j = host_offsets(i); j < host_offsets(i + 1); ++j) + std::cout << "point " << host_values(j).index << ", rank " + << host_values(j).rank << std::endl; + } + } + Kokkos::finalize(); + MPI_Finalize(); + return 0; +} From 018c7caf5472580dad47174b18e441cb86cc051f Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Wed, 31 Aug 2022 18:10:40 -0400 Subject: [PATCH 4/7] avoid global_mpi_rank --- .../distributed_intersects_callback.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/distributed_tree/distributed_intersects_callback.cpp b/examples/distributed_tree/distributed_intersects_callback.cpp index 128bb9a2e..3b290f61d 100644 --- a/examples/distributed_tree/distributed_intersects_callback.cpp +++ b/examples/distributed_tree/distributed_intersects_callback.cpp @@ -24,8 +24,6 @@ using ExecutionSpace = Kokkos::DefaultExecutionSpace; using MemorySpace = ExecutionSpace::memory_space; -int global_mpi_rank; - namespace Example { template @@ -33,9 +31,10 @@ struct Intersects { Points points; float radius; + int mpi_rank; }; template -Intersects(Points const &, int) -> Intersects; +Intersects(Points const &, float, int) -> Intersects; struct IndexAndRank { @@ -83,7 +82,7 @@ struct ArborX::AccessTraits, ArborX::PredicatesTag> static KOKKOS_FUNCTION auto get(Example::Intersects const &x, int i) { return attach(ArborX::intersects(ArborX::Sphere(x.points(i), x.radius)), - Example::IndexAndRank{i, global_mpi_rank}); + Example::IndexAndRank{i, x.mpi_rank}); } using memory_space = MemorySpace; }; @@ -96,7 +95,6 @@ int main(int argc, char *argv[]) MPI_Comm comm = MPI_COMM_WORLD; int comm_rank; MPI_Comm_rank(comm, &comm_rank); - global_mpi_rank = comm_rank; int comm_size; MPI_Comm_size(comm, &comm_size); ArborX::Point lower_left_corner = {static_cast(comm_rank), @@ -117,7 +115,7 @@ int main(int argc, char *argv[]) Kokkos::View values("values", 0); Kokkos::View offsets("offsets", 0); tree.query( - exec, Example::Intersects{points_device, 1.}, + exec, Example::Intersects{points_device, 1., comm_rank}, Example::InlinePrintCallback(points_device, comm_rank), values, offsets); From 23a266d72e832a89214fd4ddbe40eec916946682 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Mon, 12 Sep 2022 10:44:10 -0600 Subject: [PATCH 5/7] Use MPIEXEC_PREFLAGS in installed examples --- .jenkins/continuous.groovy | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.jenkins/continuous.groovy b/.jenkins/continuous.groovy index b71f28e90..42fbd8617 100644 --- a/.jenkins/continuous.groovy +++ b/.jenkins/continuous.groovy @@ -89,6 +89,8 @@ pipeline { -D CMAKE_CXX_COMPILER=$KOKKOS_DIR/bin/nvcc_wrapper \ -D CMAKE_CXX_EXTENSIONS=OFF \ -D CMAKE_PREFIX_PATH="$KOKKOS_DIR;$ARBORX_DIR" \ + -D MPIEXEC_PREFLAGS="--allow-run-as-root" \ + -D MPIEXEC_MAX_NUMPROCS=4 \ examples \ ''' sh 'make VERBOSE=1' @@ -148,6 +150,8 @@ pipeline { -D CMAKE_CXX_COMPILER=$KOKKOS_DIR/bin/nvcc_wrapper \ -D CMAKE_CXX_EXTENSIONS=OFF \ -D CMAKE_PREFIX_PATH="$KOKKOS_DIR;$ARBORX_DIR" \ + -D MPIEXEC_PREFLAGS="--allow-run-as-root" \ + -D MPIEXEC_MAX_NUMPROCS=4 \ examples \ ''' sh 'make VERBOSE=1' @@ -205,6 +209,8 @@ pipeline { -D CMAKE_CXX_COMPILER=clang++ \ -D CMAKE_CXX_EXTENSIONS=OFF \ -D CMAKE_PREFIX_PATH="$KOKKOS_DIR;$ARBORX_DIR" \ + -D MPIEXEC_PREFLAGS="--allow-run-as-root" \ + -D MPIEXEC_MAX_NUMPROCS=4 \ examples \ ''' sh 'make VERBOSE=1' @@ -266,6 +272,8 @@ pipeline { -D CMAKE_CXX_COMPILER=clang++ \ -D CMAKE_CXX_EXTENSIONS=OFF \ -D CMAKE_PREFIX_PATH="$KOKKOS_DIR;$ARBORX_DIR" \ + -D MPIEXEC_PREFLAGS="--allow-run-as-root" \ + -D MPIEXEC_MAX_NUMPROCS=4 \ examples \ ''' sh 'make VERBOSE=1' @@ -329,6 +337,8 @@ pipeline { -D CMAKE_CXX_EXTENSIONS=OFF \ -D CMAKE_BUILD_TYPE=RelWithDebInfo \ -D CMAKE_PREFIX_PATH="$KOKKOS_DIR;$ARBORX_DIR" \ + -D MPIEXEC_PREFLAGS="--allow-run-as-root" \ + -D MPIEXEC_MAX_NUMPROCS=4 \ examples \ ''' sh 'make VERBOSE=1' @@ -391,6 +401,8 @@ pipeline { -D CMAKE_CXX_FLAGS="-Wno-unknown-cuda-version" \ -D CMAKE_PREFIX_PATH="$KOKKOS_DIR;$ARBORX_DIR;$ONE_DPL_DIR" \ -D ONEDPL_PAR_BACKEND=serial \ + -D MPIEXEC_PREFLAGS="--allow-run-as-root" \ + -D MPIEXEC_MAX_NUMPROCS=4 \ examples \ ''' sh 'make VERBOSE=1' From 7785caf9cd8d98e4c0d86db07e5757adb4300b6a Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 11 Oct 2022 11:56:31 -0400 Subject: [PATCH 6/7] Reduce boilerplate --- .../distributed_intersects.cpp | 29 +++--------- .../distributed_intersects_callback.cpp | 29 +++--------- examples/distributed_tree/distributed_knn.cpp | 29 +++--------- .../distributed_tree/distributed_setup.hpp | 45 +++++++++++++++++++ 4 files changed, 63 insertions(+), 69 deletions(-) create mode 100644 examples/distributed_tree/distributed_setup.hpp diff --git a/examples/distributed_tree/distributed_intersects.cpp b/examples/distributed_tree/distributed_intersects.cpp index 8d6a7658a..e19d09bdd 100644 --- a/examples/distributed_tree/distributed_intersects.cpp +++ b/examples/distributed_tree/distributed_intersects.cpp @@ -13,12 +13,7 @@ #include -#include -#include -#include -#include -#include - +#include "distributed_setup.hpp" #include using ExecutionSpace = Kokkos::DefaultExecutionSpace; @@ -64,24 +59,10 @@ int main(int argc, char *argv[]) Kokkos::initialize(argc, argv); { MPI_Comm comm = MPI_COMM_WORLD; - int comm_rank; - MPI_Comm_rank(comm, &comm_rank); - int comm_size; - MPI_Comm_size(comm, &comm_size); - ArborX::Point lower_left_corner = {static_cast(comm_rank), - static_cast(comm_rank), - static_cast(comm_rank)}; - ArborX::Point center = {static_cast(comm_rank) + .5f, - static_cast(comm_rank) + .5f, - static_cast(comm_rank) + .5f}; - std::vector points = {lower_left_corner, center}; - auto points_device = Kokkos::create_mirror_view_and_copy( - MemorySpace{}, - Kokkos::View(points.data(), points.size())); - ExecutionSpace exec; - ArborX::DistributedTree tree(comm, exec, points_device); + Kokkos::View points_device; + ArborX::DistributedTree tree = + ArborXExample::create_tree(comm, exec, points_device); Kokkos::View values("values", 0); Kokkos::View offsets("offsets", 0); @@ -91,6 +72,8 @@ int main(int argc, char *argv[]) Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, values); auto host_offsets = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, offsets); + int comm_rank; + MPI_Comm_rank(comm, &comm_rank); for (unsigned int i = 0; i + 1 < host_offsets.size(); ++i) { std::cout << "Results for query " << i << " on MPI rank " << comm_rank diff --git a/examples/distributed_tree/distributed_intersects_callback.cpp b/examples/distributed_tree/distributed_intersects_callback.cpp index 3b290f61d..91069207a 100644 --- a/examples/distributed_tree/distributed_intersects_callback.cpp +++ b/examples/distributed_tree/distributed_intersects_callback.cpp @@ -13,12 +13,7 @@ #include -#include -#include -#include -#include -#include - +#include "distributed_setup.hpp" #include using ExecutionSpace = Kokkos::DefaultExecutionSpace; @@ -93,27 +88,15 @@ int main(int argc, char *argv[]) Kokkos::initialize(argc, argv); { MPI_Comm comm = MPI_COMM_WORLD; - int comm_rank; - MPI_Comm_rank(comm, &comm_rank); - int comm_size; - MPI_Comm_size(comm, &comm_size); - ArborX::Point lower_left_corner = {static_cast(comm_rank), - static_cast(comm_rank), - static_cast(comm_rank)}; - ArborX::Point center = {static_cast(comm_rank) + .5f, - static_cast(comm_rank) + .5f, - static_cast(comm_rank) + .5f}; - std::vector points = {lower_left_corner, center}; - auto points_device = Kokkos::create_mirror_view_and_copy( - MemorySpace{}, - Kokkos::View(points.data(), points.size())); - ExecutionSpace exec; - ArborX::DistributedTree tree(comm, exec, points_device); + Kokkos::View points_device; + ArborX::DistributedTree tree = + ArborXExample::create_tree(comm, exec, points_device); Kokkos::View values("values", 0); Kokkos::View offsets("offsets", 0); + int comm_rank; + MPI_Comm_rank(comm, &comm_rank); tree.query( exec, Example::Intersects{points_device, 1., comm_rank}, Example::InlinePrintCallback(points_device, comm_rank), diff --git a/examples/distributed_tree/distributed_knn.cpp b/examples/distributed_tree/distributed_knn.cpp index 565915db1..29005dd28 100644 --- a/examples/distributed_tree/distributed_knn.cpp +++ b/examples/distributed_tree/distributed_knn.cpp @@ -13,12 +13,7 @@ #include -#include -#include -#include -#include -#include - +#include "distributed_setup.hpp" #include using ExecutionSpace = Kokkos::DefaultExecutionSpace; @@ -64,24 +59,10 @@ int main(int argc, char *argv[]) Kokkos::initialize(argc, argv); { MPI_Comm comm = MPI_COMM_WORLD; - int comm_rank; - MPI_Comm_rank(comm, &comm_rank); - int comm_size; - MPI_Comm_size(comm, &comm_size); - ArborX::Point lower_left_corner = {static_cast(comm_rank), - static_cast(comm_rank), - static_cast(comm_rank)}; - ArborX::Point center = {static_cast(comm_rank) + .5f, - static_cast(comm_rank) + .5f, - static_cast(comm_rank) + .5f}; - std::vector points = {lower_left_corner, center}; - auto points_device = Kokkos::create_mirror_view_and_copy( - MemorySpace{}, - Kokkos::View(points.data(), points.size())); - ExecutionSpace exec; - ArborX::DistributedTree tree(comm, exec, points_device); + Kokkos::View points_device; + ArborX::DistributedTree tree = + ArborXExample::create_tree(comm, exec, points_device); Kokkos::View values("values", 0); Kokkos::View offsets("offsets", 0); @@ -91,6 +72,8 @@ int main(int argc, char *argv[]) Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, values); auto host_offsets = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, offsets); + int comm_rank; + MPI_Comm_rank(comm, &comm_rank); for (unsigned int i = 0; i + 1 < host_offsets.size(); ++i) { std::cout << "Results for query " << i << " on MPI rank " << comm_rank diff --git a/examples/distributed_tree/distributed_setup.hpp b/examples/distributed_tree/distributed_setup.hpp new file mode 100644 index 000000000..5c44354cd --- /dev/null +++ b/examples/distributed_tree/distributed_setup.hpp @@ -0,0 +1,45 @@ +/**************************************************************************** + * Copyright (c) 2017-2022 by the ArborX authors * + * All rights reserved. * + * * + * This file is part of the ArborX library. ArborX is * + * distributed under a BSD 3-clause license. For the licensing terms see * + * the LICENSE file in the top-level directory. * + * * + * SPDX-License-Identifier: BSD-3-Clause * + ****************************************************************************/ + +#include + +#include + +#include + +namespace ArborXExample +{ + +template +ArborX::DistributedTree +create_tree(MPI_Comm comm, ExecutionSpace const &exec, + Kokkos::View &points_device) +{ + int comm_rank; + MPI_Comm_rank(comm, &comm_rank); + int comm_size; + MPI_Comm_size(comm, &comm_size); + ArborX::Point lower_left_corner = {static_cast(comm_rank), + static_cast(comm_rank), + static_cast(comm_rank)}; + ArborX::Point center = {static_cast(comm_rank) + .5f, + static_cast(comm_rank) + .5f, + static_cast(comm_rank) + .5f}; + std::vector points = {lower_left_corner, center}; + points_device = Kokkos::create_mirror_view_and_copy( + MemorySpace{}, + Kokkos::View( + points.data(), points.size())); + + ArborX::DistributedTree tree(comm, exec, points_device); + return tree; +} +} // namespace ArborXExample From aa0f99e6501863fe09062d69887b321f1b467f17 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Wed, 12 Oct 2022 15:30:15 -0400 Subject: [PATCH 7/7] Fix sign comparison warnings --- examples/distributed_tree/distributed_intersects.cpp | 2 +- examples/distributed_tree/distributed_intersects_callback.cpp | 2 +- examples/distributed_tree/distributed_knn.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/distributed_tree/distributed_intersects.cpp b/examples/distributed_tree/distributed_intersects.cpp index e19d09bdd..3f9576ed1 100644 --- a/examples/distributed_tree/distributed_intersects.cpp +++ b/examples/distributed_tree/distributed_intersects.cpp @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) { std::cout << "Results for query " << i << " on MPI rank " << comm_rank << '\n'; - for (unsigned int j = host_offsets(i); j < host_offsets(i + 1); ++j) + for (int j = host_offsets(i); j < host_offsets(i + 1); ++j) std::cout << "point " << host_values(j).index << ", rank " << host_values(j).rank << std::endl; } diff --git a/examples/distributed_tree/distributed_intersects_callback.cpp b/examples/distributed_tree/distributed_intersects_callback.cpp index 91069207a..9c46e481c 100644 --- a/examples/distributed_tree/distributed_intersects_callback.cpp +++ b/examples/distributed_tree/distributed_intersects_callback.cpp @@ -110,7 +110,7 @@ int main(int argc, char *argv[]) { std::cout << "Results for query " << i << " on MPI rank " << comm_rank << '\n'; - for (unsigned int j = host_offsets(i); j < host_offsets(i + 1); ++j) + for (int j = host_offsets(i); j < host_offsets(i + 1); ++j) std::cout << "point " << host_values(j).index << ", rank " << host_values(j).rank << std::endl; } diff --git a/examples/distributed_tree/distributed_knn.cpp b/examples/distributed_tree/distributed_knn.cpp index 29005dd28..9497e3c47 100644 --- a/examples/distributed_tree/distributed_knn.cpp +++ b/examples/distributed_tree/distributed_knn.cpp @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) { std::cout << "Results for query " << i << " on MPI rank " << comm_rank << '\n'; - for (unsigned int j = host_offsets(i); j < host_offsets(i + 1); ++j) + for (int j = host_offsets(i); j < host_offsets(i + 1); ++j) std::cout << "point " << host_values(j).index << ", rank " << host_values(j).rank << std::endl; }