Skip to content

A computational tool to benchmark large-scale simulations.

Notifications You must be signed in to change notification settings

jlokimlin/cpu_timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cpu_timer - A modern Fortran (2008+) library for timing program execution

An object-oriented library for computing elapsed CPU time. More specifically, you can determine the CPU time consumed by a particular piece of your code, that is:

	!... start timer	
	do i = 1, n
		
		!...some big calculation...
	
	end do
	
	!...stop timer
	print *, 'Elapsed CPU time = ', blah

Contributing

This project is still a work in progress and anyone is free to contribute under the proviso that they abstain from using the dreaded go to.

For bug reports or feature requests please open an issue on github.


Requirements


To build the project

Type the following command line arguments

git clone https://github.com/jlokimlin/cpu_timer.git

cd cpu_timer; make all

Usage:

use, intrinsic :: ISO_C_binding, only: &
    wp => C_DOUBLE, &
    ip => C_INT
    
use cpu_timer_library, only: &
    CpuTimer

! Explicit typing only
implicit none

type (CpuTimer) :: timer
real (wp)       :: wall_clock_time
real (wp)	    :: total_processor_time
integer (ip)    :: units = 0 ! (optional argument) = 0 for seconds, or 1 for minutes, or 2 for hours

! Starting the timer
call timer%start()

! Stopping the timer
call timer%stop()

! Reading the time
wall_clock_time = timer%get_elapsed_time(units)

total_processor_time = timer%get_total_cpu_time(units)

! Write time stamp to standard output
call timer%print_time_stamp()

! Write compiler info to standard output
call timer%print_compiler_info()

Result

		  
	
	  Demonstrate the usage of type (CpuTimer).
	
	August 20 2016   6:07:14.320 PM
	
	*********************************************
	
	 time_random_number_routine
	
	 times the intrinsic random_number routine:
	
	    call random_number( x(1:n) )
	
	  Data vectors will be of minimum size              1
	  Data vectors will be of maximum size        1048576
	  Number of repetitions of the operation:           5
	
	  Timing results:
	
	       Size    Rep #1         Rep #2         Rep #3         Rep #4         Rep #5         MINVAL         SUM            MAXVAL         
	
	          1    1.76191E-02    1.60609E-02    1.44475E-02    1.45581E-02    1.44137E-02    1.44137E-02    1.54199E-02    1.76191E-02
	          2    1.44452E-02    1.44981E-02    2.08713E-02    2.02675E-02    1.47711E-02    1.44452E-02    1.69706E-02    2.08713E-02
	          4    1.47064E-02    1.46856E-02    1.61794E-02    1.57239E-02    1.47874E-02    1.46856E-02    1.52165E-02    1.61794E-02
	          8    1.47851E-02    1.47053E-02    1.50504E-02    1.52278E-02    1.53919E-02    1.47053E-02    1.50321E-02    1.53919E-02
	         16    1.77258E-02    1.70115E-02    1.48718E-02    1.52452E-02    1.51357E-02    1.48718E-02    1.59980E-02    1.77258E-02
	         32    1.47998E-02    1.48585E-02    1.46464E-02    1.46236E-02    1.43961E-02    1.43961E-02    1.46649E-02    1.48585E-02
	         64    1.44532E-02    1.43647E-02    1.43166E-02    1.45666E-02    1.51698E-02    1.43166E-02    1.45742E-02    1.51698E-02
	        128    1.46443E-02    1.92390E-02    1.45861E-02    1.46580E-02    1.44909E-02    1.44909E-02    1.55236E-02    1.92390E-02
	        256    1.49488E-02    1.54366E-02    1.46981E-02    1.46584E-02    1.54032E-02    1.46584E-02    1.50290E-02    1.54366E-02
	        512    1.50235E-02    1.53618E-02    1.51830E-02    1.50881E-02    1.44276E-02    1.44276E-02    1.50168E-02    1.53618E-02
	       1024    1.43234E-02    1.43455E-02    1.44745E-02    1.43079E-02    1.43134E-02    1.43079E-02    1.43529E-02    1.44745E-02
	       2048    1.43336E-02    1.46181E-02    1.43538E-02    1.43268E-02    1.42984E-02    1.42984E-02    1.43861E-02    1.46181E-02
	       4096    1.42910E-02    1.49904E-02    1.54230E-02    1.50998E-02    1.63991E-02    1.42910E-02    1.52407E-02    1.63991E-02
	       8192    2.22919E-02    1.61469E-02    1.52908E-02    1.52855E-02    1.48256E-02    1.48256E-02    1.67681E-02    2.22919E-02
	      16384    1.44122E-02    1.47464E-02    1.44421E-02    1.42999E-02    1.42838E-02    1.42838E-02    1.44369E-02    1.47464E-02
	      32768    1.42835E-02    1.42998E-02    1.42837E-02    1.43208E-02    1.43324E-02    1.42835E-02    1.43040E-02    1.43324E-02
	      65536    1.42861E-02    1.42856E-02    1.43340E-02    1.42667E-02    1.42299E-02    1.42299E-02    1.42804E-02    1.43340E-02
	     131072    1.42717E-02    1.42638E-02    1.42335E-02    1.42323E-02    1.42705E-02    1.42323E-02    1.42543E-02    1.42717E-02
	     262144    1.42374E-02    1.45162E-02    1.43331E-02    1.42933E-02    1.42409E-02    1.42374E-02    1.43242E-02    1.45162E-02
	     524288    1.45305E-02    1.46229E-02    1.46774E-02    1.43601E-02    1.42351E-02    1.42351E-02    1.44852E-02    1.46774E-02
	    1048576    1.42561E-02    1.42542E-02    1.42915E-02    1.42444E-02    1.42370E-02    1.42370E-02    1.42567E-02    1.42915E-02
	
	*********************************************
	
	  time_vectorized_exp_routine:
	
	    y(1:n) = x(1:n)  
	    y(1:n) = PI * x(1:n)  
	    y(1:n) = sqrt( x(1:n) )
	    y(1:n) = exp( x(1:n) )
	
	  Data vectors will be of minimum size           4096
	  Data vectors will be of maximum size        4194304
	  Number of repetitions of the operation:           5
	
	  Timing results:
	
	       Size    Rep #1         Rep #2         Rep #3         Rep #4         Rep #5         
	
	       4096    3.66000E-07    2.82000E-07    2.99000E-07    2.78000E-07    2.79000E-07
	       8192    2.84000E-07    2.71000E-07    2.75000E-07    2.72000E-07    2.91000E-07
	      16384    3.82000E-07    3.00000E-07    2.77000E-07    2.90000E-07    6.16000E-07
	      32768    3.47000E-07    3.01000E-07    4.47000E-07    2.86000E-07    4.66000E-07
	      65536    3.08000E-07    2.92000E-07    3.54000E-07    2.88000E-07    2.75000E-07
	     131072    2.76000E-07    2.75000E-07    2.87000E-07    2.79000E-07    4.21000E-07
	     262144    3.45000E-07    2.87000E-07    2.94000E-07    2.81000E-07    2.74000E-07
	     524288    3.54000E-07    2.96000E-07    2.95000E-07    3.76000E-07    2.74000E-07
	    1048576    3.05000E-07    2.79000E-07    2.95000E-07    2.76000E-07    2.95000E-07
	    2097152    2.73000E-07    3.26000E-07    2.74000E-07    2.78000E-07    2.87000E-07
	    4194304    2.95000E-07    3.14000E-07    2.71000E-07    2.82000E-07    3.96000E-07
	
	  Timing results:
	
	       Size    Rep #1         Rep #2         Rep #3         Rep #4         Rep #5         
	
	       4096    3.79000E-07    2.74000E-07    2.82000E-07    3.07000E-07    2.75000E-07
	       8192    2.78000E-07    2.74000E-07    2.89000E-07    3.10000E-07    2.98000E-07
	      16384    3.89000E-07    2.84000E-07    2.87000E-07    2.95000E-07    2.83000E-07
	      32768    7.84000E-07    3.03000E-07    2.98000E-07    2.76000E-07    2.88000E-07
	      65536    4.64000E-07    3.09000E-07    2.87000E-07    3.03000E-07    2.74000E-07
	     131072    3.52000E-07    3.03000E-07    3.03000E-07    2.87000E-07    3.09000E-07
	     262144    2.96000E-07    2.96000E-07    3.06000E-07    2.82000E-07    2.95000E-07
	     524288    2.77000E-07    2.91000E-07    2.82000E-07    3.00000E-07    3.03000E-07
	    1048576    3.07000E-07    2.95000E-07    3.01000E-07    3.08000E-07    2.86000E-07
	    2097152    2.89000E-07    3.17000E-07    2.83000E-07    2.82000E-07    3.03000E-07
	    4194304    2.79000E-07    3.08000E-07    3.44000E-07    2.92000E-07    2.87000E-07
	
	  Timing results:
	
	       Size    Rep #1         Rep #2         Rep #3         Rep #4         Rep #5         
	
	       4096    3.64000E-07    3.06000E-07    2.76000E-07    2.76000E-07    3.17000E-07
	       8192    3.13000E-07    3.36000E-07    3.48000E-07    3.11000E-07    2.96000E-07
	      16384    2.81000E-07    5.65000E-07    3.01000E-07    2.82000E-07    3.01000E-07
	      32768    2.76000E-07    2.81000E-07    2.74000E-07    3.07000E-07    2.76000E-07
	      65536    2.75000E-07    3.39000E-07    2.85000E-07    3.01000E-07    3.12000E-07
	     131072    2.71000E-07    2.87000E-07    2.79000E-07    2.80000E-07    2.96000E-07
	     262144    2.86000E-07    3.60000E-07    2.95000E-07    2.99000E-07    2.75000E-07
	     524288    2.76000E-07    4.03000E-07    2.89000E-07    2.74000E-07    2.88000E-07
	    1048576    2.86000E-07    2.76000E-07    2.80000E-07    2.79000E-07    2.74000E-07
	    2097152    2.85000E-07    2.79000E-07    3.02000E-07    2.99000E-07    2.78000E-07
	    4194304    3.00000E-07    3.02000E-07    2.77000E-07    2.73000E-07    2.95000E-07
	
	  Timing results:
	
	       Size    Rep #1         Rep #2         Rep #3         Rep #4         Rep #5         
	
	       4096    3.52000E-07    2.74000E-07    2.71000E-07    2.81000E-07    3.20000E-07
	       8192    2.98000E-07    3.73000E-07    2.75000E-07    3.08000E-07    2.90000E-07
	      16384    2.80000E-07    2.96000E-07    3.00000E-07    2.76000E-07    1.81300E-06
	      32768    2.75000E-07    2.74000E-07    3.02000E-07    2.78000E-07    2.77000E-07
	      65536    2.99000E-07    2.74000E-07    2.96000E-07    3.02000E-07    2.80000E-07
	     131072    2.73000E-07    2.97000E-07    2.90000E-07    2.98000E-07    3.02000E-07
	     262144    2.91000E-07    2.77000E-07    2.85000E-07    2.83000E-07    2.78000E-07
	     524288    2.74000E-07    2.74000E-07    3.17000E-07    2.97000E-07    2.97000E-07
	    1048576    2.97000E-07    3.08000E-07    2.95000E-07    2.82000E-07    3.01000E-07
	    2097152    2.73000E-07    2.74000E-07    3.79000E-07    2.74000E-07    2.86000E-07
	    4194304    2.84000E-07    2.78000E-07    3.08000E-07    2.98000E-07    2.80000E-07
	
	*********************************************
	
	 time_unvectorized_exp_routine
	
	    do i = 1, n
	      y(i) = x(i)  
	      y(i) = PI * x(i)  
	      y(i) = sqrt(x(i))
	      y(i) = exp(x(i))
	    end do
	
	  Data vectors will be of minimum size           4096
	  Data vectors will be of maximum size        4194304
	  Number of repetitions of the operation:           5
	
	*********************************************
	
	  Timing results:
	
	       Size    Rep #1         Rep #2         Rep #3         Rep #4         Rep #5         
	
	       4096    2.83500E-06    1.71700E-06    1.71900E-06    1.71900E-06    1.72000E-06
	       8192    3.13300E-06    3.13200E-06    3.13100E-06    3.12800E-06    3.14000E-06
	      16384    5.96200E-06    5.96100E-06    5.98700E-06    5.96000E-06    5.96000E-06
	      32768    1.16440E-05    1.16390E-05    1.16320E-05    1.16300E-05    1.16380E-05
	      65536    2.29470E-05    2.29490E-05    2.29530E-05    2.29490E-05    2.29680E-05
	     131072    4.56090E-05    4.56150E-05    4.56620E-05    4.56670E-05    4.56700E-05
	     262144    1.02447E-04    9.09140E-05    9.09750E-05    9.09640E-05    9.58640E-05
	     524288    1.81567E-04    1.81517E-04    1.81586E-04    1.81575E-04    1.81579E-04
	    1048576    3.62764E-04    3.62957E-04    3.62778E-04    3.86554E-04    3.67647E-04
	    2097152    7.29749E-04    7.30339E-04    7.25192E-04    7.30078E-04    7.25190E-04
	    4194304    1.44997E-03    1.45979E-03    1.63218E-03    1.45459E-03    1.44997E-03
	
	*********************************************
	
	  Timing results:
	
	       Size    Rep #1         Rep #2         Rep #3         Rep #4         Rep #5         
	
	       4096    1.84400E-06    1.72400E-06    1.72400E-06    1.72300E-06    1.72200E-06
	       8192    3.13900E-06    3.13700E-06    3.14500E-06    3.14400E-06    3.14000E-06
	      16384    5.96600E-06    5.95800E-06    5.96800E-06    5.97300E-06    5.97800E-06
	      32768    1.16310E-05    1.16320E-05    1.16360E-05    1.16330E-05    1.16470E-05
	      65536    2.29570E-05    2.29670E-05    2.29410E-05    2.29650E-05    2.29720E-05
	     131072    4.56760E-05    4.56730E-05    4.96240E-05    4.56790E-05    4.56210E-05
	     262144    9.09620E-05    1.81755E-04    9.24530E-05    1.81777E-04    9.09840E-05
	     524288    1.81562E-04    3.07141E-04    1.81572E-04    1.81583E-04    1.81706E-04
	    1048576    3.62825E-04    3.62710E-04    3.62762E-04    3.62770E-04    3.62780E-04
	    2097152    7.25155E-04    7.27263E-04    7.25156E-04    7.28876E-04    7.30041E-04
	    4194304    1.47559E-03    1.47717E-03    1.44997E-03    1.47738E-03    1.45533E-03
	
	*********************************************
	
	  Timing results:
	
	       Size    Rep #1         Rep #2         Rep #3         Rep #4         Rep #5         
	
	       4096    1.79200E-06    2.48900E-06    1.72600E-06    1.72500E-06    1.72700E-06
	       8192    3.14200E-06    4.63400E-06    3.13100E-06    3.13100E-06    3.13200E-06
	      16384    5.99100E-06    6.62700E-06    5.97400E-06    5.96200E-06    5.96000E-06
	      32768    1.16510E-05    1.27240E-05    1.24910E-05    1.16270E-05    1.16260E-05
	      65536    2.66640E-05    2.29740E-05    3.28560E-05    2.29480E-05    2.29590E-05
	     131072    4.56070E-05    4.56700E-05    5.29360E-05    4.56720E-05    4.56780E-05
	     262144    9.09920E-05    9.09900E-05    1.01756E-04    9.09160E-05    9.09680E-05
	     524288    1.81559E-04    1.81654E-04    1.81563E-04    2.02443E-04    1.85238E-04
	    1048576    3.62845E-04    3.73505E-04    3.62770E-04    3.62795E-04    3.67811E-04
	    2097152    7.31032E-04    7.66585E-04    7.33419E-04    7.30162E-04    7.27893E-04
	    4194304    1.60041E-03    1.52588E-03    1.45480E-03    1.45483E-03    1.47871E-03
	
	*********************************************
	
	  Timing results:
	
	       Size    Rep #1         Rep #2         Rep #3         Rep #4         Rep #5         
	
	       4096    1.89400E-06    1.71700E-06    1.72400E-06    1.71500E-06    1.71900E-06
	       8192    3.14600E-06    3.13300E-06    3.69200E-06    3.13800E-06    3.13200E-06
	      16384    5.97000E-06    5.96400E-06    1.17780E-05    5.96000E-06    5.96200E-06
	      32768    1.16490E-05    1.16310E-05    1.16450E-05    1.16180E-05    1.16320E-05
	      65536    2.29860E-05    2.29550E-05    2.29580E-05    2.29430E-05    2.29530E-05
	     131072    4.56220E-05    4.56830E-05    4.56090E-05    4.56820E-05    4.56790E-05
	     262144    9.09790E-05    9.09070E-05    9.09830E-05    9.97750E-05    9.09740E-05
	     524288    1.81771E-04    1.81572E-04    2.12770E-04    1.81569E-04    1.81575E-04
	    1048576    3.62770E-04    3.68055E-04    3.74247E-04    3.62812E-04    3.62769E-04
	    2097152    7.25126E-04    7.30202E-04    7.25179E-04    7.25123E-04    7.69377E-04
	    4194304    2.32765E-03    1.45476E-03    1.44998E-03    1.46017E-03    1.44994E-03
	
	*********************************************
	
	  time_2d_nearest_neighbor_problem
	
	  Given x(2,n) and y(2),
	
	    find x(2,*) closest to y(2).
	
	    do i = 1, n
	      if distance( x(2,i), y ) < minimum so far
	        x_min = x(2,i)
	    end do
	
	  Data vectors will be of minimum size           1024
	  Data vectors will be of maximum size        1048576
	  Number of repetitions of the operation:           5
	
	  Timing results:
	
	       Size    Rep #1         Rep #2         Rep #3         Rep #4         Rep #5         
	
	       1024    8.29000E-07    6.45000E-07    6.47000E-07    6.44000E-07    6.43000E-07
	       2048    1.00000E-06    9.95000E-07    9.96000E-07    9.95000E-07    9.98000E-07
	       4096    1.70500E-06    1.70700E-06    1.70300E-06    1.70300E-06    1.70300E-06
	       8192    3.13500E-06    3.11500E-06    3.12000E-06    3.12200E-06    3.12000E-06
	      16384    5.94700E-06    5.95200E-06    5.94700E-06    5.94900E-06    5.95600E-06
	      32768    1.16150E-05    1.16140E-05    1.16160E-05    1.16130E-05    1.16150E-05
	      65536    2.78350E-05    2.29340E-05    2.29360E-05    2.29370E-05    2.29400E-05
	     131072    4.55930E-05    4.55870E-05    4.55880E-05    4.55870E-05    4.55910E-05
	     262144    9.08930E-05    9.08860E-05    1.11564E-04    9.08870E-05    9.08860E-05
	     524288    1.81487E-04    1.81489E-04    2.05870E-04    1.81486E-04    1.81489E-04
	    1048576    3.62689E-04    3.99389E-04    3.62688E-04    3.62684E-04    3.62705E-04
	
	*********************************************
	
	  time_matrix_multiplication_problem
	
	  Compute C = A * B
	
	  where
	    A is an L by M matrix,
	    B is an M by N matrix,
	  and so
	    C is an L by N matrix.
	
	  Minimum value of L = M = N =                      4
	  Maximum value of L = M = N =                   1024
	  Number of repetitions of the operation:           5
	
	  Use nested do loops for matrix multiplication.
	
	  Timing results using nested do loops:
	
	       Size    Rep #1         Rep #2         Rep #3         Rep #4         Rep #5         
	
	          4    7.11000E-07    5.88000E-07    5.74000E-07    7.17000E-07    5.32000E-07
	         16    7.92100E-06    8.18500E-06    8.17900E-06    8.81500E-06    7.96500E-06
	         64    4.68022E-04    4.73999E-04    4.84999E-04    5.03218E-04    4.63941E-04
	        256    4.90532E-02    4.63972E-02    5.22809E-02    6.63487E-02    4.62401E-02
	       1024    9.25886E+00    9.29856E+00    8.90819E+00    9.25549E+00    8.51152E+00
	
	  Use the matmul routine for matrix multiplication.
	
	  Timing results using matmul:
	
	       Size    Rep #1         Rep #2         Rep #3         Rep #4         Rep #5         
	
	          4    1.28800E-06    8.50000E-07    9.12000E-07    1.02600E-06    8.21000E-07
	         16    2.24210E-05    1.16830E-05    1.28290E-05    1.16680E-05    1.15010E-05
	         64    6.94844E-04    6.79922E-04    7.13658E-04    6.86136E-04    6.85324E-04
	        256    4.19184E-02    4.03149E-02    4.28599E-02    4.05020E-02    4.05167E-02
	       1024    2.65927E+00    2.71235E+00    2.71320E+00    2.85616E+00    2.67387E+00
	
	 type (CpuTimer) tests.
	
	 Normal end of execution.
	
	August 20 2016   6:08:30.878 PM
	
	 This file was compiled by GCC version 6.1.1 20160802 using the options -I ../objs -I ../lib -mtune=generic -march=x86-64 -auxbase-strip ../objs/type_CpuTimer.o -Wall -fimplicit-none -fcheck=all -J ../lib

		

About

A computational tool to benchmark large-scale simulations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published