Timer_dh.c

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 "Timer_dh.h"
00031 #include "Mem_dh.h"
00032 
00033 #undef __FUNC__
00034 #define __FUNC__ "Timer_dhCreate"
00035 void
00036 Timer_dhCreate (Timer_dh * t)
00037 {
00038   START_FUNC_DH
00039     struct _timer_dh *tmp =
00040     (struct _timer_dh *) MALLOC_DH (sizeof (struct _timer_dh));
00041   CHECK_V_ERROR;
00042   *t = tmp;
00043 
00044   tmp->isRunning = false;
00045   tmp->begin_wall = 0.0;
00046   tmp->end_wall = 0.0;
00047 #ifdef WIN32
00048   tmp->sc_clk_tck = CLOCKS_PER_SEC;
00049 #else
00050   tmp->sc_clk_tck = sysconf (128);
00051 #endif
00052 
00053 #if defined(EUCLID_TIMING)
00054   sprintf (msgBuf_dh, "using EUCLID_TIMING; _SC_CLK_TCK = %i",
00055        (int) tmp->sc_clk_tck);
00056   SET_INFO (msgBuf_dh);
00057 #elif defined(MPI_TIMING)
00058   SET_INFO ("using MPI timing")
00059 #else
00060   SET_INFO ("using JUNK timing")
00061 #endif
00062 END_FUNC_DH}
00063 
00064 #undef __FUNC__
00065 #define __FUNC__ "Timer_dhDestroy"
00066 void
00067 Timer_dhDestroy (Timer_dh t)
00068 {
00069   START_FUNC_DH FREE_DH (t);
00070 END_FUNC_DH}
00071 
00072 /*-------------------------------------------------------------------------------
00073  * EUCLID_TIMING timing methods; these use times() to record 
00074  * both wall and cpu time.
00075  *-------------------------------------------------------------------------------*/
00076 
00077 #ifdef EUCLID_TIMING
00078 
00079 #undef __FUNC__
00080 #define __FUNC__ "Timer_dhStart"
00081 void
00082 Timer_dhStart (Timer_dh t)
00083 {
00084   START_FUNC_DH t->begin_wall = times (&(t->begin_cpu));
00085   t->isRunning = true;
00086 END_FUNC_DH}
00087 
00088 #undef __FUNC__
00089 #define __FUNC__ "Timer_dhStop"
00090 void
00091 Timer_dhStop (Timer_dh t)
00092 {
00093   START_FUNC_DH t->end_wall = times (&(t->end_cpu));
00094   t->isRunning = false;
00095 END_FUNC_DH}
00096 
00097 #undef __FUNC__
00098 #define __FUNC__ "Timer_dhReadWall"
00099 double
00100 Timer_dhReadWall (Timer_dh t)
00101 {
00102   START_FUNC_DH double retval = 0.0;
00103   long int sc_clk_tck = t->sc_clk_tck;
00104   if (t->isRunning)
00105     t->end_wall = times (&(t->end_cpu));
00106   retval = (double) (t->end_wall - t->begin_wall) / (double) sc_clk_tck;
00107 END_FUNC_VAL (retval)}
00108 
00109 #undef __FUNC__
00110 #define __FUNC__ "Timer_dhReadCPU"
00111 double
00112 Timer_dhReadCPU (Timer_dh t)
00113 {
00114   START_FUNC_DH double retval;
00115   long int sc_clk_tck = t->sc_clk_tck;
00116   if (t->isRunning)
00117     t->end_wall = times (&(t->end_cpu));
00118   retval = (double) (t->end_cpu.tms_utime - t->begin_cpu.tms_utime
00119              + t->end_cpu.tms_stime - t->begin_cpu.tms_stime
00120              + t->end_cpu.tms_cutime - t->begin_cpu.tms_cutime
00121              + t->end_cpu.tms_cstime - t->begin_cpu.tms_cstime)
00122     / (double) sc_clk_tck;
00123 END_FUNC_VAL (retval)}
00124 
00125 #undef __FUNC__
00126 #define __FUNC__ "Timer_dhReadUsage"
00127 double
00128 Timer_dhReadUsage (Timer_dh t)
00129 {
00130   START_FUNC_DH double cpu = Timer_dhReadCPU (t);
00131   double wall = Timer_dhReadWall (t);
00132   double retval = 100.0 * cpu / wall;
00133   END_FUNC_VAL (retval);
00134 }
00135 
00136 /*-------------------------------------------------------------------------------
00137  * Parallel timing functions; these use MPI_Wtime() to record 
00138  * wall-clock time only.
00139  *-------------------------------------------------------------------------------*/
00140 
00141 #elif defined(MPI_TIMING)
00142 
00143 #undef __FUNC__
00144 #define __FUNC__ "Timer_dhStart"
00145 void
00146 Timer_dhStart (Timer_dh t)
00147 {
00148   START_FUNC_DH t->begin_wall = MPI_Wtime ();
00149   t->isRunning = true;
00150 END_FUNC_DH}
00151 
00152 #undef __FUNC__
00153 #define __FUNC__ "Timer_dhStop"
00154 void
00155 Timer_dhStop (Timer_dh t)
00156 {
00157   START_FUNC_DH t->end_wall = MPI_Wtime ();
00158   t->isRunning = false;
00159 END_FUNC_DH}
00160 
00161 #undef __FUNC__
00162 #define __FUNC__ "Timer_dhReadWall"
00163 double
00164 Timer_dhReadWall (Timer_dh t)
00165 {
00166   START_FUNC_DH double retval;
00167   if (t->isRunning)
00168     t->end_wall = MPI_Wtime ();
00169   retval = t->end_wall - t->begin_wall;
00170 END_FUNC_VAL (retval)}
00171 
00172 #undef __FUNC__
00173 #define __FUNC__ "Timer_dhReadCPU"
00174 double
00175 Timer_dhReadCPU (Timer_dh t)
00176 {
00177 START_FUNC_DH END_FUNC_VAL (-1.0)}
00178 
00179 #undef __FUNC__
00180 #define __FUNC__ "Timer_dhReadUsage"
00181 double
00182 Timer_dhReadUsage (Timer_dh t)
00183 {
00184   START_FUNC_DH END_FUNC_VAL (-1.0);
00185 }
00186 
00187 
00188 /*-------------------------------------------------------------------------------
00189  * junk timing methods -- these do nothing!
00190  *-------------------------------------------------------------------------------*/
00191 
00192 #else
00193 
00194 #undef __FUNC__
00195 #define __FUNC__ "Timer_dhStart"
00196 void
00197 Timer_dhStart (Timer_dh t)
00198 {
00199 START_FUNC_DH END_FUNC_DH}
00200 
00201 #undef __FUNC__
00202 #define __FUNC__ "Timer_dhStop"
00203 void
00204 Timer_dhStop (Timer_dh t)
00205 {
00206 START_FUNC_DH END_FUNC_DH}
00207 
00208 #undef __FUNC__
00209 #define __FUNC__ "Timer_dhReadWall"
00210 double
00211 Timer_dhReadWall (Timer_dh t)
00212 {
00213 START_FUNC_DH END_FUNC_VAL (-1.0)}
00214 
00215 #undef __FUNC__
00216 #define __FUNC__ "Timer_dhReadCPU"
00217 double
00218 Timer_dhReadCPU (Timer_dh t)
00219 {
00220 START_FUNC_DH END_FUNC_VAL (-1.0)}
00221 
00222 #undef __FUNC__
00223 #define __FUNC__ "Timer_dhReadUsage"
00224 double
00225 Timer_dhReadUsage (Timer_dh t)
00226 {
00227   START_FUNC_DH END_FUNC_VAL (-1.0);
00228 }
00229 
00230 #endif

Generated on Wed May 12 21:30:18 2010 for IFPACK by  doxygen 1.4.7