PSCF v1.3
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
12namespace 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 */
26 void MpiLogger::begin()
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 */
42 void MpiLogger::end()
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
Utility classes for scientific computation.