Simpatico  v1.10
MpiLogger.cpp
1 #ifdef UTIL_MPI
2 /*
3 * Util Package - C++ Utilities for Scientific Computation
4 *
5 * Copyright 2010 - 2017, The Regents of the University of Minnesota
6 * Distributed under the terms of the GNU General Public License.
7 */
8 
9 #include "MpiLogger.h"
10 #include "MpiSendRecv.h"
11 
12 namespace Util
13 {
14 
15  /*
16  * Constructor.
17  */
18  MpiLogger::MpiLogger(MPI::Intracomm& comm)
19  : communicatorPtr_(&comm),
20  rank_(-1),
21  size_(-1)
22  {}
23 
24  /*
25  */
27  {
28  communicatorPtr_->Barrier();
29  rank_ = communicatorPtr_->Get_rank();
30  size_ = communicatorPtr_->Get_size();
31  int data;
32  if (rank_ > 0) {
33  recv<int>(*communicatorPtr_, data, rank_ - 1, 0);
34  } else {
35  std::cout << std::endl;
36  std::cout.flush();
37  }
38  }
39 
40  /*
41  */
43  {
44  std::cout.flush();
45  if (rank_ < size_ - 1) {
46  send<int>(*communicatorPtr_, rank_, rank_ + 1, 0);
47  }
48  communicatorPtr_->Barrier();
49  }
50 
51 }
52 #endif
void begin()
Begin logging block.
Definition: MpiLogger.cpp:26
void end()
End logging block.
Definition: MpiLogger.cpp:42
MpiLogger(MPI::Intracomm &comm=MPI::COMM_WORLD)
Constructor.
Definition: MpiLogger.cpp:18
Utility classes for scientific computation.
Definition: accumulators.mod:1
This file contains templates for global functions send<T>, recv<T> and bcast<T>.