16#ifndef CABANA_HALO_HPP
17#define CABANA_HALO_HPP
21#include <Cabana_Core_Config.hpp>
24#include <Kokkos_Core.hpp>
25#include <Kokkos_Profiling_ScopedRegion.hpp>
59template <
class MemorySpace,
class BuildType =
Export,
60 class CommSpaceType =
Mpi>
107 template <
class IdViewType,
class RankViewType,
typename T = BuildType,
108 std::enable_if_t<std::is_same<T, Export>::value,
int> = 0>
110 const IdViewType& element_ids,
const RankViewType& element_ranks,
111 const std::vector<int>& neighbor_ranks )
114 build( num_local, element_ids, element_ranks, neighbor_ranks );
149 template <
class IdViewType,
class RankViewType,
typename T = BuildType,
150 std::enable_if_t<std::is_same<T, Export>::value,
int> = 0>
152 const IdViewType& element_ids,
const RankViewType& element_ranks )
155 build( num_local, element_ids, element_ranks );
198 template <
class IdViewType,
class RankViewType,
typename T = BuildType,
199 std::enable_if_t<std::is_same<T, Import>::value,
int> = 0>
201 const IdViewType& element_ids,
const RankViewType& element_ranks,
202 const std::vector<int>& neighbor_ranks )
205 build( num_local, element_ids, element_ranks, neighbor_ranks );
239 template <
class IdViewType,
class RankViewType,
typename T = BuildType,
240 std::enable_if_t<std::is_same<T, Import>::value,
int> = 0>
242 const IdViewType& element_ids,
const RankViewType& element_ranks )
245 build( num_local, element_ids, element_ranks );
253 template <
class IdViewType,
class RankViewType,
typename T = BuildType,
254 std::enable_if_t<std::is_same<T, Export>::value,
int> = 0>
255 void build(
const std::size_t num_local,
const IdViewType& element_ids,
256 const RankViewType& element_ranks,
257 const std::vector<int>& neighbor_ranks )
259 _num_local = num_local;
260 if ( element_ids.size() != element_ranks.size() )
261 throw std::runtime_error(
"Cabana::Halo (export): ids and ranks "
262 "views are different sizes!" );
265 BuildType(), element_ranks, neighbor_ranks );
274 template <
class IdViewType,
class RankViewType,
typename T = BuildType,
275 std::enable_if_t<std::is_same<T, Export>::value,
int> = 0>
276 void build(
const std::size_t num_local,
const IdViewType& element_ids,
277 const RankViewType& element_ranks )
279 _num_local = num_local;
280 if ( element_ids.size() != element_ranks.size() )
281 throw std::runtime_error(
"Cabana::Halo (export): ids and ranks "
282 "views are different sizes!" );
294 template <
class IdViewType,
class RankViewType,
typename T = BuildType,
295 std::enable_if_t<std::is_same<T, Import>::value,
int> = 0>
296 void build(
const std::size_t num_local,
const IdViewType& element_ids,
297 const RankViewType& element_ranks,
298 const std::vector<int>& neighbor_ranks )
300 _num_local = num_local;
301 if ( element_ids.size() != element_ranks.size() )
302 throw std::runtime_error(
"Cabana::Halo (import): ids and ranks "
303 "views are different sizes!" );
306 BuildType(), element_ranks, element_ids, neighbor_ranks );
308 std::get<1>( neighbor_ids_ranks_indices ),
309 std::get<2>( neighbor_ids_ranks_indices ) );
317 template <
class IdViewType,
class RankViewType,
typename T = BuildType,
318 std::enable_if_t<std::is_same<T, Import>::value,
int> = 0>
319 void build(
const std::size_t num_local,
const IdViewType& element_ids,
320 const RankViewType& element_ranks )
322 _num_local = num_local;
323 if ( element_ids.size() != element_ranks.size() )
324 throw std::runtime_error(
"Cabana::Halo (import): ids and ranks "
325 "views are different sizes!" );
328 BuildType(), element_ranks, element_ids );
330 std::get<1>( neighbor_ids_ranks_indices ),
331 std::get<2>( neighbor_ids_ranks_indices ) );
339 std::size_t
numLocal()
const {
return _num_local; }
351 std::size_t _num_local;
357struct is_halo_impl :
public std::false_type
361template <
typename MemorySpace,
typename BuildType,
typename CommSpaceType>
362struct is_halo_impl<
Halo<MemorySpace, BuildType, CommSpaceType>>
363 :
public std::true_type
370struct is_halo :
public is_halo_impl<typename std::remove_cv<T>::type>::type
383template <
class Halo,
class ParticleData>
385 const Halo& halo,
const ParticleData& particles,
392template <
class HaloType,
class AoSoAType,
class SFINAE =
void>
407template <
class HaloType,
class AoSoAType>
409 typename std::enable_if<is_aosoa<AoSoAType>::value>::type>
443 Gather( HaloType halo, AoSoAType aosoa,
const double overallocation = 1.0 )
444 :
base_type( halo, aosoa, overallocation )
450 auto totalSend() {
return _comm_plan.totalNumExport(); }
454 auto totalSend(
const HaloType& halo ) {
return halo.totalNumExport(); }
456 auto totalReceive(
const HaloType& halo ) {
return halo.totalNumImport(); }
466 template <
class ExecutionSpace,
class CommSpaceType>
467 std::enable_if_t<std::is_same<CommSpaceType, Mpi>::value,
void>
478 void reserve(
const HaloType& halo, AoSoAType& aosoa )
481 throw std::runtime_error(
482 "Cabana::Gather:reserve: "
483 "AoSoA is the wrong size for gather! (Label: " +
484 aosoa.label() +
")" );
486 this->reserveImpl( halo, aosoa,
totalSend( halo ),
497 void reserve(
const HaloType& halo, AoSoAType& aosoa,
498 const double overallocation )
501 throw std::runtime_error(
502 "Cabana::Gather:reserve: "
503 "AoSoA is the wrong size for gather! (Label: " +
504 aosoa.label() +
")" );
511 using base_type::_comm_plan;
512 using base_type::_recv_size;
513 using base_type::_send_size;
527template <
class HaloType,
class SliceType>
529 typename std::enable_if<is_slice<SliceType>::value>::type>
563 Gather( HaloType halo, SliceType
slice,
const double overallocation = 1.0 )
570 auto totalSend() {
return _comm_plan.totalNumExport(); }
574 auto totalSend(
const HaloType& halo ) {
return halo.totalNumExport(); }
576 auto totalReceive(
const HaloType& halo ) {
return halo.totalNumImport(); }
586 template <
class ExecutionSpace,
class CommSpaceType>
587 std::enable_if_t<std::is_same<CommSpaceType, Mpi>::value,
void>
601 const double overallocation )
604 throw std::runtime_error(
605 "Cabana::Gather:reserve: "
606 "Slice is the wrong size for gather! (Label: " +
607 slice.label() +
")" );
623 throw std::runtime_error(
624 "Cabana::Gather:reserve: "
625 "Slice is the wrong size for gather! (Label: " +
626 slice.label() +
")" );
633 using base_type::_comm_plan;
634 using base_type::_recv_size;
635 using base_type::_send_size;
652template <
class HaloType,
class ParticleDataType>
654 const double overallocation = 1.0 )
677template <
class HaloType,
class ParticleDataType>
678void gather(
const HaloType& halo, ParticleDataType& data )
700template <
class HaloType,
class SliceType>
735 Scatter( HaloType halo, SliceType
slice,
const double overallocation = 1.0 )
742 auto totalSend() {
return _comm_plan.totalNumImport(); }
746 auto totalSend(
const HaloType& halo ) {
return halo.totalNumImport(); }
748 auto totalReceive(
const HaloType& halo ) {
return halo.totalNumExport(); }
758 template <
class ExecutionSpace,
class CommSpaceType>
759 std::enable_if_t<std::is_same<CommSpaceType, Mpi>::value,
void>
774 const double overallocation )
777 throw std::runtime_error(
778 "Cabana::Scatter::reserve: "
779 "Slice is the wrong size for scatter! (Label: " +
780 slice.label() +
")" );
794 throw std::runtime_error(
795 "Cabana::Scatter::reserve: "
796 "Slice is the wrong size for scatter! (Label: " +
797 slice.label() +
")" );
804 using base_type::_comm_plan;
805 using base_type::_recv_size;
806 using base_type::_send_size;
812#ifdef Cabana_ENABLE_MPI
832template <
class HaloType,
class SliceType>
834 const double overallocation = 1.0,
860template <
class HaloType,
class SliceType>
Array-of-Struct-of-Arrays particle data structure.
Multi-node communication patterns. Base class.
Multi-node particle scatter/gather, Mpi implementations.
Slice a single particle property from an AoSoA.
Definition Cabana_CommunicationPlanBase.hpp:964
std::size_t totalNumImport() const
Get the total number of imports this rank will do.
Definition Cabana_CommunicationPlanBase.hpp:522
void createExportSteering(const PackViewType &neighbor_ids, const RankViewType &element_export_ranks)
Create the export steering vector.
Definition Cabana_CommunicationPlanBase.hpp:569
MPI_Comm comm() const
Get the MPI communicator.
Definition Cabana_CommunicationPlanBase.hpp:465
Kokkos::View< size_type *, memory_space > createWithTopology(ExecutionSpace exec_space, Export, const RankViewType &element_export_ranks, const std::vector< int > &neighbor_ranks)
Neighbor and export rank creator. Use this when you already know which ranks neighbor each other (i....
Definition Cabana_CommunicationPlan_Mpi.hpp:107
Kokkos::View< size_type *, memory_space > createWithoutTopology(ExecutionSpace exec_space, Export, const RankViewType &element_export_ranks)
Export rank creator. Use this when you don't know who you will receiving from - only who you are send...
Definition Cabana_CommunicationPlan_Mpi.hpp:272
CommunicationPlan(MPI_Comm comm)
Constructor.
Definition Cabana_CommunicationPlan_Mpi.hpp:59
auto totalSend(const HaloType &halo)
Total gather send size for this rank.
Definition Cabana_Halo.hpp:454
typename base_type::memory_space memory_space
Kokkos memory space.
Definition Cabana_Halo.hpp:425
auto totalReceive(const HaloType &halo)
Total gather receive size for this rank.
Definition Cabana_Halo.hpp:456
typename HaloType::commspace_type commspace_type
Communication space type.
Definition Cabana_Halo.hpp:416
void apply() override
Perform the gather operation.
Definition Cabana_Halo.hpp:461
void reserve(const HaloType &halo, AoSoAType &aosoa, const double overallocation)
Reserve new buffers as needed and update the halo and AoSoA data.
Definition Cabana_Halo.hpp:497
auto totalSend()
Total gather send size for this rank.
Definition Cabana_Halo.hpp:450
typename base_type::data_type data_type
Communication data type.
Definition Cabana_Halo.hpp:427
Gather(HaloType halo, AoSoAType aosoa, const double overallocation=1.0)
Definition Cabana_Halo.hpp:443
auto totalReceive()
Total gather receive size for this rank.
Definition Cabana_Halo.hpp:452
typename base_type::buffer_type buffer_type
Communication buffer type.
Definition Cabana_Halo.hpp:429
typename base_type::plan_type plan_type
Communication plan type (Halo)
Definition Cabana_Halo.hpp:421
typename base_type::execution_space execution_space
Kokkos execution space.
Definition Cabana_Halo.hpp:423
std::enable_if_t< std::is_same< CommSpaceType, Mpi >::value, void > applyImpl(ExecutionSpace, CommSpaceType)
Vanilla Mpi implementation of the gather operation.
void reserve(const HaloType &halo, AoSoAType &aosoa)
Reserve new buffers as needed and update the halo and AoSoA data.
Definition Cabana_Halo.hpp:478
CommunicationData< HaloType, CommunicationDataAoSoA< AoSoAType > > base_type
Base type.
Definition Cabana_Halo.hpp:418
auto totalSend(const HaloType &halo)
Total gather send size for this rank.
Definition Cabana_Halo.hpp:574
typename base_type::memory_space memory_space
Kokkos memory space.
Definition Cabana_Halo.hpp:545
typename base_type::buffer_type buffer_type
Communication buffer type.
Definition Cabana_Halo.hpp:549
CommunicationData< HaloType, CommunicationDataSlice< SliceType > > base_type
Base type.
Definition Cabana_Halo.hpp:538
void apply() override
Perform the gather operation.
Definition Cabana_Halo.hpp:581
auto totalReceive()
Total gather receive size for this rank.
Definition Cabana_Halo.hpp:572
Gather(HaloType halo, SliceType slice, const double overallocation=1.0)
Definition Cabana_Halo.hpp:563
std::enable_if_t< std::is_same< CommSpaceType, Mpi >::value, void > applyImpl(ExecutionSpace, CommSpaceType)
Vanilla Mpi implementation of the gather operation.
auto totalReceive(const HaloType &halo)
Total gather receive size for this rank.
Definition Cabana_Halo.hpp:576
void reserve(const HaloType &halo, const SliceType &slice, const double overallocation)
Reserve new buffers as needed and update the halo and slice data.
Definition Cabana_Halo.hpp:600
typename base_type::execution_space execution_space
Kokkos execution space.
Definition Cabana_Halo.hpp:543
typename HaloType::commspace_type commspace_type
Communication space type.
Definition Cabana_Halo.hpp:536
typename base_type::plan_type plan_type
Communication plan type (Halo)
Definition Cabana_Halo.hpp:541
auto totalSend()
Total gather send size for this rank.
Definition Cabana_Halo.hpp:570
void reserve(const HaloType &halo, const SliceType &slice)
Reserve new buffers as needed and update the halo and slice data.
Definition Cabana_Halo.hpp:620
typename base_type::data_type data_type
Communication data type.
Definition Cabana_Halo.hpp:547
Definition Cabana_Halo.hpp:393
A communication plan for scattering and gathering of ghosted data.
Definition Cabana_Halo.hpp:62
CommSpaceType commspace_type
Communication space type.
Definition Cabana_Halo.hpp:65
void build(const std::size_t num_local, const IdViewType &element_ids, const RankViewType &element_ranks)
Export rank (re)build interface.
Definition Cabana_Halo.hpp:276
std::size_t numGhost() const
Get the number of ghost elements this rank. Use this to resize a data structure for scatter/gather op...
Definition Cabana_Halo.hpp:348
void build(const std::size_t num_local, const IdViewType &element_ids, const RankViewType &element_ranks, const std::vector< int > &neighbor_ranks)
Neighbor and export rank (re)build interface.
Definition Cabana_Halo.hpp:255
std::size_t numLocal() const
Get the number of elements locally owned by this rank.
Definition Cabana_Halo.hpp:339
Halo(MPI_Comm comm, const std::size_t num_local, const IdViewType &element_ids, const RankViewType &element_ranks)
Export rank constructor. Use this when you don't know who you will receiving from - only who you are ...
Definition Cabana_Halo.hpp:151
Halo(MPI_Comm comm, const std::size_t num_local, const IdViewType &element_ids, const RankViewType &element_ranks, const std::vector< int > &neighbor_ranks)
Neighbor and export rank constructor. Use this when you don't know who you will receiving from - only...
Definition Cabana_Halo.hpp:109
Synchronously scatter data from the ghosts to the local decomposition of a slice using the halo rever...
Definition Cabana_Halo.hpp:703
void reserve(const HaloType &halo, const SliceType &slice)
Reserve new buffers as needed and update the halo and slice data.
Definition Cabana_Halo.hpp:791
CommunicationData< HaloType, CommunicationDataSlice< SliceType > > base_type
Base type.
Definition Cabana_Halo.hpp:710
typename base_type::memory_space memory_space
Kokkos memory space.
Definition Cabana_Halo.hpp:717
auto totalSend(const HaloType &halo)
Total gather send size for this rank.
Definition Cabana_Halo.hpp:746
typename base_type::data_type data_type
Communication data type.
Definition Cabana_Halo.hpp:719
void reserve(const HaloType &halo, const SliceType &slice, const double overallocation)
Reserve new buffers as needed and update the halo and slice data. Reallocation only occurs if there i...
Definition Cabana_Halo.hpp:773
typename HaloType::commspace_type commspace_type
Communication space type.
Definition Cabana_Halo.hpp:708
typename base_type::plan_type plan_type
Communication plan type (Halo).
Definition Cabana_Halo.hpp:713
std::enable_if_t< std::is_same< CommSpaceType, Mpi >::value, void > applyImpl(ExecutionSpace, CommSpaceType)
Vanilla Mpi implementation of the scatter operation.
auto totalReceive()
Total scatter receive size for this rank.
Definition Cabana_Halo.hpp:744
void apply() override
Perform the scatter operation.
Definition Cabana_Halo.hpp:753
typename base_type::buffer_type buffer_type
Communication buffer type.
Definition Cabana_Halo.hpp:721
typename base_type::execution_space execution_space
Kokkos execution space.
Definition Cabana_Halo.hpp:715
auto totalReceive(const HaloType &halo)
Total gather receive size for this rank.
Definition Cabana_Halo.hpp:748
Scatter(HaloType halo, SliceType slice, const double overallocation=1.0)
Definition Cabana_Halo.hpp:735
auto totalSend()
Total scatter send size for this rank.
Definition Cabana_Halo.hpp:742
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36
void gather(const HaloType &halo, ParticleDataType &data)
Synchronously gather data from the local decomposition to the ghosts using the halo forward communica...
Definition Cabana_Halo.hpp:678
AoSoA_t::template member_slice_type< M > slice(const AoSoA_t &aosoa, const std::string &slice_label="")
Create a slice from an AoSoA.
Definition Cabana_AoSoA.hpp:77
void scatter(const HaloType &halo, SliceType &slice, typename std::enable_if<(is_halo< HaloType >::value &&is_slice< SliceType >::value), int >::type *=0)
Synchronously scatter data from the ghosts to the local decomposition of a slice using the halo rever...
Definition Cabana_Halo.hpp:861
auto createScatter(const HaloType &halo, const SliceType &slice, const double overallocation=1.0, typename std::enable_if<(is_halo< HaloType >::value &&is_slice< SliceType >::value), int >::type *=0)
Create the scatter.
Definition Cabana_Halo.hpp:833
auto createGather(const HaloType &halo, const ParticleDataType &data, const double overallocation=1.0)
Create the gather.
Definition Cabana_Halo.hpp:653
bool haloCheckValidSize(const Halo &halo, const ParticleData &particles, typename std::enable_if<(is_halo< Halo >::value), int >::type *=0)
Ensure the particle size matches the total halo (local and ghost) size.
Definition Cabana_Halo.hpp:384
Export-based tag - default.
Definition Cabana_Tags.hpp:38
Vanilla MPI backend tag - default.
Definition Cabana_Tags.hpp:28
Halo static type checker.
Definition Cabana_Halo.hpp:371
Slice static type checker.
Definition Cabana_Slice.hpp:868