From: Wolfgang Bangerth Date: Tue, 30 Oct 2007 20:23:45 +0000 (+0000) Subject: Use the Timer class rather than handwritten calls to clock(). X-Git-Tag: v8.0.0~9697 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9c7c8e4c01cb3e26dcc9e4cf9e4c7f3a4f7f235;p=dealii.git Use the Timer class rather than handwritten calls to clock(). git-svn-id: https://svn.dealii.org/trunk@15399 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/examples/step-29/step-29.cc b/deal.II/examples/step-29/step-29.cc index a9a2bad2f1..c2d99cd5ef 100644 --- a/deal.II/examples/step-29/step-29.cc +++ b/deal.II/examples/step-29/step-29.cc @@ -62,10 +62,11 @@ // are provided in this header file: #include - // The last header is from the C++ standard library and provides - // functions that will allow us to measure execution time - // of various parts of our program: -#include + // Finally, include the header file that declares the + // Timer class that we will use to determine how + // much time each of the operations of our program + // takes: +#include // Although we'll follow good deal.ii practice and keep // all of the code dimension independent, we will @@ -74,13 +75,6 @@ using namespace dealii; - // The next line provides a shorthand to the CLOCKS_PER_SEC - // constant, which is defined in the ctime header - // and contains the number of processor ticks in each second. - // Henceforth we can compute actual time from ticks by simply dividing - // by tps. -const double tps = CLOCKS_PER_SEC; - // @sect3{The DirichletBoundaryValues class} @@ -455,10 +449,11 @@ template void UltrasoundProblem::make_grid () { // First we generate some logging output - // and store the current number of ticks to be able to + // and start a timer so we can // compute execution time when this function is done: deallog << "Generating grid... "; - clock_t start = clock(); + Timer timer; + timer.start (); // Then we query the values for the focal distance of the // transducer lens and the number of mesh refinement steps @@ -530,18 +525,12 @@ void UltrasoundProblem::make_grid () // and we don't want the triangulation to keep a hanging pointer. triangulation.set_boundary(1); - // Lastly, we generate some more logging output. By querying - // the present number of ticks again and comparing to - // what we had at the beginning of the function, we can - // calculate execution time by dividing by tps. - // Note that the resolution of the clock() function - // is implementation depended, and also the clock_t values - // it returns may overflow, so this way of measuring execution - // time should be taken with a grain of salt as it may not - // be very accurate and even completely wrong for longer timespans: - clock_t end = clock(); + // Lastly, we generate some more logging output. We stop + // the timer and query the number of CPU seconds + // elapsed since the beginning of the function: + timer.stop (); deallog << "done (" - << (end - start) / tps + << timer() << "s)" << std::endl; @@ -552,14 +541,18 @@ void UltrasoundProblem::make_grid () // @sect4{UltrasoundProblem::setup_system} + // // Initialization of the system matrix, sparsity patterns // and vectors are the same as in previous examples - // and therefore do not need further comment: + // and therefore do not need further comment. As in the + // previous function, we also output the run time of + // what we do here: template void UltrasoundProblem::setup_system () { deallog << "Setting up system... "; - clock_t start = clock(); + Timer timer; + timer.start(); dof_handler.distribute_dofs (fe); @@ -574,9 +567,9 @@ void UltrasoundProblem::setup_system () system_rhs.reinit (dof_handler.n_dofs()); solution.reinit (dof_handler.n_dofs()); - clock_t end = clock(); + timer.stop (); deallog << "done (" - << (end - start) / tps + << timer() << "s)" << std::endl; @@ -593,7 +586,8 @@ template void UltrasoundProblem::assemble_system () { deallog << "Assembling system matrix... "; - clock_t start = clock(); + Timer timer; + timer.start (); // First we query wavespeed and frequency from the // ParameterHandler object and store them in local variables, @@ -797,9 +791,9 @@ void UltrasoundProblem::assemble_system () solution, system_rhs); - clock_t end = clock(); + timer.stop (); deallog << "done (" - << (end - start) / tps + << timer() << "s)" << std::endl; } @@ -812,7 +806,8 @@ template void UltrasoundProblem::solve () { deallog << "Solving linear system... "; - clock_t start = clock(); + Timer timer; + timer.start (); // As already mentioned in the introduction, the system matrix // is neither symmetric nor definite, and so it is not @@ -843,9 +838,9 @@ void UltrasoundProblem::solve () // to multiply with the right hand side vector: A_direct.vmult(solution,system_rhs); - clock_t end = clock(); + timer.stop (); deallog << "done (" - << (end - start) / tps + << timer () << "s)" << std::endl; } @@ -865,7 +860,8 @@ template void UltrasoundProblem::output_results () const { deallog << "Generating output... "; - clock_t start = clock(); + Timer timer; + timer.start (); // Define objects of our ComputeIntensity class and a DataOut // object: @@ -921,10 +917,10 @@ void UltrasoundProblem::output_results () const data_out.build_patches (); data_out.write (output, format); - clock_t end = clock(); + timer.stop (); deallog << "done (" - << (end - start) / tps - << "s)" + << timer() + << "s)" << std::endl; }