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 #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
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 }
00164 END_FUNC_DH}