1 #ifndef DDMD_GROUP_DISTRIBUTOR_TPP 2 #define DDMD_GROUP_DISTRIBUTOR_TPP 11 #include "GroupDistributor.h" 13 #include <ddMd/storage/AtomStorage.h> 14 #include <ddMd/storage/GroupStorage.tpp> 58 atomStoragePtr_ = &atomStorage;
59 groupStoragePtr_ = &groupStorage;
69 if (cacheCapacity <= 0) {
70 UTIL_THROW(
"Attempt to set nonpositive cacheCapacity");
72 if (cache_.capacity() > 0) {
73 UTIL_THROW(
"Attempt to set cacheCapacity after allocation");
75 cacheCapacity_ = cacheCapacity;
83 { read<int>(in,
"cacheCapacity", cacheCapacity_); }
92 if (cache_.capacity() == 0) {
93 if (cacheCapacity_ == 0) {
96 cache_.allocate(cacheCapacity_);
113 if (atomStoragePtr_ == 0) {
114 UTIL_THROW(
"GroupDistributor is not initialized");
116 if (groupStoragePtr_ == 0) {
117 UTIL_THROW(
"GroupDistributor is not initialized");
120 UTIL_THROW(
"GroupDistributor::add called on slave node");
122 if (cache_.capacity() <= 0) {
123 UTIL_THROW(
"GroupDistributor cache is not allocated");
131 if (cacheSize_ == cacheCapacity_) {
132 bool isComplete =
false;
136 nSentTotal_ += cacheSize_;
144 newPtr_ = &cache_[cacheSize_];
155 if (atomStoragePtr_ == 0) {
156 UTIL_THROW(
"GroupDistributor is not initialized");
158 if (groupStoragePtr_ == 0) {
159 UTIL_THROW(
"GroupDistributor is not initialized");
161 if (domainPtr_ == 0) {
162 UTIL_THROW(
"GroupDistributor is not initialized");
168 UTIL_THROW(
"GroupDistributor::add called on slave node");
170 if (cache_.capacity() <= 0) {
171 UTIL_THROW(
"GroupDistributor cache is not allocated");
173 if (atomStoragePtr_->
nGhost() != 0) {
177 UTIL_THROW(
"newPtr is null on entry to add()");
183 Group<N>* ptr = groupStoragePtr_->newPtr();
185 groupStoragePtr_->add();
188 newPtr_->pack(*bufferPtr_);
206 if (atomStoragePtr_ == 0) {
207 UTIL_THROW(
"GroupDistributor is not initialized");
209 if (groupStoragePtr_ == 0) {
210 UTIL_THROW(
"GroupDistributor is not initialized");
212 if (domainPtr_ == 0) {
213 UTIL_THROW(
"GroupDistributor is not initialized");
215 if (bufferPtr_ == 0) {
216 UTIL_THROW(
"GroupDistributor is not initialized");
218 if (cacheCapacity_ <= 0) {
219 UTIL_THROW(
"GroupDistributor is not allocated");
222 UTIL_THROW(
"GroupDistributor::send called on slave node");
229 bool isComplete =
true;
233 nSentTotal_ += cacheSize_;
237 groupStoragePtr_->unsetNTotal();
238 groupStoragePtr_->computeNTotal(domainPtr_->
communicator());
239 if (groupStoragePtr_->nTotal() != nSentTotal_) {
240 UTIL_THROW(
"Number of groups not equal number sent");
242 groupStoragePtr_->isValid(*atomStoragePtr_, domainPtr_->
communicator(),
245 groupStoragePtr_->unsetNTotal();
246 groupStoragePtr_->computeNTotal();
247 if (groupStoragePtr_->nTotal() != nSentTotal_) {
248 UTIL_THROW(
"Number of groups not equal number sent");
250 groupStoragePtr_->isValid(*atomStoragePtr_,
false);
269 if (atomStoragePtr_ == 0) {
270 UTIL_THROW(
"GroupDistributor is not initialized");
272 if (groupStoragePtr_ == 0) {
273 UTIL_THROW(
"GroupDistributor is not initialized");
275 if (domainPtr_ == 0) {
276 UTIL_THROW(
"GroupDistributor is not initialized");
278 if (bufferPtr_ == 0) {
279 UTIL_THROW(
"GroupDistributor is not initialized");
282 UTIL_THROW(
"GroupDistributor::receive called on master node");
284 if (atomStoragePtr_->
nGhost() != 0) {
290 bool isComplete =
false;
291 const int source = 0;
294 while (!isComplete) {
301 while (bufferPtr_->
recvSize() > 0) {
302 ptr = groupStoragePtr_->newPtr();
306 groupStoragePtr_->add();
308 }
else if (nAtom == 0) {
309 groupStoragePtr_->returnPtr();
311 UTIL_THROW(
"Invalid return value from findGroupLocalAtoms");
319 groupStoragePtr_->unsetNTotal();
320 groupStoragePtr_->computeNTotal(domainPtr_->
communicator());
321 groupStoragePtr_->isValid(*atomStoragePtr_, domainPtr_->
communicator(),
336 const int source = 0;
338 .Reduce(&nAtomRecv_, &nAtomRecvTot, 1, MPI::INT, MPI::SUM, source);
340 if (nAtomRecvTot != nSentTotal_*N) {
341 Log::file() <<
"nSentTotal_*N = " << nSentTotal_*N << std::endl;
342 Log::file() <<
"nAtomRecvTot = " << nAtomRecvTot << std::endl;
343 UTIL_THROW(
"Discrepancy in number of local atoms in groups");
bool beginRecvBlock()
Begin to receive a block from the recv buffer.
void add()
Add a group to the cache for sending, send if necessary.
bool isInitialized() const
Has this Domain been initialized by calling readParam?
void unpack(Buffer &buffer)
Unpack a Group from the recv buffer.
void beginSendBlock(int sendType)
Initialize a data block.
void associate(Domain &domain, AtomStorage &atomStorage, GroupStorage< N > &groupStorage, Buffer &buffer)
Create required associations with related objects.
Parallel domain decomposition (DD) MD simulation.
~GroupDistributor()
Destructor.
MPI::Intracomm & communicator() const
Return Cartesian communicator by reference.
virtual void readParameters(std::istream &in)
Read cacheCapacity, allocate memory and initialize object.
int gridRank() const
Get rank of this processor in the processor grid.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
int nGhost() const
Return current number of ghost atoms on this processor.
Utility classes for scientific computation.
const AtomMap & map() const
Return the AtomMap by const reference.
Group< N > * newPtr()
Returns pointer an address available for a new Group<N>.
A container for all the Group<N> objects on this processor.
int recvSize() const
Number of unread items left in current recv block.
void send()
Send all atoms that have not be sent previously.
A container for all the atoms and ghost atoms on this processor.
int findGroupLocalAtoms(Group< N > &group) const
Set handles to local atoms in a Group<N> object.
GroupDistributor()
Constructor.
Buffer for interprocessor communication.
Decomposition of the system into domains associated with processors.
static std::ostream & file()
Get log ostream by reference.
void setup()
Initialize Buffer for sending.
void receive()
Receive all atoms sent by master processor.
void endSendBlock(bool isComplete=true)
Finalize a block in the send buffer.
void setClassName(const char *className)
Set class name string.
void bcast(MPI::Intracomm &comm, int source)
Broadcast a buffer.
A group of covalently interacting atoms.
void setCapacity(int cacheCapacity)
Set cacheCapacity, allocate memory and initialize object.
void clearSendBuffer()
Clear the send buffer.
Class template for distributing Group<N> objects among processors.