Ifpack Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TimeLog_dh.c
Go to the documentation of this file.
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;
57 };
58 
59 #undef __FUNC__
60 #define __FUNC__ "TimeLog_dhCreate"
61 void
63 {
64  START_FUNC_DH int i;
65  struct _timeLog_dh *tmp =
66  (struct _timeLog_dh *) MALLOC_DH (sizeof (struct _timeLog_dh));
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");
74 
75 #undef __FUNC__
76 #define __FUNC__ "TimeLog_dhDestroy"
77 void
79 {
81  FREE_DH (t);
83 
84 
85 #undef __FUNC__
86 #define __FUNC__ "TimeLog_dhStart"
87 void
89 {
92 
93 #undef __FUNC__
94 #define __FUNC__ "TimeLog_dhStop"
95 void
97 {
100 
101 #undef __FUNC__
102 #define __FUNC__ "TimeLog_dhMark"
103 void
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  }
116 
117 #undef __FUNC__
118 #define __FUNC__ "TimeLog_dhReset"
119 void
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  }
135 
136 
137 #undef __FUNC__
138 #define __FUNC__ "TimeLog_dhPrint"
139 void
140 TimeLog_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) */
char desc[MAX_TIME_MARKS][MAX_DESC_LENGTH]
Definition: TimeLog_dh.c:55
double Timer_dhReadWall(Timer_dh t)
Definition: Timer_dh.c:224
#define CHECK_V_ERROR
Definition: macros_dh.h:138
void TimeLog_dhReset(TimeLog_dh t)
Definition: TimeLog_dh.c:120
void TimeLog_dhCreate(TimeLog_dh *t)
Definition: TimeLog_dh.c:62
#define END_FUNC_DH
Definition: macros_dh.h:187
void TimeLog_dhStart(TimeLog_dh t)
Definition: TimeLog_dh.c:88
#define MALLOC_DH(s)
void TimeLog_dhDestroy(TimeLog_dh t)
Definition: TimeLog_dh.c:78
void Timer_dhDestroy(Timer_dh t)
Definition: Timer_dh.c:80
void Timer_dhStop(Timer_dh t)
Definition: Timer_dh.c:217
void Timer_dhCreate(Timer_dh *t)
Definition: Timer_dh.c:49
MPI_Comm comm_dh
Definition: globalObjects.c:64
void TimeLog_dhStop(TimeLog_dh t)
Definition: TimeLog_dh.c:96
#define MAX_TIME_MARKS
Definition: TimeLog_dh.c:47
#define START_FUNC_DH
Definition: macros_dh.h:181
double time[MAX_TIME_MARKS]
Definition: TimeLog_dh.c:54
void Timer_dhStart(Timer_dh t)
Definition: Timer_dh.c:210
Timer_dh timer
Definition: TimeLog_dh.c:56
void TimeLog_dhMark(TimeLog_dh t, char *desc)
Definition: TimeLog_dh.c:104
int myid_dh
Definition: globalObjects.c:63
#define MAX_DESC_LENGTH
Definition: TimeLog_dh.c:48
#define FREE_DH(p)
void TimeLog_dhPrint(TimeLog_dh t, FILE *fp, bool allPrint)
Definition: TimeLog_dh.c:140