|
IFPACK Development
|
00001 /*@HEADER 00002 // *********************************************************************** 00003 // 00004 // Ifpack: Object-Oriented Algebraic Preconditioner Package 00005 // Copyright (2009) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 //@HEADER 00028 */ 00029 00030 #include "TimeLog_dh.h" 00031 #include "Timer_dh.h" 00032 #include "Mem_dh.h" 00033 00034 #define MAX_TIME_MARKS 100 00035 #define MAX_DESC_LENGTH 60 00036 00037 struct _timeLog_dh 00038 { 00039 int first; 00040 int last; 00041 double time[MAX_TIME_MARKS]; 00042 char desc[MAX_TIME_MARKS][MAX_DESC_LENGTH]; 00043 Timer_dh timer; 00044 }; 00045 00046 #undef __FUNC__ 00047 #define __FUNC__ "TimeLog_dhCreate" 00048 void 00049 TimeLog_dhCreate (TimeLog_dh * t) 00050 { 00051 START_FUNC_DH int i; 00052 struct _timeLog_dh *tmp = 00053 (struct _timeLog_dh *) MALLOC_DH (sizeof (struct _timeLog_dh)); 00054 CHECK_V_ERROR; 00055 *t = tmp; 00056 tmp->first = tmp->last = 0; 00057 Timer_dhCreate (&tmp->timer); 00058 for (i = 0; i < MAX_TIME_MARKS; ++i) 00059 strcpy (tmp->desc[i], "X"); 00060 END_FUNC_DH} 00061 00062 #undef __FUNC__ 00063 #define __FUNC__ "TimeLog_dhDestroy" 00064 void 00065 TimeLog_dhDestroy (TimeLog_dh t) 00066 { 00067 START_FUNC_DH Timer_dhDestroy (t->timer); 00068 FREE_DH (t); 00069 END_FUNC_DH} 00070 00071 00072 #undef __FUNC__ 00073 #define __FUNC__ "TimeLog_dhStart" 00074 void 00075 TimeLog_dhStart (TimeLog_dh t) 00076 { 00077 START_FUNC_DH Timer_dhStart (t->timer); 00078 END_FUNC_DH} 00079 00080 #undef __FUNC__ 00081 #define __FUNC__ "TimeLog_dhStop" 00082 void 00083 TimeLog_dhStop (TimeLog_dh t) 00084 { 00085 START_FUNC_DH Timer_dhStop (t->timer); 00086 END_FUNC_DH} 00087 00088 #undef __FUNC__ 00089 #define __FUNC__ "TimeLog_dhMark" 00090 void 00091 TimeLog_dhMark (TimeLog_dh t, char *desc) 00092 { 00093 START_FUNC_DH if (t->last < MAX_TIME_MARKS - 3) 00094 { 00095 /* SET_V_ERROR("overflow; please increase MAX_TIME_MARKS and recompile"); */ 00096 Timer_dhStop (t->timer); 00097 t->time[t->last] = Timer_dhReadWall (t->timer); 00098 Timer_dhStart (t->timer); 00099 sprintf (t->desc[t->last], desc); 00100 t->last += 1; 00101 } 00102 END_FUNC_DH} 00103 00104 #undef __FUNC__ 00105 #define __FUNC__ "TimeLog_dhReset" 00106 void 00107 TimeLog_dhReset (TimeLog_dh t) 00108 { 00109 START_FUNC_DH if (t->last < MAX_TIME_MARKS - 2) 00110 { 00111 double total = 0.0; 00112 int i, first = t->first, last = t->last; 00113 for (i = first; i < last; ++i) 00114 total += t->time[i]; 00115 t->time[last] = total; 00116 sprintf (t->desc[last], "========== totals, and reset ==========\n"); 00117 t->last += 1; 00118 t->first = t->last; 00119 Timer_dhStart (t->timer); 00120 } 00121 END_FUNC_DH} 00122 00123 00124 #undef __FUNC__ 00125 #define __FUNC__ "TimeLog_dhPrint" 00126 void 00127 TimeLog_dhPrint (TimeLog_dh t, FILE * fp, bool allPrint) 00128 { 00129 START_FUNC_DH int i; 00130 double total = 0.0; 00131 double timeMax[MAX_TIME_MARKS]; 00132 double timeMin[MAX_TIME_MARKS]; 00133 static bool wasSummed = false; 00134 00135 00136 if (!wasSummed) 00137 { 00138 for (i = t->first; i < t->last; ++i) 00139 total += t->time[i]; 00140 t->time[t->last] = total; 00141 sprintf (t->desc[t->last], "========== totals, and reset ==========\n"); 00142 t->last += 1; 00143 00144 MPI_Allreduce (t->time, timeMax, t->last, MPI_DOUBLE, MPI_MAX, comm_dh); 00145 MPI_Allreduce (t->time, timeMin, t->last, MPI_DOUBLE, MPI_MIN, comm_dh); 00146 wasSummed = true; 00147 } 00148 00149 if (fp != NULL) 00150 { 00151 if (myid_dh == 0 || allPrint) 00152 { 00153 fprintf (fp, 00154 "\n----------------------------------------- timing report\n"); 00155 fprintf (fp, "\n self max min\n"); 00156 for (i = 0; i < t->last; ++i) 00157 { 00158 fprintf (fp, "%7.3f %7.3f %7.3f #%s\n", t->time[i], 00159 timeMax[i], timeMin[i], t->desc[i]); 00160 } 00161 fflush (fp); 00162 } 00163 } /* if (fp != NULL) */ 00164 END_FUNC_DH}
1.7.4