Simpatico  v1.10
DdTimer.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "DdTimer.h"
9 
10 namespace DdMd
11 {
12 
13  DdTimer::DdTimer(int size)
14  {
15  times_.allocate(size);
16  size_ = size;
17  clear();
18  }
19 
20  DdTimer::~DdTimer()
21  {}
22 
24  {
25  for (int i = 0; i < size_; i++) {
26  times_[i] = 0.0;
27  }
28  time_ = 0.0;
29  }
30 
32  {
33  begin_ = MPI_Wtime();
34  previous_ = begin_;
35  }
36 
37  void DdTimer::stamp(int id)
38  {
39  double current = MPI_Wtime();
40  times_[id] += current - previous_;
41  previous_ = current;
42  }
43 
45  { time_ += MPI_Wtime() - begin_; }
46 
47  #ifdef UTIL_MPI
48  void DdTimer::reduce(MPI::Intracomm& communicator)
49  {
50  int procs = communicator.Get_size();
51  double sum;
52  for (int i = 0; i < size_; i++) {
53  communicator.Allreduce(&times_[i], &sum, 1, MPI::DOUBLE, MPI::SUM);
54  times_[i] = sum/double(procs);
55  }
56  communicator.Allreduce(&time_, &sum, 1, MPI::DOUBLE, MPI::SUM);
57  time_ = sum/double(procs);
58  }
59  #endif
60 
61  double DdTimer::time(int id) const
62  { return times_[id]; }
63 
64  double DdTimer::time() const
65  { return time_; }
66 
67 }
void reduce(MPI::Intracomm &communicator)
Upon return, times on every processor replaced by average over procs.
Definition: DdTimer.cpp:48
void stop()
Stop total time accumulation.
Definition: DdTimer.cpp:44
Parallel domain decomposition (DD) MD simulation.
void stamp(int id)
Mark end of interval id.
Definition: DdTimer.cpp:37
double time() const
Get total time since start time, average per processor.
Definition: DdTimer.cpp:64
void allocate(int capacity)
Allocate the underlying C array.
Definition: DArray.h:191
void clear()
Clear all time statistics.
Definition: DdTimer.cpp:23
void start()
Clear statistics, mark a start time.
Definition: DdTimer.cpp:31