From 2f228f2161241ca8e48ce6e549840dd21b8923ee Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Tue, 25 Sep 2012 11:24:25 +0200 Subject: [PATCH] update & fix to FDTD simulation statistics Signed-off-by: Thorsten Liebig --- FDTD/openems_fdtd_mpi.cpp | 20 +++++++++++---- main.cpp | 2 +- openems.cpp | 53 ++++++++++++++++++++++++++++++++++----- openems.h | 7 ++++++ 4 files changed, 70 insertions(+), 12 deletions(-) diff --git a/FDTD/openems_fdtd_mpi.cpp b/FDTD/openems_fdtd_mpi.cpp index ba9ccfa..ed4d81e 100644 --- a/FDTD/openems_fdtd_mpi.cpp +++ b/FDTD/openems_fdtd_mpi.cpp @@ -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_EnergyDecrementGetNumberOfTimesteps() << " 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); } } diff --git a/main.cpp b/main.cpp index 7887a66..b85d693 100644 --- a/main.cpp +++ b/main.cpp @@ -85,7 +85,7 @@ int main(int argc, char *argv[]) #endif cout << "\t--numThreads=\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; diff --git a/openems.cpp b/openems.cpp index 3003625..aebb7bc 100644 --- a/openems.cpp +++ b/openems.cpp @@ -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; +} diff --git a/openems.h b/openems.h index 4e67a41..30fd489 100644 --- a/openems.h +++ b/openems.h @@ -22,6 +22,9 @@ #include #include +#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