Epetra Package Browser (Single Doxygen Collection)
Development
Toggle main menu visibility
Loading...
Searching...
No Matches
src
Epetra_Time.cpp
Go to the documentation of this file.
1
2
//@HEADER
3
// ************************************************************************
4
//
5
// Epetra: Linear Algebra Services Package
6
// Copyright 2011 Sandia Corporation
7
//
8
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9
// the U.S. Government retains certain rights in this software.
10
//
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are
13
// met:
14
//
15
// 1. Redistributions of source code must retain the above copyright
16
// notice, this list of conditions and the following disclaimer.
17
//
18
// 2. Redistributions in binary form must reproduce the above copyright
19
// notice, this list of conditions and the following disclaimer in the
20
// documentation and/or other materials provided with the distribution.
21
//
22
// 3. Neither the name of the Corporation nor the names of the
23
// contributors may be used to endorse or promote products derived from
24
// this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
//
38
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39
//
40
// ************************************************************************
41
//@HEADER
42
43
#include "
Epetra_Time.h
"
44
45
#ifdef EPETRA_MPI
46
#include <time.h>
47
#endif
48
#ifdef EPETRA_HAVE_OMP
49
#include <omp.h>
50
#endif
51
52
//=============================================================================
53
Epetra_Time::Epetra_Time
(
const
Epetra_Comm
& Comm)
54
:
StartTime_
(0.0),
55
Comm_
(&Comm)
56
{
57
StartTime_
=
WallTime
();
58
}
59
//=============================================================================
60
Epetra_Time::Epetra_Time
(
const
Epetra_Time
& Time)
61
:
StartTime_
(Time.
StartTime_
),
62
Comm_
(Time.
Comm_
)
63
{
64
}
65
//=============================================================================
66
Epetra_Time::~Epetra_Time
(
void
)
67
{
68
}
69
//=============================================================================
70
double
Epetra_Time::WallTime
(
void
)
const
71
{
72
#ifdef EPETRA_MPI
73
74
int
mpiInitialized;
75
MPI_Initialized(&mpiInitialized);
76
77
if
( mpiInitialized ) {
78
79
return
(MPI_Wtime());
80
81
}
82
else
{
83
84
clock_t start;
85
86
start = clock();
87
return
( (
double
)( start ) / CLOCKS_PER_SEC );
88
89
}
90
91
#else
92
93
#ifdef EPETRA_HAVE_OMP
94
return
(omp_get_wtime());
95
#else
96
#if ICL || defined(_WIN32)
97
98
clock_t start;
99
//double duration;
100
101
start = clock();
102
return
(
double
)( start ) / CLOCKS_PER_SEC;
103
104
#else
105
106
#ifndef MINGW
107
struct
timeval tp;
108
static
long
start=0, startu;
109
if
(!start)
110
{
111
gettimeofday(&tp, NULL);
112
start = tp.tv_sec;
113
startu = tp.tv_usec;
114
return
(0.0);
115
}
116
gettimeofday(&tp, NULL);
117
return
( ((
double
) (tp.tv_sec - start)) + (tp.tv_usec-startu)/1000000.0 );
118
#else
119
return
( (
double
) clock() / CLOCKS_PER_SEC );
120
#endif
// MINGW
121
122
#endif
// ICL || WIN32
123
124
#endif
// EPETRA_HAVE_OMP
125
#endif
// EPETRA_MPI
126
127
}
128
//=============================================================================
129
void
Epetra_Time::ResetStartTime
(
void
)
130
{
131
StartTime_
=
WallTime
();
132
return
;
133
}
134
//=============================================================================
135
double
Epetra_Time::ElapsedTime
(
void
)
const
136
{
137
return
(
WallTime
()-
StartTime_
);
138
}
Epetra_Time.h
Epetra_Comm
Epetra_Comm: The Epetra Communication Abstract Base Class.
Definition
Epetra_Comm.h:73
Epetra_Time::Comm_
const Epetra_Comm * Comm_
Definition
Epetra_Time.h:128
Epetra_Time::~Epetra_Time
virtual ~Epetra_Time(void)
Epetra_Time Destructor.
Definition
Epetra_Time.cpp:66
Epetra_Time::StartTime_
double StartTime_
Definition
Epetra_Time.h:127
Epetra_Time::WallTime
double WallTime(void) const
Epetra_Time wall-clock time function.
Definition
Epetra_Time.cpp:70
Epetra_Time::ResetStartTime
void ResetStartTime(void)
Epetra_Time function to reset the start time for a timer object.
Definition
Epetra_Time.cpp:129
Epetra_Time::Epetra_Time
Epetra_Time(const Epetra_Comm &Comm)
Epetra_Time Constructor.
Definition
Epetra_Time.cpp:53
Epetra_Time::ElapsedTime
double ElapsedTime(void) const
Epetra_Time elapsed time function.
Definition
Epetra_Time.cpp:135
Generated by
1.17.0