-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DistributedTree examples #732
Open
masterleinad
wants to merge
7
commits into
arborx:master
Choose a base branch
from
masterleinad:example_distributed_tree
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0a72225
Add DistributedTree nearest example
masterleinad 0768edb
Add DistributedTree intersects example
masterleinad 3e6b3e3
Add DistributedTree intersects with callback example
masterleinad 018c7ca
avoid global_mpi_rank
masterleinad 23a266d
Use MPIEXEC_PREFLAGS in installed examples
masterleinad 7785caf
Reduce boilerplate
masterleinad aa0f99e
Fix sign comparison warnings
masterleinad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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}) | ||
|
||
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/**************************************************************************** | ||
* 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 <ArborX.hpp> | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
#include "distributed_setup.hpp" | ||
#include <mpi.h> | ||
|
||
using ExecutionSpace = Kokkos::DefaultExecutionSpace; | ||
using MemorySpace = ExecutionSpace::memory_space; | ||
|
||
namespace Example | ||
{ | ||
template <class Points> | ||
struct Intersects | ||
{ | ||
Points points; | ||
float radius; | ||
}; | ||
template <class Points> | ||
Intersects(Points const &, int) -> Intersects<Points>; | ||
|
||
struct IndexAndRank | ||
{ | ||
int index; | ||
int rank; | ||
}; | ||
|
||
} // namespace Example | ||
|
||
template <class Points> | ||
struct ArborX::AccessTraits<Example::Intersects<Points>, ArborX::PredicatesTag> | ||
{ | ||
static KOKKOS_FUNCTION std::size_t size(Example::Intersects<Points> const &x) | ||
{ | ||
return x.points.extent(0); | ||
} | ||
static KOKKOS_FUNCTION auto get(Example::Intersects<Points> 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; | ||
ExecutionSpace exec; | ||
Kokkos::View<ArborX::Point *, MemorySpace> points_device; | ||
ArborX::DistributedTree<MemorySpace> tree = | ||
ArborXExample::create_tree(comm, exec, points_device); | ||
|
||
Kokkos::View<Example::IndexAndRank *, MemorySpace> values("values", 0); | ||
Kokkos::View<int *, MemorySpace> 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); | ||
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 | ||
<< '\n'; | ||
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; | ||
} | ||
} | ||
Kokkos::finalize(); | ||
MPI_Finalize(); | ||
return 0; | ||
} |
121 changes: 121 additions & 0 deletions
121
examples/distributed_tree/distributed_intersects_callback.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/**************************************************************************** | ||
* 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 <ArborX.hpp> | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
#include "distributed_setup.hpp" | ||
#include <mpi.h> | ||
|
||
using ExecutionSpace = Kokkos::DefaultExecutionSpace; | ||
using MemorySpace = ExecutionSpace::memory_space; | ||
|
||
namespace Example | ||
{ | ||
template <class Points> | ||
struct Intersects | ||
{ | ||
Points points; | ||
float radius; | ||
int mpi_rank; | ||
}; | ||
template <class Points> | ||
Intersects(Points const &, float, int) -> Intersects<Points>; | ||
|
||
struct IndexAndRank | ||
{ | ||
int index; | ||
int rank; | ||
}; | ||
|
||
template <typename DeviceType> | ||
struct InlinePrintCallback | ||
{ | ||
Kokkos::View<ArborX::Point *, DeviceType> points; | ||
int mpi_rank; | ||
|
||
InlinePrintCallback(Kokkos::View<ArborX::Point *, DeviceType> const &points_, | ||
int mpi_rank_) | ||
: points(points_) | ||
, mpi_rank(mpi_rank_) | ||
{} | ||
|
||
template <typename Predicate, typename OutputFunctor> | ||
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 <class Points> | ||
struct ArborX::AccessTraits<Example::Intersects<Points>, ArborX::PredicatesTag> | ||
{ | ||
static KOKKOS_FUNCTION std::size_t size(Example::Intersects<Points> const &x) | ||
{ | ||
return x.points.extent(0); | ||
} | ||
static KOKKOS_FUNCTION auto get(Example::Intersects<Points> const &x, int i) | ||
{ | ||
return attach(ArborX::intersects(ArborX::Sphere(x.points(i), x.radius)), | ||
Example::IndexAndRank{i, x.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; | ||
ExecutionSpace exec; | ||
Kokkos::View<ArborX::Point *, MemorySpace> points_device; | ||
ArborX::DistributedTree<MemorySpace> tree = | ||
ArborXExample::create_tree(comm, exec, points_device); | ||
|
||
Kokkos::View<Example::IndexAndRank *, MemorySpace> values("values", 0); | ||
Kokkos::View<int *, MemorySpace> offsets("offsets", 0); | ||
int comm_rank; | ||
MPI_Comm_rank(comm, &comm_rank); | ||
tree.query( | ||
exec, Example::Intersects{points_device, 1., comm_rank}, | ||
Example::InlinePrintCallback<MemorySpace>(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 (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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/**************************************************************************** | ||
* 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 <ArborX.hpp> | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
#include "distributed_setup.hpp" | ||
#include <mpi.h> | ||
|
||
using ExecutionSpace = Kokkos::DefaultExecutionSpace; | ||
using MemorySpace = ExecutionSpace::memory_space; | ||
|
||
namespace Example | ||
{ | ||
template <class Points> | ||
struct Nearest | ||
{ | ||
Points points; | ||
int k; | ||
}; | ||
template <class Points> | ||
Nearest(Points const &, int) -> Nearest<Points>; | ||
|
||
struct IndexAndRank | ||
{ | ||
int index; | ||
int rank; | ||
}; | ||
|
||
} // namespace Example | ||
|
||
template <class Points> | ||
struct ArborX::AccessTraits<Example::Nearest<Points>, ArborX::PredicatesTag> | ||
{ | ||
static KOKKOS_FUNCTION std::size_t size(Example::Nearest<Points> const &x) | ||
{ | ||
return x.points.extent(0); | ||
} | ||
static KOKKOS_FUNCTION auto get(Example::Nearest<Points> 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; | ||
ExecutionSpace exec; | ||
Kokkos::View<ArborX::Point *, MemorySpace> points_device; | ||
ArborX::DistributedTree<MemorySpace> tree = | ||
ArborXExample::create_tree(comm, exec, points_device); | ||
|
||
Kokkos::View<Example::IndexAndRank *, MemorySpace> values("values", 0); | ||
Kokkos::View<int *, MemorySpace> 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); | ||
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 | ||
<< '\n'; | ||
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; | ||
} | ||
} | ||
Kokkos::finalize(); | ||
MPI_Finalize(); | ||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering whether we should comment that we don't need it from C++20