00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "TimeLog_dh.h"
00044 #include "Timer_dh.h"
00045 #include "Mem_dh.h"
00046
00047 #define MAX_TIME_MARKS 100
00048 #define MAX_DESC_LENGTH 60
00049
00050 struct _timeLog_dh
00051 {
00052 int first;
00053 int last;
00054 double time[MAX_TIME_MARKS];
00055 char desc[MAX_TIME_MARKS][MAX_DESC_LENGTH];
00056 Timer_dh timer;
00057 };
00058
00059 #undef __FUNC__
00060 #define __FUNC__ "TimeLog_dhCreate"
00061 void
00062 TimeLog_dhCreate (TimeLog_dh * t)
00063 {
00064 START_FUNC_DH int i;
00065 struct _timeLog_dh *tmp =
00066 (struct _timeLog_dh *) MALLOC_DH (sizeof (struct _timeLog_dh));
00067 CHECK_V_ERROR;
00068 *t = tmp;
00069 tmp->first = tmp->last = 0;
00070 Timer_dhCreate (&tmp->timer);
00071 for (i = 0; i < MAX_TIME_MARKS; ++i)
00072 strcpy (tmp->desc[i], "X");
00073 END_FUNC_DH}
00074
00075 #undef __FUNC__
00076 #define __FUNC__ "TimeLog_dhDestroy"
00077 void
00078 TimeLog_dhDestroy (TimeLog_dh t)
00079 {
00080 START_FUNC_DH Timer_dhDestroy (t->timer);
00081 FREE_DH (t);
00082 END_FUNC_DH}
00083
00084
00085 #undef __FUNC__
00086 #define __FUNC__ "TimeLog_dhStart"
00087 void
00088 TimeLog_dhStart (TimeLog_dh t)
00089 {
00090 START_FUNC_DH Timer_dhStart (t->timer);
00091 END_FUNC_DH}
00092
00093 #undef __FUNC__
00094 #define __FUNC__ "TimeLog_dhStop"
00095 void
00096 TimeLog_dhStop (TimeLog_dh t)
00097 {
00098 START_FUNC_DH Timer_dhStop (t->timer);
00099 END_FUNC_DH}
00100
00101 #undef __FUNC__
00102 #define __FUNC__ "TimeLog_dhMark"
00103 void
00104 TimeLog_dhMark (TimeLog_dh t, char *desc)
00105 {
00106 START_FUNC_DH if (t->last < MAX_TIME_MARKS - 3)
00107 {
00108
00109 Timer_dhStop (t->timer);
00110 t->time[t->last] = Timer_dhReadWall (t->timer);
00111 Timer_dhStart (t->timer);
00112 sprintf (t->desc[t->last], desc);
00113 t->last += 1;
00114 }
00115 END_FUNC_DH}
00116
00117 #undef __FUNC__
00118 #define __FUNC__ "TimeLog_dhReset"
00119 void
00120 TimeLog_dhReset (TimeLog_dh t)
00121 {
00122 START_FUNC_DH if (t->last < MAX_TIME_MARKS - 2)
00123 {
00124 double total = 0.0;
00125 int i, first = t->first, last = t->last;
00126 for (i = first; i < last; ++i)
00127 total += t->time[i];
00128 t->time[last] = total;
00129 sprintf (t->desc[last], "========== totals, and reset ==========\n");
00130 t->last += 1;
00131 t->first = t->last;
00132 Timer_dhStart (t->timer);
00133 }
00134 END_FUNC_DH}
00135
00136
00137 #undef __FUNC__
00138 #define __FUNC__ "TimeLog_dhPrint"
00139 void
00140 TimeLog_dhPrint (TimeLog_dh t, FILE * fp, bool allPrint)
00141 {
00142 START_FUNC_DH int i;
00143 double total = 0.0;
00144 double timeMax[MAX_TIME_MARKS];
00145 double timeMin[MAX_TIME_MARKS];
00146 static bool wasSummed = false;
00147
00148
00149 if (!wasSummed)
00150 {
00151 for (i = t->first; i < t->last; ++i)
00152 total += t->time[i];
00153 t->time[t->last] = total;
00154 sprintf (t->desc[t->last], "========== totals, and reset ==========\n");
00155 t->last += 1;
00156
00157 MPI_Allreduce (t->time, timeMax, t->last, MPI_DOUBLE, MPI_MAX, comm_dh);
00158 MPI_Allreduce (t->time, timeMin, t->last, MPI_DOUBLE, MPI_MIN, comm_dh);
00159 wasSummed = true;
00160 }
00161
00162 if (fp != NULL)
00163 {
00164 if (myid_dh == 0 || allPrint)
00165 {
00166 fprintf (fp,
00167 "\n----------------------------------------- timing report\n");
00168 fprintf (fp, "\n self max min\n");
00169 for (i = 0; i < t->last; ++i)
00170 {
00171 fprintf (fp, "%7.3f %7.3f %7.3f #%s\n", t->time[i],
00172 timeMax[i], timeMin[i], t->desc[i]);
00173 }
00174 fflush (fp);
00175 }
00176 }
00177 END_FUNC_DH}