update & fix to FDTD simulation statistics

Signed-off-by: Thorsten Liebig <Thorsten.Liebig@gmx.de>
pull/1/head
Thorsten Liebig 2012-09-25 11:24:25 +02:00
parent 36d869a41a
commit 2f228f2161
4 changed files with 70 additions and 12 deletions

View File

@ -449,14 +449,18 @@ void openEMS_FDTD_MPI::RunFDTD()
m_ProcField->AddStep(maxExcite);
int prevTS=0,currTS=0;
double speed = m_NumberCells/1e6;
double numCells = FDTD_Op->GetNumberCells();
double speed = 0;
double t_diff;
double t_run;
timeval currTime;
gettimeofday(&currTime,NULL);
timeval startTime = currTime;
timeval prevTime= currTime;
if (m_DumpStats)
InitRunStatistics(__OPENEMS_RUN_STAT_FILE__);
//*************** simulate ************//
PA->PreProcess();
int step = GetNextStep();
@ -484,13 +488,18 @@ void openEMS_FDTD_MPI::RunFDTD()
currE = CalcEnergy();
if (m_MyID==0)
{
cout << "[@" << FormatTime(CalcDiffTime(currTime,startTime)) << "] Timestep: " << setw(12) << currTS ;
cout << " || Speed: " << setw(6) << setprecision(1) << std::fixed << speed*(currTS-prevTS)/t_diff << " MC/s (" << setw(4) << setprecision(3) << std::scientific << t_diff/(currTS-prevTS) << " s/TS)" ;
t_run = CalcDiffTime(currTime,startTime);
speed = numCells*(currTS-prevTS)/t_diff;
cout << "[@" << FormatTime(t_run) << "] Timestep: " << setw(12) << currTS ;
cout << " || Speed: " << setw(6) << setprecision(1) << std::fixed << speed*1e-6 << " MC/s (" << setw(4) << setprecision(3) << std::scientific << t_diff/(currTS-prevTS) << " s/TS)" ;
cout << " || Energy: ~" << setw(6) << setprecision(2) << std::scientific << currE << " (-" << setw(5) << setprecision(2) << std::fixed << fabs(10.0*log10(m_EnergyDecrement)) << "dB)" << endl;
//set step to zero to abort simulation and send to all
if (m_EnergyDecrement<endCrit)
step=0;
if (m_DumpStats)
DumpRunStatistics(__OPENEMS_RUN_STAT_FILE__, t_run, currTS, speed, currE);
}
MPI_Bcast(&step, 1, MPI_INT, 0, MPI_COMM_WORLD);
@ -516,8 +525,9 @@ void openEMS_FDTD_MPI::RunFDTD()
if (m_MyID==0)
{
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: " << numCells*(double)FDTD_Eng->GetNumberOfTimesteps()/t_diff*1e-6 << " MCells/s " << endl;
DumpStatistics("openEMS_stats.txt", t_diff);
if (m_DumpStats)
DumpStatistics(__OPENEMS_STAT_FILE__, t_diff);
}
}

View File

@ -85,7 +85,7 @@ int main(int argc, char *argv[])
#endif
cout << "\t--numThreads=<n>\tForce use n threads for multithreaded engine (needs: --engine=multithreaded)" << endl;
cout << "\t--no-simulation\t\tonly run preprocessing; do not simulate" << endl;
cout << "\t--dump-statistics\tdump simulation statistics to 'openEMS_stats.txt'" << endl;
cout << "\t--dump-statistics\tdump simulation statistics to '" << __OPENEMS_RUN_STAT_FILE__ << "' and '" << __OPENEMS_STAT_FILE__ << "'" << endl;
cout << "\n\t Additional global arguments " << endl;
g_settings.ShowArguments(cout,"\t");
cout << endl;

View File

@ -187,7 +187,7 @@ bool openEMS::parseCommandLineArgument( const char *argv )
}
else if (strcmp(argv,"--dump-statistics")==0)
{
cout << "openEMS - dump simulation statistics to 'openEMS_stats.txt'" << endl;
cout << "openEMS - dump simulation statistics to '" << __OPENEMS_RUN_STAT_FILE__ << "' and '" << __OPENEMS_STAT_FILE__ << "'" << endl;
m_DumpStats = true;
return true;
}
@ -790,14 +790,18 @@ void openEMS::RunFDTD()
double change=1;
int prevTS=0,currTS=0;
double speed = FDTD_Op->GetNumberCells()/1e6;
double numCells = FDTD_Op->GetNumberCells();
double speed = 0;
double t_diff;
double t_run;
timeval currTime;
gettimeofday(&currTime,NULL);
timeval startTime = currTime;
timeval prevTime= currTime;
if (m_DumpStats)
InitRunStatistics(__OPENEMS_RUN_STAT_FILE__);
//*************** simulate ************//
PA->PreProcess();
@ -822,13 +826,16 @@ void openEMS::RunFDTD()
gettimeofday(&currTime,NULL);
t_diff = CalcDiffTime(currTime,prevTime);
if (t_diff>4)
{
currE = ProcField->CalcTotalEnergyEstimate();
if (currE>maxE)
maxE=currE;
cout << "[@" << FormatTime(CalcDiffTime(currTime,startTime)) << "] Timestep: " << setw(12) << currTS ;
cout << " || Speed: " << setw(6) << setprecision(1) << std::fixed << speed*(currTS-prevTS)/t_diff << " MC/s (" << setw(4) << setprecision(3) << std::scientific << t_diff/(currTS-prevTS) << " s/TS)" ;
t_run = CalcDiffTime(currTime,startTime);
speed = numCells*(currTS-prevTS)/t_diff;
cout << "[@" << FormatTime(t_run) << "] Timestep: " << setw(12) << currTS ;
cout << " || Speed: " << setw(6) << setprecision(1) << std::fixed << speed*1e-6 << " MC/s (" << setw(4) << setprecision(3) << std::scientific << t_diff/(currTS-prevTS) << " s/TS)" ;
if (maxE)
change = currE/maxE;
cout << " || Energy: ~" << setw(6) << setprecision(2) << std::scientific << currE << " (-" << setw(5) << setprecision(2) << std::fixed << fabs(10.0*log10(change)) << "dB)" << endl;
@ -836,6 +843,9 @@ void openEMS::RunFDTD()
prevTS=currTS;
PA->FlushNext();
if (m_DumpStats)
DumpRunStatistics(__OPENEMS_RUN_STAT_FILE__, t_run, currTS, speed, currE);
}
}
if ((change>endCrit) && (FDTD_Op->GetExcitationSignal()->GetExciteType()==0))
@ -851,9 +861,10 @@ void openEMS::RunFDTD()
t_diff = CalcDiffTime(currTime,startTime);
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: " << numCells*(double)FDTD_Eng->GetNumberOfTimesteps()/t_diff*1e-6 << " MCells/s " << endl;
DumpStatistics("openEMS_stats.txt", t_diff);
if (m_DumpStats)
DumpStatistics(__OPENEMS_STAT_FILE__, t_diff);
}
bool openEMS::DumpStatistics(const string& filename, double time)
@ -877,3 +888,33 @@ bool openEMS::DumpStatistics(const string& filename, double time)
stat_file.close();
return true;
}
bool openEMS::InitRunStatistics(const string& filename)
{
ofstream stat_file;
stat_file.open(filename.c_str(), ios_base::out);
if (!stat_file.is_open())
{
cerr << "openEMS::InitRunStatistics: Error, opening file failed..." << endl;
return false;
}
stat_file << "%time\ttimestep\tspeed\tenergy" << endl;
stat_file.close();
return true;
}
bool openEMS::DumpRunStatistics(const string& filename, double time, unsigned int ts, double speed, double energy)
{
ofstream stat_file;
stat_file.open(filename.c_str(), ios_base::app);
if (!stat_file.is_open())
{
cerr << "openEMS::DumpRunStatistics: Error, opening file failed..." << endl;
return false;
}
stat_file << time << "\t" << ts << "\t" << speed << "\t" << energy << endl;
stat_file.close();
return true;
}

View File

@ -22,6 +22,9 @@
#include <sys/time.h>
#include <time.h>
#define __OPENEMS_STAT_FILE__ "openEMS_stats.txt"
#define __OPENEMS_RUN_STAT_FILE__ "openEMS_run_stats.txt"
using namespace std;
class Operator;
@ -115,6 +118,10 @@ protected:
//! Dump statistics to file
virtual bool DumpStatistics(const string& filename, double time);
//! Dump run statistivs to file
virtual bool InitRunStatistics(const string& filename);
virtual bool DumpRunStatistics(const string& filename, double time, unsigned int ts, double speed, double energy);
};
#endif // OPENEMS_H