ls1-MarDyn
ls1-MarDyn molecular dynamics code
DomainDecompMPIBase.h
1/*
2 * DomainDecompBaseMPI.h
3 *
4 * Created on: Nov 15, 2015
5 * Author: tchipevn
6 */
7
8#ifndef DOMAINDECOMPMPIBASE_H_
9#define DOMAINDECOMPMPIBASE_H_
10
11#include <mpi.h>
12#include <vector>
13#include <memory>
14
15#include "utils/Logger.h"
16#include "DomainDecompBase.h"
17#include "CollectiveCommunicationInterface.h"
18#include "CommunicationPartner.h"
19#include "ParticleDataForwardDeclaration.h"
20
21#define LOWER 0
22#define HIGHER 1
23
24#define DIMgeom 3
25
27
28struct HaloRegion;
29
31public:
33 virtual ~~DomainDecompMPIBase();
34
35 // documentation see father class (DomainDecompBase.h)
36 void barrier() const override {
37 MPI_CHECK(MPI_Barrier(_comm));
38 }
39
41 unsigned Ndistribution(unsigned localN, float* minrnd, float* maxrnd);
42
44 void assertIntIdentity(int IX);
45 void assertDisjunctivity(ParticleContainer* moleculeContainer) const override;
46
47 //##################################################################
48 // The following methods with prefix "collComm" are all used
49 // in the context of collective communication. Each of the methods
50 // basically has to call the corresponding method from the class
51 // CollectiveCommunication (or CollectiveCommDummy in the sequential
52 // case). To get information about how to use this methods, read
53 // the documentation of the class CollectiveCommunication and of the
54 // father class of this class (DomainDecompBase.h)
55 //##################################################################
56 void collCommInit(int numValues, int key=0) override {
57 _collCommunication->init(_comm, numValues, key);
58 }
59
60 void collCommFinalize() override {
61 _collCommunication->finalize();
62 }
63
64 void collCommAppendInt(int intValue) override {
65 _collCommunication->appendInt(intValue);
66 }
67
68 void collCommAppendUnsLong(unsigned long unsLongValue) override {
69 _collCommunication->appendUnsLong(unsLongValue);
70 }
71
72 void collCommAppendFloat(float floatValue) override {
73 _collCommunication->appendFloat(floatValue);
74 }
75
76 void collCommAppendDouble(double doubleValue) override {
77 _collCommunication->appendDouble(doubleValue);
78 }
79
80 void collCommAppendLongDouble(long double longDoubleValue) override {
81 _collCommunication->appendLongDouble(longDoubleValue);
82 }
83
84 int collCommGetInt() override {
85 return _collCommunication->getInt();
86 }
87
88 unsigned long collCommGetUnsLong() override {
89 return _collCommunication->getUnsLong();
90 }
91
92 float collCommGetFloat() override {
93 return _collCommunication->getFloat();
94 }
95
96 double collCommGetDouble() override {
97 return _collCommunication->getDouble();
98 }
99
100 long double collCommGetLongDouble() override {
101 return _collCommunication->getLongDouble();
102 }
103
104 void collCommAllreduceSum() override {
105 _collCommunication->allreduceSum();
106 }
107
108 void collCommAllreduceSumAllowPrevious() override;
109
110 void collCommAllreduceCustom(ReduceType type) override {
111 _collCommunication->allreduceCustom(type);
112 }
113
114 void collCommScanSum() override {
115 _collCommunication->scanSum();
116 }
117
118 void collCommBroadcast(int root = 0) override {
119 _collCommunication->broadcast(root);
120 }
121
131 virtual void balanceAndExchangeInitNonBlocking(bool forceRebalancing, ParticleContainer* moleculeContainer,
132 Domain* domain);
133
142 virtual void prepareNonBlockingStage(bool forceRebalancing, ParticleContainer* moleculeContainer, Domain* domain,
143 unsigned int stageNumber) = 0;
144
153 virtual void finishNonBlockingStage(bool forceRebalancing, ParticleContainer* moleculeContainer, Domain* domain,
154 unsigned int stageNumber) = 0;
155
167 void exchangeMoleculesMPI(ParticleContainer* moleculeContainer, Domain* domain, MessageType msgType,
168 bool doHaloPositionCheck = true, bool removeRecvDuplicates = false);
169
170 void exchangeForces(ParticleContainer* moleculeContainer, Domain* domain) override;
171
172 std::vector<int> getNeighbourRanks() override = 0;
173 std::vector<int> getNeighbourRanksFullShell() override = 0;
174
175 virtual std::vector<CommunicationPartner> getNeighboursFromHaloRegion(Domain* domain, const HaloRegion& haloRegion, double cutoff) = 0;
176
177
178#if defined(ENABLE_MPI)
179 MPI_Datatype getMPIParticleType() {
180 return _mpiParticleType;
181 }
182 MPI_Datatype getMPIParticleForceType() {
183 return _mpiParticleForceType;
184 }
185 MPI_Comm getCommunicator() override {
186 return _comm;
187 }
188#endif
189
207 virtual void readXML(XMLfileUnits& xmlconfig);
208
215 virtual void setCommunicationScheme(const std::string& scheme, const std::string& comScheme);
216
217 // documentation in base class
218 virtual int getNonBlockingStageCount() override;
219
220 virtual size_t getTotalSize() override;
221
222 virtual void printSubInfo(int offset) override;
223
224 virtual void printDecomp(const std::string &filename, Domain *domain, ParticleContainer *particleContainer) override;
225
226 virtual std::string getName() override {
227 return "DomainDecompMPIBase";
228 }
229
230 void printCommunicationPartners(std::string filename) const override;
231protected:
232
240 virtual void prepareNonBlockingStageImpl(ParticleContainer* moleculeContainer, Domain* domain,
241 unsigned int stageNumber, MessageType msgType, bool removeRecvDuplicates = false);
242
251 virtual void finishNonBlockingStageImpl(ParticleContainer* moleculeContainer, Domain* domain,
252 unsigned int stageNumber, MessageType msgType, bool removeRecvDuplicates = false);
253
254 MPI_Datatype _mpiParticleType;
255 MPI_Datatype _mpiParticleForceType;
256
257 MPI_Comm _comm;
258
259 std::unique_ptr<NeighbourCommunicationScheme> _neighbourCommunicationScheme;
260
266 bool _forceDirectPP{false};
267private:
268 std::unique_ptr<CollectiveCommunicationInterface> _collCommunication;
273 unsigned long _overlappingStartAtStep {5ul};
274};
275
276#endif /* DOMAINDECOMPMPIBASE_H_ */
handle boundary region and multiple processes
Definition: DomainDecompBase.h:51
Definition: DomainDecompMPIBase.h:30
void barrier() const override
synchronizes all processes
Definition: DomainDecompMPIBase.h:36
double collCommGetDouble() override
has to call getDouble method of a CollComm class
Definition: DomainDecompMPIBase.h:96
unsigned Ndistribution(unsigned localN, float *minrnd, float *maxrnd)
returns total number of molecules
Definition: DomainDecompMPIBase.cpp:173
virtual void prepareNonBlockingStage(bool forceRebalancing, ParticleContainer *moleculeContainer, Domain *domain, unsigned int stageNumber)=0
void collCommInit(int numValues, int key=0) override
has to call init method of a CollComm class
Definition: DomainDecompMPIBase.h:56
void collCommFinalize() override
has to call finalize method of a CollComm class
Definition: DomainDecompMPIBase.h:60
void assertDisjunctivity(ParticleContainer *moleculeContainer) const override
Definition: DomainDecompMPIBase.cpp:206
float collCommGetFloat() override
has to call getFloat method of a CollComm class
Definition: DomainDecompMPIBase.h:92
virtual void balanceAndExchangeInitNonBlocking(bool forceRebalancing, ParticleContainer *moleculeContainer, Domain *domain)
Definition: DomainDecompMPIBase.cpp:260
long double collCommGetLongDouble() override
has to call getLongDouble method of a CollComm class
Definition: DomainDecompMPIBase.h:100
int collCommGetInt() override
has to call getInt method of a CollComm class
Definition: DomainDecompMPIBase.h:84
virtual void prepareNonBlockingStageImpl(ParticleContainer *moleculeContainer, Domain *domain, unsigned int stageNumber, MessageType msgType, bool removeRecvDuplicates=false)
Definition: DomainDecompMPIBase.cpp:266
void collCommScanSum() override
has to call scanSum method of a CollComm class (none in sequential version)
Definition: DomainDecompMPIBase.h:114
virtual int getNonBlockingStageCount() override
Definition: DomainDecompMPIBase.cpp:131
void collCommAllreduceSum() override
has to call allreduceSum method of a CollComm class (none in sequential version)
Definition: DomainDecompMPIBase.h:104
void collCommAppendDouble(double doubleValue) override
has to call appendDouble method of a CollComm class
Definition: DomainDecompMPIBase.h:76
void collCommBroadcast(int root=0) override
has to call broadcast method of a CollComm class (none in sequential version)
Definition: DomainDecompMPIBase.h:118
virtual void finishNonBlockingStage(bool forceRebalancing, ParticleContainer *moleculeContainer, Domain *domain, unsigned int stageNumber)=0
void collCommAllreduceSumAllowPrevious() override
has to call allreduceSum method of a CollComm class (none in sequential version), allows for values o...
Definition: DomainDecompMPIBase.cpp:361
virtual void finishNonBlockingStageImpl(ParticleContainer *moleculeContainer, Domain *domain, unsigned int stageNumber, MessageType msgType, bool removeRecvDuplicates=false)
Definition: DomainDecompMPIBase.cpp:273
void collCommAppendLongDouble(long double longDoubleValue) override
has to call appendLongDouble method of a CollComm class
Definition: DomainDecompMPIBase.h:80
virtual void printDecomp(const std::string &filename, Domain *domain, ParticleContainer *particleContainer) override
writes information about the current decomposition into the given file
Definition: DomainDecompMPIBase.cpp:306
void collCommAppendInt(int intValue) override
has to call appendInt method of a CollComm class
Definition: DomainDecompMPIBase.h:64
void collCommAppendUnsLong(unsigned long unsLongValue) override
has to call appendUnsLong method of a CollComm class
Definition: DomainDecompMPIBase.h:68
virtual void readXML(XMLfileUnits &xmlconfig)
Read in XML configuration for DomainDecompMPIBase.
Definition: DomainDecompMPIBase.cpp:58
void exchangeForces(ParticleContainer *moleculeContainer, Domain *domain) override
Exchanges forces at the domain boundaries if it's required by the cell container.
Definition: DomainDecompMPIBase.cpp:292
virtual void setCommunicationScheme(const std::string &scheme, const std::string &comScheme)
Definition: DomainDecompMPIBase.cpp:135
void exchangeMoleculesMPI(ParticleContainer *moleculeContainer, Domain *domain, MessageType msgType, bool doHaloPositionCheck=true, bool removeRecvDuplicates=false)
exchange molecules between processes
Definition: DomainDecompMPIBase.cpp:279
void collCommAppendFloat(float floatValue) override
has to call appendFloat method of a CollComm class
Definition: DomainDecompMPIBase.h:72
void assertIntIdentity(int IX)
checks identity of random number generators
Definition: DomainDecompMPIBase.cpp:189
void collCommAllreduceCustom(ReduceType type) override
has to call allreduceCustom method of a CollComm class (none in sequential version)
Definition: DomainDecompMPIBase.h:110
bool _forceDirectPP
Definition: DomainDecompMPIBase.h:266
unsigned long collCommGetUnsLong() override
has to call getUnsLong method of a CollComm class
Definition: DomainDecompMPIBase.h:88
This class is used to read in the phasespace and to handle macroscopic values.
Definition: Domain.h:47
Definition: NeighbourCommunicationScheme.h:18
This Interface is used to get access to particles and pairs of particles.
Definition: ParticleContainer.h:69
XML file with unit attributes abstraction.
Definition: xmlfileUnits.h:25
Enumeration class corresponding to the type schema type.
Definition: vtk-unstructured.h:1746
::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