ls1-MarDyn
ls1-MarDyn molecular dynamics code
CommunicationPartner.h
1/*
2 * CommunicationPartner.h
3 *
4 * Created on: Nov 16, 2015
5 * Author: tchipevn
6 */
7
8#ifndef COMMUNICATIONPARTNER_H_
9#define COMMUNICATIONPARTNER_H_
10
11#include <mpi.h>
12#include <vector>
13#include <stddef.h>
14#include "CommunicationBuffer.h"
15
16typedef enum {
17 LEAVING_AND_HALO_COPIES = 0,
18 HALO_COPIES = 1,
19 LEAVING_ONLY = 2,
20 FORCES = 3
21} MessageType;
22
24
26 double _bothLow[3], _bothHigh[3];
27 double _leavingLow[3], _leavingHigh[3];
28 double _copiesLow[3], _copiesHigh[3];
29 double _shift[3];
30 int _offset[3];
31 bool _enlarged[3][2];
32};
33
34
39public:
40 CommunicationPartner(const int r, const double hLo[3], const double hHi[3], const double bLo[3],
41 const double bHi[3], const double sh[3], const int offset[3], const bool enlarged[3][2]);
42 CommunicationPartner(const int r);
43 CommunicationPartner(const int r, const double leavingLo[3], const double leavingHi[3]);
44
46
47 CommunicationPartner() = delete;
48
49 CommunicationPartner& operator =(const CommunicationPartner& b);
50
52
53 void initSend(ParticleContainer* moleculeContainer, const MPI_Comm& comm, const MPI_Datatype& type,
54 MessageType msgType, std::vector<Molecule>& invalidParticles, bool mightUseInvalidParticles,
55 bool doHaloPositionCheck, bool removeFromContainer = false);
56
57 bool testSend();
58
59 void resetReceive();
60
61 bool iprobeCount(const MPI_Comm& comm, const MPI_Datatype& type);
62
63 bool testRecv(ParticleContainer* moleculeContainer, bool removeRecvDuplicates, bool force = false);
64
65 void initRecv(int numParticles, const MPI_Comm& comm, const MPI_Datatype& type);
66
67 void deadlockDiagnosticSendRecv();
68 void deadlockDiagnosticSend();
69 void deadlockDiagnosticRecv();
70
71 int getRank() const {
72 return _rank;
73 }
74
75 const int* getOffset() {
76 return _haloInfo[0]._offset;
77 }
78
81 bool isFaceCommunicator() const {
82 return (!!_haloInfo[0]._offset[0] + !!_haloInfo[0]._offset[1] + !!_haloInfo[0]._offset[2]) == 1;
83 }
86 if (!isFaceCommunicator())
87 return -1;
88 return !!_haloInfo[0]._offset[1] * 1 + !!_haloInfo[0]._offset[2] * 2;
89 }
90
91 void enlargeInOtherDirections(unsigned int d, double enlargement) {
92 for (unsigned int p = 0; p < _haloInfo.size(); p++) {
93 for (unsigned int d2 = 0; d2 < 3; d2++) {
94 if (d2 == d)
95 continue;
96 if (!_haloInfo[p]._enlarged[d2][0]) {
97 _haloInfo[p]._bothLow[d2] -= enlargement;
98 _haloInfo[p]._leavingLow[d2] -= enlargement;
99 _haloInfo[p]._copiesLow[d2] -= enlargement;
100 _haloInfo[p]._enlarged[d2][0] = true;
101 }
102 if (!_haloInfo[p]._enlarged[d2][1]) {
103 _haloInfo[p]._bothHigh[d2] += enlargement;
104 _haloInfo[p]._leavingHigh[d2] += enlargement;
105 _haloInfo[p]._copiesHigh[d2] += enlargement;
106 _haloInfo[p]._enlarged[d2][1] = true;
107 }
108 }
109 }
110 }
111
114 void add(CommunicationPartner partner);
115
116 size_t getDynamicSize();
117
118 void print(std::ostream& stream) const;
119private:
120 enum HaloOrLeavingCorrection{
121 HALO,
122 LEAVING,
123 NONE,
124 FORCES // necessary?
125 };
126 void collectMoleculesInRegion(ParticleContainer* moleculeContainer, const double lowCorner[3],
127 const double highCorner[3], const double shift[3], bool removeFromContainer,
128 HaloOrLeavingCorrection haloLeaveCorr, bool doHaloPositionCheck = true);
129
130 int _rank;
131 int _countTested;
132 std::vector<PositionInfo> _haloInfo;
133
134 // technical variables
135 MPI_Request *_sendRequest, *_recvRequest;
136 MPI_Status *_sendStatus, *_recvStatus;
137 CommunicationBuffer _sendBuf, _recvBuf; // used to be ParticleData and
138 bool _msgSent, _countReceived, _msgReceived, _isSending, _isReceiving;
139
140 void collectLeavingMoleculesFromInvalidParticles(std::vector<Molecule>& invalidParticles, double lowCorner [3], double highCorner [3], double shift [3]);
141
142 friend class NeighborAcquirerTest;
143};
144
145#endif /* COMMUNICATIONPARTNER_H_ */
Definition: CommunicationBuffer.h:37
Definition: CommunicationPartner.h:38
bool isFaceCommunicator() const
Definition: CommunicationPartner.h:81
int getFaceCommunicationDirection() const
Definition: CommunicationPartner.h:85
void add(CommunicationPartner partner)
Definition: CommunicationPartner.cpp:428
This Interface is used to get access to particles and pairs of particles.
Definition: ParticleContainer.h:69
Enumeration class corresponding to the type schema type.
Definition: vtk-unstructured.h:1746
Definition: CommunicationPartner.h:25
int _offset[3]
for periodic boundaries
Definition: CommunicationPartner.h:30