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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.4.p2)


  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: G4Timer.cc,v 1.15 2006-06-29 19:04:30 gunter Exp $
 29 // Revision: G.Cosmo, 29.04.97 - Added timings <<  28 // GEANT4 tag $Name: geant4-09-04-patch-02 $
 30 // ------------------------------------------- <<  29 //
                                                   >>  30 // 
                                                   >>  31 // ----------------------------------------------------------------------
                                                   >>  32 // class G4Timer
                                                   >>  33 //
                                                   >>  34 // Implementation
                                                   >>  35 // 29.04.97 G.Cosmo Added timings for Windows systems
 31                                                    36 
 32 #include "G4Timer.hh"                              37 #include "G4Timer.hh"
 33 #include "G4ios.hh"                                38 #include "G4ios.hh"
 34 #include "G4Exception.hh"                      << 
 35                                                    39 
 36 #include <iomanip>                             <<  40 #undef times
                                                   >>  41 
                                                   >>  42 // Global error function
                                                   >>  43 void G4Exception(const char* s=0);
 37                                                    44 
 38 #if defined(IRIX6_2)                               45 #if defined(IRIX6_2)
 39 #  if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE <<  46 #  if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE_EXTENDED==1)
 40 #    define __vfork vfork                          47 #    define __vfork vfork
 41 #  endif                                           48 #  endif
 42 #endif                                             49 #endif
 43                                                    50 
 44 #ifdef WIN32                                       51 #ifdef WIN32
 45 #  include <sys/types.h>                           52 #  include <sys/types.h>
 46 #  include <windows.h>                             53 #  include <windows.h>
 47                                                    54 
 48 // extract milliseconds time unit              <<  55    // extract milliseconds time unit
 49 G4int sysconf(G4int a)                         <<  56    int sysconf(int a){
 50 {                                              <<  57      if( a == _SC_CLK_TCK ) return 1000;
 51   if(a == _SC_CLK_TCK)                         <<  58      else return 0;
 52     return 1000;                               <<  59    }
 53   else                                         <<  60 
 54     return 0;                                  <<  61    static clock_t filetime2msec( FILETIME* t ){
 55 }                                              <<  62    
                                                   >>  63       return (clock_t)((((float)t->dwHighDateTime)*429496.7296)+
                                                   >>  64               (((float)t->dwLowDateTime)*.0001) );
                                                   >>  65    }
                                                   >>  66 
                                                   >>  67 
                                                   >>  68    clock_t times(struct tms * t){
                                                   >>  69            FILETIME      ct = {0,0}, et = {0,0}, st = {0,0}, ut = {0,0}, rt = {0,0};
                                                   >>  70            SYSTEMTIME realtime;
                                                   >>  71 
                                                   >>  72            GetSystemTime( &realtime );
                                                   >>  73            SystemTimeToFileTime( &realtime, &rt ); // get real time in 10^-9 sec
                                                   >>  74            if( t != 0 ){
                                                   >>  75                    GetProcessTimes( GetCurrentProcess(), &ct, &et, &st, &ut);// get process time in 10^-9 sec
                                                   >>  76                    t->tms_utime = t->tms_cutime = filetime2msec(&ut);
                                                   >>  77                    t->tms_stime = t->tms_cstime = filetime2msec(&st);
                                                   >>  78            }
                                                   >>  79            return filetime2msec(&rt);
                                                   >>  80    }
                                                   >>  81 #endif /* WIN32 */
 56                                                    82 
 57 static clock_t filetime2msec(FILETIME* t)      <<  83 // Print timer status n std::ostream
                                                   >>  84 std::ostream& operator << (std::ostream& os, const G4Timer& t)
 58 {                                                  85 {
 59   return (clock_t)((((G4float) t->dwHighDateTi <<  86     if (t.IsValid())
 60                    (((G4float) t->dwLowDateTim <<  87         {
                                                   >>  88             os << "User=" << t.GetUserElapsed()
                                                   >>  89                << "s Real=" << t.GetRealElapsed()
                                                   >>  90                << "s Sys=" << t.GetSystemElapsed() << "s";
                                                   >>  91         }
                                                   >>  92     else
                                                   >>  93         {
                                                   >>  94             os << "User=****s Real=****s Sys=****s";
                                                   >>  95         }
                                                   >>  96     return os;
 61 }                                                  97 }
 62                                                    98 
 63 clock_t times(struct tms* t)                   <<  99 G4Timer::G4Timer()
                                                   >> 100   : fValidTimes(false)
 64 {                                                 101 {
 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 }                                                 102 }
 80 #endif /* WIN32 */                             << 
 81                                                   103 
 82 // Print timer status on std::ostream          << 104 G4double G4Timer::GetRealElapsed() const
 83 //                                             << 
 84 std::ostream& operator<<(std::ostream& os, con << 
 85 {                                                 105 {
 86   // so fixed doesn't propagate                << 106     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     {                                             107     {
 97       G4double cpu_util = (t.GetUserElapsed()  << 108       G4Exception("G4Timer::GetRealElapsed - Timer not stopped or times not recorded");
 98                           t.GetRealElapsed() * << 
 99       ss << std::setprecision(1);              << 
100       ss << " [Cpu=" << std::setprecision(1) < << 
101     }                                             109     }
102 #endif                                         << 110     G4double diff=fEndRealTime-fStartRealTime;
103   }                                            << 111     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 }                                                 112 }
112                                                   113 
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                                                   114 
124 G4double G4Timer::GetSystemElapsed() const        115 G4double G4Timer::GetSystemElapsed() const
125 {                                                 116 {
126   if(!fValidTimes)                             << 117     if (!fValidTimes)
127   {                                            << 118     {
128     G4Exception("G4Timer::GetSystemElapsed()", << 119       G4Exception("G4Timer::GetSystemElapsed - Timer not stopped or times not recorded");
129                 FatalException, "Timer not sto << 120     }
130   }                                            << 121     G4double diff=fEndTimes.tms_stime-fStartTimes.tms_stime;
131   G4double diff = fEndTimes.tms_stime - fStart << 122     return diff/sysconf(_SC_CLK_TCK);
132   return diff / sysconf(_SC_CLK_TCK);          << 
133 }                                                 123 }
134                                                   124 
135 G4double G4Timer::GetUserElapsed() const          125 G4double G4Timer::GetUserElapsed() const
136 {                                                 126 {
137   if(!fValidTimes)                             << 127     if (!fValidTimes)
138   {                                            << 128     {
139     G4Exception("G4Timer::GetUserElapsed()", " << 129       G4Exception("G4Timer::GetUserElapsed - Timer not stopped or times not recorded");
140                 "Timer not stopped or times no << 130     }
141   }                                            << 131     G4double diff=fEndTimes.tms_utime-fStartTimes.tms_utime;
142   G4double diff = fEndTimes.tms_utime - fStart << 132     return diff/sysconf(_SC_CLK_TCK);
143   return diff / sysconf(_SC_CLK_TCK);          << 
144 }                                                 133 }
                                                   >> 134 
145                                                   135