IFPACK Development
Loading...
Searching...
No Matches
TimeLog_dh.c
1/*@HEADER
2// ***********************************************************************
3//
4// Ifpack: Object-Oriented Algebraic Preconditioner Package
5// Copyright (2002) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38//
39// ***********************************************************************
40//@HEADER
41*/
42
43#include "TimeLog_dh.h"
44#include "Timer_dh.h"
45#include "Mem_dh.h"
46
47#define MAX_TIME_MARKS 100
48#define MAX_DESC_LENGTH 60
49
51{
52 int first;
53 int last;
54 double time[MAX_TIME_MARKS];
55 char desc[MAX_TIME_MARKS][MAX_DESC_LENGTH];
56 Timer_dh timer;
57};
58
59#undef __FUNC__
60#define __FUNC__ "TimeLog_dhCreate"
61void
62TimeLog_dhCreate (TimeLog_dh * t)
63{
64 START_FUNC_DH int i;
65 struct _timeLog_dh *tmp =
66 (struct _timeLog_dh *) MALLOC_DH (sizeof (struct _timeLog_dh));
67 CHECK_V_ERROR;
68 *t = tmp;
69 tmp->first = tmp->last = 0;
70 Timer_dhCreate (&tmp->timer);
71 for (i = 0; i < MAX_TIME_MARKS; ++i)
72 strcpy (tmp->desc[i], "X");
73END_FUNC_DH}
74
75#undef __FUNC__
76#define __FUNC__ "TimeLog_dhDestroy"
77void
78TimeLog_dhDestroy (TimeLog_dh t)
79{
80 START_FUNC_DH Timer_dhDestroy (t->timer);
81 FREE_DH (t);
82END_FUNC_DH}
83
84
85#undef __FUNC__
86#define __FUNC__ "TimeLog_dhStart"
87void
88TimeLog_dhStart (TimeLog_dh t)
89{
90 START_FUNC_DH Timer_dhStart (t->timer);
91END_FUNC_DH}
92
93#undef __FUNC__
94#define __FUNC__ "TimeLog_dhStop"
95void
96TimeLog_dhStop (TimeLog_dh t)
97{
98 START_FUNC_DH Timer_dhStop (t->timer);
99END_FUNC_DH}
100
101#undef __FUNC__
102#define __FUNC__ "TimeLog_dhMark"
103void
104TimeLog_dhMark (TimeLog_dh t, char *desc)
105{
106 START_FUNC_DH if (t->last < MAX_TIME_MARKS - 3)
107 {
108/* SET_V_ERROR("overflow; please increase MAX_TIME_MARKS and recompile"); */
109 Timer_dhStop (t->timer);
110 t->time[t->last] = Timer_dhReadWall (t->timer);
111 Timer_dhStart (t->timer);
112 sprintf (t->desc[t->last], desc);
113 t->last += 1;
114 }
115END_FUNC_DH}
116
117#undef __FUNC__
118#define __FUNC__ "TimeLog_dhReset"
119void
120TimeLog_dhReset (TimeLog_dh t)
121{
122 START_FUNC_DH if (t->last < MAX_TIME_MARKS - 2)
123 {
124 double total = 0.0;
125 int i, first = t->first, last = t->last;
126 for (i = first; i < last; ++i)
127 total += t->time[i];
128 t->time[last] = total;
129 sprintf (t->desc[last], "========== totals, and reset ==========\n");
130 t->last += 1;
131 t->first = t->last;
132 Timer_dhStart (t->timer);
133 }
134END_FUNC_DH}
135
136
137#undef __FUNC__
138#define __FUNC__ "TimeLog_dhPrint"
139void
140TimeLog_dhPrint (TimeLog_dh t, FILE * fp, bool allPrint)
141{
142 START_FUNC_DH int i;
143 double total = 0.0;
144 double timeMax[MAX_TIME_MARKS];
145 double timeMin[MAX_TIME_MARKS];
146 static bool wasSummed = false;
147
148
149 if (!wasSummed)
150 {
151 for (i = t->first; i < t->last; ++i)
152 total += t->time[i];
153 t->time[t->last] = total;
154 sprintf (t->desc[t->last], "========== totals, and reset ==========\n");
155 t->last += 1;
156
157 MPI_Allreduce (t->time, timeMax, t->last, MPI_DOUBLE, MPI_MAX, comm_dh);
158 MPI_Allreduce (t->time, timeMin, t->last, MPI_DOUBLE, MPI_MIN, comm_dh);
159 wasSummed = true;
160 }
161
162 if (fp != NULL)
163 {
164 if (myid_dh == 0 || allPrint)
165 {
166 fprintf (fp,
167 "\n----------------------------------------- timing report\n");
168 fprintf (fp, "\n self max min\n");
169 for (i = 0; i < t->last; ++i)
170 {
171 fprintf (fp, "%7.3f %7.3f %7.3f #%s\n", t->time[i],
172 timeMax[i], timeMin[i], t->desc[i]);
173 }
174 fflush (fp);
175 }
176 } /* if (fp != NULL) */
177END_FUNC_DH}