16#ifndef CABANA_GRID_HALO_MPI_HPP
17#define CABANA_GRID_HALO_MPI_HPP
24#include <Kokkos_Core.hpp>
25#include <Kokkos_Profiling_ScopedRegion.hpp>
45template <
class MemorySpace>
60 template <
class Pattern,
class... ArrayTypes>
61 Halo(
const Pattern& pattern,
const int width,
const ArrayTypes&... arrays )
62 :
HaloBase<MemorySpace>( pattern, width, arrays... )
76 template <
class ExecutionSpace,
class... ArrayTypes>
77 void gather(
const ExecutionSpace& exec_space,
78 const ArrayTypes&... arrays )
const
80 Kokkos::Profiling::ScopedRegion region(
"Cabana::Grid::gather" );
88 auto comm = this->
getComm( arrays... );
91 std::vector<MPI_Request> requests( 2 * num_n, MPI_REQUEST_NULL );
95 const int mpi_tag = 1234;
98 for (
int n = 0; n < num_n; ++n )
112 for (
int n = 0; n < num_n; ++n )
126 &requests[num_n + n] );
131 bool unpack_complete =
false;
132 while ( !unpack_complete )
135 int unpack_index = MPI_UNDEFINED;
136 MPI_Waitany( num_n, requests.data(), &unpack_index,
140 if ( MPI_UNDEFINED == unpack_index )
142 unpack_complete =
true;
156 MPI_Waitall( num_n, requests.data() + num_n, MPI_STATUSES_IGNORE );
166 template <
class ExecutionSpace,
class ReduceOp,
class... ArrayTypes>
167 void scatter(
const ExecutionSpace& exec_space,
const ReduceOp& reduce_op,
168 const ArrayTypes&... arrays )
const
170 Kokkos::Profiling::ScopedRegion region(
"Cabana::Grid::scatter" );
178 auto comm = this->
getComm( arrays... );
181 std::vector<MPI_Request> requests( 2 * num_n, MPI_REQUEST_NULL );
185 const int mpi_tag = 2345;
188 for (
int n = 0; n < num_n; ++n )
202 for (
int n = 0; n < num_n; ++n )
217 &requests[num_n + n] );
222 bool unpack_complete =
false;
223 while ( !unpack_complete )
226 int unpack_index = MPI_UNDEFINED;
227 MPI_Waitany( num_n, requests.data(), &unpack_index,
231 if ( MPI_UNDEFINED == unpack_index )
233 unpack_complete =
true;
245 MPI_Waitall( num_n, requests.data() + num_n, MPI_STATUSES_IGNORE );
Pack variadic template parameters for device capture.
std::vector< int > _neighbor_ranks
The ranks we will send/receive from.
Definition Cabana_Grid_HaloBase.hpp:742
std::vector< Kokkos::View< char *, memory_space > > _ghosted_buffers
For each neighbor, send/receive buffers for data we ghost.
Definition Cabana_Grid_HaloBase.hpp:754
void packBuffer(const ExecutionSpace &exec_space, const Kokkos::View< char *, memory_space > &buffer, const Kokkos::View< int **, memory_space > &steering, ArrayViews... array_views) const
Pack arrays into a buffer.
Definition Cabana_Grid_HaloBase.hpp:579
std::vector< int > _receive_tags
The tag we use for receiving from each neighbor.
Definition Cabana_Grid_HaloBase.hpp:748
HaloBase(const Pattern &pattern, const int width, const ArrayTypes &... arrays)
Constructor.
Definition Cabana_Grid_HaloBase.hpp:220
std::vector< Kokkos::View< int **, memory_space > > _owned_steering
For each neighbor, steering vector for the owned buffer.
Definition Cabana_Grid_HaloBase.hpp:757
MemorySpace memory_space
Memory space.
Definition Cabana_Grid_HaloBase.hpp:207
std::vector< Kokkos::View< char *, memory_space > > _owned_buffers
For each neighbor, send/receive buffers for data we own.
Definition Cabana_Grid_HaloBase.hpp:751
std::vector< Kokkos::View< int **, memory_space > > _ghosted_steering
For each neighbor, steering vector for the ghosted buffer.
Definition Cabana_Grid_HaloBase.hpp:760
void unpackBuffer(const ReduceOp &reduce_op, const ExecutionSpace &exec_space, const Kokkos::View< char *, memory_space > &buffer, const Kokkos::View< int **, memory_space > &steering, ArrayViews... array_views) const
Unpack arrays from a buffer.
Definition Cabana_Grid_HaloBase.hpp:720
MPI_Comm getComm(const Array_t &array) const
Get the communicator.
Definition Cabana_Grid_HaloBase.hpp:285
std::vector< int > _send_tags
The tag we use for sending to each neighbor.
Definition Cabana_Grid_HaloBase.hpp:745
Halo(const Pattern &pattern, const int width, const ArrayTypes &... arrays)
Constructor.
Definition Cabana_Grid_Halo_Mpi.hpp:61
void scatter(const ExecutionSpace &exec_space, const ReduceOp &reduce_op, const ArrayTypes &... arrays) const
Scatter data from our ghosts to their owners using the given type of reduce operation.
Definition Cabana_Grid_Halo_Mpi.hpp:167
void gather(const ExecutionSpace &exec_space, const ArrayTypes &... arrays) const
Gather data into our ghosts from their owners.
Definition Cabana_Grid_Halo_Mpi.hpp:77
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36
auto size(SliceType slice, typename std::enable_if< is_slice< SliceType >::value, int >::type *=0)
Check slice size (differs from Kokkos View).
Definition Cabana_Slice.hpp:1019
Definition Cabana_Grid_HaloBase.hpp:184
Vanilla MPI backend tag - default.
Definition Cabana_Tags.hpp:28