Timers

From ScorecWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 14:58, 7 August 2011
Cwsmith (Talk | contribs)

← Previous diff
Current revision
Cwsmith (Talk | contribs)

Line 1: Line 1:
This page serves as a gateway for information related to computing the elapsed time between two positions in your software. This page serves as a gateway for information related to computing the elapsed time between two positions in your software.
-==C/C++==+==cycle counting (rdtsc cycle counter)==
- +* [http://www.mcs.anl.gov/~kazutomo/rdtsc.html source code]
-1- cycle counting (rdtsc cycle counter) - [http://www.mcs.anl.gov/~kazutomo/rdtsc.html source code]+* precise
-* precise (CS)+
* cpu frequency required * cpu frequency required
-** get the cpu frequency with <code>+** get the cpu frequency in MHz with <code>
cat /proc/cpuinfo | grep -i "cpu MHZ" -m 1 | awk '{print $4}'</code> cat /proc/cpuinfo | grep -i "cpu MHZ" -m 1 | awk '{print $4}'</code>
-** sample code <code> +example code <code>
#define CPUFREQ <INSERT FREQUENCY IN Hz HERE> #define CPUFREQ <INSERT FREQUENCY IN Hz HERE>
unsigned long long start_time = 0; unsigned long long start_time = 0;
Line 18: Line 17:
total_time = finish_time - start_time; total_time = finish_time - start_time;
printf ("It took %.8lf seconds.\n", total_time / CPUFREQ );</code> printf ("It took %.8lf seconds.\n", total_time / CPUFREQ );</code>
-* low cost and resolution (OS)+* low cost and high resolution
- +
-2- MPI_WTime()+
-* May offer a high resolution than 1 second.(CS)+
- +
-3- MPI_WTick()+
-* can be queried to determine resolution. (CS)+
-4- getTimeOfDay() and friends (sys/time.h)+==MPI_WTime()==
-* portable (BM)+* May offer a high resolution than 1 second.
-* not always precise or accurate (BM)+** MPI_WTick() - query to determine resolution.
-* may be relatively expensive on IBM BG (compared to cycle counting) (OS)+
-5- time.h/ctime.h functions (Reference : http://www.cppreference.com/wiki/c/date/start )+==getTimeOfDay() and friends (sys/time.h)==
-* Have a higher resolution than 1 second (CS)+* portable
-* clock function returns elapsed CPU cycles (CS)+* not always precise or accurate
-* Needs cpu frequency which may be inaccurate on POSIX compilers (CS)+* may be relatively expensive on IBM BG (compared to cycle counting)
-Note: Feel free to make corrections -- MM+==time.h/ctime.h functions ==
 +* [http://www.cppreference.com/wiki/c/date/start Reference]
 +* Have a higher resolution than 1 second
 +* clock function returns elapsed CPU cycles
 +* Needs cpu frequency which may be inaccurate on POSIX compilers
[[Category:Tutorials]] [[Category:Tutorials]]
[[Category:Software]] [[Category:Software]]

Current revision

This page serves as a gateway for information related to computing the elapsed time between two positions in your software.

Contents

cycle counting (rdtsc cycle counter)

  • source code
  • precise
  • cpu frequency required
    • get the cpu frequency in MHz with
   cat /proc/cpuinfo | grep -i "cpu MHZ" -m 1 | awk '{print $4}'

example code

   #define CPUFREQ <INSERT FREQUENCY IN Hz HERE> 
   unsigned long long start_time = 0;
   unsigned long long finish_time = 0;
   unsigned long long total_time = 0;
   start_time = rdtsc();
   //do stuff
   finish_time = rdtsc();
   total_time = finish_time - start_time;  
   printf ("It took %.8lf seconds.\n", total_time / CPUFREQ );
  • low cost and high resolution

MPI_WTime()

  • May offer a high resolution than 1 second.
    • MPI_WTick() - query to determine resolution.

getTimeOfDay() and friends (sys/time.h)

  • portable
  • not always precise or accurate
  • may be relatively expensive on IBM BG (compared to cycle counting)

time.h/ctime.h functions

  • Reference
  • Have a higher resolution than 1 second
  • clock function returns elapsed CPU cycles
  • Needs cpu frequency which may be inaccurate on POSIX compilers
Personal tools