ls1-MarDyn
ls1-MarDyn molecular dynamics code
NeighbourCommunicationScheme.h
1/*
2 * NeighbourCommunicationScheme.h
3 *
4 * Created on: Sep 29, 2016
5 * Author: seckler
6 */
7
8#pragma once
9
10#include <vector>
11
12#include "parallel/CommunicationPartner.h"
13
15class Domain;
16class ZonalMethod;
17class HaloRegion;
19 friend class NeighbourCommunicationSchemeTest;
20
21public:
27 unsigned int getCommDims() {
28 return _commDimms;
29 }
31 NeighbourCommunicationScheme(unsigned int commDimms, ZonalMethod* zonalMethod, bool pushPull);
32
34
36 void operator=(NeighbourCommunicationScheme const &other) = delete;
37
38 virtual void prepareNonBlockingStageImpl(ParticleContainer* moleculeContainer, Domain* domain,
39 unsigned int stageNumber, MessageType msgType, bool removeRecvDuplicates,
40 DomainDecompMPIBase* domainDecomp) = 0;
41
42 virtual void finishNonBlockingStageImpl(ParticleContainer* moleculeContainer, Domain* domain,
43 unsigned int stageNumber, MessageType msgType, bool removeRecvDuplicates,
44 DomainDecompMPIBase* domainDecomp) = 0;
45
46 virtual void exchangeMoleculesMPI(ParticleContainer* moleculeContainer, Domain* domain, MessageType msgType,
47 bool removeRecvDuplicates, DomainDecompMPIBase* domainDecomp, bool doHaloPositionCheck=true) = 0;
48
49 void setCoverWholeDomain(unsigned int d, bool covers) {
50 _coversWholeDomain[d] = covers;
51 }
52
53 virtual void initCommunicationPartners(double cutoffRadius, Domain * domain,
54 DomainDecompMPIBase* domainDecomp,
55 ParticleContainer* moleculeContainer) = 0;
56
57 virtual std::vector<int> get3StageNeighbourRanks() = 0;
58
59 virtual std::vector<int> getFullShellNeighbourRanks() {
60 std::vector<int> neighbourRanks;
61 for (auto & _fullShellNeighbour : _fullShellNeighbours) {
62 neighbourRanks.push_back(_fullShellNeighbour.getRank());
63 }
64 return neighbourRanks;
65 }
66
67
68 virtual size_t getDynamicSize() {
69 size_t totSize = 0;
70 // _fullShellNeighbours
71 totSize += sizeof(*this);
72 //std::cout << "pre FSN:" << totSize;
73 totSize += _fullShellNeighbours.capacity() * sizeof(CommunicationPartner);
75 totSize += neigh.getDynamicSize();
76 //std::cout << "FSN:" << neigh.getDynamicSize();
77 }
78 //std::cout << "post FSN/pre neigh:" << totSize;
79 totSize += (*_neighbours).capacity() * sizeof(CommunicationPartner);
80 for (auto& neighList : (*_neighbours)) {
81 for (auto& neigh : neighList) {
82 totSize += neigh.getDynamicSize();
83 //std::cout << "Neigh:" << neigh.getDynamicSize();
84 }
85 }
86 //std::cout << "post Neigh:" << totSize;
87 return totSize;
88 }
89
90 void printCommunicationPartners(std::string filename) const;
91
92 void setSequentialFallback(bool useSequentialFallback) {
93 _useSequentialFallback = useSequentialFallback;
94 }
95
96protected:
97
99 std::vector<std::vector<CommunicationPartner>> *_neighbours;
100
101 // -------------------------------------------------------------------------
102 std::vector<std::vector<CommunicationPartner>> *_haloExportForceImportNeighbours;
103 std::vector<std::vector<CommunicationPartner>> *_haloImportForceExportNeighbours;
104 std::vector<std::vector<CommunicationPartner>> *_leavingExportNeighbours;
105 std::vector<std::vector<CommunicationPartner>> *_leavingImportNeighbours;
106
107 void selectNeighbours(MessageType msgType, bool import);
108 // -------------------------------------------------------------------------
109
114
115 unsigned int _commDimms;
116
119
121 std::vector<CommunicationPartner> _fullShellNeighbours;
122
123 bool _pushPull;
124
125 bool _useSequentialFallback{true};
126};
127
129 friend class NeighbourCommunicationSchemeTest;
130public:
131 DirectNeighbourCommunicationScheme(ZonalMethod* zonalMethod, bool pushPull) :
132 NeighbourCommunicationScheme(1, zonalMethod, pushPull) {
133 }
134 ~~DirectNeighbourCommunicationScheme() override = default;
135 void initCommunicationPartners(double cutoffRadius, Domain * domain,
136 DomainDecompMPIBase* domainDecomp,
137 ParticleContainer* moleculeContainer) override;
138
139 std::vector<int> get3StageNeighbourRanks() override {
140 std::vector<int> neighbourRanks;
141 for (auto & i : (*_neighbours)[0]) {
142 if (i.isFaceCommunicator()) {
143 neighbourRanks.push_back(i.getRank());
144 }
145 }
146 return neighbourRanks;
147 }
148
149 void prepareNonBlockingStageImpl(ParticleContainer* moleculeContainer, Domain* domain,
150 unsigned int stageNumber, MessageType msgType, bool removeRecvDuplicates,
151 DomainDecompMPIBase* domainDecomp) override;
152
153 void finishNonBlockingStageImpl(ParticleContainer* moleculeContainer, Domain* domain,
154 unsigned int stageNumber, MessageType msgType, bool removeRecvDuplicates,
155 DomainDecompMPIBase* domainDecomp) override;
156
157 void exchangeMoleculesMPI(ParticleContainer* moleculeContainer, Domain* domain, MessageType msgType,
158 bool removeRecvDuplicates, DomainDecompMPIBase* domainDecomp, bool doHaloPositionCheck=true) override;
159
160protected:
161 void finalizeExchangeMoleculesMPI(ParticleContainer* moleculeContainer, Domain* /*domain*/, MessageType /*msgType*/,
162 bool removeRecvDuplicates, DomainDecompMPIBase* domainDecomp);
163 void initExchangeMoleculesMPI(ParticleContainer* moleculeContainer, Domain* /*domain*/, MessageType msgType,
164 bool /*removeRecvDuplicates*/, DomainDecompMPIBase* domainDecomp, bool doHaloPositionCheck);
165
166private:
167 void doDirectFallBackExchange(const std::vector<HaloRegion>& haloRegions, MessageType msgType,
168 DomainDecompMPIBase* domainDecomp, ParticleContainer*& moleculeContainer,
169 std::vector<Molecule>& invalidParticles, bool doHaloPositionCheck);
170};
171
173 friend class NeighbourCommunicationSchemeTest;
174public:
175
177 NeighbourCommunicationScheme(3, zonalMethod, false) {
178 }
179 ~~IndirectNeighbourCommunicationScheme() override = default;
180 void exchangeMoleculesMPI(ParticleContainer* moleculeContainer, Domain* domain, MessageType msgType,
181 bool removeRecvDuplicates, DomainDecompMPIBase* domainDecomp, bool doHaloPositionCheck=true) override;
182
183 void initCommunicationPartners(double cutoffRadius, Domain * domain,
184 DomainDecompMPIBase* domainDecomp,
185 ParticleContainer* moleculeContainer) override;
186 std::vector<int> get3StageNeighbourRanks() override {
187 std::vector<int> neighbourRanks;
188 for (auto & _fullShellNeighbour : _fullShellNeighbours) {
189 if (_fullShellNeighbour.isFaceCommunicator()) {
190 neighbourRanks.push_back(_fullShellNeighbour.getRank());
191 }
192 }
193 return neighbourRanks;
194 }
195
196 void prepareNonBlockingStageImpl(ParticleContainer* moleculeContainer, Domain* domain,
197 unsigned int stageNumber, MessageType msgType, bool removeRecvDuplicates,
198 DomainDecompMPIBase* domainDecomp) override;
199
200 void finishNonBlockingStageImpl(ParticleContainer* moleculeContainer, Domain* domain,
201 unsigned int stageNumber, MessageType msgType, bool removeRecvDuplicates,
202 DomainDecompMPIBase* domainDecomp) override;
203
204protected:
205 void initExchangeMoleculesMPI1D(ParticleContainer* moleculeContainer, Domain* domain, MessageType msgType,
206 bool removeRecvDuplicates, unsigned short d, DomainDecompMPIBase* domainDecomp);
207
208 void finalizeExchangeMoleculesMPI1D(ParticleContainer* moleculeContainer, Domain* domain, MessageType msgType,
209 bool removeRecvDuplicates, unsigned short d, DomainDecompMPIBase* domainDecomp);
210 void exchangeMoleculesMPI1D(ParticleContainer* moleculeContainer, Domain* domain, MessageType msgType,
211 bool removeRecvDuplicates, unsigned short d, DomainDecompMPIBase* domainDecomp);
212 void convert1StageTo3StageNeighbours(const std::vector<CommunicationPartner>& commPartners,
213 std::vector<std::vector<CommunicationPartner>>& neighbours, HaloRegion& ownRegion, double cutoffRadius);
214
215};
Definition: CommunicationPartner.h:38
Definition: NeighbourCommunicationScheme.h:128
Definition: DomainDecompMPIBase.h:30
This class is used to read in the phasespace and to handle macroscopic values.
Definition: Domain.h:47
Definition: NeighbourCommunicationScheme.h:172
Definition: NeighbourCommunicationScheme.h:18
std::vector< std::vector< CommunicationPartner > > * _neighbours
vector of neighbours. The first dimension should be of size getCommDims().
Definition: NeighbourCommunicationScheme.h:99
unsigned int getCommDims()
Definition: NeighbourCommunicationScheme.h:27
std::vector< CommunicationPartner > _fullShellNeighbours
list of all neighbours (non-squeezed)
Definition: NeighbourCommunicationScheme.h:121
ZonalMethod * _zonalMethod
zonal method (FullShell, HalfShell, ...)
Definition: NeighbourCommunicationScheme.h:118
bool _coversWholeDomain[3]
Definition: NeighbourCommunicationScheme.h:113
This Interface is used to get access to particles and pairs of particles.
Definition: ParticleContainer.h:69
Definition: ZonalMethod.h:14
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
Definition: vtk-punstructured.h:270
Definition: HaloRegion.h:10