MaMiCo 1.2
Loading...
Searching...
No Matches
SendReceiveBuffer.h
1// Copyright (C) 2015 Technische Universitaet Muenchen
2// This file is part of the Mamico project. For conditions of distribution
3// and use, please see the copyright notice in Mamico's main folder, or at
4// www5.in.tum.de/mamico
5#ifndef _MOLECULARDYNAMICS_COUPLING_SENDRECV_SENDRECEIVEBUFFER_H_
6#define _MOLECULARDYNAMICS_COUPLING_SENDRECV_SENDRECEIVEBUFFER_H_
7
8#include "DataExchangeFromMD2Macro.h"
9#include "coupling/CouplingMDDefinitions.h"
10#include "coupling/indexing/IndexingService.h"
11#include "coupling/sendrecv/DataExchange.h"
12#include "tarch/la/Vector.h"
13#include <algorithm>
14#include <map>
15#include <set>
16#include <string.h>
17#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
18#include <mpi.h>
19#endif
20
21namespace coupling {
22namespace sendrecv {
23template <class Cell_T, unsigned int dim> class SendReceiveBuffer;
24}
25} // namespace coupling
26
35template <class Cell_T, unsigned int dim> class coupling::sendrecv::SendReceiveBuffer {
36public:
41
42protected:
45
51 template <class Container_T> void writeToSendBuffer(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Container_T& cells);
52
59 void writeToBcastBuffer(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Cell_T& cell, I01 idx);
60
67 void writeToReduceBuffer(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Cell_T& cell, I01 idx);
68
75 template <class Container_T> void readFromReceiveBuffer(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Container_T& cells);
76
77 void readFromCollectiveBuffer(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, Cell_T& couplingCell, I01 idx);
78
85 void readFromReduceBuffer(coupling::sendrecv::DataExchangeFromMD2Macro<dim>& dataExchange, Cell_T& couplingCell, I01 idx);
86
93
99
105
111
115 void triggerBcasts(unsigned int rank);
116
122
126 void triggerReduce(unsigned int rank);
127
131
134
138
142 void allocateBcastRequests(unsigned int thisRank);
143
147 void allocateReduceRequests(unsigned int thisRank);
148
149private:
151 struct BufferWithID {
152 double* buffer;
153 unsigned int bufferSize;
154
155 BufferWithID() : buffer(NULL), bufferSize(0) {}
156 };
157
158 struct BufferCollective {
159 std::vector<double> buffer;
160 std::set<unsigned int> nonRootRanks;
161 std::set<unsigned int> cellIndices;
162 unsigned int rootRank;
163
164 BufferCollective() : buffer(), nonRootRanks(), cellIndices(), rootRank(-1) {}
165 };
166
170 void deleteBuffer(std::map<unsigned int, BufferWithID>& buffer);
171
174 std::map<unsigned int, BufferWithID> _receiveBuffer;
175 std::map<unsigned int, BufferWithID> _sendBuffer;
176
178 std::map<unsigned int, BufferCollective> _bcastBuffer;
179 std::map<unsigned int, BufferCollective> _reduceBuffer;
180
181#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
182 bool _requestsAllocated;
184 MPI_Request* _requests;
185 int _receiveSize;
187
188 std::vector<MPI_Comm> _subComms;
189 std::vector<MPI_Group> _subGroups;
190 int _bcastOrReduceSize;
191
192 static void elementWiseSum(void* in, void* inout, int* len, MPI_Datatype* datatype) {
193 auto* output = (double*)inout;
194 auto* input = (double*)in;
195 for (int i = 0; i < *len; ++i) {
196 output[i] += input[i];
197 }
198 }
199
200 MPI_Op elementWiseSumOperation;
201#endif
202};
203
204#include "SendReceiveBuffer.cpph"
205
206#endif // _MOLECULARDYNAMICS_COUPLING_SENDRECV_SENDRECEIVEBUFFER_H_
data exchange from the MD solver to the macroscopic solver. Derived from the class coupling::sendrecv...
Definition DataExchangeFromMD2Macro.h:36
generic class for the the data exchange purposes.
Definition DataExchange.h:27
generic class for send-/ receive methodology.
Definition SendReceiveBuffer.h:35
void allocateReceiveBuffers(coupling::sendrecv::DataExchange< Cell_T, dim > &dataExchange, I01 idx)
void allocateBcastBufferForReceiving(coupling::sendrecv::DataExchange< Cell_T, dim > &dataExchange, I01 idx)
void deleteBuffers()
deletes the buffers
void writeToSendBuffer(coupling::sendrecv::DataExchange< Cell_T, dim > &dataExchange, const Container_T &cells)
fills all information that needs to be sent from a coupling cell into the send-buffer.
void readFromReceiveBuffer(coupling::sendrecv::DataExchange< Cell_T, dim > &dataExchange, const Container_T &cells)
void triggerReceiving(coupling::sendrecv::DataExchange< Cell_T, dim > &dataExchange)
void allocateReduceRequests(unsigned int thisRank)
std::vector< MPI_Comm > _subComms
Definition SendReceiveBuffer.h:188
int _sendSize
Definition SendReceiveBuffer.h:186
void triggerSending(coupling::sendrecv::DataExchange< Cell_T, dim > &dataExchange)
void writeToReduceBuffer(coupling::sendrecv::DataExchange< Cell_T, dim > &dataExchange, const Cell_T &cell, I01 idx)
fills all information that needs to be reduced to a coupling cell into the reduce-buffer.
void triggerBcasts(unsigned int rank)
void allocateBcastRequests(unsigned int thisRank)
std::map< unsigned int, BufferWithID > _receiveBuffer
Definition SendReceiveBuffer.h:174
MPI_Request * _requests
Definition SendReceiveBuffer.h:184
void allocateReduceBufferForReceiving(coupling::sendrecv::DataExchange< Cell_T, dim > &dataExchange, I01 idx)
std::map< unsigned int, BufferCollective > _bcastBuffer
Definition SendReceiveBuffer.h:178
void triggerReduce(unsigned int rank)
void deleteBuffer(std::map< unsigned int, BufferWithID > &buffer)
void readFromReduceBuffer(coupling::sendrecv::DataExchangeFromMD2Macro< dim > &dataExchange, Cell_T &couplingCell, I01 idx)
void writeToBcastBuffer(coupling::sendrecv::DataExchange< Cell_T, dim > &dataExchange, const Cell_T &cell, I01 idx)
fills all information that needs to be broadcast from a coupling cell into the broadcast-buffer.
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15