Documentation 6b54b78464
Loading...
Searching...
No Matches
NdFlattener< K_, Data_t_, Index_t_ > Class Template Reference

Serialize pointer-to-pointer-... array into one 1D array, keeping track of the offsets in few additional 1D arrays. More...

#include <ndflattener.hpp>

Public Types

using Data_t = Data_t_
 
using Index_t = Index_t_
 
using Base = NdFlattener< K - 1, Data_t, Index_t >
 
using CurrentLayer = NdFlattener< K, Data_t, Index_t >
 
using LowestLayer = typename Base::LowestLayer
 

Public Member Functions

Index_t * GetIndices ()
 
const Index_t * GetIndices () const
 
 NdFlattener ()
 Basic constructor. Afterwards, initialization can be done with initialize_or_refresh.
 
template<class... ARGS>
 NdFlattener (ARGS const &... args)
 Constructor which calls initialize_or_refresh.
 
template<class... ARGS>
void initialize_or_refresh (ARGS const &... args)
 Initialize or refresh the NdFlattener.
 
bool initialized ()
 Initialization status of the NdFlattener.
 
template<class f_type >
void initialize (f_type f)
 Initialize from a 'recursive function'.
 
template<class f_type >
void refresh (f_type f)
 Refresh the data according to the 'recursive function'.
 
template<typename MPI_Environment_type >
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.
 
template<typename MPI_Environment_type >
void refresh (MPI_Environment_type const &mpi_env, Base const &local_version)
 Refresh the data by MPI collective communication.
 
Index_t size () const
 
helpers::IndexAccumulator< K - 1, NdFlattener< K - 1, Data_t, Index_t > > operator[] (Index_t i0)
 Look-up with IndexAccumulator, non-const version.
 
helpers::IndexAccumulator< K - 1, const NdFlattener< K - 1, Data_t, Index_t > > operator[] (Index_t i0) const
 Look-up with IndexAccumulator, const version.
 

Static Public Attributes

static constexpr size_t K = K_
 

Protected Member Functions

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) and 'to' (exclusive).
 
void allocate ()
 Allocate the indices array after nNodes has been determined.
 
void reset_iNode ()
 Set iNode to 0 in all layers.
 
template<class f_type >
void count_f (f_type f)
 Determine the space required for reading the 'recursive function'.
 
template<class f_type >
void set_f (f_type f, bool refresh)
 Read the 'recursive function' into the allocated arrays.
 
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.
 
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.
 

Friends

std::ostream & operator<< (std::ostream &output, NdFlattener const &nd)
 Write in Python-list style.
 

Detailed Description

template<size_t K_, typename Data_t_, typename Index_t_>
class NdFlattener< K_, Data_t_, Index_t_ >

Serialize pointer-to-pointer-... array into one 1D array, keeping track of the offsets in few additional 1D arrays.

The pointer-to-pointer-... array can be provided by a nested lambda function ('recursive function') or by gathering such arrays from MPI processes ('collective communication'). After initializing an NdFlattener with either of these data, it can be refreshed in the same way after the the pointer-to-pointer-... array's values (but not its structure) have changed.

Template Parameters
K- number of indices
Data_t- Type of stored array data
Index- Type of index

Member Typedef Documentation

◆ Base

template<size_t K_, typename Data_t_ , typename Index_t_ >
using NdFlattener< K_, Data_t_, Index_t_ >::Base = NdFlattener<K - 1, Data_t, Index_t>

◆ CurrentLayer

template<size_t K_, typename Data_t_ , typename Index_t_ >
using NdFlattener< K_, Data_t_, Index_t_ >::CurrentLayer = NdFlattener<K, Data_t, Index_t>

◆ Data_t

template<size_t K_, typename Data_t_ , typename Index_t_ >
using NdFlattener< K_, Data_t_, Index_t_ >::Data_t = Data_t_

◆ Index_t

template<size_t K_, typename Data_t_ , typename Index_t_ >
using NdFlattener< K_, Data_t_, Index_t_ >::Index_t = Index_t_

◆ LowestLayer

template<size_t K_, typename Data_t_ , typename Index_t_ >
using NdFlattener< K_, Data_t_, Index_t_ >::LowestLayer = typename Base::LowestLayer

Constructor & Destructor Documentation

◆ NdFlattener() [1/2]

template<size_t K_, typename Data_t_ , typename Index_t_ >
NdFlattener< K_, Data_t_, Index_t_ >::NdFlattener ( )
inline

Basic constructor. Afterwards, initialization can be done with initialize_or_refresh.

Called recursively when a derived class (higher K) is constructed.

◆ NdFlattener() [2/2]

template<size_t K_, typename Data_t_ , typename Index_t_ >
template<class... ARGS>
NdFlattener< K_, Data_t_, Index_t_ >::NdFlattener ( ARGS const &...  args)
inline

Constructor which calls initialize_or_refresh.

Member Function Documentation

◆ allocate()

template<size_t K_, typename Data_t_ , typename Index_t_ >
void NdFlattener< K_, Data_t_, Index_t_ >::allocate ( )
inlineprotected

Allocate the indices array after nNodes has been determined.

◆ count_f()

template<size_t K_, typename Data_t_ , typename Index_t_ >
template<class f_type >
void NdFlattener< K_, Data_t_, Index_t_ >::count_f ( f_type  f)
inlineprotected

Determine the space required for reading the 'recursive function'.

Parameters
f- the 'recursive function'

◆ count_g()

template<size_t K_, typename Data_t_ , typename Index_t_ >
void NdFlattener< K_, Data_t_, Index_t_ >::count_g ( Nd_MPI_Environment const &  mpi_env,
su2matrix< Index_t > &  Nodes_all,
CurrentLayer const &  local_version 
)
inlineprotected

Count the distributed flatteners' numbers of nodes, and set nNodes.

Parameters
[in]mpi_env- MPI environment for communication
[out]Nodes_all- [k][r] is set to number of nodes in layer (k+1), rank r.
[in]local_version- local instance to be send to the other processes

◆ GetIndices() [1/2]

template<size_t K_, typename Data_t_ , typename Index_t_ >
Index_t * NdFlattener< K_, Data_t_, Index_t_ >::GetIndices ( )
inline

◆ GetIndices() [2/2]

template<size_t K_, typename Data_t_ , typename Index_t_ >
const Index_t * NdFlattener< K_, Data_t_, Index_t_ >::GetIndices ( ) const
inline

◆ initialize() [1/2]

template<size_t K_, typename Data_t_ , typename Index_t_ >
template<class f_type >
void NdFlattener< K_, Data_t_, Index_t_ >::initialize ( f_type  f)
inline

Initialize from a 'recursive function'.

The function should return a pair. Its first entry is the number of children. Its second entry is a function with the same meaning, recursively one layer down.

Parameters
f- the 'recursive function'

◆ initialize() [2/2]

template<size_t K_, typename Data_t_ , typename Index_t_ >
template<typename MPI_Environment_type >
void NdFlattener< K_, Data_t_, Index_t_ >::initialize ( MPI_Environment_type const &  mpi_env,
Base const &  local_version 
)
inline

Initialize a flattener with K indices by combining distributed flatteners with (K-1) indices each.

The new first index will encode the rank of the process. Data is exchanged in MPI::Allgatherv-style collective communication.

Parameters
[in]mpi_env- The MPI environment used for communication.
[in]local_version- The local NdFlattener structure with (K-1) indices.

◆ initialize_or_refresh()

template<size_t K_, typename Data_t_ , typename Index_t_ >
template<class... ARGS>
void NdFlattener< K_, Data_t_, Index_t_ >::initialize_or_refresh ( ARGS const &...  args)
inline

Initialize or refresh the NdFlattener.

Either a 'recursive function' or 'collective communication' may be used. When the NdFlattener does not hold data yet, it is initialized, meaning that the data are collected and the indices arrays are allocated and filled. Otherwise it is refreshed, meaning that the data are recollected under the assumption that the indices arrays did not change.

◆ initialized()

template<size_t K_, typename Data_t_ , typename Index_t_ >
bool NdFlattener< K_, Data_t_, Index_t_ >::initialized ( )
inline

Initialization status of the NdFlattener.

Returns
true if the NdFlattener has been initialized

◆ operator[]() [1/2]

template<size_t K_, typename Data_t_ , typename Index_t_ >
helpers::IndexAccumulator< K - 1, NdFlattener< K - 1, Data_t, Index_t > > NdFlattener< K_, Data_t_, Index_t_ >::operator[] ( Index_t  i0)
inline

Look-up with IndexAccumulator, non-const version.

◆ operator[]() [2/2]

template<size_t K_, typename Data_t_ , typename Index_t_ >
helpers::IndexAccumulator< K - 1, const NdFlattener< K - 1, Data_t, Index_t > > NdFlattener< K_, Data_t_, Index_t_ >::operator[] ( Index_t  i0) const
inline

Look-up with IndexAccumulator, const version.

◆ refresh() [1/2]

template<size_t K_, typename Data_t_ , typename Index_t_ >
template<class f_type >
void NdFlattener< K_, Data_t_, Index_t_ >::refresh ( f_type  f)
inline

Refresh the data according to the 'recursive function'.

The NdFlattener must have been constructed with a 'recursive function'. Now refresh the values with another 'recursive function'. The subarray lengths resulting from both 'recursive functions' must coincide, as the indices arrays are not changed.

Parameters
f- the 'recursive function'
Template Parameters
f_type- to allow for any type of the 'recursive function'

◆ refresh() [2/2]

template<size_t K_, typename Data_t_ , typename Index_t_ >
template<typename MPI_Environment_type >
void NdFlattener< K_, Data_t_, Index_t_ >::refresh ( MPI_Environment_type const &  mpi_env,
Base const &  local_version 
)
inline

Refresh the data by MPI collective communication.

The NdFlattener must have been constructed by MPI collective communication. Now refresh the values with another collective communication. The subarray lengths resulting from both collective communications must coincide, as the indices arrays are not changed.

Parameters
[in]mpi_env- The MPI environment used for communication.
[in]local_version- The local NdFlattener structure.

◆ reset_iNode()

template<size_t K_, typename Data_t_ , typename Index_t_ >
void NdFlattener< K_, Data_t_, Index_t_ >::reset_iNode ( )
inlineprotected

Set iNode to 0 in all layers.

◆ set_f()

template<size_t K_, typename Data_t_ , typename Index_t_ >
template<class f_type >
void NdFlattener< K_, Data_t_, Index_t_ >::set_f ( f_type  f,
bool  refresh 
)
inlineprotected

Read the 'recursive function' into the allocated arrays.

Parameters
f- the 'recursive function'
refresh- if true, the object is already initialized and only the data in layer 1 have to be overwritten
Template Parameters
f_type- to allow for any type of the 'recursive function'

◆ set_g()

template<size_t K_, typename Data_t_ , typename Index_t_ >
void NdFlattener< K_, Data_t_, Index_t_ >::set_g ( Nd_MPI_Environment const &  mpi_env,
su2matrix< Index_t > const &  Nodes_all,
CurrentLayer const &  local_version 
)
inlineprotected

Gather the distributed flatteners' data and index arrays into the allocated arrays.

Parameters
[in]mpi_env- MPI environment for communication
[in]Nodes_all- [k][r] is the number of nodes in layer (k+1), rank r.
[in]local_version- local instance to be sent to the other processes

◆ size()

template<size_t K_, typename Data_t_ , typename Index_t_ >
Index_t NdFlattener< K_, Data_t_, Index_t_ >::size ( ) const
inline

◆ toPythonString_fromto()

template<size_t K_, typename Data_t_ , typename Index_t_ >
void NdFlattener< K_, Data_t_, Index_t_ >::toPythonString_fromto ( std::ostream &  output,
Index_t  from,
Index_t  to 
) const
inlineprotected

Write to stream in Python-list style, using the data of the indices array between 'from' (inclusive) and 'to' (exclusive).

Like this: [[1, 2], [10, 20, 30]]

Parameters
[in]output- Stream
[in]from- Beginning of the representation in the indices array.
[in]to- Ending of the representation in the indices array.

Friends And Related Symbol Documentation

◆ operator<<

template<size_t K_, typename Data_t_ , typename Index_t_ >
std::ostream & operator<< ( std::ostream &  output,
NdFlattener< K_, Data_t_, Index_t_ > const &  nd 
)
friend

Write in Python-list style.

Like this: [[1, 2], [10, 20, 30]]

Member Data Documentation

◆ K

template<size_t K_, typename Data_t_ , typename Index_t_ >
constexpr size_t NdFlattener< K_, Data_t_, Index_t_ >::K = K_
staticconstexpr

The documentation for this class was generated from the following file: