aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/timestat.cc
blob: addd1540d0135f77b31545fd9647f8439189a1d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#include <algorithm>
#include <cassert>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>

#include <mpi.h>

#include "cctk.h"
#include "cctk_Arguments.h"
#include "cctk_Parameters.h"

#include "dist.hh"
#include "timestat.hh"



using namespace std;



timestat::timestat ()
  : wtime(0.0), wtime2(0.0), wmin(0.0), wmax(0.0),
    bytes(0.0), bytes2(0.0), bmin(0.0), bmax(0.0),
    count(0.0),
    running(false)
{
}

void timestat::addstat (double const t, double const b)
{
  wtime += t;
  wtime2 += t*t;
  wmin = min (wmin, t);
  wmax = max (wmax, t);
  
  bytes += b;
  bytes2 += b*b;
  bmin = min (bmin, b);
  bmax = max (bmax, b);
  
  ++count;
}

void timestat::start ()
{
  assert (! running);
  running = true;
  starttime = MPI_Wtime();
}

void timestat::stop (double const b)
{
  assert (running);
  running = false;
  double const endtime = MPI_Wtime();
  addstat (endtime - starttime, b);
}



ostream& operator<< (ostream& os, const timestat& wt)
{
  double avg, stddev, bavg, bstddev;
  if (wt.count == 0.0) {
    avg = 0.0;
    stddev = 0.0;
    bavg = 0.0;
    bstddev = 0.0;
  } else {
    avg = wt.wtime / wt.count;
    stddev = sqrt (max (0.0, wt.wtime2 / wt.count - pow (avg, 2)));
    bavg = wt.bytes / wt.count;
    bstddev = sqrt (max (0.0, wt.bytes2 / wt.count - pow (bavg, 2)));
  }
  os << "timestat[seconds]:"
     << " cnt: " << wt.count
     << "   time: sum: " << wt.wtime
     << " avg: " << avg
     << " stddev: " << stddev
     << " min: " << wt.wmin
     << " max: " << wt.wmax
     << "   bytes: sum: " << wt.bytes
     << " avg: " << bavg
     << " stddev: " << bstddev
     << " min: " << wt.bmin
     << " max: " << wt.bmax;
  return os;
}



timestat wtime_copyfrom_recv;
timestat wtime_copyfrom_send;
timestat wtime_copyfrom_wait;

timestat wtime_copyfrom_recv_maketyped;
timestat wtime_copyfrom_recv_allocate;
timestat wtime_copyfrom_recv_changeproc_recv;
timestat wtime_copyfrom_send_copyfrom_nocomm1;
timestat wtime_copyfrom_send_copyfrom_nocomm2;
timestat wtime_copyfrom_send_changeproc_send;
timestat wtime_copyfrom_wait_changeproc_wait;
timestat wtime_copyfrom_wait_copyfrom_nocomm;
timestat wtime_copyfrom_wait_delete;

timestat wtime_copyfrom_recvinner_allocate;
timestat wtime_copyfrom_recvinner_recv;
timestat wtime_copyfrom_sendinner_allocate;
timestat wtime_copyfrom_sendinner_copy;
timestat wtime_copyfrom_sendinner_send;
timestat wtime_copyfrom_recvwaitinner_wait;
timestat wtime_copyfrom_recvwaitinner_copy;
timestat wtime_copyfrom_recvwaitinner_delete;
timestat wtime_copyfrom_sendwaitinner_wait;
timestat wtime_copyfrom_sendwaitinner_delete;

timestat wtime_changeproc_recv;
timestat wtime_changeproc_send;
timestat wtime_changeproc_wait;

timestat wtime_irecv;
timestat wtime_isend;
timestat wtime_isendwait;
timestat wtime_irecvwait;

timestat wtime_commstate_sizes_irecv;
timestat wtime_commstate_waitall_final;
timestat wtime_commstate_waitall;
timestat wtime_commstate_waitsome;
timestat wtime_commstate_send;
timestat wtime_commstate_ssend;
timestat wtime_commstate_isend;
timestat wtime_commstate_memcpy;
timestat wtime_commstate_interpolate_irecv;
timestat wtime_commstate_interpolate_from_isend;
timestat wtime_commstate_interpolate_to_isend;



timestat wtime_restrict;
timestat wtime_prolongate;
timestat wtime_prolongate_copy;
timestat wtime_prolongate_Lagrange;
timestat wtime_prolongate_ENO;
timestat wtime_prolongate_WENO;



extern "C" void CarpetLib_printtimestats (CCTK_ARGUMENTS);

void CarpetLib_printtimestats (CCTK_ARGUMENTS)
{
  DECLARE_CCTK_ARGUMENTS;
  DECLARE_CCTK_PARAMETERS;
  if (print_timestats or
      (print_timestats_every and
       cctk_iteration % print_timestats_every == 0))
  {
    ostringstream filenamebuf;
    filenamebuf << out_dir << "/" << timestat_file
                << "." << setw(4) << setfill('0') << dist::rank()
                << ".txt";
    string const filename = filenamebuf.str();
    
    ofstream file;
    static bool do_truncate = true;
    if (do_truncate) {
      if (not IO_TruncateOutputFiles (cctkGH)) {
        do_truncate = false;
      }
    }
    if (do_truncate) {
      do_truncate = false;
      file.open (filename.c_str(), ios::out | ios::trunc);
    } else {
      file.open (filename.c_str(), ios::out | ios::app);
    }
    
    static bool do_print_info = true;
    if (do_print_info) {
      do_print_info = false;
      if (CCTK_IsFunctionAliased ("UniqueBuildID")) {
        char const * const build_id
          = static_cast<char const *> (UniqueBuildID (cctkGH));
        file << "Build ID: " << build_id << endl;
      }
      if (CCTK_IsFunctionAliased ("UniqueSimulationID")) {
        char const * const job_id
          = static_cast<char const *> (UniqueSimulationID (cctkGH));
        file << "Simulation ID: " << job_id << endl;
      }
      file << "Running on " << dist::size() << " processors" << endl;
    }
    
    file << endl
         << "********************************************************************************" << endl
         << "Timing statistics from CarpetLib at iteration " << cctkGH->cctk_iteration << " time  " << cctkGH->cctk_time << ":" << endl
         << "   wtime_copyfrom_recv:                    " << wtime_copyfrom_recv                    << endl
         << "   wtime_copyfrom_send:                    " << wtime_copyfrom_send                    << endl
         << "   wtime_copyfrom_wait:                    " << wtime_copyfrom_wait                    << endl
         << endl
         << "   wtime_copyfrom_recv_maketyped:          " << wtime_copyfrom_recv_maketyped          << endl   
         << "   wtime_copyfrom_recv_allocate:           " << wtime_copyfrom_recv_allocate           << endl
         << "   wtime_copyfrom_recv_changeproc_recv:    " << wtime_copyfrom_recv_changeproc_recv    << endl
         << "   wtime_copyfrom_send_copyfrom_nocomm1:   " << wtime_copyfrom_send_copyfrom_nocomm1   << endl
         << "   wtime_copyfrom_send_copyfrom_nocomm2:   " << wtime_copyfrom_send_copyfrom_nocomm2   << endl
         << "   wtime_copyfrom_send_changeproc_send:    " << wtime_copyfrom_send_changeproc_send    << endl
         << "   wtime_copyfrom_wait_changeproc_wait:    " << wtime_copyfrom_wait_changeproc_wait    << endl
         << "   wtime_copyfrom_wait_copyfrom_nocomm2:   " << wtime_copyfrom_wait_copyfrom_nocomm    << endl
         << "   wtime_copyfrom_wait_delete:             " << wtime_copyfrom_wait_delete             << endl
         << endl
         << "   wtime_copyfrom_recvinner_allocate:      " << wtime_copyfrom_recvinner_allocate      << endl
         << "   wtime_copyfrom_recvinner_recv:          " << wtime_copyfrom_recvinner_recv          << endl
         << "   wtime_copyfrom_sendinner_allocate:      " << wtime_copyfrom_sendinner_allocate      << endl
         << "   wtime_copyfrom_sendinner_copy:          " << wtime_copyfrom_sendinner_copy          << endl
         << "   wtime_copyfrom_sendinner_send:          " << wtime_copyfrom_sendinner_send          << endl
         << "   wtime_copyfrom_recvwaitinner_wait:      " << wtime_copyfrom_recvwaitinner_wait      << endl
         << "   wtime_copyfrom_recvwaitinner_copy:      " << wtime_copyfrom_recvwaitinner_copy      << endl
         << "   wtime_copyfrom_recvwaitinner_delete:    " << wtime_copyfrom_recvwaitinner_delete    << endl
         << "   wtime_copyfrom_sendwaitinner_wait:      " << wtime_copyfrom_sendwaitinner_wait      << endl
         << "   wtime_copyfrom_sendwaitinner_delete:    " << wtime_copyfrom_sendwaitinner_delete    << endl
         << endl
         << "   wtime_changeproc_recv:                  " << wtime_changeproc_recv                  << endl
         << "   wtime_changeproc_send:                  " << wtime_changeproc_send                  << endl
         << "   wtime_changeproc_wait:                  " << wtime_changeproc_wait                  << endl
         << endl
         << "   wtime_irecv:                            " << wtime_irecv                            << endl
         << "   wtime_isend:                            " << wtime_isend                            << endl
         << "   wtime_isendwait:                        " << wtime_isendwait                        << endl
         << "   wtime_irecvwait:                        " << wtime_irecvwait                        << endl
         << endl
         << "   wtime_commstate_sizes_irecv:            " << wtime_commstate_sizes_irecv            << endl
         << "   wtime_commstate_waitall_final:          " << wtime_commstate_waitall_final          << endl
         << "   wtime_commstate_waitall:                " << wtime_commstate_waitall                << endl
         << "   wtime_commstate_waitsome:               " << wtime_commstate_waitsome               << endl
         << "   wtime_commstate_send:                   " << wtime_commstate_send                   << endl
         << "   wtime_commstate_ssend:                  " << wtime_commstate_ssend                  << endl
         << "   wtime_commstate_isend:                  " << wtime_commstate_isend                  << endl
         << "   wtime_commstate_memcpy:                 " << wtime_commstate_memcpy                 << endl
         << "   wtime_commstate_interpolate_irecv:      " << wtime_commstate_interpolate_irecv      << endl
         << "   wtime_commstate_interpolate_from_isend: " << wtime_commstate_interpolate_from_isend << endl
         << "   wtime_commstate_interpolate_to_isend:   " << wtime_commstate_interpolate_to_isend   << endl
         << endl
         << "   wtime_restrict:                         " << wtime_restrict                         << endl
         << "   wtime_prolongate:                       " << wtime_prolongate                       << endl
         << "   wtime_prolongate_Lagrange:              " << wtime_prolongate_Lagrange              << endl
         << "   wtime_prolongate_ENO:                   " << wtime_prolongate_ENO                   << endl
         << "   wtime_prolongate_WENO:                  " << wtime_prolongate_WENO                  << endl
         << endl;
  }
}