36#include "../containers/C2DContainer.hpp"
37#include "../parallelization/mpi_structure.hpp"
207template <
size_t K,
typename Data_t_ = su2
double,
typename Index_t_ =
unsigned long>
215static inline void SU2_MPI_Allgatherv_safe(
const void* sendbuf,
int sendcount,
SU2_MPI::Datatype sendtype,
216 void* recvbuf,
const int* recvcounts,
const int* displs,
221 SU2_MPI::Allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
276template <
size_t N_,
typename Nd_t_,
bool Check>
279 static constexpr size_t N = N_;
302template <
size_t N_,
typename Nd_t_,
bool Check = false>
306 static constexpr size_t N = N_;
345template <
typename Nd_t_,
bool Check>
349 static constexpr size_t N = 1;
414template <
size_t K_,
typename Data_t_,
typename Index_t_>
417 static constexpr size_t K = K_;
437 std::vector<Index_t> indices;
466 for (
Index_t i = from; i < to;) {
468 if (++i < to) output <<
", ";
483 template <
class... ARGS>
495 template <
class... ARGS>
513 indices.resize(nNodes + 1);
534 template <
class f_type>
551 template <
class f_type>
562 template <
class f_type>
565 for (
Index_t iChild = 0; iChild < nChild; iChild++) {
578 template <
class f_type>
581 for (
Index_t iChild = 0; iChild < nChild; iChild++) {
584 indices[iNode + 1] = indices[iNode] + f.second(iChild).first;
586 if (indices[iNode + 1] != indices[iNode] + f.second(iChild).first) {
604 template <
typename MPI_Environment_type>
605 void initialize(MPI_Environment_type
const& mpi_env,
Base const& local_version) {
609 for (
int r = 0; r < mpi_env.size; r++) {
610 nNodes += Nodes_all[
K - 1][r] = 1;
618 for (
int r = 0; r < mpi_env.size; r++) {
619 indices[r + 1] = indices[r] + Nodes_all[
K - 2][r];
633 template <
typename MPI_Environment_type>
634 void refresh(MPI_Environment_type
const& mpi_env,
Base const& local_version) {
636 LowestLayer::count_g(mpi_env, Nodes_all_0, local_version);
637 LowestLayer::set_g(mpi_env, Nodes_all_0, local_version);
652 for (
int r = 0; r < mpi_env.
size; r++) {
653 nNodes += Nodes_all[
K - 1][r];
666 std::vector<int> Nodes_all_K_as_int(mpi_env.
size);
667 std::vector<int> Nodes_all_k_cumulated(mpi_env.
size + 1);
671 Nodes_all_k_cumulated[0] = 1;
672 for (
int r = 0; r < mpi_env.
size; r++) {
673 Nodes_all_k_cumulated[r + 1] = Nodes_all_k_cumulated[r] + Nodes_all[
K - 1][r];
674 Nodes_all_K_as_int[r] = Nodes_all[
K - 1][r];
677 indices.data(), Nodes_all_K_as_int.data(), Nodes_all_k_cumulated.data(),
680 for (
int r = 1; r < mpi_env.
size; r++) {
681 Index_t first_entry_to_be_shifted = Nodes_all_k_cumulated[r];
682 Index_t last_entry_to_be_shifted = Nodes_all_k_cumulated[r + 1] - 1;
683 Index_t shift = indices[first_entry_to_be_shifted - 1];
684 for (
Index_t i = first_entry_to_be_shifted; i <= last_entry_to_be_shifted; i++) {
710template <
typename Data_t_,
typename Index_t_>
713 static constexpr size_t K = 1;
723 std::vector<Data_t> data_;
729 for (
Index_t i = from; i < to;) {
731 if (++i < to) output <<
", ";
739 template <
class... ARGS>
744 template <
class... ARGS>
760 template <
class f_type>
767 template <
class f_type>
780 template <
typename f_type>
785 template <
typename f_type>
788 for (
Index_t iChild = 0; iChild < nChild; iChild++) {
789 data_[iNode] = f.second(iChild);
801 for (
int r = 0; r < mpi_env.
size; r++) {
802 nNodes += Nodes_all[0][r];
808 std::vector<int> Nodes_all_0_as_int(mpi_env.
size);
809 std::vector<int> Nodes_all_0_cumulated(mpi_env.
size + 1);
810 Nodes_all_0_cumulated[0] = 0;
811 for (
int r = 0; r < mpi_env.
size; r++) {
812 Nodes_all_0_cumulated[r + 1] = Nodes_all_0_cumulated[r] + Nodes_all[0][r];
813 Nodes_all_0_as_int[r] = Nodes_all[0][r];
817 Nodes_all_0_as_int.data(), Nodes_all_0_cumulated.data(), mpi_env.
mpi_data, mpi_env.
comm);
A templated matrix/vector-like object.
Definition C2DContainer.hpp:374
Definition mpi_structure.hpp:501
static void Allgatherv(const void *sendbuf, int sendcnt, Datatype sendtype, void *recvbuf, const int *recvcnt, const int *displs, Datatype recvtype, Comm comm)
Definition mpi_structure.hpp:584
static Comm GetComm()
Definition mpi_structure.hpp:530
int Datatype
Definition mpi_structure.hpp:504
static void Error(const std::string &ErrorMsg, const std::string &FunctionName)
Definition mpi_structure.cpp:131
int Comm
Definition mpi_structure.hpp:503
static int GetSize()
Definition mpi_structure.hpp:526
static void CopyData(const void *sendbuf, void *recvbuf, int size, Datatype datatype, int recvshift=0, int sendshift=0)
Definition mpi_structure.cpp:144
static void Allgather(const void *sendbuf, int sendcnt, Datatype sendtype, void *recvbuf, int recvcnt, Datatype recvtype, Comm comm)
Definition mpi_structure.hpp:589
void refresh(f_type f)
Definition ndflattener.hpp:768
void initialize_or_refresh(ARGS const &... args)
Definition ndflattener.hpp:745
const Data_t & operator[](Index_t i0) const
Data look-up, const version.
Definition ndflattener.hpp:832
Data_t_ Data_t
Definition ndflattener.hpp:714
Index_t_ Index_t
Definition ndflattener.hpp:715
Data_t & operator[](Index_t i0)
Data look-up, non-const version.
Definition ndflattener.hpp:829
const Data_t * data() const
Definition ndflattener.hpp:836
void set_f(f_type f, bool refresh)
Definition ndflattener.hpp:786
bool initialized()
Definition ndflattener.hpp:753
void toPythonString_fromto(std::ostream &output, Index_t from, Index_t to) const
Definition ndflattener.hpp:727
Index_t size() const
Definition ndflattener.hpp:824
void count_g(Nd_MPI_Environment const &mpi_env, su2matrix< Index_t > &Nodes_all, CurrentLayer const &local_version)
Definition ndflattener.hpp:796
NdFlattener(ARGS const &... args)
Definition ndflattener.hpp:740
void count_f(f_type f)
Definition ndflattener.hpp:781
void set_g(Nd_MPI_Environment const &mpi_env, su2matrix< Index_t > const &Nodes_all, CurrentLayer const &local_version)
Definition ndflattener.hpp:806
Data_t * data()
Definition ndflattener.hpp:834
void reset_iNode()
Definition ndflattener.hpp:776
void allocate()
Definition ndflattener.hpp:774
void initialize(f_type f)
Definition ndflattener.hpp:761
NdFlattener(void)
Definition ndflattener.hpp:737
Serialize pointer-to-pointer-... array into one 1D array, keeping track of the offsets in few additio...
Definition ndflattener.hpp:415
NdFlattener< K, Data_t, Index_t > CurrentLayer
Definition ndflattener.hpp:422
const Index_t * GetIndices() const
Definition ndflattener.hpp:442
NdFlattener()
Basic constructor. Afterwards, initialization can be done with initialize_or_refresh.
Definition ndflattener.hpp:478
void toPythonString_fromto(std::ostream &output, Index_t from, Index_t to) const
Write to stream in Python-list style, using the data of the indices array between 'from' (inclusive) ...
Definition ndflattener.hpp:464
Index_t * GetIndices()
Definition ndflattener.hpp:441
void refresh(f_type f)
Refresh the data according to the 'recursive function'.
Definition ndflattener.hpp:552
helpers::IndexAccumulator< K - 1, NdFlattener< K - 1, Data_t, Index_t > > operator[](Index_t i0)
Look-up with IndexAccumulator, non-const version.
Definition ndflattener.hpp:700
bool initialized()
Initialization status of the NdFlattener.
Definition ndflattener.hpp:507
friend std::ostream & operator<<(std::ostream &output, NdFlattener const &nd)
Write in Python-list style.
Definition ndflattener.hpp:450
void initialize(MPI_Environment_type const &mpi_env, Base const &local_version)
Initialize a flattener with K indices by combining distributed flatteners with (K-1) indices each.
Definition ndflattener.hpp:605
void allocate()
Allocate the indices array after nNodes has been determined.
Definition ndflattener.hpp:512
static constexpr size_t K
Definition ndflattener.hpp:417
void count_g(Nd_MPI_Environment const &mpi_env, su2matrix< Index_t > &Nodes_all, CurrentLayer const &local_version)
Count the distributed flatteners' numbers of nodes, and set nNodes.
Definition ndflattener.hpp:647
typename Base::LowestLayer LowestLayer
Definition ndflattener.hpp:423
void initialize(f_type f)
Initialize from a 'recursive function'.
Definition ndflattener.hpp:535
void initialize_or_refresh(ARGS const &... args)
Initialize or refresh the NdFlattener.
Definition ndflattener.hpp:496
Data_t_ Data_t
Definition ndflattener.hpp:418
helpers::IndexAccumulator< K - 1, const NdFlattener< K - 1, Data_t, Index_t > > operator[](Index_t i0) const
Look-up with IndexAccumulator, const version.
Definition ndflattener.hpp:705
NdFlattener(ARGS const &... args)
Constructor which calls initialize_or_refresh.
Definition ndflattener.hpp:484
Index_t size() const
Definition ndflattener.hpp:694
void count_f(f_type f)
Determine the space required for reading the 'recursive function'.
Definition ndflattener.hpp:563
void reset_iNode()
Set iNode to 0 in all layers.
Definition ndflattener.hpp:520
Index_t_ Index_t
Definition ndflattener.hpp:419
void set_f(f_type f, bool refresh)
Read the 'recursive function' into the allocated arrays.
Definition ndflattener.hpp:579
void refresh(MPI_Environment_type const &mpi_env, Base const &local_version)
Refresh the data by MPI collective communication.
Definition ndflattener.hpp:634
void set_g(Nd_MPI_Environment const &mpi_env, su2matrix< Index_t > const &Nodes_all, CurrentLayer const &local_version)
Gather the distributed flatteners' data and index arrays into the allocated arrays.
Definition ndflattener.hpp:664
LookupType_const & operator[](Index_t i) const
Return const reference to the corresponding data element, checking if the index is in its range.
Definition ndflattener.hpp:379
LookupType_const * data() const
Return const pointer to data.
Definition ndflattener.hpp:393
IndexAccumulator(Nd_t &nd, Index_t offset, Index_t size)
Definition ndflattener.hpp:353
LookupType * data()
Return (possibly const) pointer to data, non-const version.
Definition ndflattener.hpp:390
Nd_t_ Nd_t
Definition ndflattener.hpp:350
typename Nd_t::Index_t Index_t
Definition ndflattener.hpp:351
LookupType & operator[](Index_t i)
Return (possibly const) reference to the corresponding data element, checking if the index is in its ...
Definition ndflattener.hpp:372
const typename Nd_t::Data_t LookupType_const
Definition ndflattener.hpp:359
su2conditional_t< std::is_const< Nd_t >::value, const typename Nd_t::Data_t, typename Nd_t::Data_t > LookupType
Definition ndflattener.hpp:358
Parent class of IndexAccumulator.
Definition ndflattener.hpp:277
Nd_t & nd
The accessed NdFlattener.
Definition ndflattener.hpp:288
void CheckBound(Index_t i) const
Definition ndflattener.hpp:294
static constexpr size_t N
Definition ndflattener.hpp:279
const Index_t size_
Exclusive upper bound for the next index.
Definition ndflattener.hpp:290
IndexAccumulator_Base(Nd_t &nd, Index_t offset, Index_t size)
Definition ndflattener.hpp:292
Nd_t_ Nd_t
Definition ndflattener.hpp:280
Index_t size() const
Return exclusive upper bound for next index.
Definition ndflattener.hpp:285
const Index_t offset
Index in the currently accessed layer.
Definition ndflattener.hpp:289
typename Nd_t::Index_t Index_t
Definition ndflattener.hpp:281
Data structure holding an offset for the NdFlattener, to provide a []...[]-interface.
Definition ndflattener.hpp:303
Nd_t_ Nd_t
Definition ndflattener.hpp:307
IndexAccumulator< N - 1, const typename Nd_t::Base > LookupType_const
Definition ndflattener.hpp:318
static constexpr size_t N
Definition ndflattener.hpp:306
Nd_t & nd
The accessed NdFlattener.
Definition ndflattener.hpp:288
void CheckBound(Index_t i) const
Definition ndflattener.hpp:294
su2conditional_t< std::is_const< Nd_t >::value, const typename Nd_t::Base, typename Nd_t::Base > Nd_Base_t
Definition ndflattener.hpp:314
LookupType_const operator[](Index_t i) const
Read one more index, const version.
Definition ndflattener.hpp:337
IndexAccumulator(Nd_t &nd, Index_t offset, Index_t size)
Definition ndflattener.hpp:310
IndexAccumulator< N - 1, Nd_Base_t > LookupType
Definition ndflattener.hpp:316
Index_t size() const
Return exclusive upper bound for next index.
Definition ndflattener.hpp:285
const Index_t offset
Index in the currently accessed layer.
Definition ndflattener.hpp:289
typename Nd_t::Index_t Index_t
Definition ndflattener.hpp:308
LookupType operator[](Index_t i)
Read one more index, checking whether it is in the range dictated by the NdFlattener and previous ind...
Definition ndflattener.hpp:328
typename su2conditional< B, T, F >::type su2conditional_t
Definition code_config.hpp:88
#define FORCEINLINE
Definition code_config.hpp:44
#define CURRENT_FUNCTION
Definition mpi_structure.hpp:59
#define MPI_UNSIGNED_LONG
Definition mpi_structure.hpp:480
#define MPI_DOUBLE
Definition mpi_structure.hpp:484
Definition ndflattener.hpp:259
Contains information for the collective communication of NdFlatteners.
Definition ndflattener.hpp:232
decltype(&(SU2_MPI::Allgather)) MPI_Allgather_t
Definition ndflattener.hpp:233
MPI_Communicator_t comm
Definition ndflattener.hpp:240
typename SU2_MPI::Datatype MPI_Datatype_t
Definition ndflattener.hpp:235
const int size
Definition ndflattener.hpp:244
decltype(&(SU2_MPI::Allgatherv)) MPI_Allgatherv_t
Definition ndflattener.hpp:234
typename SU2_MPI::Comm MPI_Communicator_t
Definition ndflattener.hpp:236
MPI_Allgather_t MPI_Allgather_fun
Definition ndflattener.hpp:241
MPI_Allgatherv_t MPI_Allgatherv_fun
Definition ndflattener.hpp:242
const MPI_Datatype_t mpi_data
Definition ndflattener.hpp:238
const MPI_Datatype_t mpi_index
Definition ndflattener.hpp:239
const int rank
Definition ndflattener.hpp:243
Nd_MPI_Environment(MPI_Datatype_t mpi_data=4, MPI_Datatype_t mpi_index=1, MPI_Communicator_t comm=SU2_MPI::GetComm(), MPI_Allgather_t MPI_Allgather_fun=&(SU2_MPI::Allgather), MPI_Allgatherv_t MPI_Allgatherv_fun=&(SU2_MPI_Allgatherv_safe))
Definition ndflattener.hpp:246