16 #include <deal.II/base/timer.h> 17 #include <deal.II/base/exceptions.h> 18 #include <deal.II/base/mpi.h> 19 #include <deal.II/base/utilities.h> 20 #include <deal.II/base/signaling_nan.h> 27 #if defined(DEAL_II_HAVE_SYS_TIME_H) && defined(DEAL_II_HAVE_SYS_RESOURCE_H) 28 # include <sys/time.h> 29 # include <sys/resource.h> 38 DEAL_II_NAMESPACE_OPEN
46 start_time_children (0.),
49 cumulative_wall_time (0.),
52 #ifdef DEAL_II_WITH_MPI
54 mpi_communicator (MPI_COMM_SELF),
55 sync_wall_time (false)
58 #ifdef DEAL_II_WITH_MPI 70 #ifdef DEAL_II_WITH_MPI 72 const bool sync_wall_time_)
75 start_time_children (0.),
78 cumulative_wall_time (0.),
81 mpi_communicator (mpi_communicator),
82 sync_wall_time(sync_wall_time_)
84 #ifdef DEAL_II_WITH_MPI 103 LARGE_INTEGER freq, time;
104 QueryPerformanceFrequency(&freq);
105 QueryPerformanceCounter(&time);
106 return (
double) time.QuadPart / freq.QuadPart;
112 FILETIME cpuTime, sysTime, createTime, exitTime;
113 if (GetProcessTimes(GetCurrentProcess(), &createTime,
114 &exitTime, &sysTime, &cpuTime))
116 return (
double)(((
unsigned long long)cpuTime.dwHighDateTime << 32)
117 | cpuTime.dwLowDateTime) / 1e6;
131 #ifdef DEAL_II_WITH_MPI 139 #if defined(DEAL_II_HAVE_SYS_TIME_H) && defined(DEAL_II_HAVE_SYS_RESOURCE_H) 143 struct timeval wall_timer;
144 gettimeofday(&wall_timer, NULL);
148 getrusage (RUSAGE_SELF, &usage);
149 start_time = usage.ru_utime.tv_sec + 1.e-6 * usage.ru_utime.tv_usec;
151 rusage usage_children;
152 getrusage (RUSAGE_CHILDREN, &usage_children);
153 start_time_children = usage_children.ru_utime.tv_sec + 1.e-6 * usage_children.ru_utime.tv_usec;
155 #elif defined(DEAL_II_MSVC) 160 # error Unsupported platform. Porting not finished. 172 #if defined(DEAL_II_HAVE_SYS_TIME_H) && defined(DEAL_II_HAVE_SYS_RESOURCE_H) 176 getrusage (RUSAGE_SELF, &usage);
177 const double dtime = usage.ru_utime.tv_sec + 1.e-6 * usage.ru_utime.tv_usec;
180 rusage usage_children;
181 getrusage (RUSAGE_CHILDREN, &usage_children);
182 const double dtime_children =
183 usage_children.ru_utime.tv_sec + 1.e-6 * usage_children.ru_utime.tv_usec;
186 struct timeval wall_timer;
187 gettimeofday(&wall_timer, NULL);
188 last_lap_time = wall_timer.tv_sec + 1.e-6 * wall_timer.tv_usec
190 #elif defined(DEAL_II_MSVC) 194 # error Unsupported platform. Porting not finished. 197 #ifdef DEAL_II_WITH_MPI 226 #if defined(DEAL_II_HAVE_SYS_TIME_H) && defined(DEAL_II_HAVE_SYS_RESOURCE_H) 228 getrusage (RUSAGE_SELF, &usage);
229 const double dtime = usage.ru_utime.tv_sec + 1.e-6 * usage.ru_utime.tv_usec;
231 rusage usage_children;
232 getrusage (RUSAGE_CHILDREN, &usage_children);
233 const double dtime_children =
234 usage_children.ru_utime.tv_sec + 1.e-6 * usage_children.ru_utime.tv_usec;
236 const double running_time = dtime -
start_time + dtime_children
245 #elif defined(DEAL_II_MSVC) 249 # error Unsupported platform. Porting not finished. 264 #if defined(DEAL_II_HAVE_SYS_TIME_H) && defined(DEAL_II_HAVE_SYS_RESOURCE_H) 265 struct timeval wall_timer;
266 gettimeofday(&wall_timer, NULL);
267 return (wall_timer.tv_sec
268 + 1.e-6 * wall_timer.tv_usec
298 output_frequency (output_frequency),
299 output_type (output_type),
300 out_stream (stream, true),
301 output_is_enabled (true)
302 #ifdef DEAL_II_WITH_MPI
303 , mpi_communicator (MPI_COMM_SELF)
313 output_frequency (output_frequency),
314 output_type (output_type),
316 output_is_enabled (true)
317 #ifdef DEAL_II_WITH_MPI
318 , mpi_communicator (MPI_COMM_SELF)
323 #ifdef DEAL_II_WITH_MPI 326 std::ostream &stream,
330 output_frequency (output_frequency),
331 output_type (output_type),
332 out_stream (stream, true),
333 output_is_enabled (true),
334 mpi_communicator (mpi_communicator)
344 output_frequency (output_frequency),
345 output_type (output_type),
347 output_is_enabled (true),
348 mpi_communicator (mpi_communicator)
376 Assert (section_name.empty() ==
false,
381 ExcMessage (std::string(
"Cannot enter the already active section <")
382 + section_name +
">."));
386 #ifdef DEAL_II_WITH_MPI 401 sections[section_name].total_cpu_time = 0;
402 sections[section_name].total_wall_time = 0;
406 sections[section_name].timer.reset();
407 sections[section_name].timer.start();
419 ExcMessage(
"Cannot exit any section because none has been entered!"));
423 if (section_name !=
"")
426 ExcMessage (
"Cannot delete a section that was never created."));
429 ExcMessage (
"Cannot delete a section that has not been entered."));
434 const std::string actual_section_name = (section_name ==
"" ?
438 sections[actual_section_name].timer.stop();
439 sections[actual_section_name].total_wall_time
440 +=
sections[actual_section_name].timer.wall_time();
446 const double cpu_time =
sections[actual_section_name].timer();
447 sections[actual_section_name].total_cpu_time += cpu_time;
453 std::string output_time;
454 std::ostringstream cpu;
455 cpu << cpu_time <<
"s";
456 std::ostringstream wall;
457 wall <<
sections[actual_section_name].timer.wall_time() <<
"s";
459 output_time =
", CPU time: " + cpu.str();
461 output_time =
", wall time: " + wall.str() +
".";
463 output_time =
", CPU/wall time: " + cpu.str() +
" / " + wall.str() +
".";
465 out_stream << actual_section_name << output_time
472 actual_section_name));
498 double check_time = 0.;
499 for (std::map<std::string, Section>::const_iterator
501 check_time += i->second.total_cpu_time;
503 const double time_gap = check_time-total_cpu_time;
505 total_cpu_time = check_time;
509 <<
"+---------------------------------------------+------------" 510 <<
"+------------+\n" 511 <<
"| Total CPU time elapsed since start |";
512 out_stream << std::setw(10) << std::setprecision(3) << std::right;
519 out_stream <<
" CPU time " <<
" | % of total |\n";
520 out_stream <<
"+---------------------------------+-----------+------------" 522 for (std::map<std::string, Section>::const_iterator
525 std::string name_out = i->first;
529 unsigned int pos_non_space = name_out.find_first_not_of (
" ");
530 name_out.erase(0, pos_non_space);
531 name_out.resize (32,
' ');
539 out_stream << i->second.total_cpu_time <<
"s |";
541 if (total_cpu_time != 0)
546 const double fraction = i->second.total_cpu_time/total_cpu_time;
547 if (fraction > 0.001)
561 <<
"+---------------------------------+-----------+" 562 <<
"------------+------------+\n" 567 <<
"Note: The sum of counted times is " << time_gap
568 <<
" seconds larger than the total time.\n" 569 <<
"(Timer function may have introduced too much overhead, or different\n" 570 <<
"section timers may have run at the same time.)" << std::endl;
580 <<
"+---------------------------------------------+------------" 581 <<
"+------------+\n" 582 <<
"| Total wallclock time elapsed since start |";
583 out_stream << std::setw(10) << std::setprecision(3) << std::right;
591 out_stream <<
"+---------------------------------+-----------+------------" 593 for (std::map<std::string, Section>::const_iterator
596 std::string name_out = i->first;
600 unsigned int pos_non_space = name_out.find_first_not_of (
" ");
601 name_out.erase(0, pos_non_space);
602 name_out.resize (32,
' ');
610 out_stream << i->second.total_wall_time <<
"s |";
613 if (total_wall_time != 0)
618 const double fraction = i->second.total_wall_time/total_wall_time;
619 if (fraction > 0.001)
633 <<
"+---------------------------------+-----------+" 634 <<
"------------+------------+\n" 670 DEAL_II_NAMESPACE_CLOSE
void print_summary() const
static const unsigned int invalid_unsigned_int
double get_lap_time() const
MPI_Comm mpi_communicator
MPI_Comm mpi_communicator
Utilities::MPI::MinMaxAvg mpi_data
static ::ExceptionBase & ExcMessage(std::string arg1)
T sum(const T &t, const MPI_Comm &mpi_communicator)
#define Assert(cond, exc)
double operator()() const
double start_time_children
TimerOutput(std::ostream &stream, const enum OutputFrequency output_frequency, const enum OutputType output_type)
std::list< std::string > active_sections
#define AssertThrowMPI(error_code)
std::map< std::string, Section > sections
ConditionalOStream out_stream
double cumulative_wall_time
std::ostream & get_stream() const
void enter_subsection(const std::string §ion_name)
MinMaxAvg min_max_avg(const double my_value, const MPI_Comm &mpi_communicator)
OutputFrequency output_frequency
T max(const T &t, const MPI_Comm &mpi_communicator)
void leave_subsection(const std::string §ion_name=std::string())