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.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /global/management/src/G4Timer.cc (Version 11.3.0) and /global/management/src/G4Timer.cc (Version 9.6.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4Timer class implementation                << 
 27 //                                                 26 //
 28 // Author: P.Kent, 21.08.95 - First implementa <<  27 // $Id$
 29 // Revision: G.Cosmo, 29.04.97 - Added timings <<  28 //
 30 // ------------------------------------------- <<  29 // 
                                                   >>  30 // ----------------------------------------------------------------------
                                                   >>  31 // class G4Timer
                                                   >>  32 //
                                                   >>  33 // Implementation
                                                   >>  34 // 29.04.97 G.Cosmo Added timings for Windows systems
 31                                                    35 
 32 #include "G4Timer.hh"                              36 #include "G4Timer.hh"
 33 #include "G4ios.hh"                                37 #include "G4ios.hh"
 34 #include "G4Exception.hh"                      << 
 35                                                    38 
 36 #include <iomanip>                             <<  39 #undef times
                                                   >>  40 
                                                   >>  41 // Global error function
                                                   >>  42 #include "G4ExceptionSeverity.hh"
                                                   >>  43 void G4Exception(const char* originOfException,
                                                   >>  44                  const char* exceptionCode,
                                                   >>  45                              G4ExceptionSeverity severity,
                                                   >>  46                  const char* comments);
 37                                                    47 
 38 #if defined(IRIX6_2)                               48 #if defined(IRIX6_2)
 39 #  if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE <<  49 #  if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE_EXTENDED==1)
 40 #    define __vfork vfork                          50 #    define __vfork vfork
 41 #  endif                                           51 #  endif
 42 #endif                                             52 #endif
 43                                                    53 
 44 #ifdef WIN32                                       54 #ifdef WIN32
 45 #  include <sys/types.h>                           55 #  include <sys/types.h>
 46 #  include <windows.h>                             56 #  include <windows.h>
 47                                                    57 
 48 // extract milliseconds time unit              <<  58    // extract milliseconds time unit
 49 G4int sysconf(G4int a)                         <<  59    int sysconf(int a){
 50 {                                              <<  60      if( a == _SC_CLK_TCK ) return 1000;
 51   if(a == _SC_CLK_TCK)                         <<  61      else return 0;
 52     return 1000;                               <<  62    }
 53   else                                         <<  63 
 54     return 0;                                  <<  64    static clock_t filetime2msec( FILETIME* t ){
 55 }                                              <<  65    
                                                   >>  66       return (clock_t)((((float)t->dwHighDateTime)*429496.7296)+
                                                   >>  67               (((float)t->dwLowDateTime)*.0001) );
                                                   >>  68    }
                                                   >>  69 
                                                   >>  70 
                                                   >>  71    clock_t times(struct tms * t){
                                                   >>  72            FILETIME      ct = {0,0}, et = {0,0}, st = {0,0}, ut = {0,0}, rt = {0,0};
                                                   >>  73            SYSTEMTIME realtime;
                                                   >>  74 
                                                   >>  75            GetSystemTime( &realtime );
                                                   >>  76            SystemTimeToFileTime( &realtime, &rt ); // get real time in 10^-9 sec
                                                   >>  77            if( t != 0 ){
                                                   >>  78                    GetProcessTimes( GetCurrentProcess(), &ct, &et, &st, &ut);// get process time in 10^-9 sec
                                                   >>  79                    t->tms_utime = t->tms_cutime = filetime2msec(&ut);
                                                   >>  80                    t->tms_stime = t->tms_cstime = filetime2msec(&st);
                                                   >>  81            }
                                                   >>  82            return filetime2msec(&rt);
                                                   >>  83    }
                                                   >>  84 #endif /* WIN32 */
 56                                                    85 
 57 static clock_t filetime2msec(FILETIME* t)      <<  86 // Print timer status n std::ostream
                                                   >>  87 std::ostream& operator << (std::ostream& os, const G4Timer& t)
 58 {                                                  88 {
 59   return (clock_t)((((G4float) t->dwHighDateTi <<  89     if (t.IsValid())
 60                    (((G4float) t->dwLowDateTim <<  90         {
                                                   >>  91             os << "User=" << t.GetUserElapsed()
                                                   >>  92                << "s Real=" << t.GetRealElapsed()
                                                   >>  93                << "s Sys=" << t.GetSystemElapsed() << "s";
                                                   >>  94         }
                                                   >>  95     else
                                                   >>  96         {
                                                   >>  97             os << "User=****s Real=****s Sys=****s";
                                                   >>  98         }
                                                   >>  99     return os;
 61 }                                                 100 }
 62                                                   101 
 63 clock_t times(struct tms* t)                   << 102 G4Timer::G4Timer()
                                                   >> 103   : fValidTimes(false)
 64 {                                                 104 {
 65   FILETIME ct = { 0, 0 }, et = { 0, 0 }, st =  << 
 66            rt = { 0, 0 };                      << 
 67   SYSTEMTIME realtime;                         << 
 68                                                << 
 69   GetSystemTime(&realtime);                    << 
 70   SystemTimeToFileTime(&realtime, &rt);  // ge << 
 71   if(t != 0)                                   << 
 72   {                                            << 
 73     GetProcessTimes(GetCurrentProcess(), &ct,  << 
 74     // get process time in 10^-9 sec           << 
 75     t->tms_utime = t->tms_cutime = filetime2ms << 
 76     t->tms_stime = t->tms_cstime = filetime2ms << 
 77   }                                            << 
 78   return filetime2msec(&rt);                   << 
 79 }                                                 105 }
 80 #endif /* WIN32 */                             << 
 81                                                   106 
 82 // Print timer status on std::ostream          << 107 G4double G4Timer::GetRealElapsed() const
 83 //                                             << 
 84 std::ostream& operator<<(std::ostream& os, con << 
 85 {                                                 108 {
 86   // so fixed doesn't propagate                << 109     if (!fValidTimes)
 87   std::stringstream ss;                        << 
 88   ss << std::fixed;                            << 
 89   if(t.IsValid())                              << 
 90   {                                            << 
 91     ss << "User=" << t.GetUserElapsed() << "s  << 
 92        << "s Sys=" << t.GetSystemElapsed() <<  << 
 93 #ifdef G4MULTITHREADED                         << 
 94     // avoid possible FPE error                << 
 95     if(t.GetRealElapsed() > 1.0e-6)            << 
 96     {                                             110     {
 97       G4double cpu_util = (t.GetUserElapsed()  << 111       G4Exception("G4Timer::GetRealElapsed()", "InvalidCondition",
 98                           t.GetRealElapsed() * << 112                   FatalException, "Timer not stopped or times not recorded!");
 99       ss << std::setprecision(1);              << 
100       ss << " [Cpu=" << std::setprecision(1) < << 
101     }                                             113     }
102 #endif                                         << 114     G4double diff=fEndRealTime-fStartRealTime;
103   }                                            << 115     return diff/sysconf(_SC_CLK_TCK);
104   else                                         << 
105   {                                            << 
106     ss << "User=****s Real=****s Sys=****s";   << 
107   }                                            << 
108   os << ss.str();                              << 
109                                                << 
110   return os;                                   << 
111 }                                                 116 }
112                                                   117 
113 G4double G4Timer::GetRealElapsed() const       << 
114 {                                              << 
115   if(!fValidTimes)                             << 
116   {                                            << 
117     G4Exception("G4Timer::GetRealElapsed()", " << 
118                 "Timer not stopped or times no << 
119   }                                            << 
120   std::chrono::duration<G4double> diff = fEndR << 
121   return diff.count();                         << 
122 }                                              << 
123                                                   118 
124 G4double G4Timer::GetSystemElapsed() const        119 G4double G4Timer::GetSystemElapsed() const
125 {                                                 120 {
126   if(!fValidTimes)                             << 121     if (!fValidTimes)
127   {                                            << 122     {
128     G4Exception("G4Timer::GetSystemElapsed()", << 123       G4Exception("G4Timer::GetSystemElapsed()", "InvalidCondition",
129                 FatalException, "Timer not sto << 124                   FatalException, "Timer not stopped or times not recorded!");
130   }                                            << 125     }
131   G4double diff = fEndTimes.tms_stime - fStart << 126     G4double diff=fEndTimes.tms_stime-fStartTimes.tms_stime;
132   return diff / sysconf(_SC_CLK_TCK);          << 127     return diff/sysconf(_SC_CLK_TCK);
133 }                                                 128 }
134                                                   129 
135 G4double G4Timer::GetUserElapsed() const          130 G4double G4Timer::GetUserElapsed() const
136 {                                                 131 {
137   if(!fValidTimes)                             << 132     if (!fValidTimes)
138   {                                            << 133     {
139     G4Exception("G4Timer::GetUserElapsed()", " << 134       G4Exception("G4Timer::GetUserElapsed()", "InvalidCondition",
140                 "Timer not stopped or times no << 135                   FatalException, "Timer not stopped or times not recorded");
141   }                                            << 136     }
142   G4double diff = fEndTimes.tms_utime - fStart << 137     G4double diff=fEndTimes.tms_utime-fStartTimes.tms_utime;
143   return diff / sysconf(_SC_CLK_TCK);          << 138     return diff/sysconf(_SC_CLK_TCK);
144 }                                                 139 }
                                                   >> 140 
145                                                   141