new and more accurate time measurement

pull/1/head
Thorsten Liebig 2010-03-25 15:08:54 +01:00
parent 51cad6e1b6
commit a938460c34
1 changed files with 20 additions and 8 deletions

View File

@ -23,11 +23,20 @@
#include "FDTD/processvoltage.h" #include "FDTD/processvoltage.h"
#include "FDTD/processcurrent.h" #include "FDTD/processcurrent.h"
#include "FDTD/processfields_td.h" #include "FDTD/processfields_td.h"
#include <sys/time.h>
#include <time.h>
//external libs //external libs
#include "tinyxml.h" #include "tinyxml.h"
#include "ContinuousStructure.h" #include "ContinuousStructure.h"
double CalcDiffTime(timeval t1, timeval t2)
{
double s_diff = difftime(t1.tv_sec,t2.tv_sec);
s_diff += ((double)t1.tv_usec-(double)t2.tv_usec)*1e-6;
return s_diff;
}
openEMS::openEMS() openEMS::openEMS()
{ {
FDTD_Op=NULL; FDTD_Op=NULL;
@ -260,9 +269,11 @@ int openEMS::SetupFDTD(const char* file)
void openEMS::RunFDTD() void openEMS::RunFDTD()
{ {
cout << "Running FDTD engine... this may take a while... grab a coup of coffee?!?" << endl; cout << "Running FDTD engine... this may take a while... grab a coup of coffee?!?" << endl;
time_t currTime = time(NULL);
time_t startTime = currTime; timeval currTime;
time_t prevTime=currTime; gettimeofday(&currTime,NULL);
timeval startTime = currTime;
timeval prevTime= currTime;
ProcessFields ProcField(FDTD_Op,FDTD_Eng); ProcessFields ProcField(FDTD_Op,FDTD_Eng);
double maxE=0,currE=0; double maxE=0,currE=0;
double change=1; double change=1;
@ -280,14 +291,15 @@ void openEMS::RunFDTD()
currTS = FDTD_Eng->GetNumberOfTimesteps(); currTS = FDTD_Eng->GetNumberOfTimesteps();
if ((step<0) || (step>NrTS - currTS)) step=NrTS - currTS; if ((step<0) || (step>NrTS - currTS)) step=NrTS - currTS;
currTime = time(NULL); gettimeofday(&currTime,NULL);
t_diff = difftime(currTime,prevTime);
t_diff = CalcDiffTime(currTime,prevTime);
if (t_diff>4) if (t_diff>4)
{ {
currE = ProcField.CalcTotalEnergy(); currE = ProcField.CalcTotalEnergy();
if (currE>maxE) if (currE>maxE)
maxE=currE; maxE=currE;
cout << "[@" << setw(8) << (int)difftime(currTime,startTime) << "s] Timestep: " << setw(12) << currTS << " (" << setw(6) << setprecision(2) << std::fixed << (double)currTS/(double)NrTS*100.0 << "%)" ; cout << "[@" << setw(8) << (int)CalcDiffTime(currTime,startTime) << "s] Timestep: " << setw(12) << currTS << " (" << setw(6) << setprecision(2) << std::fixed << (double)currTS/(double)NrTS*100.0 << "%)" ;
cout << " with currently " << setw(6) << setprecision(1) << std::fixed << speed*(double)(currTS-prevTS)/t_diff << " MCells/s" ; cout << " with currently " << setw(6) << setprecision(1) << std::fixed << speed*(double)(currTS-prevTS)/t_diff << " MCells/s" ;
if (maxE) if (maxE)
change = currE/maxE; change = currE/maxE;
@ -299,9 +311,9 @@ void openEMS::RunFDTD()
//*************** postproc ************// //*************** postproc ************//
prevTime = currTime; prevTime = currTime;
currTime = time(NULL); gettimeofday(&currTime,NULL);
t_diff = difftime(currTime,startTime); t_diff = CalcDiffTime(currTime,startTime);
cout << "Time for " << FDTD_Eng->GetNumberOfTimesteps() << " iterations with " << FDTD_Op->GetNumberCells() << " cells : " << t_diff << " sec" << endl; cout << "Time for " << FDTD_Eng->GetNumberOfTimesteps() << " iterations with " << FDTD_Op->GetNumberCells() << " cells : " << t_diff << " sec" << endl;
cout << "Speed: " << speed*(double)FDTD_Eng->GetNumberOfTimesteps()/t_diff << " MCells/s " << endl; cout << "Speed: " << speed*(double)FDTD_Eng->GetNumberOfTimesteps()/t_diff << " MCells/s " << endl;