00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "Teuchos_Time.hpp"
00033
00034 #ifdef HAVE_MPI
00035 #include "mpi.h"
00036 #elif ICL
00037 #include <time.h>
00038 #else
00039 #include <sys/time.h>
00040 #ifndef MINGW
00041 #include <sys/resource.h>
00042 #endif
00043 #endif
00044
00045 using namespace Teuchos;
00046
00047
00048 Time::Time(const string& name, bool start)
00049 : startTime_(0), totalTime_(0), isRunning_(false), name_(name)
00050 {
00051 if(start) this->start();
00052 }
00053
00054 void Time::start(bool reset)
00055 {
00056 isRunning_ = true;
00057 startTime_ = wallTime();
00058 if(reset) totalTime_ = 0;
00059 }
00060
00061 double Time::stop()
00062 {
00063 totalTime_ += ( wallTime() - startTime_ );
00064 isRunning_ = false;
00065 startTime_ = 0;
00066 return totalTime_;
00067 }
00068
00069
00070
00071
00072 double Time::wallTime()
00073 {
00074
00075
00076 #ifdef HAVE_MPI
00077
00078 return(MPI_Wtime());
00079
00080 #elif ICL
00081
00082 clock_t start;
00083
00084 start = clock();
00085 return( (double)( start ) / CLOCKS_PER_SEC );
00086
00087 #else
00088
00089 # ifndef MINGW
00090 struct timeval tp;
00091 static long start = 0, startu;
00092 if (!start)
00093 {
00094 gettimeofday(&tp, NULL);
00095 start = tp.tv_sec;
00096 startu = tp.tv_usec;
00097 return(0.0);
00098 }
00099 gettimeofday(&tp, NULL);
00100 return( ((double) (tp.tv_sec - start)) + (tp.tv_usec-startu)/1000000.0 );
00101 # else
00102 return( (double) clock() / CLOCKS_PER_SEC );
00103 # endif
00104
00105 #endif
00106
00107 }