From 9bc9bfb50b20ab1460e7b22f1659241d307e990a Mon Sep 17 00:00:00 2001 From: HomesGH <55833544+HomesGH@users.noreply.github.com> Date: Tue, 11 Jul 2023 16:53:25 +0200 Subject: [PATCH 1/4] Enable plugin timers for all calls --- src/Simulation.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index ff3e5da5c9..a337cd822a 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -1020,7 +1020,9 @@ void Simulation::simulate() { global_log -> debug() << "[BEFORE EVENT NEW TIMESTEP] Performing beforeEventNewTimestep plugin call" << endl; for (auto plugin : _plugins) { global_log -> debug() << "[BEFORE EVENT NEW TIMESTEP] Plugin: " << plugin->getPluginName() << endl; + global_simulation->timers()->start(plugin->getPluginName()); plugin->beforeEventNewTimestep(_moleculeContainer, _domainDecomposition, _simstep); + global_simulation->timers()->stop(plugin->getPluginName()); } _ensemble->beforeEventNewTimestep(_moleculeContainer, _domainDecomposition, _simstep); @@ -1031,7 +1033,9 @@ void Simulation::simulate() { global_log -> debug() << "[BEFORE FORCES] Performing BeforeForces plugin call" << endl; for (auto plugin : _plugins) { global_log -> debug() << "[BEFORE FORCES] Plugin: " << plugin->getPluginName() << endl; + global_simulation->timers()->start(plugin->getPluginName()); plugin->beforeForces(_moleculeContainer, _domainDecomposition, _simstep); + global_simulation->timers()->stop(plugin->getPluginName()); } computationTimer->stop(); @@ -1075,7 +1079,9 @@ void Simulation::simulate() { global_log -> debug() << "[SITEWISE FORCES] Performing siteWiseForces plugin call" << endl; for (auto plugin : _plugins) { global_log -> debug() << "[SITEWISE FORCES] Plugin: " << plugin->getPluginName() << endl; + global_simulation->timers()->start(plugin->getPluginName()); plugin->siteWiseForces(_moleculeContainer, _domainDecomposition, _simstep); + global_simulation->timers()->stop(plugin->getPluginName()); } // longRangeCorrection is a site-wise force plugin, so we have to call it before updateForces() @@ -1109,7 +1115,9 @@ void Simulation::simulate() { global_log -> debug() << "[AFTER FORCES] Performing AfterForces plugin call" << endl; for (auto plugin : _plugins) { global_log -> debug() << "[AFTER FORCES] Plugin: " << plugin->getPluginName() << endl; + global_simulation->timers()->start(plugin->getPluginName()); plugin->afterForces(_moleculeContainer, _domainDecomposition, _simstep); + global_simulation->timers()->stop(plugin->getPluginName()); } _ensemble->afterForces(_moleculeContainer, _domainDecomposition, _cellProcessor, _simstep); From ffe78a0038329cce478ce864a4e5d65765029881 Mon Sep 17 00:00:00 2001 From: HomesGH <55833544+HomesGH@users.noreply.github.com> Date: Wed, 12 Jul 2023 11:44:12 +0200 Subject: [PATCH 2/4] At timing of further plugin calls --- src/Simulation.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index a337cd822a..5b1bdc663e 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -916,7 +916,9 @@ void Simulation::prepare_start() { for (auto plugin : _plugins) { global_log->debug() << "[AFTER FORCES] Plugin: " << plugin->getPluginName() << endl; + global_simulation->timers()->start(plugin->getPluginName()); plugin->afterForces(_moleculeContainer, _domainDecomposition, _simstep); + global_simulation->timers()->stop(plugin->getPluginName()); } #ifndef MARDYN_AUTOPAS @@ -1234,7 +1236,9 @@ void Simulation::simulate() { global_log->info() << "Finish plugins" << endl; for (auto plugin : _plugins) { + global_simulation->timers()->start(plugin->getPluginName()); plugin->finish(_moleculeContainer, _domainDecomposition, _domain); + global_simulation->timers()->stop(plugin->getPluginName()); } global_simulation->timers()->getTimer("SIMULATION_FINAL_IO")->stop(); From 7c08f93aac312acfdbb441557cfd4e4ab6b275c8 Mon Sep 17 00:00:00 2001 From: Jakob <122977094+JakNiem@users.noreply.github.com> Date: Fri, 4 Aug 2023 14:41:52 +0200 Subject: [PATCH 3/4] Update to refreshParticleIDs 1) assigning IDs starting from 0 instead of 1 in refreshParticleIDs 2) parsing the XML-information on refreshParticleIDs earlier in the Simulation 3) calling refreshparticleIDs earlier in the Simulation --- src/Simulation.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 5b1bdc663e..54b4e4f2d9 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -744,6 +744,13 @@ void Simulation::initConfigXML(const string& inputfilename) { global_log->error() << "Simulation section missing" << endl; Simulation::exit(1); } + + inp.getNodeValue("simulation/options/option", _prepare_start_opt.refreshIDs); + if(_prepare_start_opt.refreshIDs) + global_log->info() << "Particle IDs will be refreshed before simulation start." << endl; + else + global_log->info() << "Particle IDs will NOT be refreshed before simulation start." << endl; + } catch (const std::exception& e) { global_log->error() << "Error in XML config. Please check your input file!" << std::endl; global_log->error() << "Exception: " << e.what() << std::endl; @@ -769,6 +776,10 @@ void Simulation::initConfigXML(const string& inputfilename) { _moleculeContainer->update(); _moleculeContainer->deleteOuterParticles(); + /** refresh particle IDs */ + if(_prepare_start_opt.refreshIDs) + this->refreshParticleIDs(); + unsigned long globalNumMolecules = _domain->getglobalNumMolecules(true, _moleculeContainer, _domainDecomposition); double rho_global = globalNumMolecules / _ensemble->V(); global_log->info() << "Setting domain class parameters: N_global: " << globalNumMolecules @@ -1460,6 +1471,6 @@ void Simulation::refreshParticleIDs() for (auto pit = _moleculeContainer->iterator(ParticleIterator::ONLY_INNER_AND_BOUNDARY); pit.isValid(); ++pit) { - pit->setid(++start_ID); + pit->setid(start_ID++); } } From c794e7fd54b70a89ab769c692b7a9891ccd17ff2 Mon Sep 17 00:00:00 2001 From: FG-TUM Date: Tue, 8 Aug 2023 16:41:25 +0200 Subject: [PATCH 4/4] rework parsing of miscOptions (formerly prepare_start_opt) --- examples/all-options.xml | 6 ++++ src/Simulation.cpp | 73 ++++++++++++++++------------------------ src/Simulation.h | 24 ++++++++----- 3 files changed, 51 insertions(+), 52 deletions(-) diff --git a/examples/all-options.xml b/examples/all-options.xml index cf47f309fb..50e46eb6c8 100644 --- a/examples/all-options.xml +++ b/examples/all-options.xml @@ -11,6 +11,12 @@ + + + + + + 0 diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 54b4e4f2d9..4eb6325dce 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -669,38 +669,6 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { } xmlconfig.changecurrentnode(oldpath); - - /** Prepare start options, affecting behavior of method prepare_start() */ - _prepare_start_opt.refreshIDs = false; - - oldpath = xmlconfig.getcurrentnodepath(); - if(xmlconfig.changecurrentnode("options")) { - unsigned long numOptions = 0; - XMLfile::Query query = xmlconfig.query("option"); - numOptions = query.card(); - global_log->info() << "Number of prepare start options: " << numOptions << endl; - - XMLfile::Query::const_iterator optionIter; - for( optionIter = query.begin(); optionIter; optionIter++ ) { - xmlconfig.changecurrentnode(optionIter); - std::string strOptionName; - xmlconfig.getNodeValue("@name", strOptionName); - if(strOptionName == "refreshIDs") { - bool bVal = false; - xmlconfig.getNodeValue(".", bVal); - _prepare_start_opt.refreshIDs = bVal; - if(_prepare_start_opt.refreshIDs) - global_log->info() << "Particle IDs will be refreshed before simulation start." << endl; - else - global_log->info() << "Particle IDs will NOT be refreshed before simulation start." << endl; - } - else - { - global_log->warning() << "Unknown option '" << strOptionName << "'" << endl; - } - } - } - xmlconfig.changecurrentnode(oldpath); } @@ -744,13 +712,14 @@ void Simulation::initConfigXML(const string& inputfilename) { global_log->error() << "Simulation section missing" << endl; Simulation::exit(1); } - - inp.getNodeValue("simulation/options/option", _prepare_start_opt.refreshIDs); - if(_prepare_start_opt.refreshIDs) - global_log->info() << "Particle IDs will be refreshed before simulation start." << endl; - else - global_log->info() << "Particle IDs will NOT be refreshed before simulation start." << endl; - + + parseMiscOptions(inp); + if(_miscOptions["refreshIDs"]) { + global_log->info() << "Particle IDs will be refreshed before simulation start." << endl; + } else { + global_log->info() << "Particle IDs will NOT be refreshed before simulation start." << endl; + } + } catch (const std::exception& e) { global_log->error() << "Error in XML config. Please check your input file!" << std::endl; global_log->error() << "Exception: " << e.what() << std::endl; @@ -776,9 +745,10 @@ void Simulation::initConfigXML(const string& inputfilename) { _moleculeContainer->update(); _moleculeContainer->deleteOuterParticles(); - /** refresh particle IDs */ - if(_prepare_start_opt.refreshIDs) + /** reset particle IDs */ + if(_miscOptions["refreshIDs"]) { this->refreshParticleIDs(); + } unsigned long globalNumMolecules = _domain->getglobalNumMolecules(true, _moleculeContainer, _domainDecomposition); double rho_global = globalNumMolecules / _ensemble->V(); @@ -958,9 +928,6 @@ void Simulation::prepare_start() { global_log->info() << "Set initial time step to start from to " << _initSimulation << endl; global_log->info() << "System initialised with " << _domain->getglobalNumMolecules(true, _moleculeContainer, _domainDecomposition) << " molecules." << endl; - /** refresh particle IDs */ - if(_prepare_start_opt.refreshIDs) - this->refreshParticleIDs(); } void Simulation::simulate() { @@ -1474,3 +1441,21 @@ void Simulation::refreshParticleIDs() pit->setid(start_ID++); } } + +void Simulation::parseMiscOptions(XMLfileUnits& xmlconfig) { + const auto oldpath = xmlconfig.getcurrentnodepath(); + const XMLfile::Query optionNodes = xmlconfig.query("/mardyn/simulation/options/option"); + // parse everything in this path + for (auto optionIter = optionNodes.begin(); optionIter; optionIter++) { + xmlconfig.changecurrentnode(optionIter); + std::string strOptionName; + xmlconfig.getNodeValue("@name", strOptionName); + xmlconfig.getNodeValue(".", _miscOptions[strOptionName]); + } + // log what was parsed + global_log->info() << "Parsed " << optionNodes.card() << " misc options: \n" << std::boolalpha; + for (const auto& [name, value] : _miscOptions) { + global_log->info() << " " << name << ": " << value << std::endl; + } + xmlconfig.changecurrentnode(oldpath); +} diff --git a/src/Simulation.h b/src/Simulation.h index a81ea891c6..b78c7da946 100644 --- a/src/Simulation.h +++ b/src/Simulation.h @@ -454,7 +454,7 @@ class Simulation { CellProcessor *getCellProcessor() const; - /** @brief Refresh particle IDs to continuous numbering*/ + /** @brief Refresh particle IDs to continuous numbering starting at zero*/ void refreshParticleIDs(); /** @brief Checks if Simsteps or MaxWallTime are reached */ @@ -462,6 +462,13 @@ class Simulation { private: + /** + * Parse everything in the XML path + * and store it in _miscOptions. + * @param xmlconfig + */ + void parseMiscOptions(XMLfileUnits& xmlconfig); + /// the timer used for the load calculation. Timer* _timerForLoad{nullptr}; @@ -515,15 +522,16 @@ class Simulation { unsigned long _nWriteFreqGlobalEnergy; std::string _globalEnergyLogFilename; - /** Prepare start options, affecting behavior of method prepare_start() - * Options - * ------- - * refreshIDs: Refresh particle IDs to continuous numbering by method refreshParticleIDs() + /** + * Mechanism to easily add arbitrary options via the XML path + * Any option is identified via the label "name" + * + * @note Currently, only bool options are supported. * + * Example: + * */ - struct PrepareStartOptions { - bool refreshIDs; - } _prepare_start_opt; + std::map _miscOptions; FixedSizeQueue _lastTraversalTimeHistory; };