4#include <thrust/host_vector.h>
21template<
template<
typename>
typename Vector>
22struct MPIContiguousKroneckerGather
24 MPIContiguousKroneckerGather( MPI_Comm comm = MPI_COMM_NULL) : m_mpi_gather(comm){ }
25 MPIContiguousKroneckerGather(
26 const std::map<
int, thrust::host_vector<int>>& recvIdx,
29 : m_recvIdx(recvIdx), m_chunk_size(chunk_size)
32 mpi_cartdim_get( comm_1d, &ndims);
35 MPI_Comm_rank( comm_1d, &rank);
37 "Only Shared vectors allowed");
38 auto recvChunks = detail::MPIContiguousGather::make_chunks(
40 m_mpi_gather = dg::detail::MPIContiguousGather( recvChunks, comm_1d);
41 m_buffer_size = m_mpi_gather.buffer_size(
false);
43 template<
template<
class>
class OtherVector>
44 friend struct MPIContiguousKroneckerGather;
46 template<
template<
typename >
typename OtherVector>
47 MPIContiguousKroneckerGather(
const MPIContiguousKroneckerGather<OtherVector>& src)
48 : m_mpi_gather( src.m_mpi_gather),
49 m_recvIdx(src.m_recvIdx),
50 m_chunk_size(src.m_chunk_size),
51 m_buffer_size(src.m_buffer_size)
55 MPI_Comm communicator()
const{
return m_mpi_gather.communicator();}
57 unsigned buffer_size()
const {
return detail::flatten_map( m_recvIdx).size(); }
58 unsigned chunk_size()
const {
return m_chunk_size; }
59 bool isCommunicating()
const{
return m_mpi_gather.isCommunicating(); }
61 template<
class ContainerType>
62 void global_gather_init(
const ContainerType& gatherFrom)
const
65 m_buffer.template set<value_type>( m_buffer_size);
66 auto& buffer = m_buffer.template get<value_type>();
67 m_mpi_gather.global_gather_init( gatherFrom, buffer,
false);
69 template<
class ContainerType>
70 void global_gather_wait(
const ContainerType& gatherFrom,
74 auto& buffer = m_buffer.template get<value_type>();
75 m_mpi_gather.global_gather_wait( buffer);
78 MPI_Comm_rank( communicator(), &rank);
79 unsigned start = 0, buffer_start = 0;
80 for(
auto& idx : m_recvIdx)
81 for(
unsigned u=0; u<idx.second.size(); u++)
83 if( rank != idx.first)
85 buffer_ptrs[start] = thrust::raw_pointer_cast(
86 buffer.data()) + buffer_start*m_chunk_size;
90 buffer_ptrs[start] = thrust::raw_pointer_cast(
91 gatherFrom.data()) + idx.second[u]*m_chunk_size;
97 dg::detail::MPIContiguousGather m_mpi_gather;
98 std::map<int,thrust::host_vector<int>> m_recvIdx;
99 unsigned m_chunk_size = 0;
100 unsigned m_buffer_size = 0;
101 mutable detail::AnyVector<Vector> m_buffer;
143template<
template<
typename>
typename Vector>
166 const std::map<
int, thrust::host_vector<int>>& recvIdx,
172 m_contiguous = (left_size==1);
174 if( not m_contiguous)
178 detail::Unique<int> uni = detail::find_unique_order_preserving(
179 detail::flatten_map( sendIdx));
180 auto uni_sendIdx = detail::make_map_t<thrust::host_vector<int>>(
181 detail::combine_gather( uni.gather1, uni.gather2),
182 detail::get_size_map( sendIdx));
186 m_mpi_gather = detail::MPIContiguousKroneckerGather<Vector>(
187 uni_recvIdx,
n*left_size*right_size, comm_1d);
191 thrust::host_vector<int> g2( uni.unique.size()*
n*left_size*
193 for(
unsigned l=0; l<uni.unique.size(); l++)
194 for(
unsigned j=0; j<
n; j++)
195 for(
unsigned i=0; i<left_size; i++)
196 for(
unsigned k=0; k<right_size; k++)
197 g2[((l*
n+j)*left_size+i)*right_size + k] =
198 ((i*num_cols + uni.unique[l])*
n + j)*right_size + k;
202 m_mpi_gather = detail::MPIContiguousKroneckerGather<Vector>(
203 recvIdx,
n*left_size*right_size, comm_1d);
207 template<
template<
class>
class OtherVector>
211 template<
template<
typename >
typename OtherVector>
213 : m_contiguous( src.m_contiguous),
215 m_mpi_gather( src.m_mpi_gather)
223 unsigned buffer_size()
const {
return m_mpi_gather.buffer_size(); }
225 unsigned chunk_size()
const {
return m_mpi_gather.chunk_size(); }
242 template<
class ContainerType>
246 if( not m_contiguous)
248 m_store.template set<value_type>( m_g2.size());
249 auto& store = m_store.template get<value_type>();
250 thrust::gather( m_g2.begin(), m_g2.end(), gatherFrom.begin(),
252 m_mpi_gather.global_gather_init( store);
255 m_mpi_gather.global_gather_init( gatherFrom);
269 template<
class ContainerType>
273 if( not m_contiguous)
276 auto& store = m_store.template get<value_type>();
277 m_mpi_gather.global_gather_wait( store, buffer_ptrs);
280 m_mpi_gather.global_gather_wait( gatherFrom, buffer_ptrs);
284 bool m_contiguous=
false;
286 dg::detail::MPIContiguousKroneckerGather<Vector> m_mpi_gather;
287 mutable detail::AnyVector<Vector> m_store;
Error classes or the dg library.
constexpr bool is_vector_v
Utility typedef.
Definition predicate.h:75
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition tensor_traits.h:45
std::map< int, MessageType > mpi_permute(const std::map< int, MessageType > &messages, MPI_Comm comm)
Exchange messages between processes in a communicator.
Definition mpi_permutation.h:90
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Communicator for asynchronous communication of MPISparseBlockMat.
Definition mpi_gather_kron.h:145
void global_gather_init(const ContainerType &gatherFrom) const
. Globally (across processes) asynchronously gather data into a buffer
Definition mpi_gather_kron.h:243
bool isCommunicating() const
True if the gather/scatter operation involves actual MPI communication.
Definition mpi_gather_kron.h:227
MPI_Comm communicator() const
The internal MPI communicator used.
Definition mpi_gather_kron.h:220
void global_gather_wait(const ContainerType &gatherFrom, Vector< const dg::get_value_type< ContainerType > * > &buffer_ptrs) const
Wait for asynchronous communication to finish and gather received data into buffer and return pointer...
Definition mpi_gather_kron.h:270
MPIKroneckerGather(unsigned left_size, const std::map< int, thrust::host_vector< int > > &recvIdx, unsigned n, unsigned num_cols, unsigned right_size, MPI_Comm comm_1d)
Construct from communication pattern.
Definition mpi_gather_kron.h:165
MPIKroneckerGather(const MPIKroneckerGather< OtherVector > &src)
Construct from other execution policy.
Definition mpi_gather_kron.h:212
unsigned chunk_size() const
n*left_size*right_size
Definition mpi_gather_kron.h:225
MPIKroneckerGather(MPI_Comm comm=MPI_COMM_NULL)
no communication
Definition mpi_gather_kron.h:147
unsigned buffer_size() const
Number of pointers in receive buffer equals number of indices in recvIdx.
Definition mpi_gather_kron.h:223