Discontinuous Galerkin Library
#include "dg/algorithm.h"
mpi_communicator.h
Go to the documentation of this file.
1#pragma once
2
3#include <mpi.h>
4
5namespace dg
6{
8template<class value_type>
9static inline MPI_Datatype getMPIDataType(){ assert( false && "Type not supported!\n" ); return MPI_DOUBLE; }
10template<>
11inline MPI_Datatype getMPIDataType<double>(){ return MPI_DOUBLE;}
12template<>
13inline MPI_Datatype getMPIDataType<float>(){ return MPI_FLOAT;}
14template<>
15inline MPI_Datatype getMPIDataType<int>(){ return MPI_INT;}
16template<>
17inline MPI_Datatype getMPIDataType<bool>(){ return MPI_C_BOOL;}
18template<>
19inline MPI_Datatype getMPIDataType<unsigned>(){ return MPI_UNSIGNED;}
21
96template< class LocalContainer>
98{
100
101 using container_type = LocalContainer;
102
109 LocalContainer allocate_buffer( )const{
110 if( do_size() == 0 ) return LocalContainer();
111 return do_make_buffer();
112 }
113
124 void global_gather( const value_type* values, LocalContainer& buffer)const
125 {
126 do_global_gather( values, buffer);
127 }
128
140 LocalContainer global_gather( const value_type* values) const
141 {
142 LocalContainer tmp = do_make_buffer();
143 do_global_gather( values, tmp);
144 return tmp;
145 }
146
159 void global_scatter_reduce( const LocalContainer& toScatter, value_type* values) const{
160 do_global_scatter_reduce(toScatter, values);
161 }
162
178 unsigned buffer_size() const{return do_size();}
190 unsigned local_size() const{return m_source_size;}
211 bool isCommunicating() const{
212 return do_isCommunicating();
213 }
220 MPI_Comm communicator() const{return do_communicator();}
223 virtual aCommunicator* clone() const =0;
225 virtual ~aCommunicator(){}
226 protected:
229 aCommunicator(unsigned local_size=0):m_source_size(local_size){}
232 aCommunicator(const aCommunicator& src):m_source_size( src.m_source_size){ }
237 m_source_size = src.m_source_size;
238 return *this;
239 }
242 void set_local_size( unsigned new_size){
243 m_source_size = new_size;
244 }
245 private:
246 unsigned m_source_size;
247 virtual MPI_Comm do_communicator() const=0;
248 virtual unsigned do_size() const=0;
249 virtual LocalContainer do_make_buffer( )const=0;
250 virtual void do_global_gather( const value_type* values, LocalContainer& gathered)const=0;
251 virtual void do_global_scatter_reduce( const LocalContainer& toScatter, value_type* values) const=0;
252 virtual bool do_isCommunicating( ) const {
253 return true;
254 }
255};
256
257
258
259
260
261}//namespace dg
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition: tensor_traits.h:38
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Struct that performs collective scatter and gather operations across processes on distributed vectors...
Definition: mpi_communicator.h:98
void global_gather(const value_type *values, LocalContainer &buffer) const
. Globally (across processes) gather data into a buffer
Definition: mpi_communicator.h:124
aCommunicator & operator=(const aCommunicator &src)
only derived classes can assign
Definition: mpi_communicator.h:236
unsigned local_size() const
The local size of the source vector v = local size of the dg::MPI_Vector
Definition: mpi_communicator.h:190
aCommunicator(const aCommunicator &src)
only derived classes can copy
Definition: mpi_communicator.h:232
void global_scatter_reduce(const LocalContainer &toScatter, value_type *values) const
. Globally (across processes) scatter data accross processes and reduce on multiple indices
Definition: mpi_communicator.h:159
LocalContainer container_type
reveal local container type
Definition: mpi_communicator.h:101
get_value_type< LocalContainer > value_type
reveal value type
Definition: mpi_communicator.h:99
unsigned buffer_size() const
The local size of the buffer vector w = local map size.
Definition: mpi_communicator.h:178
void set_local_size(unsigned new_size)
Set the local size of the source vector v.
Definition: mpi_communicator.h:242
virtual ~aCommunicator()
vritual destructor
Definition: mpi_communicator.h:225
LocalContainer global_gather(const value_type *values) const
. Globally (across processes) gather data into a buffer (memory allocating version)
Definition: mpi_communicator.h:140
LocalContainer allocate_buffer() const
Allocate a buffer object of size buffer_size()
Definition: mpi_communicator.h:109
bool isCommunicating() const
True if the gather/scatter operation involves actual MPI communication.
Definition: mpi_communicator.h:211
MPI_Comm communicator() const
The internal MPI communicator used.
Definition: mpi_communicator.h:220
virtual aCommunicator * clone() const =0
Generic copy method.
aCommunicator(unsigned local_size=0)
only derived classes can construct
Definition: mpi_communicator.h:229