Line data Source code
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_DATAEXCHANGE_H_
6 : #define _MOLECULARDYNAMICS_COUPLING_SENDRECV_DATAEXCHANGE_H_
7 :
8 : #include "coupling/datastructures/CouplingCell.h"
9 : #include "tarch/la/Vector.h"
10 :
11 : namespace coupling {
12 : namespace sendrecv {
13 : template <class Cell_T, unsigned int dim> class DataExchange;
14 : }
15 : } // namespace coupling
16 :
17 : /** This class holds information on the data exchange between processes. In
18 : *contrast to the SendReceiveBuffer which solely handles the technical part of
19 : *sending and receiving, this class needs to guarantee the validity in
20 : *communication, e.g. make sure that each source rank matches to a target rank
21 : *etc.
22 : * @brief generic class for the the data exchange purposes.
23 : * @tparam CouplingCell cell type
24 : * @tparam dim Number of dimensions; it can be 1, 2 or 3
25 : * @author Philipp Neumann
26 : */
27 : template <class Cell_T, unsigned int dim> class coupling::sendrecv::DataExchange {
28 : public:
29 : /** Constructor: assign an tag (_tag) to the DataExchange.
30 : * @param tag
31 : */
32 4 : DataExchange(unsigned int tag) : _tag(tag) {}
33 : /** Destructor */
34 0 : virtual ~DataExchange() {}
35 :
36 : /** returns the tag associated to messages for this DataExchange. @return
37 : * _tag*/
38 0 : unsigned int getTag() const { return _tag; }
39 :
40 : /** returns the ranks to which a particular cell (at index idx)
41 : * should be sent. This method should globally define the target ranks for
42 : * each global cell index of a coupling cell.
43 : * @param idx unique global cell index
44 : */
45 : virtual std::vector<unsigned int> getTargetRanks(I01 idx) = 0;
46 :
47 : /** returns all ranks from which a particular cell (at index idx)
48 : * is sent. This method should globally define the source ranks for each
49 : * global cell index of a coupling cell.
50 : * @param idx unique global cell index
51 : */
52 : virtual std::vector<unsigned int> getSourceRanks(I01 idx) = 0;
53 :
54 : /** local rule to read from a coupling cell and write data to (e.g. send)
55 : * buffer
56 : * @param buffer
57 : * @param cell
58 : */
59 : virtual void readFromCell(double* const buffer, const Cell_T& cell) = 0;
60 :
61 : /** local rule to read from receive buffer and write data to coupling cell
62 : * @param buffer
63 : * @param cell
64 : */
65 : virtual void writeToCell(const double* const buffer, Cell_T& cell) = 0;
66 :
67 : /** returns the number of doubles that are sent per coupling cell. */
68 : virtual unsigned int getDoublesPerCell() const = 0;
69 :
70 : private:
71 : /** tag to uniquely determine these kinds of messages that are sent between
72 : * processes. */
73 : const unsigned int _tag;
74 : };
75 :
76 : #endif // _MOLECULARDYNAMICS_COUPLING_SENDRECV_DATAEXCHANGE_H_
|