IFPACK  Development
 All Classes Files Functions Variables Enumerations Friends
TimeLog_dh.c
00001 /*@HEADER
00002 // ***********************************************************************
00003 //
00004 //       Ifpack: Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2002) 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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 //@HEADER
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 /*     SET_V_ERROR("overflow; please increase MAX_TIME_MARKS and recompile"); */
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     }               /* if (fp != NULL) */
00177 END_FUNC_DH}
 All Classes Files Functions Variables Enumerations Friends