Import Geant4 10.5.0 source tree
This commit is contained in:
@@ -24,7 +24,6 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4Timer.cc 110674 2018-06-07 10:30:11Z gcosmo $
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
@@ -56,62 +55,67 @@ void G4Exception(const char* originOfException,
|
||||
# include <windows.h>
|
||||
|
||||
// extract milliseconds time unit
|
||||
int sysconf(int a){
|
||||
G4int sysconf(G4int a)
|
||||
{
|
||||
if( a == _SC_CLK_TCK ) return 1000;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
static clock_t filetime2msec( FILETIME* t ){
|
||||
|
||||
return (clock_t)((((float)t->dwHighDateTime)*429496.7296)+
|
||||
(((float)t->dwLowDateTime)*.0001) );
|
||||
static clock_t filetime2msec( FILETIME* t )
|
||||
{
|
||||
return (clock_t)((((G4float)t->dwHighDateTime)*429496.7296)+
|
||||
(((G4float)t->dwLowDateTime)*.0001) );
|
||||
}
|
||||
|
||||
|
||||
clock_t times(struct tms * t){
|
||||
FILETIME ct = {0,0}, et = {0,0}, st = {0,0}, ut = {0,0}, rt = {0,0};
|
||||
SYSTEMTIME realtime;
|
||||
clock_t times(struct tms * t)
|
||||
{
|
||||
FILETIME ct = {0,0}, et = {0,0}, st = {0,0}, ut = {0,0}, rt = {0,0};
|
||||
SYSTEMTIME realtime;
|
||||
|
||||
GetSystemTime( &realtime );
|
||||
SystemTimeToFileTime( &realtime, &rt ); // get real time in 10^-9 sec
|
||||
if( t != 0 ){
|
||||
GetProcessTimes( GetCurrentProcess(), &ct, &et, &st, &ut);// get process time in 10^-9 sec
|
||||
t->tms_utime = t->tms_cutime = filetime2msec(&ut);
|
||||
t->tms_stime = t->tms_cstime = filetime2msec(&st);
|
||||
}
|
||||
return filetime2msec(&rt);
|
||||
GetSystemTime( &realtime );
|
||||
SystemTimeToFileTime( &realtime, &rt ); // get real time in 10^-9 sec
|
||||
if( t != 0 )
|
||||
{
|
||||
GetProcessTimes( GetCurrentProcess(), &ct, &et, &st, &ut);
|
||||
// get process time in 10^-9 sec
|
||||
t->tms_utime = t->tms_cutime = filetime2msec(&ut);
|
||||
t->tms_stime = t->tms_cstime = filetime2msec(&st);
|
||||
}
|
||||
return filetime2msec(&rt);
|
||||
}
|
||||
#endif /* WIN32 */
|
||||
|
||||
// Print timer status n std::ostream
|
||||
// Print timer status on std::ostream
|
||||
//
|
||||
std::ostream& operator << (std::ostream& os, const G4Timer& t)
|
||||
{
|
||||
// so fixed doesn't propagate
|
||||
std::stringstream ss;
|
||||
ss << std::fixed;
|
||||
if (t.IsValid())
|
||||
{
|
||||
ss << "User=" << t.GetUserElapsed()
|
||||
<< "s Real=" << t.GetRealElapsed()
|
||||
<< "s Sys=" << t.GetSystemElapsed() << "s";
|
||||
// so fixed doesn't propagate
|
||||
std::stringstream ss;
|
||||
ss << std::fixed;
|
||||
if (t.IsValid())
|
||||
{
|
||||
ss << "User=" << t.GetUserElapsed()
|
||||
<< "s Real=" << t.GetRealElapsed()
|
||||
<< "s Sys=" << t.GetSystemElapsed() << "s";
|
||||
#ifdef G4MULTITHREADED
|
||||
// avoid possible FPE error
|
||||
if(t.GetRealElapsed() > 1.0e-6)
|
||||
{
|
||||
double cpu_util = (t.GetUserElapsed()+t.GetRealElapsed()) /
|
||||
t.GetRealElapsed() * 100.0;
|
||||
ss << std::setprecision(1);
|
||||
ss << " [Cpu=" << std::setprecision(1) << cpu_util << "%]";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
// avoid possible FPE error
|
||||
if(t.GetRealElapsed() > 1.0e-6)
|
||||
{
|
||||
ss << "User=****s Real=****s Sys=****s";
|
||||
G4double cpu_util = (t.GetUserElapsed()+t.GetSystemElapsed()) /
|
||||
t.GetRealElapsed() * 100.0;
|
||||
ss << std::setprecision(1);
|
||||
ss << " [Cpu=" << std::setprecision(1) << cpu_util << "%]";
|
||||
}
|
||||
os << ss.str();
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
ss << "User=****s Real=****s Sys=****s";
|
||||
}
|
||||
os << ss.str();
|
||||
|
||||
return os;
|
||||
return os;
|
||||
}
|
||||
|
||||
G4Timer::G4Timer()
|
||||
@@ -121,35 +125,34 @@ G4Timer::G4Timer()
|
||||
|
||||
G4double G4Timer::GetRealElapsed() const
|
||||
{
|
||||
if (!fValidTimes)
|
||||
{
|
||||
G4Exception("G4Timer::GetRealElapsed()", "InvalidCondition",
|
||||
FatalException, "Timer not stopped or times not recorded!");
|
||||
}
|
||||
std::chrono::duration<double> diff=fEndRealTime-fStartRealTime;
|
||||
return diff.count();
|
||||
if (!fValidTimes)
|
||||
{
|
||||
G4Exception("G4Timer::GetRealElapsed()", "InvalidCondition",
|
||||
FatalException, "Timer not stopped or times not recorded!");
|
||||
}
|
||||
std::chrono::duration<G4double> diff=fEndRealTime-fStartRealTime;
|
||||
return diff.count();
|
||||
}
|
||||
|
||||
|
||||
G4double G4Timer::GetSystemElapsed() const
|
||||
{
|
||||
if (!fValidTimes)
|
||||
{
|
||||
G4Exception("G4Timer::GetSystemElapsed()", "InvalidCondition",
|
||||
FatalException, "Timer not stopped or times not recorded!");
|
||||
}
|
||||
G4double diff=fEndTimes.tms_stime-fStartTimes.tms_stime;
|
||||
return diff/sysconf(_SC_CLK_TCK);
|
||||
if (!fValidTimes)
|
||||
{
|
||||
G4Exception("G4Timer::GetSystemElapsed()", "InvalidCondition",
|
||||
FatalException, "Timer not stopped or times not recorded!");
|
||||
}
|
||||
G4double diff=fEndTimes.tms_stime-fStartTimes.tms_stime;
|
||||
return diff/sysconf(_SC_CLK_TCK);
|
||||
}
|
||||
|
||||
G4double G4Timer::GetUserElapsed() const
|
||||
{
|
||||
if (!fValidTimes)
|
||||
{
|
||||
G4Exception("G4Timer::GetUserElapsed()", "InvalidCondition",
|
||||
FatalException, "Timer not stopped or times not recorded");
|
||||
}
|
||||
G4double diff=fEndTimes.tms_utime-fStartTimes.tms_utime;
|
||||
return diff/sysconf(_SC_CLK_TCK);
|
||||
if (!fValidTimes)
|
||||
{
|
||||
G4Exception("G4Timer::GetUserElapsed()", "InvalidCondition",
|
||||
FatalException, "Timer not stopped or times not recorded");
|
||||
}
|
||||
G4double diff=fEndTimes.tms_utime-fStartTimes.tms_utime;
|
||||
return diff/sysconf(_SC_CLK_TCK);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user