9#include <kernel/util/dist.hpp>
11#include <kernel/lafem/dense_vector.hpp>
12#include <kernel/global/synch_vec.hpp>
13#include <kernel/global/synch_scal.hpp>
49 template<
typename LocalVector_,
typename Mirror_>
54 typedef typename LocalVector_::DataType
DataType;
78 template <
typename LocalVector2_,
typename Mirror2_>
82 template <
typename DataType2_,
typename IndexType2_>
121 _ranks = std::forward<std::vector<int>>(other._ranks);
122 _mirrors = std::forward<std::vector<Mirror_>>(other._mirrors);
123 _freqs = std::forward<LocalVector_>(other._freqs);
190 template<
typename LVT2_,
typename MT2_>
193 if((
void*)
this == (
void*)&other)
196 this->_comm = other._comm;
197 this->_ranks = other._ranks;
199 this->_mirrors.resize(other._mirrors.size());
200 for(std::size_t i(0); i < other._mirrors.size(); ++i)
202 this->_mirrors.at(i).convert(other._mirrors.at(i));
205 this->_freqs.convert(other._freqs);
227 template<
typename LVT2_>
230 if((
void*)
this == (
void*)&other)
233 this->_ranks.clear();
234 this->_mirrors.clear();
235 this->_mirrors.resize(other._mirrors.size());
236 this->_freqs.clear();
238 this->_comm = other._comm;
239 this->_ranks = other._ranks;
242 for(std::size_t i(0); i <
_mirrors.size(); ++i)
244 _mirrors.at(i).clone(other._mirrors.at(i), mode);
248 compile(std::forward<LocalVector_>(vector));
260 temp +=
_ranks.size() *
sizeof(int);
274 void push(
int rank, Mirror_&& mirror)
276 XASSERT(this->_comm !=
nullptr);
283 _mirrors.push_back(std::move(mirror));
299 _freqs = std::move(vector);
303 for(std::size_t i(0); i <
_mirrors.size(); ++i)
325 template<LAFEM::Perspective perspective_ = LAFEM::Perspective::native>
328 return _freqs.template size<perspective_>();
342 template<LAFEM::Perspective perspective_ = LAFEM::Perspective::native>
345 XASSERT(this->_comm !=
nullptr);
346 if(this->_comm->
size() <= 1)
347 return this->
template get_num_local_dofs<perspective_>();
350 const int my_rank = this->_comm->
rank();
353 const Index loc_dofs = this->
template get_num_local_dofs<perspective_>();
356 std::vector<int> mask(std::size_t(loc_dofs), 1);
359 for(std::size_t i(0); i <
_mirrors.size(); ++i)
361 if(this->_ranks.at(i) < my_rank)
362 this->_mirrors.at(i).template mask_scatter<perspective_>(this->_freqs, mask, 0);
366 Index owned_dofs(0u);
367 for(
const auto& k : mask)
368 owned_dofs +=
Index(k);
371 Index global_dofs(0u);
391 vector.component_product(vector,
_freqs);
510 return sum(x.dot(y));
#define XASSERT(expr)
Assertion macro definition.
void allreduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking All-Reduce.
int size() const
Returns the size of this communicator.
int rank() const
Returns the rank of this process in this communicator.
Global gate implementation.
void compile(LocalVector_ &&vector)
Compiles the gate to finish its setup.
virtual ~Gate()
virtual destructor
void sync_0(LocalVector_ &vector) const
Synchronizes a type-0 vector, resulting in a type-1 vector.
void convert(const Gate< LVT2_, MT2_ > &other)
Conversion function for same vector container type but with different MDI-Type.
const Dist::Comm * get_comm() const
Returns a const pointer to the underlying communicator.
const LocalVector_ & get_freqs() const
Returns a const reference to the frequencies vector.
void push(int rank, Mirror_ &&mirror)
Adds a mirror for a neighbor process.
void from_1_to_0(LocalVector_ &vector) const
Converts a type-1 vector into a type-0 vector.
Index get_num_local_dofs() const
Returns the number of local DOFs.
LocalVector_::IndexType IndexType
the index type
LAFEM::DenseVector< DataType, IndexType > BufferVectorType
the internal buffer vector type
ScalarTicketType sum_async(DataType x, bool sqrt=false) const
Computes a reduced sum over all processes.
DataType max(DataType x) const
Computes the maximum of a scalar variable over all processes.
Gate()
standard constructor
ScalarTicketType min_async(DataType x) const
Computes the minimum of a scalar variable over all processes.
std::vector< Mirror_ > _mirrors
vector mirrors
Index get_num_global_dofs() const
Returns the number of global DOFs.
DataType norm2(DataType x) const
Computes a reduced 2-norm over all processes.
LocalVector_ LocalVectorType
the local vector type
ScalarTicketType norm2_async(DataType x) const
Computes a reduced 2-norm over all processes.
void set_comm(const Dist::Comm *comm_)
Sets the communicator for this gate.
const Dist::Comm * _comm
our communicator
Gate & operator=(Gate &&other)
move-assign operator
const std::vector< Mirror_ > & get_mirrors() const
Returns a const reference to the neighbor mirrors vector.
void convert(const Gate< LVT2_, Mirror_ > &other, LocalVector_ &&vector, LAFEM::CloneMode mode=LAFEM::CloneMode::Shallow)
Conversion function for different vector container type.
ScalarTicketType dot_async(const LocalVector_ &x, const LocalVector_ &y, bool sqrt=false) const
Computes a synchronized dot-product of two type-1 vectors.
ScalarTicketType max_async(DataType x) const
Computes the maximum of a scalar variable over all processes.
Mirror_ MirrorType
the mirror type
void sync_1(LocalVector_ &vector) const
Synchronizes a type-1 vector, resulting in a type-1 vector.
VectorTicketType sync_1_async(LocalVector_ &vector) const
Synchronizes a type-1 vector, resulting in a type-1 vector.
LocalVector_ _freqs
frequency vector
const std::vector< int > get_ranks() const
Returns a const reference to the neighbor ranks vector.
DataType sum(DataType x) const
Computes a reduced sum over all processes.
DataType min(DataType x) const
Computes the minimum of a scalar variable over all processes.
VectorTicketType sync_0_async(LocalVector_ &vector) const
Synchronizes a type-0 vector, resulting in a type-1 vector.
Gate(Gate &&other)
move constructor
std::vector< int > _ranks
communication ranks
DataType dot(const LocalVector_ &x, const LocalVector_ &y) const
Computes a synchronized dot-product of two type-1 vectors.
LocalVector_::DataType DataType
the data type
std::size_t bytes() const
Returns the total amount of bytes allocated.
Gate(const Dist::Comm &comm)
Constructor.
Ticket class for asynchronous global operations on scalars.
Ticket class for asynchronous global operations on vectors.
Dense data vector class template.
const Operation op_min(MPI_MIN)
Operation wrapper for MPI_MIN.
const Operation op_max(MPI_MAX)
Operation wrapper for MPI_MAX.
const Operation op_sum(MPI_SUM)
Operation wrapper for MPI_SUM.
std::uint64_t Index
Index data type.