Epetra_Time.cpp

Go to the documentation of this file.
00001 
00002 //@HEADER
00003 // ************************************************************************
00004 // 
00005 //               Epetra: Linear Algebra Services Package 
00006 //                 Copyright (2001) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //  
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00026 // 
00027 // ************************************************************************
00028 //@HEADER
00029 
00030 #include "Epetra_Time.h"
00031 
00032 #ifdef EPETRA_MPI
00033 #include <time.h>
00034 #endif
00035 
00036 //=============================================================================
00037 Epetra_Time::Epetra_Time(const Epetra_Comm& Comm) 
00038   : StartTime_(0.0),
00039     Comm_(&Comm)
00040 {
00041   StartTime_ = WallTime();
00042 }
00043 //=============================================================================
00044 Epetra_Time::Epetra_Time(const Epetra_Time& Time) 
00045   : StartTime_(Time.StartTime_),
00046     Comm_(Time.Comm_)
00047 {
00048 }
00049 //=============================================================================
00050 Epetra_Time::~Epetra_Time(void)  
00051 {
00052 }
00053 //=============================================================================
00054 double Epetra_Time::WallTime(void) const
00055 {
00056 #ifdef EPETRA_MPI
00057 
00058   int mpiInitialized;
00059   MPI_Initialized(&mpiInitialized);
00060 
00061   if( mpiInitialized ) {
00062 
00063     return(MPI_Wtime());
00064 
00065   }
00066   else {
00067 
00068     clock_t start;
00069 
00070     start = clock();
00071     return( (double)( start ) / CLOCKS_PER_SEC );
00072 
00073   }
00074 
00075 #else
00076 
00077 #if ICL || defined(_WIN32)
00078 
00079    clock_t start;
00080    //double duration;
00081 
00082    start = clock();
00083   return (double)( start ) / CLOCKS_PER_SEC;
00084 
00085 #else
00086 
00087 #ifndef MINGW
00088    struct timeval tp;
00089    static long start=0, startu;
00090    if (!start)
00091    {
00092       gettimeofday(&tp, NULL);
00093       start = tp.tv_sec;
00094       startu = tp.tv_usec;
00095       return(0.0);
00096    }
00097    gettimeofday(&tp, NULL);
00098    return( ((double) (tp.tv_sec - start)) + (tp.tv_usec-startu)/1000000.0 );
00099 #else
00100    return( (double) clock() / CLOCKS_PER_SEC );
00101 #endif
00102 
00103 #endif
00104 #endif
00105 
00106 }
00107 //=============================================================================
00108 void Epetra_Time::ResetStartTime(void)
00109 {
00110   StartTime_ = WallTime();
00111   return;
00112 }
00113 //=============================================================================
00114 double Epetra_Time::ElapsedTime(void) const
00115 {
00116   return(WallTime()-StartTime_);
00117 }

Generated on Wed May 12 21:41:05 2010 for Epetra Package Browser (Single Doxygen Collection) by  doxygen 1.4.7