Epetra Package Browser (Single Doxygen Collection) Development
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 the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00039 // 
00040 // ************************************************************************
00041 //@HEADER
00042 
00043 #include "Epetra_Time.h"
00044 
00045 #ifdef EPETRA_MPI
00046 #include <time.h>
00047 #endif
00048 #ifdef Epetra_HAVE_OMP
00049 #include <omp.h>
00050 #endif
00051 
00052 //=============================================================================
00053 Epetra_Time::Epetra_Time(const Epetra_Comm& Comm) 
00054   : StartTime_(0.0),
00055     Comm_(&Comm)
00056 {
00057   StartTime_ = WallTime();
00058 }
00059 //=============================================================================
00060 Epetra_Time::Epetra_Time(const Epetra_Time& Time) 
00061   : StartTime_(Time.StartTime_),
00062     Comm_(Time.Comm_)
00063 {
00064 }
00065 //=============================================================================
00066 Epetra_Time::~Epetra_Time(void)  
00067 {
00068 }
00069 //=============================================================================
00070 double Epetra_Time::WallTime(void) const
00071 {
00072 #ifdef EPETRA_MPI
00073 
00074   int mpiInitialized;
00075   MPI_Initialized(&mpiInitialized);
00076 
00077   if( mpiInitialized ) {
00078 
00079     return(MPI_Wtime());
00080 
00081   }
00082   else {
00083 
00084     clock_t start;
00085 
00086     start = clock();
00087     return( (double)( start ) / CLOCKS_PER_SEC );
00088 
00089   }
00090 
00091 #else
00092 
00093 #ifdef Epetra_HAVE_OMP
00094        return(omp_get_wtime());
00095 #else
00096 #if ICL || defined(_WIN32)
00097 
00098    clock_t start;
00099    //double duration;
00100 
00101    start = clock();
00102   return (double)( start ) / CLOCKS_PER_SEC;
00103 
00104 #else
00105 
00106 #ifndef MINGW
00107    struct timeval tp;
00108    static long start=0, startu;
00109    if (!start)
00110    {
00111       gettimeofday(&tp, NULL);
00112       start = tp.tv_sec;
00113       startu = tp.tv_usec;
00114       return(0.0);
00115    }
00116    gettimeofday(&tp, NULL);
00117    return( ((double) (tp.tv_sec - start)) + (tp.tv_usec-startu)/1000000.0 );
00118 #else
00119    return( (double) clock() / CLOCKS_PER_SEC );
00120 #endif // MINGW
00121 
00122 #endif // ICL || WIN32
00123 
00124 #endif // Epetra_HAVE_OMP
00125 #endif // EPETRA_MPI
00126 
00127 }
00128 //=============================================================================
00129 void Epetra_Time::ResetStartTime(void)
00130 {
00131   StartTime_ = WallTime();
00132   return;
00133 }
00134 //=============================================================================
00135 double Epetra_Time::ElapsedTime(void) const
00136 {
00137   return(WallTime()-StartTime_);
00138 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines