40 reserve(
const unsigned int max_size)
42 times.reserve(max_size);
49 accumulated_time = 0.0;
54 temp = std::chrono::system_clock::now();
59 const double dt = std::chrono::duration_cast<std::chrono::microseconds>(
60 std::chrono::system_clock::now() - temp)
63 accumulated_time += dt;
65 if (times.capacity() > 0)
78 get_accumulated_time()
const
80 return accumulated_time;
83 const std::vector<double> &
90 unsigned int counter = 0;
91 std::chrono::time_point<std::chrono::system_clock> temp;
92 double accumulated_time = 0.0;
93 std::vector<double> times;
98 static const unsigned int max_levels = 10;
99 static const unsigned int max_timers = 100;
100 static const unsigned int max_iterations = 1000;
103 Timers(
const bool log_all_calls)
104 : log_all_calls(log_all_calls)
106 path.reserve(max_levels);
107 timers.reserve(max_timers);
109 path.emplace_back(
"");
112 Timer &operator[](
const std::string &label)
114 const std::string label_ = path.back() + label;
116 const auto ptr = map.find(label_);
118 if (ptr == map.end())
120 timers.resize(timers.size() + 1);
121 map[label_] = timers.size() - 1;
123 if (this->log_all_calls)
124 timers.back().reserve(max_iterations);
125 return timers.back();
128 return timers[ptr->second];
134 for (
auto &timer : timers)
139 enter(
const std::string &label)
141 path.emplace_back(path.back() + label +
":");
147 path.resize(path.size() - 1);
150 template <
typename StreamType>
152 print(
const MPI_Comm &comm, StreamType &stream)
const
154 std::vector<std::pair<std::string, std::array<double, 1>>> list;
155 std::vector<std::pair<std::string, unsigned int>> list_count;
157 unsigned int counter = 0;
158 unsigned int max_counter = 0;
160 for (
const auto &time : map)
162 list.emplace_back(time.first,
163 std::array<double, 1>{
164 {timers[time.second].get_accumulated_time() /
166 list_count.emplace_back(time.first,
167 timers[time.second].get_counter());
169 if (time.first ==
"id_total")
170 max_counter = counter;
176 stream, comm, list, list_count, {
"Time [sec]"}, max_counter);
180 print_log(
const MPI_Comm &comm_global,
const std::string &prefix)
const
182 const auto print_statistics =
183 [&](
const auto &v, std::string slabel,
const unsigned int tag) {
185 dealii::Utilities::MPI::this_mpi_process(comm_global);
189 std::ofstream myfile;
190 myfile.open(prefix +
"_" + slabel +
".stat");
192 for (
unsigned int i = 0;
193 i < dealii::Utilities::MPI::n_mpi_processes(comm_global);
196 std::vector<double> recv_data;
206 MPI_Probe(MPI_ANY_SOURCE, tag, comm_global, &status);
207 AssertThrowMPI(ierr);
214 dealii::Utilities::MPI::mpi_type_id_for_type<double>,
217 recv_data.resize(len);
223 dealii::Utilities::MPI::mpi_type_id_for_type<double>,
230 for (
const auto j : recv_data)
231 myfile << i <<
" " << j << std::endl;
240 dealii::Utilities::MPI::mpi_type_id_for_type<double>,
246 MPI_Barrier(comm_global);
250 unsigned int tag = 110;
251 for (
const auto &time : map)
252 print_statistics(timers[time.second].get_log(),
253 std::string(time.first),
259 std::map<std::string, unsigned int> map;
262 std::vector<Timer> timers;
264 std::vector<std::string> path;
266 const bool log_all_calls;