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