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 #elif ICL
00076 
00077    clock_t start;
00078    //double duration;
00079 
00080    start = clock();
00081   return (double)( start ) / CLOCKS_PER_SEC;
00082 
00083 #else
00084 
00085 #ifndef MINGW
00086    struct timeval tp;
00087    static long start=0, startu;
00088    if (!start)
00089    {
00090       gettimeofday(&tp, NULL);
00091       start = tp.tv_sec;
00092       startu = tp.tv_usec;
00093       return(0.0);
00094    }
00095    gettimeofday(&tp, NULL);
00096    return( ((double) (tp.tv_sec - start)) + (tp.tv_usec-startu)/1000000.0 );
00097 #else
00098    return( (double) clock() / CLOCKS_PER_SEC );
00099 #endif
00100 
00101 #endif
00102 
00103 }
00104 //=============================================================================
00105 void Epetra_Time::ResetStartTime(void)
00106 {
00107   StartTime_ = WallTime();
00108   return;
00109 }
00110 //=============================================================================
00111 double Epetra_Time::ElapsedTime(void) const
00112 {
00113   return(WallTime()-StartTime_);
00114 }

Generated on Thu Sep 18 12:37:58 2008 for Epetra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1