diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 0b1aece4f8..8f89b94cde 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -17,3 +17,8 @@ Please describe the tests that you ran to verify your changes. - [ ] Test A - [ ] Test B + +## Documentation +(Only relevant if this PR introduces new features) +- [ ] `all-options.xml` documents how to use the feature. +- [ ] The responsible `readXML()` documents how to use the feature. diff --git a/README.md b/README.md index bfeb0e4027..88bf3beef2 100644 --- a/README.md +++ b/README.md @@ -161,10 +161,13 @@ MarDyn [options] ``` where `MarDyn` is the executable build in the INSTALLATION section, `[options]` are any "--"-prefixed options as listed by `MarDyn --help` and `` is a input file. -Detailed help can be obtained by running +To get an overview of further command line options run ```sh MarDyn --help ``` + +To understand how to write an input file check out [examples/all-options.xml](https://github.com/ls1mardyn/ls1-mardyn/blob/master/examples/all-options.xml), the various examples in the examples folder and the documentation of the various `readXML()` methods, e.g. via our doxygen documentation. + ### running examples ls1-MarDyn comes with a set of examples, which can be found in the examples folder. ```sh diff --git a/src/Domain.cpp b/src/Domain.cpp index 15cfc49a76..80657e2f36 100644 --- a/src/Domain.cpp +++ b/src/Domain.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -93,7 +94,9 @@ void Domain::readXML(XMLfileUnits& xmlconfig) { << _globalLength[2] << std::endl; } else { - Log::global_log->error() << "Unsupported volume type " << type << std::endl; + std::ostringstream error_message; + error_message << "Unsupported volume type " << type << std::endl; + MARDYN_EXIT(error_message.str()); } xmlconfig.changecurrentnode(".."); } @@ -552,8 +555,9 @@ void Domain::writeCheckpointHeader(std::string filename, mixingss << "\t"; } } else { - Log::global_log->error() << "Only LB mixing rule supported" << std::endl; - mardyn_exit(123); + std::ostringstream error_message; + error_message << "Only LB mixing rule supported" << std::endl; + MARDYN_EXIT(error_message.str()); } } } @@ -710,8 +714,9 @@ void Domain::enableComponentwiseThermostat() void Domain::setComponentThermostat(int cid, int thermostat) { if ((0 > cid) || (0 >= thermostat)) { - Log::global_log->error() << "Domain::setComponentThermostat: cid or thermostat id too low" << std::endl; - mardyn_exit(787); + std::ostringstream error_message; + error_message << "Domain::setComponentThermostat: cid or thermostat id too low" << std::endl; + MARDYN_EXIT(error_message.str()); } this->_componentToThermostatIdMap[cid] = thermostat; this->_universalThermostatN[thermostat] = 0; diff --git a/src/MarDyn.cpp b/src/MarDyn.cpp index 9a4cf21924..0d269c6a8d 100644 --- a/src/MarDyn.cpp +++ b/src/MarDyn.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "WrapOpenMP.h" @@ -58,42 +59,42 @@ void initOptions(optparse::OptionParser *op) { /** * @brief Helper function outputting program build information to given logger */ -void program_build_info(Log::Logger *log) { - log->info() << "Compilation info:" << std::endl; +void log_program_build_info() { + Log::global_log->info() << "Compilation info:" << std::endl; char info_str[MAX_INFO_STRING_LENGTH]; get_compiler_info(info_str); - log->info() << " Compiler: " << info_str << std::endl; + Log::global_log->info() << " Compiler: " << info_str << std::endl; get_compile_time(info_str); - log->info() << " Compiled on: " << info_str << std::endl; + Log::global_log->info() << " Compiled on: " << info_str << std::endl; get_precision_info(info_str); - log->info() << " Precision: " << info_str << std::endl; + Log::global_log->info() << " Precision: " << info_str << std::endl; get_intrinsics_info(info_str); - log->info() << " Intrinsics: " << info_str << std::endl; + Log::global_log->info() << " Intrinsics: " << info_str << std::endl; get_rmm_normal_info(info_str); - log->info() << " RMM/normal: " << info_str << std::endl; + Log::global_log->info() << " RMM/normal: " << info_str << std::endl; get_openmp_info(info_str); - log->info() << " OpenMP: " << info_str << std::endl; + Log::global_log->info() << " OpenMP: " << info_str << std::endl; get_mpi_info(info_str); - log->info() << " MPI: " << info_str << std::endl; + Log::global_log->info() << " MPI: " << info_str << std::endl; } /** * @brief Helper function outputting program invocation information to given logger */ -void program_execution_info(int argc, char **argv, Log::Logger *log) { - log->info() << "Execution info:" << std::endl; +void log_program_execution_info(int argc, char **argv) { + Log::global_log->info() << "Execution info:" << std::endl; char info_str[MAX_INFO_STRING_LENGTH]; get_timestamp(info_str); - log->info() << " Started: " << info_str << std::endl; + Log::global_log->info() << " Started: " << info_str << std::endl; get_host(info_str); - log->info() << " Execution host: " << info_str << std::endl; + Log::global_log->info() << " Execution host: " << info_str << std::endl; std::stringstream arguments; for (int i = 0; i < argc; i++) { arguments << " " << argv[i]; } - log->info() << " Started with arguments: " << arguments.str() << std::endl; + Log::global_log->info() << " Started with arguments: " << arguments.str() << std::endl; #if defined(_OPENMP) int num_threads = mardyn_get_max_threads(); @@ -135,18 +136,31 @@ int main(int argc, char** argv) { MPI_Init(&argc, &argv); #endif - /* Initialize the global log file */ - Log::global_log = new Log::Logger(Log::Info); -#ifdef ENABLE_MPI - Log::global_log->set_mpi_output_root(0); - //global_log->set_mpi_output_all(); -#endif + // Open scope to exclude MPI_Init() and MPI_Finalize(). + // This way, all simulation objects are cleaned up before MPI finalizes. + { optparse::OptionParser op; initOptions(&op); optparse::Values options = op.parse_args(argc, argv); std::vector args = op.args(); + /* Initialize the global log file */ + if( options.is_set_by_user("logfile") ) { + // Print to file + std::string logfileNamePrefix(options.get("logfile")); + std::cout << "Using logfile with prefix " << logfileNamePrefix << std::endl; + Log::global_log = std::make_unique(Log::Info, logfileNamePrefix); + } else { + // Print to stream (default: std::cout) + Log::global_log = std::make_unique(Log::Info); + } + +#ifdef ENABLE_MPI + Log::global_log->set_mpi_output_root(0); + //global_log->set_mpi_output_all(); +#endif + Log::global_log->info() << "Running ls1-MarDyn version " << MARDYN_VERSION << std::endl; #ifdef MARDYN_AUTOPAS @@ -157,12 +171,6 @@ int main(int argc, char** argv) { Log::global_log->warning() << "This ls1-MarDyn binary is a DEBUG build!" << std::endl; #endif - if( options.is_set_by_user("logfile") ) { - std::string logfileNamePrefix(options.get("logfile")); - Log::global_log->info() << "Using logfile with prefix " << logfileNamePrefix << std::endl; - delete Log::global_log; - Log::global_log = new Log::Logger(Log::Info, logfileNamePrefix); - } if( options.is_set_by_user("verbose") ) { Log::global_log->info() << "Enabling verbose log output." << std::endl; Log::global_log->set_log_level(Log::All); @@ -173,8 +181,8 @@ int main(int argc, char** argv) { registerSigsegvHandler(); // from SigsegvHandler.h } #endif - program_build_info(Log::global_log); - program_execution_info(argc, argv, Log::global_log); + log_program_build_info(); + log_program_execution_info(argc, argv); /* Run built in tests and exit */ @@ -183,7 +191,7 @@ int main(int argc, char** argv) { #ifdef ENABLE_MPI MPI_Finalize(); #endif - exit(testresult); // using exit here should be OK + std::exit(testresult); // using exit here should be OK } @@ -192,9 +200,10 @@ int main(int argc, char** argv) { auto numArgs = args.size(); if(numArgs != 1) { - Log::global_log->error() << "Incorrect number of arguments provided." << std::endl; op.print_usage(); - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Incorrect number of arguments provided." << std::endl; + MARDYN_EXIT(error_message.str()); } /* First read the given config file if it exists, then overwrite parameters with command line arguments. */ std::string configFileName(args[0]); @@ -202,8 +211,9 @@ int main(int argc, char** argv) { Log::global_log->info() << "Config file: " << configFileName << std::endl; simulation.readConfigFile(configFileName); } else { - Log::global_log->error() << "Cannot open config file '" << configFileName << "'" << std::endl; - mardyn_exit(-2); + std::ostringstream error_message; + error_message << "Cannot open config file '" << configFileName << "'" << std::endl; + MARDYN_EXIT(error_message.str()); } /* processing command line arguments */ @@ -281,7 +291,7 @@ int main(int argc, char** argv) { simulation.finalize(); - delete Log::global_log; + } // End of scope to exclude MPI_Init() and MPI_Finalize() #ifdef ENABLE_MPI MPI_Finalize(); diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 02adceb4a1..78b29b737b 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -72,6 +72,7 @@ #include "utils/FileUtils.h" #include "utils/Logger.h" +#include "utils/mardyn_assert.h" #include "longRange/LongRangeCorrection.h" #include "longRange/Homogeneous.h" @@ -173,21 +174,25 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { Log::global_log->info() << "Integrator type: " << integratorType << std::endl; if(integratorType == "Leapfrog") { #ifdef ENABLE_REDUCED_MEMORY_MODE - Log::global_log->error() << "The reduced memory mode (RMM) requires the LeapfrogRMM integrator." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "The reduced memory mode (RMM) requires the LeapfrogRMM integrator." << std::endl; + MARDYN_EXIT(error_message.str()); #endif _integrator = new Leapfrog(); } else if (integratorType == "LeapfrogRMM") { _integrator = new LeapfrogRMM(); } else { - Log::global_log-> error() << "Unknown integrator " << integratorType << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Unknown integrator " << integratorType << std::endl; + MARDYN_EXIT(error_message.str()); } _integrator->readXML(xmlconfig); _integrator->init(); xmlconfig.changecurrentnode(".."); } else { - Log::global_log->error() << "Integrator section missing." << std::endl; + std::ostringstream error_message; + error_message << "Integrator section missing." << std::endl; + MARDYN_EXIT(error_message.str()); } /* run section */ @@ -207,7 +212,9 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { } xmlconfig.changecurrentnode(".."); } else { - Log::global_log->error() << "Run section missing." << std::endl; + std::ostringstream error_message; + error_message << "Run section missing." << std::endl; + MARDYN_EXIT(error_message.str()); } /* ensemble */ @@ -223,8 +230,9 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { /* TODO: GrandCanonical terminates as readXML is not implemented and it is not tested yet. */ _ensemble = new GrandCanonicalEnsemble(); } else { - Log::global_log->error() << "Unknown ensemble type: " << ensembletype << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Unknown ensemble type: " << ensembletype << std::endl; + MARDYN_EXIT(error_message.str()); } _ensemble->readXML(xmlconfig); /** @todo Here we store data in the _domain member as long as we do not use the ensemble everywhere */ @@ -236,8 +244,9 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { xmlconfig.changecurrentnode(".."); } else { - Log::global_log->error() << "Ensemble section missing." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Ensemble section missing." << std::endl; + MARDYN_EXIT(error_message.str()); } /* algorithm */ @@ -257,14 +266,16 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { * maybe use map/list to store cutoffs for different potentials? */ _cutoffRadius = std::max(_cutoffRadius, _LJCutoffRadius); if(_cutoffRadius <= 0) { - Log::global_log->error() << "cutoff radius <= 0." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "cutoff radius <= 0." << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "dimensionless cutoff radius:\t" << _cutoffRadius << std::endl; xmlconfig.changecurrentnode(".."); } else { - Log::global_log->error() << "Cutoff section missing." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Cutoff section missing." << std::endl; + MARDYN_EXIT(error_message.str()); } /* electrostatics */ @@ -276,16 +287,17 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { _domain->setepsilonRF(epsilonRF); xmlconfig.changecurrentnode(".."); } else { - Log::global_log->error() << "Electrostatics section for reaction field setup missing." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Electrostatics section for reaction field setup missing." << std::endl; + MARDYN_EXIT(error_message.str()); } if (xmlconfig.changecurrentnode("electrostatic[@type='FastMultipoleMethod']")) { #ifdef MARDYN_AUTOPAS - Log::global_log->fatal() - << "The fast multipole method is not compatible with AutoPas. Please disable the AutoPas mode (ENABLE_AUTOPAS)!" - << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "The fast multipole method is not compatible with AutoPas. " + << "Please disable the AutoPas mode (ENABLE_AUTOPAS)!" << std::endl; + MARDYN_EXIT(error_message.str()); #endif _FMM = new bhfmm::FastMultipoleMethod(); _FMM->readXML(xmlconfig); @@ -339,12 +351,13 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { if (datastructuretype == "AutoPas" or datastructuretype == "AutoPasContainer") { // check if skin is specified if (xmlconfig.getNodeValue("skin", skin) == 0) { - Log::global_log->error() << "Skin not set in datastructure/AutoPas. " + std::ostringstream error_message; + error_message << "Skin not set in datastructure/AutoPas. " "This will lead to a different interaction length in the container " "vs the GeneralDomainDecomposition which can lead ALL to shrink the " "domain too small." << std::endl; - mardyn_exit(512435340); + MARDYN_EXIT(error_message.str()); } } else { Log::global_log->warning() << "Using the GeneralDomainDecomposition without AutoPas is not " @@ -359,18 +372,21 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { } Log::global_log->info() << "Using skin = " << skin << " for the GeneralDomainDecomposition." << std::endl; } else { - Log::global_log->error() << "Datastructure section missing" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Datastructure section missing" << std::endl; + MARDYN_EXIT(error_message.str()); } if(not xmlconfig.changecurrentnode("../parallelisation")){ - Log::global_log->error() << "Could not go back to parallelisation path. Aborting." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Could not go back to parallelisation path. Aborting." << std::endl; + MARDYN_EXIT(error_message.str()); } delete _domainDecomposition; _domainDecomposition = new GeneralDomainDecomposition(getcutoffRadius() + skin, _domain, forceLatchingToLinkedCellsGrid); } else { - Log::global_log->error() << "Unknown parallelisation type: " << parallelisationtype << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Unknown parallelisation type: " << parallelisationtype << std::endl; + MARDYN_EXIT(error_message.str()); } #else /* serial */ if(parallelisationtype != "DummyDecomposition") { @@ -378,7 +394,6 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { << "Executable was compiled without support for parallel execution: " << parallelisationtype << " not available. Using serial mode." << std::endl; - //mardyn_exit(1); } //_domainDecomposition = new DomainDecompBase(); // already set in initialize() #endif @@ -394,9 +409,10 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { Log::global_log->info() << "Using timer " << loadTimerStr << " for the load calculation." << std::endl; _timerForLoad = timers()->getTimer(loadTimerStr); if (not _timerForLoad) { - Log::global_log->error() << "'timerForLoad' set to a timer that does not exist('" << loadTimerStr + std::ostringstream error_message; + error_message << "'timerForLoad' set to a timer that does not exist('" << loadTimerStr << "')! Aborting!" << std::endl; - exit(1); + MARDYN_EXIT(error_message.str()); } std::size_t timerForLoadAveragingLength{1ul}; @@ -404,8 +420,9 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { Log::global_log->info() << "Averaging over " << timerForLoadAveragingLength << "time steps for the load calculation." << std::endl; if(timerForLoadAveragingLength < 1ul) { - Log::global_log->fatal() << "timerForLoadAveragingLength has to be at least 1" << std::endl; - mardyn_exit(15843); + std::ostringstream error_message; + error_message << "timerForLoadAveragingLength has to be at least 1" << std::endl; + MARDYN_EXIT(error_message.str()); } _lastTraversalTimeHistory.setCapacity(timerForLoadAveragingLength); @@ -443,8 +460,9 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { } else { #ifdef ENABLE_MPI - Log::global_log->error() << "Parallelisation section missing." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Parallelisation section missing." << std::endl; + MARDYN_EXIT(error_message.str()); #else /* serial */ // set _timerForLoad, s.t. it always exists. _timerForLoad = timers()->getTimer("SIMULATION_COMPUTATION"); @@ -459,10 +477,11 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { Log::global_log->info() << "Datastructure type: " << datastructuretype << std::endl; if(datastructuretype == "LinkedCells") { #ifdef MARDYN_AUTOPAS - Log::global_log->fatal() + std::ostringstream error_message; + error_message << "LinkedCells not compiled (use AutoPas instead, or compile with disabled autopas mode)!" << std::endl; - mardyn_exit(33); + MARDYN_EXIT(error_message.str()); #else _moleculeContainer = new LinkedCells(); /** @todo Review if we need to know the max cutoff radius usable with any datastructure. */ @@ -470,21 +489,24 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { _moleculeContainer->setCutoff(_cutoffRadius); #endif } else if(datastructuretype == "AdaptiveSubCells") { - Log::global_log->warning() << "AdaptiveSubCells no longer supported." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "AdaptiveSubCells no longer supported." << std::endl; + MARDYN_EXIT(error_message.str()); } else if(datastructuretype == "AutoPas" || datastructuretype == "AutoPasContainer") { #ifdef MARDYN_AUTOPAS Log::global_log->info() << "Using AutoPas container." << std::endl; _moleculeContainer = new AutoPasContainer(_cutoffRadius); Log::global_log->info() << "Setting cell cutoff radius for AutoPas container to " << _cutoffRadius << std::endl; #else - Log::global_log->fatal() << "AutoPas not compiled (use LinkedCells instead, or compile with enabled autopas mode)!" << std::endl; - mardyn_exit(33); + std::ostringstream error_message; + error_message << "AutoPas not compiled (use LinkedCells instead, or compile with enabled autopas mode)!" << std::endl; + MARDYN_EXIT(error_message.str()); #endif } else { - Log::global_log->error() << "Unknown data structure type: " << datastructuretype << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Unknown data structure type: " << datastructuretype << std::endl; + MARDYN_EXIT(error_message.str()); } _moleculeContainer->readXML(xmlconfig); @@ -495,8 +517,9 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { _domainDecomposition->updateSendLeavingWithCopies(sendTogether); xmlconfig.changecurrentnode(".."); } else { - Log::global_log->error() << "Datastructure section missing" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Datastructure section missing" << std::endl; + MARDYN_EXIT(error_message.str()); } // TODO: move parts to readXML in TemperatureControl? @@ -538,9 +561,9 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { _temperatureControl = new TemperatureControl(); _temperatureControl->readXML(xmlconfig); } else { - Log::global_log->error() << "Instance of TemperatureControl allready exist! Programm exit ..." - << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Instance of TemperatureControl already exist!" << std::endl; + MARDYN_EXIT(error_message.str()); } } else @@ -562,8 +585,9 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { std::string type; if( !xmlconfig.getNodeValue("@type", type) ) { - Log::global_log->error() << "LongRangeCorrection: Missing type specification. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "LongRangeCorrection: Missing type specification. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } if("planar" == type) { @@ -586,8 +610,9 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { } else { - Log::global_log->error() << "LongRangeCorrection: Wrong type. Expected type == homogeneous|planar|none. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "LongRangeCorrection: Wrong type. Expected type == homogeneous|planar|none. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } xmlconfig.changecurrentnode(".."); } else { @@ -599,7 +624,9 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { xmlconfig.changecurrentnode(".."); /* algorithm section */ } else { - Log::global_log->error() << "Algorithm section missing." << std::endl; + std::ostringstream error_message; + error_message << "Algorithm section missing." << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log -> info() << "Registering default plugins..." << std::endl; @@ -652,8 +679,9 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { } #endif else { - Log::global_log->error() << "Unknown phase space file type" << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Unknown phase space file type" << std::endl; + MARDYN_EXIT(error_message.str()); } } xmlconfig.changecurrentnode(oldpath); @@ -682,8 +710,9 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { _inputReader = new PerCellGenerator(); } else { - Log::global_log->error() << "Unknown generator: " << generatorName << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Unknown generator: " << generatorName << std::endl; + MARDYN_EXIT(error_message.str()); } _inputReader->readXML(xmlconfig); } @@ -717,8 +746,9 @@ void Simulation::readConfigFile(std::string filename) { initConfigXML(filename); } else { - Log::global_log->error() << "Unknown config file extension '" << extension << "'." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Unknown config file extension '" << extension << "'." << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -731,9 +761,10 @@ void Simulation::initConfigXML(const std::string& inputfilename) { Log::global_log->debug() << "Input XML:" << std::endl << std::string(inp) << std::endl; if(inp.changecurrentnode("/mardyn") < 0) { - Log::global_log->error() << "Cound not find root node /mardyn in XML input file." << std::endl; - Log::global_log->fatal() << "Not a valid MarDyn XML input file." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Cound not find root node /mardyn in XML input file." << std::endl; + error_message << "Not a valid MarDyn XML input file." << std::endl; + MARDYN_EXIT(error_message.str()); } std::string version("unknown"); @@ -747,8 +778,9 @@ void Simulation::initConfigXML(const std::string& inputfilename) { inp.changecurrentnode(".."); } // simulation-section else { - Log::global_log->error() << "Simulation section missing" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Simulation section missing" << std::endl; + MARDYN_EXIT(error_message.str()); } parseMiscOptions(inp); @@ -759,9 +791,10 @@ void Simulation::initConfigXML(const std::string& inputfilename) { } } catch (const std::exception& e) { - Log::global_log->error() << "Error in XML config. Please check your input file!" << std::endl; - Log::global_log->error() << "Exception: " << e.what() << std::endl; - mardyn_exit(7); + std::ostringstream error_message; + error_message << "Error in XML config. Please check your input file!" << std::endl; + error_message << "Exception: " << e.what() << std::endl; + MARDYN_EXIT(error_message.str()); } #ifdef ENABLE_MPI @@ -886,8 +919,9 @@ void Simulation::prepare_start() { Log::global_log->info() << "Initializing LongRangeCorrection" << std::endl; _longRangeCorrection->init(); } else { - Log::global_log->fatal() << "No _longRangeCorrection set!" << std::endl; - mardyn_exit(93742); + std::ostringstream error_message; + error_message << "No _longRangeCorrection set!" << std::endl; + MARDYN_EXIT(error_message.str()); } // longRangeCorrection is a site-wise force plugin, so we have to call it before updateForces() _longRangeCorrection->calculateLongRange(); @@ -980,9 +1014,12 @@ void Simulation::preSimLoopSteps() //sanity checks if(preSimLoopStepsDone || simulationDone || postSimLoopStepsDone) { - Log::global_log->error() << "Unexpected call to preSimLoopSteps()! Status: (pre sim loop steps done:" << preSimLoopStepsDone << ", simulation done: " << simulationDone << - ", post sim loop steps done: " << postSimLoopStepsDone << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Unexpected call to preSimLoopSteps()! " + << "Status: (pre sim loop steps done:" << preSimLoopStepsDone + << ", simulation done: " << simulationDone + << ", post sim loop steps done: " << postSimLoopStepsDone << std::endl; + MARDYN_EXIT(error_message.str()); } @@ -1043,9 +1080,12 @@ void Simulation::simulateOneTimestep() //sanity checks if(!preSimLoopStepsDone || simulationDone || postSimLoopStepsDone) { - Log::global_log->error() << "Unexpected call to simulateOneTimeStep()! Status: (pre sim loop steps done:" << preSimLoopStepsDone << ", simulation done: " << simulationDone << - ", post sim loop steps done: " << postSimLoopStepsDone << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Unexpected call to simulateOneTimeStep()! " + << "Status: (pre sim loop steps done:" << preSimLoopStepsDone + << ", simulation done: " << simulationDone + << ", post sim loop steps done: " << postSimLoopStepsDone << std::endl; + MARDYN_EXIT(error_message.str()); } #ifdef MAMICO_COUPLING @@ -1278,9 +1318,12 @@ void Simulation::postSimLoopSteps() //sanity checks if(!preSimLoopStepsDone || !simulationDone || postSimLoopStepsDone) { - Log::global_log->error() << "Unexpected call to postSimLoopSteps()! Status: (pre sim loop steps done:" << preSimLoopStepsDone << ", simulation done: " << simulationDone << - ", post sim loop steps done: " << postSimLoopStepsDone << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Unexpected call to postSimLoopSteps()! " + << "Status: (pre sim loop steps done:" << preSimLoopStepsDone + << ", simulation done: " << simulationDone + << ", post sim loop steps done: " << postSimLoopStepsDone << std::endl; + MARDYN_EXIT(error_message.str()); } @@ -1344,8 +1387,9 @@ void Simulation::pluginEndStepCall(unsigned long simstep) { << _domain->getGlobalUpot() << "\tp = " << _domain->getGlobalPressure() << std::endl; if (std::isnan(_domain->getGlobalCurrentTemperature()) || std::isnan(_domain->getGlobalUpot()) || std::isnan(_domain->getGlobalPressure())) { - Log::global_log->error() << "NaN detected, exiting." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "NaN detected, exiting." << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -1418,8 +1462,9 @@ void Simulation::performOverlappingDecompositionAndCellTraversalStep(double etim #ifdef ENABLE_MPI auto* dd = dynamic_cast(_domainDecomposition); if (not dd) { - Log::global_log->fatal() << "DomainDecompMPIBase* required for overlapping comm, but dynamic_cast failed." << std::endl; - mardyn_exit(873456); + std::ostringstream error_message; + error_message << "DomainDecompMPIBase* required for overlapping comm, but dynamic_cast failed." << std::endl; + MARDYN_EXIT(error_message.str()); } NonBlockingMPIMultiStepHandler nonBlockingMPIHandler {dd, _moleculeContainer, _domain, _cellProcessor}; @@ -1427,8 +1472,9 @@ void Simulation::performOverlappingDecompositionAndCellTraversalStep(double etim nonBlockingMPIHandler.performOverlappingTasks(forceRebalancing, etime); #else - Log::global_log->fatal() << "performOverlappingDecompositionAndCellTraversalStep() called with disabled MPI." << std::endl; - mardyn_exit(873457); + std::ostringstream error_message; + error_message << "performOverlappingDecompositionAndCellTraversalStep() called with disabled MPI." << std::endl; + MARDYN_EXIT(error_message.str()); #endif } diff --git a/src/bhfmm/FastMultipoleMethod.cpp b/src/bhfmm/FastMultipoleMethod.cpp index 3e4533219e..f40d474b52 100644 --- a/src/bhfmm/FastMultipoleMethod.cpp +++ b/src/bhfmm/FastMultipoleMethod.cpp @@ -67,10 +67,11 @@ void FastMultipoleMethod::init(double globalDomainLength[3], double bBoxMin[3], and _LJCellSubdivisionFactor != 2 and _LJCellSubdivisionFactor != 4 and _LJCellSubdivisionFactor != 8) { - Log::global_log->error() << "Fast Multipole Method: bad subdivision factor:" + std::ostringstream error_message; + error_message << "Fast Multipole Method: bad subdivision factor:" << _LJCellSubdivisionFactor << std::endl; - Log::global_log->error() << "expected 1,2,4 or 8" << std::endl; - mardyn_exit(5); + error_message << "expected 1,2,4 or 8" << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "Fast Multipole Method: each LJ cell will be subdivided in " @@ -107,8 +108,9 @@ void FastMultipoleMethod::init(double globalDomainLength[3], double bBoxMin[3], } else { // TODO: Debugging in Progress! #if defined(ENABLE_MPI) - Log::global_log->error() << "MPI in combination with adaptive is not supported yet" << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "MPI in combination with adaptive is not supported yet" << std::endl; + MARDYN_EXIT(error_message.str()); #endif //int threshold = 100; _pseudoParticleContainer = new AdaptivePseudoParticleContainer( @@ -313,8 +315,9 @@ void FastMultipoleMethod::runner(int type, void *data) { #else #pragma omp critical { - Log::global_log->error() << "Quicksched runner without FMM_FFT not implemented!" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Quicksched runner without FMM_FFT not implemented!" << std::endl; + MARDYN_EXIT(error_message.str()); } #endif /* FMM_FFT */ } diff --git a/src/bhfmm/HaloBufferNoOverlap.h b/src/bhfmm/HaloBufferNoOverlap.h index 68af77b11b..3bdce11545 100644 --- a/src/bhfmm/HaloBufferNoOverlap.h +++ b/src/bhfmm/HaloBufferNoOverlap.h @@ -11,25 +11,24 @@ template class HaloBufferNoOverlap { public: HaloBufferNoOverlap(int xHaloSize, int yHaloSize, int zHaloSize); - virtual ~HaloBufferNoOverlap(); - void initOverlap(); - //void initNoOverlap(int xHaloSize, int yHaloSize, int zHaloSize); - T * getFrontBuffer(){ + virtual ~HaloBufferNoOverlap() = default; + + auto & getFrontBuffer(){ return _frontBuffer; } - T * getBackBuffer(){ + auto & getBackBuffer(){ return _backBuffer; } - T * getTopBuffer(){ + auto & getTopBuffer(){ return _topBuffer; } - T * getBottomBuffer(){ + auto & getBottomBuffer(){ return _bottomBuffer; } - T * getLeftBuffer(){ + auto & getLeftBuffer(){ return _leftBuffer; } - T * getRightBuffer(){ + auto & getRightBuffer(){ return _rightBuffer; } int getXSize(){ @@ -44,10 +43,9 @@ template class HaloBufferNoOverlap { void clear(); private: - T* _leftBuffer, * _rightBuffer, * _topBuffer, * _bottomBuffer, * _frontBuffer, * _backBuffer; //arrays for MPI halo transfer (send) + // arrays for MPI halo transfer (send) + std::vector _leftBuffer, _rightBuffer, _topBuffer, _bottomBuffer, _frontBuffer, _backBuffer; int _xHaloSize,_yHaloSize,_zHaloSize; - - }; #include @@ -59,33 +57,23 @@ HaloBufferNoOverlap::HaloBufferNoOverlap(int xHaloSize, int yHaloSize, int zH _yHaloSize = yHaloSize; _zHaloSize = zHaloSize; - _leftBuffer = new T[_xHaloSize]; - _rightBuffer = new T[_xHaloSize]; + _leftBuffer = std::vector(_xHaloSize); + _rightBuffer = std::vector(_xHaloSize); - _bottomBuffer = new T[_yHaloSize]; - _topBuffer = new T[_yHaloSize]; + _bottomBuffer = std::vector(_yHaloSize); + _topBuffer = std::vector(_yHaloSize); - _backBuffer = new T[_zHaloSize]; - _frontBuffer = new T[_zHaloSize]; -} - -template -HaloBufferNoOverlap::~HaloBufferNoOverlap() { - delete[] _leftBuffer; - delete[] _rightBuffer; - delete[] _bottomBuffer; - delete[] _topBuffer; - delete[] _backBuffer; - delete[] _frontBuffer; + _backBuffer = std::vector(_zHaloSize); + _frontBuffer = std::vector(_zHaloSize); } template void HaloBufferNoOverlap::clear(){ - std::fill(_leftBuffer, _leftBuffer + _xHaloSize , 0.0); - std::fill(_rightBuffer, _rightBuffer + _xHaloSize , 0.0); - std::fill(_frontBuffer, _frontBuffer + _zHaloSize, 0.0); - std::fill(_backBuffer, _backBuffer + _zHaloSize, 0.0); - std::fill(_topBuffer, _topBuffer + _yHaloSize, 0.0); - std::fill(_bottomBuffer, _bottomBuffer + _yHaloSize, 0.0); + std::fill(_leftBuffer.begin(), _leftBuffer.end(), 0.0); + std::fill(_rightBuffer.begin(), _rightBuffer.end(), 0.0); + std::fill(_frontBuffer.begin(), _frontBuffer.end(), 0.0); + std::fill(_backBuffer.begin(), _backBuffer.end(), 0.0); + std::fill(_topBuffer.begin(), _topBuffer.end(), 0.0); + std::fill(_bottomBuffer.begin(), _bottomBuffer.end(), 0.0); } #endif /* HALOBUFFER_H_ */ diff --git a/src/bhfmm/HaloBufferOverlap.h b/src/bhfmm/HaloBufferOverlap.h index 71f21d0ca8..58a842e48d 100644 --- a/src/bhfmm/HaloBufferOverlap.h +++ b/src/bhfmm/HaloBufferOverlap.h @@ -10,6 +10,7 @@ #include "bhfmm/utils/Vector3.h" #include #include +#include #ifdef ENABLE_MPI #include "mpi.h" @@ -21,7 +22,7 @@ class HaloBufferOverlap { HaloBufferOverlap(Vector3 areaHaloSize, Vector3 edgeHaloSize, int cornerHaloSize, MPI_Comm comm, std::vector& areaNeighbours,std::vector& edgeNeighbours,std::vector& cornerNeighbours, bool isSend, bool doNT, int areaNumber = 6, int edgeNumber = 12, int cornerNumber = 8 , std::vector>> allRanks = std::vector>>(0), Vector3 numCellsOnGlobalLevel = Vector3(1), bool fuseGlobalCommunication = false); - virtual ~HaloBufferOverlap(); + virtual ~HaloBufferOverlap() = default; void startCommunication(); //communicate without persistent sends and receives void communicate(bool postProcessing); @@ -29,13 +30,13 @@ class HaloBufferOverlap { void wait(); int testIfFinished(); - std::vector& getAreaBuffers(){ + auto & getAreaBuffers(){ return _areaBuffers; } - std::vector& getEdgeBuffers(){ + auto & getEdgeBuffers(){ return _edgeBuffers; } - std::vector& getCornerBuffers(){ + auto & getCornerBuffers(){ return _cornerBuffers; } @@ -48,13 +49,15 @@ class HaloBufferOverlap { void communicateLevelGlobal(int level, int globalLevel, int offset, bool backCommunication); void initCommunicationDouble(); void fillArraySizes(Vector3 areaSizes, Vector3 edgeSizes); - std::vector _areaBuffers, _edgeBuffers, _cornerBuffers; //arrays for MPI halo transfer (send) + std::vector> _areaBuffers, _edgeBuffers, _cornerBuffers; //arrays for MPI halo transfer (send) Vector3 _areaHaloSize,_edgeHaloSize; int _cornerHaloSize; //these arrays save for every halo element the specific size -> if neighbour rank order is changed these arrays have to be changed too but nothing else std::vector _areaHaloSizes, _edgeHaloSizes; //corner Arrays are always of the same size! std::vector _areaNeighbours, _edgeNeighbours,_cornerNeighbours; - MPI_Request * _areaRequests, *_edgeRequests, *_cornerRequests; + std::vector _areaRequests; + std::vector _edgeRequests; + std::vector _cornerRequests; MPI_Comm _comm; bool _isSend; bool _doNT; @@ -74,7 +77,8 @@ class HaloBufferOverlap { template HaloBufferOverlap::HaloBufferOverlap(Vector3 areaHaloSize, Vector3 edgeHaloSize, int cornerHaloSize, MPI_Comm comm, std::vector& areaNeighbours,std::vector& edgeNeighbours,std::vector& cornerNeighbours, bool isSend, bool doNT, int areaNumber, int edgeNumber, int cornerNumber, std::vector>> allRanks, Vector3 numCellsOnGlobalLevel, bool fuseGlobalCommunication): -_areaBuffers(areaNumber), _edgeBuffers(edgeNumber), _cornerBuffers(cornerNumber), _areaHaloSize(areaHaloSize), _edgeHaloSize(edgeHaloSize), _areaNeighbours(areaNeighbours), _edgeNeighbours(edgeNeighbours), _cornerNeighbours(cornerNeighbours), _doNT(doNT), _allRanks(allRanks), _numCellsOnGlobalLevel(numCellsOnGlobalLevel), _fuseGlobalCommunication(fuseGlobalCommunication) { +_areaBuffers(areaNumber), _edgeBuffers(edgeNumber), _cornerBuffers(cornerNumber), _areaHaloSize(areaHaloSize), _edgeHaloSize(edgeHaloSize), _areaNeighbours(areaNeighbours), _edgeNeighbours(edgeNeighbours), _cornerNeighbours(cornerNeighbours), _doNT(doNT), _allRanks(allRanks), _numCellsOnGlobalLevel(numCellsOnGlobalLevel), _fuseGlobalCommunication(fuseGlobalCommunication), +_areaRequests(areaNumber), _edgeRequests(edgeNumber), _cornerRequests(cornerNumber) { _cornerHaloSize = cornerHaloSize; if(edgeNumber == 0){ @@ -91,41 +95,28 @@ _areaBuffers(areaNumber), _edgeBuffers(edgeNumber), _cornerBuffers(cornerNumber) _isGlobal = false; } - if(areaNumber != 0){ - - _areaRequests = new MPI_Request[_areaBuffers.size()]; -// std::cout << "areaBufferSize: "<<_areaBuffers.size() << "\n"; - } - if(edgeNumber != 0){ - _edgeRequests = new MPI_Request[_edgeBuffers.size()]; - } - if(cornerNumber != 0){ - _cornerRequests = new MPI_Request[_cornerBuffers.size()]; - } - fillArraySizes(areaHaloSize,edgeHaloSize); -// _cornerHaloSizes = new int[_cornerBuffers.size()]; _comm = comm; if(areaNumber != 0){ for(unsigned int i=0; i<_areaBuffers.size();i++){ if(!_isGlobal){ - _areaBuffers[i] = new T[_areaHaloSizes[i]]; + _areaBuffers[i] = std::vector(_areaHaloSizes[i]); } else{ - _areaBuffers[i] = new T[_areaHaloSizes[0]]; + _areaBuffers[i] = std::vector(_areaHaloSizes[0]); } } } if(edgeNumber != 0){ for(unsigned int i=0; i<_edgeBuffers.size();i++){ - _edgeBuffers[i] = new T[_edgeHaloSizes[i]]; + _edgeBuffers[i] = std::vector(_edgeHaloSizes[i]); } } if(cornerNumber != 0){ for(unsigned int i=0; i<_cornerBuffers.size();i++){ - _cornerBuffers[i] = new T[cornerHaloSize]; + _cornerBuffers[i] = std::vector(cornerHaloSize); } } _isSend = isSend; @@ -182,48 +173,23 @@ void HaloBufferOverlap::fillArraySizes(Vector3 areaSizes, Vector3 e _edgeHaloSizes[i] = edgeSizes[2-i/4]; } } - else{ -// _edgeHaloSizes = new int[_edgeBuffers.size()]; -// for(unsigned int i = 0; i < _edgeBuffers.size(); i++){ -// _edgeHaloSizes[i] = edgeSizes[0]; -// } - } -} -template -HaloBufferOverlap::~HaloBufferOverlap() { - - for(unsigned int i=0; i<_areaBuffers.size();i++){ -// MPI_Request_free(&_areaRequests[i]); - delete[] (_areaBuffers[i]); - } - if(!_isGlobal){ - - for(unsigned int i=0; i<_edgeBuffers.size();i++){ - // MPI_Request_free(&_edgeRequests[i]); - delete[] _edgeBuffers[i]; - } - for(unsigned int i=0; i<_cornerBuffers.size();i++){ - // MPI_Request_free(&_cornerRequests[i]); - delete[] _cornerBuffers[i]; - } - } } template void HaloBufferOverlap::clear(){ for(unsigned int i = 0; i < _areaBuffers.size(); i++){ if(!_isGlobal){ - std::fill(_areaBuffers[i], _areaBuffers[i] + _areaHaloSizes[i] , 0.0); + std::fill(_areaBuffers[i].begin(), _areaBuffers[i].end(), 0.0); } else{ - std::fill(_areaBuffers[i], _areaBuffers[i] + _areaHaloSizes[0] , 0.0); + std::fill(_areaBuffers[i].begin(), _areaBuffers[i].end(), 0.0); } } for(unsigned int i = 0; i < _edgeBuffers.size(); i++){ - std::fill(_edgeBuffers[i], _edgeBuffers[i] + _edgeHaloSizes[i] , 0.0); + std::fill(_edgeBuffers[i].begin(), _edgeBuffers[i].end(), 0.0); } for(unsigned int i = 0; i < _cornerBuffers.size(); i++){ - std::fill(_cornerBuffers[i], _cornerBuffers[i] + _cornerHaloSize , 0.0); + std::fill(_cornerBuffers[i].begin(), _cornerBuffers[i].end(), 0.0); } } @@ -232,35 +198,30 @@ template void HaloBufferOverlap::initCommunicationDouble(){ for (unsigned int i = 0; i < _areaBuffers.size(); i++){ if(_isSend){ - MPI_Rsend_init(_areaBuffers[i], _areaHaloSizes[i], MPI_DOUBLE, _areaNeighbours[i], i + 42, _comm, &_areaRequests[i]); - //MPI_Rsend_init(_areaBuffers[i], _areaHaloSize, MPI_DOUBLE, _areaNeighbours[i], i + 42, _comm, &_areaRequests[i]); - + MPI_Rsend_init(_areaBuffers[i].data(), _areaHaloSizes[i], MPI_DOUBLE, _areaNeighbours[i], i + 42, _comm, &_areaRequests[i]); } else{ //adjusts that the tag of receive corresponds to send int indexShift = (i%2 == 0)? +1: -1; - MPI_Recv_init(_areaBuffers[i], _areaHaloSizes[i], MPI_DOUBLE, _areaNeighbours[i], i + 42 + indexShift, _comm, &_areaRequests[i]); + MPI_Recv_init(_areaBuffers[i].data(), _areaHaloSizes[i], MPI_DOUBLE, _areaNeighbours[i], i + 42 + indexShift, _comm, &_areaRequests[i]); } } for (unsigned int i = 0; i < _edgeBuffers.size(); i++){ if(_isSend){ - MPI_Rsend_init(_edgeBuffers[i], _edgeHaloSizes[i], MPI_DOUBLE, _edgeNeighbours[i], i + 42, _comm, &_edgeRequests[i]); - //MPI_Rsend_init(_edgeBuffers[i], _edgeHaloSize, MPI_DOUBLE, _edgeNeighbours[i], i + 42, _comm, &_edgeRequests[i]); - + MPI_Rsend_init(_edgeBuffers[i].data(), _edgeHaloSizes[i], MPI_DOUBLE, _edgeNeighbours[i], i + 42, _comm, &_edgeRequests[i]); } else{ int indexShift = (i%2 == 0)? +1: -1; - MPI_Recv_init(_edgeBuffers[i], _edgeHaloSizes[i], MPI_DOUBLE, _edgeNeighbours[i], i + 42 + indexShift, _comm, &_edgeRequests[i]); + MPI_Recv_init(_edgeBuffers[i].data(), _edgeHaloSizes[i], MPI_DOUBLE, _edgeNeighbours[i], i + 42 + indexShift, _comm, &_edgeRequests[i]); } } for (unsigned int i = 0; i < _cornerBuffers.size(); i++){ if(_isSend){ - MPI_Rsend_init(_cornerBuffers[i], _cornerHaloSize, MPI_DOUBLE, _cornerNeighbours[i], i + 42, _comm, &_cornerRequests[i]); - // MPI_Rsend_init(_cornerBuffers[i], _cornerHaloSize, MPI_DOUBLE, _cornerNeighbours[i], i + 42, _comm, &_cornerRequests[i]); + MPI_Rsend_init(_cornerBuffers[i].data(), _cornerHaloSize, MPI_DOUBLE, _cornerNeighbours[i], i + 42, _comm, &_cornerRequests[i]); } else{ int indexShift = (i%2 == 0)? +1: -1; - MPI_Recv_init(_cornerBuffers[i], _cornerHaloSize, MPI_DOUBLE, _cornerNeighbours[i], i + 42 + indexShift, _comm, &_cornerRequests[i]); + MPI_Recv_init(_cornerBuffers[i].data(), _cornerHaloSize, MPI_DOUBLE, _cornerNeighbours[i], i + 42 + indexShift, _comm, &_cornerRequests[i]); } } } @@ -283,13 +244,11 @@ void HaloBufferOverlap::communicate(bool postProcessing){ } } if(postProcessing) - MPI_Isend(_areaBuffers[i], _areaHaloSizes[i], MPI_DOUBLE, _areaNeighbours[i], i + 42, _comm, &_areaRequests[requestIndex]); + MPI_Isend(_areaBuffers[i].data(), _areaHaloSizes[i], MPI_DOUBLE, _areaNeighbours[i], i + 42, _comm, &_areaRequests[requestIndex]); else - MPI_Irsend(_areaBuffers[i], _areaHaloSizes[i], MPI_DOUBLE, _areaNeighbours[i], i + 42, _comm, &_areaRequests[requestIndex]); + MPI_Irsend(_areaBuffers[i].data(), _areaHaloSizes[i], MPI_DOUBLE, _areaNeighbours[i], i + 42, _comm, &_areaRequests[requestIndex]); requestIndex++; - //MPI_Rsend_init(_areaBuffers[i], _areaHaloSize, MPI_DOUBLE, _areaNeighbours[i], i + 42, _comm, &_areaRequests[i]); - } else{ if(_doNT){ @@ -306,7 +265,7 @@ void HaloBufferOverlap::communicate(bool postProcessing){ } //adjusts that the tag of receive corresponds to send int indexShift = (i%2 == 0)? +1: -1; - MPI_Irecv(_areaBuffers[i], _areaHaloSizes[i], MPI_DOUBLE, _areaNeighbours[i], i + 42 + indexShift, _comm, &_areaRequests[requestIndex]); + MPI_Irecv(_areaBuffers[i].data(), _areaHaloSizes[i], MPI_DOUBLE, _areaNeighbours[i], i + 42 + indexShift, _comm, &_areaRequests[requestIndex]); requestIndex++; } } @@ -326,12 +285,10 @@ void HaloBufferOverlap::communicate(bool postProcessing){ } } if(postProcessing) - MPI_Isend(_edgeBuffers[i], _edgeHaloSizes[i], MPI_DOUBLE, _edgeNeighbours[i], i + 42, _comm, &_edgeRequests[requestIndex]); + MPI_Isend(_edgeBuffers[i].data(), _edgeHaloSizes[i], MPI_DOUBLE, _edgeNeighbours[i], i + 42, _comm, &_edgeRequests[requestIndex]); else - MPI_Irsend(_edgeBuffers[i], _edgeHaloSizes[i], MPI_DOUBLE, _edgeNeighbours[i], i + 42, _comm, &_edgeRequests[requestIndex]); + MPI_Irsend(_edgeBuffers[i].data(), _edgeHaloSizes[i], MPI_DOUBLE, _edgeNeighbours[i], i + 42, _comm, &_edgeRequests[requestIndex]); requestIndex++; - //MPI_Rsend_init(_edgeBuffers[i], _edgeHaloSize, MPI_DOUBLE, _edgeNeighbours[i], i + 42, _comm, &_edgeRequests[i]); - } else{ if(_doNT){ @@ -347,7 +304,7 @@ void HaloBufferOverlap::communicate(bool postProcessing){ } } int indexShift = (i%2 == 0)? +1: -1; - MPI_Irecv(_edgeBuffers[i], _edgeHaloSizes[i], MPI_DOUBLE, _edgeNeighbours[i], i + 42 + indexShift, _comm, &_edgeRequests[requestIndex]); + MPI_Irecv(_edgeBuffers[i].data(), _edgeHaloSizes[i], MPI_DOUBLE, _edgeNeighbours[i], i + 42 + indexShift, _comm, &_edgeRequests[requestIndex]); requestIndex++; } } @@ -355,13 +312,12 @@ void HaloBufferOverlap::communicate(bool postProcessing){ if(not(_doNT)){ for (unsigned int i = 0; i < _cornerBuffers.size(); i++){ if(_isSend){ - MPI_Irsend(_cornerBuffers[i], _cornerHaloSize, MPI_DOUBLE, _cornerNeighbours[i], i + 42, _comm, &_cornerRequests[requestIndex]); + MPI_Irsend(_cornerBuffers[i].data(), _cornerHaloSize, MPI_DOUBLE, _cornerNeighbours[i], i + 42, _comm, &_cornerRequests[requestIndex]); requestIndex++; - // MPI_Rsend_init(_cornerBuffers[i], _cornerHaloSize, MPI_DOUBLE, _cornerNeighbours[i], i + 42, _comm, &_cornerRequests[i]); } else{ int indexShift = (i%2 == 0)? +1: -1; - MPI_Irecv(_cornerBuffers[i], _cornerHaloSize, MPI_DOUBLE, _cornerNeighbours[i], i + 42 + indexShift, _comm, &_cornerRequests[requestIndex]); + MPI_Irecv(_cornerBuffers[i].data(), _cornerHaloSize, MPI_DOUBLE, _cornerNeighbours[i], i + 42 + indexShift, _comm, &_cornerRequests[requestIndex]); requestIndex++; } } @@ -481,31 +437,42 @@ void HaloBufferOverlap::communicateLevelGlobal(int level, int globalLevel, in int numCellsOnLevel = (level == globalLevel)? _numCellsOnGlobalLevel[0] * _numCellsOnGlobalLevel[1] * _numCellsOnGlobalLevel[2] : 1; if(_isSend){ if(!backCommunication){ - MPI_Irsend(_areaBuffers[8*(globalLevel-level) + 4*zOffset + 2*yOffset + xOffset], _areaHaloSizes[0], MPI_DOUBLE, rank, 1000 + zOffset * 4 + yOffset * 2 + xOffset + 8 * (globalLevel - level), _comm, &_areaRequests[indexPosition + offset]); + MPI_Irsend(_areaBuffers[8*(globalLevel-level) + 4*zOffset + 2*yOffset + xOffset].data(), + _areaHaloSizes[0], + MPI_DOUBLE, + rank, + 1000 + zOffset * 4 + yOffset * 2 + xOffset + 8 * (globalLevel - level), + _comm, + &_areaRequests[indexPosition + offset]); } else{ if(_fuseGlobalCommunication){ //in the back communication only 1 (or equal to the number of cells one owns on global level) cell is send instead of 8 - MPI_Isend(_areaBuffers[indexPosition + offset], _areaHaloSizes[0] / 8 * numCellsOnLevel , MPI_DOUBLE, rank, 1000 + zOffset * 4 + yOffset * 2 + xOffset + 8 * (globalLevel - level), _comm, &_areaRequests[indexPosition + offset]); + MPI_Isend(_areaBuffers[indexPosition + offset].data(), + _areaHaloSizes[0] / 8 * numCellsOnLevel , MPI_DOUBLE, rank, + 1000 + zOffset * 4 + yOffset * 2 + xOffset + 8 * (globalLevel - level), + _comm, &_areaRequests[indexPosition + offset]); } else{ - MPI_Isend(_areaBuffers[indexPosition + offset], _areaHaloSizes[0], MPI_DOUBLE, rank, 1000 + zOffset * 4 + yOffset * 2 + xOffset + 8 * (globalLevel - level), _comm, &_areaRequests[indexPosition + offset]); + MPI_Isend(_areaBuffers[indexPosition + offset].data(), + _areaHaloSizes[0], MPI_DOUBLE, rank, + 1000 + zOffset * 4 + yOffset * 2 + xOffset + 8 * (globalLevel - level), + _comm, &_areaRequests[indexPosition + offset]); } } indexPosition++; - // MPI_Rsend_init(_cornerBuffers[i], _cornerHaloSize, MPI_DOUBLE, _cornerNeighbours[i], i + 42, _comm, &_cornerRequests[i]); } else{ // std::cout << indexPosition << "\n"; // MPI_Barrier(_comm); if(!backCommunication){ - MPI_Irecv(_areaBuffers[indexPosition + offset], _areaHaloSizes[0], MPI_DOUBLE, rank, 1000 + zOffset * 4 + yOffset * 2 + xOffset + 8 * (globalLevel - level), _comm, &_areaRequests[indexPosition + offset]); + MPI_Irecv(_areaBuffers[indexPosition + offset].data(), _areaHaloSizes[0], MPI_DOUBLE, rank, 1000 + zOffset * 4 + yOffset * 2 + xOffset + 8 * (globalLevel - level), _comm, &_areaRequests[indexPosition + offset]); } else{ if(_fuseGlobalCommunication){ //in the back communication only 1 (or equal to the number of cells one owns on global level) cell is send instead if 8 - MPI_Irecv(_areaBuffers[indexPosition + offset], _areaHaloSizes[0] / 8 * numCellsOnLevel, MPI_DOUBLE, rank, 1000 + zOffset * 4 + yOffset * 2 + xOffset + 8 * (globalLevel - level), _comm, &_areaRequests[indexPosition + offset]); + MPI_Irecv(_areaBuffers[indexPosition + offset].data(), _areaHaloSizes[0] / 8 * numCellsOnLevel, MPI_DOUBLE, rank, 1000 + zOffset * 4 + yOffset * 2 + xOffset + 8 * (globalLevel - level), _comm, &_areaRequests[indexPosition + offset]); } else{ - MPI_Irecv(_areaBuffers[indexPosition + offset], _areaHaloSizes[0], MPI_DOUBLE, rank, 1000 + zOffset * 4 + yOffset * 2 + xOffset + 8 * (globalLevel - level), _comm, &_areaRequests[indexPosition + offset]); + MPI_Irecv(_areaBuffers[indexPosition + offset].data(), _areaHaloSizes[0], MPI_DOUBLE, rank, 1000 + zOffset * 4 + yOffset * 2 + xOffset + 8 * (globalLevel - level), _comm, &_areaRequests[indexPosition + offset]); } } indexPosition++; @@ -528,15 +495,14 @@ template void HaloBufferOverlap::startCommunication(){ //outdated!!! if(not(_doNT)){ - MPI_Startall(_areaBuffers.size(), _areaRequests); - MPI_Startall(_edgeBuffers.size(), _edgeRequests); - MPI_Startall(_cornerBuffers.size(), _cornerRequests); + MPI_Startall(_areaBuffers.size(), _areaRequests.data()); + MPI_Startall(_edgeBuffers.size(), _edgeRequests.data()); + MPI_Startall(_cornerBuffers.size(), _cornerRequests.data()); } else{ - MPI_Startall(4, _areaRequests); - MPI_Startall(2, _edgeRequests); + MPI_Startall(4, _areaRequests.data()); + MPI_Startall(2, _edgeRequests.data()); } -// std::cout << _areaBuffers.size() << _edgeBuffers.size() << _cornerBuffers.size() <<"\n"; } template @@ -544,20 +510,20 @@ void HaloBufferOverlap::wait(){ //outdated!!! if(not(_doNT)){ MPI_Status * areaStatusArray = new MPI_Status[_areaBuffers.size()]; - MPI_Waitall(_areaBuffers.size(),_areaRequests, areaStatusArray); + MPI_Waitall(_areaBuffers.size(),_areaRequests.data(), areaStatusArray); MPI_Status * edgeStatusArray = new MPI_Status[_edgeBuffers.size()]; - MPI_Waitall(_edgeBuffers.size(),_edgeRequests, edgeStatusArray); + MPI_Waitall(_edgeBuffers.size(),_edgeRequests.data(), edgeStatusArray); MPI_Status * cornerStatusArray = new MPI_Status[_cornerBuffers.size()]; - MPI_Waitall(_cornerBuffers.size(),_cornerRequests, cornerStatusArray); + MPI_Waitall(_cornerBuffers.size(),_cornerRequests.data(), cornerStatusArray); } else{ MPI_Status * areaStatusArray = new MPI_Status[4]; - MPI_Waitall(4,_areaRequests, areaStatusArray); + MPI_Waitall(4,_areaRequests.data(), areaStatusArray); MPI_Status * edgeStatusArray = new MPI_Status[2]; - MPI_Waitall(2,_edgeRequests, edgeStatusArray); + MPI_Waitall(2,_edgeRequests.data(), edgeStatusArray); } } @@ -568,31 +534,30 @@ int HaloBufferOverlap::testIfFinished(){ if(!_isGlobal){ std::vector areaStatusArray(_areaBuffers.size()); - MPI_Testall(_areaBuffers.size(),_areaRequests, &areaFlag, areaStatusArray.data()); + MPI_Testall(_areaBuffers.size(),_areaRequests.data(), &areaFlag, areaStatusArray.data()); std::vector edgeStatusArray(_edgeBuffers.size()); - MPI_Testall(_edgeBuffers.size(),_edgeRequests, &edgeFlag, edgeStatusArray.data()); + MPI_Testall(_edgeBuffers.size(),_edgeRequests.data(), &edgeFlag, edgeStatusArray.data()); std::vector cornerStatusArray(_cornerBuffers.size()); - MPI_Testall(_cornerBuffers.size(),_cornerRequests, &cornerFlag, cornerStatusArray.data()); + MPI_Testall(_cornerBuffers.size(),_cornerRequests.data(), &cornerFlag, cornerStatusArray.data()); return areaFlag * edgeFlag * cornerFlag; } else{ -// std::cout << _areaBuffers.size() << "\n"; if(_areaBuffers.size() == 0) return true; std::vector areaStatusArray(_areaBuffers.size()); - MPI_Testall(_areaBuffers.size(),_areaRequests, &areaFlag, areaStatusArray.data()); + MPI_Testall(_areaBuffers.size(),_areaRequests.data(), &areaFlag, areaStatusArray.data()); return areaFlag; } } else{ if(!_isGlobal){ MPI_Status areaStatusArray[4]; - MPI_Testall(4,_areaRequests, &areaFlag, areaStatusArray); + MPI_Testall(4,_areaRequests.data(), &areaFlag, areaStatusArray); MPI_Status edgeStatusArray[2]; - MPI_Testall(2,_edgeRequests, &edgeFlag, edgeStatusArray); + MPI_Testall(2,_edgeRequests.data(), &edgeFlag, edgeStatusArray); return areaFlag * edgeFlag; } else{ @@ -606,7 +571,7 @@ int HaloBufferOverlap::testIfFinished(){ } if(numRequests == 0) return true; std::vector areaStatusArray(numRequests); - MPI_Testall(numRequests,_areaRequests, &areaFlag, areaStatusArray.data()); + MPI_Testall(numRequests,_areaRequests.data(), &areaFlag, areaStatusArray.data()); // MPI_Status status; // // for(int i= 0; i +#include #include #include #ifdef _OPENMP @@ -111,8 +112,9 @@ UniformPseudoParticleContainer::UniformPseudoParticleContainer( _comm = domainDecomp.getCommunicator(); #endif #if WIGNER == 1 - //global_log->error() << "not supported yet" << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "WIGNER not supported yet" << std::endl; + MARDYN_EXIT(error_message.str()); #endif #ifdef ENABLE_MPI /* @@ -175,8 +177,9 @@ UniformPseudoParticleContainer::UniformPseudoParticleContainer( MPI_Comm_size(_comm,&numProcessors); _globalLevel = ceil(log2(numProcessors)/3.0); if(_globalLevel > _maxLevel){ - std::cout << "too many MPI ranks \n"; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Too many MPI ranks" << std::endl; + MARDYN_EXIT(error_message.str()); } //numProcessers has to be a power of 2 mardyn_assert(pow(2,log2(numProcessors)) == numProcessors); @@ -318,8 +321,7 @@ UniformPseudoParticleContainer::UniformPseudoParticleContainer( _globalNumCells = pow(_globalNumCellsPerDim, 3); #if defined(ENABLE_MPI) _globalLevelNumCells = pow(8,_globalLevel); - _occVector = new int[_globalLevelNumCells]; - std::fill(_occVector, _occVector + _globalLevelNumCells, 0); + _occVector = std::vector(_globalLevelNumCells, 0); #endif _coeffVectorLength = 0; _expansionSize = 0; @@ -378,8 +380,9 @@ UniformPseudoParticleContainer::UniformPseudoParticleContainer( int size2; MPI_Comm_size(_neighbourhoodComms[i], &size2); if(size2 > 8){ //neighbourhood comms need to have size 8 - std::cout << "Error wrong communicator \n"; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Error wrong communicator" << std::endl; + MARDYN_EXIT(error_message.str()); } } #endif @@ -489,8 +492,7 @@ UniformPseudoParticleContainer::UniformPseudoParticleContainer( _coeffVectorLength = _expansionSize*numCells; #endif - _coeffVector = new double[_coeffVectorLength * 2]; - std::fill(_coeffVector, _coeffVector + _coeffVectorLength * 2, 0.0); + _coeffVector = std::vector(_coeffVectorLength * 2, 0.0); Log::global_log->info() << "UniformPseudoParticleContainer: coeffVectorLength=" << _coeffVectorLength << " Size of MPI Buffers is " << (8 * (_coeffVectorLength * 2 + _globalNumCells) @@ -534,9 +536,7 @@ UniformPseudoParticleContainer::UniformPseudoParticleContainer( UniformPseudoParticleContainer::~UniformPseudoParticleContainer() { delete _leafContainer; - delete[] _coeffVector; #if defined(ENABLE_MPI) - delete[] _occVector; if(!_overlapComm){ delete _multipoleBuffer; delete _multipoleRecBuffer; @@ -1174,7 +1174,7 @@ int UniformPseudoParticleContainer::optimizeAllReduce(/*ParticleContainer* ljCon } _coeffVectorLength = _expansionSize*numCells; - _coeffVector = new double[_coeffVectorLength * 2]; + _coeffVector = std::vector(_coeffVectorLength * 2); _leafContainer->clearParticles(); @@ -1253,21 +1253,20 @@ void UniformPseudoParticleContainer::upwardPass(P2MCellProcessor* cp) { } int cellIndex = ((coordsLevel[2]) * mpCells + coordsLevel[1]) * mpCells + coordsLevel[0]; if(!_fuseGlobalCommunication){ - double * buffer = new double[2*_expansionSize]; + auto buffer = std::vector(2*_expansionSize); MpCell & currentCell = _mpCellGlobalTop[curLevel][cellIndex]; int index = 0; currentCell.multipole.writeValuesToMPIBuffer(buffer,index); - MPI_Allreduce(MPI_IN_PLACE,buffer,2 * _expansionSize,MPI_DOUBLE,MPI_SUM,_neighbourhoodComms[curLevel]); + MPI_Allreduce(MPI_IN_PLACE,buffer.data(),2 * _expansionSize,MPI_DOUBLE,MPI_SUM,_neighbourhoodComms[curLevel]); index = 0; currentCell.multipole.readValuesFromMPIBuffer(buffer,index); - delete[] buffer; } else{ //get values of 8 values from previous level that contributed to the parent level in addition to parent value (9 values each 2 expansions) int coordsFlooredPreviousLevel[3]; for(int d = 0; d < 3; d++){ coordsFlooredPreviousLevel[d] = (((coords[d] * _numCellsOnGlobalLevel[d]) / (stride/2)) / 2) * 2; } - double * buffer = new double[18*_expansionSize]; + auto buffer = std::vector(18*_expansionSize); MpCell & currentCell = _mpCellGlobalTop[curLevel][cellIndex]; int index = 0; currentCell.multipole.writeValuesToMPIBuffer(buffer,index); @@ -1282,7 +1281,7 @@ void UniformPseudoParticleContainer::upwardPass(P2MCellProcessor* cp) { } } } - MPI_Allreduce(MPI_IN_PLACE,buffer,18 * _expansionSize,MPI_DOUBLE,MPI_SUM,_neighbourhoodComms[curLevel]); + MPI_Allreduce(MPI_IN_PLACE,buffer.data(),18 * _expansionSize,MPI_DOUBLE,MPI_SUM,_neighbourhoodComms[curLevel]); index = 0; MpCell & currentCell2 = _mpCellGlobalTop[curLevel][cellIndex]; currentCell2.multipole.readValuesFromMPIBuffer(buffer,index); @@ -1326,7 +1325,7 @@ void UniformPseudoParticleContainer::upwardPass(P2MCellProcessor* cp) { coordsFlooredLevel[d] = (((coords[d] * _numCellsOnGlobalLevel[d]) / (stride)) / 2) * 2; } - double * buffer = new double[16*_expansionSize]; + auto buffer = std::vector(16*_expansionSize); int index = 0; for(int z = 0; z < 2; z++){ for(int y = 0; y < 2; y++){ @@ -1338,7 +1337,7 @@ void UniformPseudoParticleContainer::upwardPass(P2MCellProcessor* cp) { } } } - MPI_Allreduce(MPI_IN_PLACE,buffer,16 * _expansionSize,MPI_DOUBLE,MPI_SUM,_neighbourhoodComms[_stopLevel - 1]); + MPI_Allreduce(MPI_IN_PLACE,buffer.data(),16 * _expansionSize,MPI_DOUBLE,MPI_SUM,_neighbourhoodComms[_stopLevel - 1]); index = 0; for(int z = 0; z < 2; z++){ @@ -1510,7 +1509,7 @@ void UniformPseudoParticleContainer::horizontalPass( //Fixme? special case for curlevel == 2? -> 64 cells only? unnecessary communication in this case? //possible optimization only add up values that were modified in NT method int numCells = (curLevel == 1)? 8 : 216; - double * buffer = new double[numCells * 2 * _expansionSize]; + auto buffer = std::vector(static_cast(numCells) * 2 * _expansionSize); int index = 0; int start, end; if(curLevel == 1){ @@ -1536,7 +1535,7 @@ void UniformPseudoParticleContainer::horizontalPass( } } } - MPI_Allreduce(MPI_IN_PLACE,buffer,numCells * 2 * _expansionSize,MPI_DOUBLE,MPI_SUM,_neighbourhoodComms[curLevel - 1]); + MPI_Allreduce(MPI_IN_PLACE,buffer.data(),numCells * 2 * _expansionSize,MPI_DOUBLE,MPI_SUM,_neighbourhoodComms[curLevel - 1]); index = 0; for(int z = start; z < end; z++){ @@ -3373,8 +3372,8 @@ void UniformPseudoParticleContainer::clear() { // clear the MPI buffers #ifdef ENABLE_MPI - std::fill(_coeffVector, _coeffVector + _coeffVectorLength*2, 0.0); - std::fill(_occVector, _occVector + _globalLevelNumCells, 0); + std::fill(_coeffVector.begin(), _coeffVector.end(), 0.0); + std::fill(_occVector.begin(), _occVector.end(), 0); #endif } @@ -3392,8 +3391,8 @@ void UniformPseudoParticleContainer::AllReduceMultipoleMoments() { _occVector[cellIndex] = currentCell.occ; } - MPI_Allreduce(MPI_IN_PLACE, _coeffVector, _coeffVectorLength*2, MPI_DOUBLE, MPI_SUM, _comm); - MPI_Allreduce(MPI_IN_PLACE, _occVector, _globalLevelNumCells, MPI_INT, MPI_SUM, _comm); + MPI_Allreduce(MPI_IN_PLACE, _coeffVector.data(), _coeffVectorLength*2, MPI_DOUBLE, MPI_SUM, _comm); + MPI_Allreduce(MPI_IN_PLACE, _occVector.data(), _globalLevelNumCells, MPI_INT, MPI_SUM, _comm); coeffIndex = 0; @@ -3405,7 +3404,7 @@ void UniformPseudoParticleContainer::AllReduceMultipoleMoments() { } - std::fill(_coeffVector, _coeffVector + _coeffVectorLength * 2, 0.0); + std::fill(_coeffVector.begin(), _coeffVector.end(), 0.0); #endif global_simulation->timers()->stop("UNIFORM_PSEUDO_PARTICLE_CONTAINER_ALL_REDUCE"); @@ -3429,7 +3428,7 @@ void UniformPseudoParticleContainer::AllReduceMultipoleMomentsLevelToTop(int num numCellsLevelTemp /= 8; } int commLevel = (_avoidAllReduce && _stopLevel <= _globalLevel)? _stopLevel: _globalLevel; - MPI_Iallreduce(MPI_IN_PLACE, _coeffVector, _coeffVectorLength*2, MPI_DOUBLE, MPI_SUM, _allReduceComms[commLevel], &_allReduceRequest); + MPI_Iallreduce(MPI_IN_PLACE, _coeffVector.data(), _coeffVectorLength*2, MPI_DOUBLE, MPI_SUM, _allReduceComms[commLevel], &_allReduceRequest); } #endif @@ -3450,7 +3449,7 @@ void UniformPseudoParticleContainer::AllReduceMultipoleMomentsSetValues(int numC } numCellsLevelTemp /= 8; } - std::fill(_coeffVector, _coeffVector + _coeffVectorLength * 2, 0.0); + std::fill(_coeffVector.begin(), _coeffVector.end(), 0.0); } #endif } @@ -3471,7 +3470,7 @@ void UniformPseudoParticleContainer::AllReduceLocalMoments(int mpCells, int _cur currentCell.local.writeValuesToMPIBuffer(_coeffVector, coeffIndex); } - MPI_Allreduce(MPI_IN_PLACE, _coeffVector, coeffIndex, MPI_DOUBLE, MPI_SUM, _comm); + MPI_Allreduce(MPI_IN_PLACE, _coeffVector.data(), coeffIndex, MPI_DOUBLE, MPI_SUM, _comm); coeffIndex = 0; @@ -3483,13 +3482,13 @@ void UniformPseudoParticleContainer::AllReduceLocalMoments(int mpCells, int _cur } - std::fill(_coeffVector, _coeffVector + _coeffVectorLength * 2, 0.0); + std::fill(_coeffVector.begin(), _coeffVector.end(), 0.0); #endif global_simulation->timers()->stop("UNIFORM_PSEUDO_PARTICLE_CONTAINER_ALL_REDUCE_ME"); } -void UniformPseudoParticleContainer::getHaloValues(Vector3 localMpCellsBottom,int bottomLevel, double *buffer, +void UniformPseudoParticleContainer::getHaloValues(const Vector3 &localMpCellsBottom,int bottomLevel, std::vector &buffer, int xLow, int xHigh, int yLow, int yHigh, int zLow, int zHigh, bool doLocalExpansion){ #if defined(ENABLE_MPI) int coeffIndex = 0; @@ -3526,7 +3525,7 @@ void UniformPseudoParticleContainer::getHaloValues(Vector3 localMpCellsBott #endif } -void UniformPseudoParticleContainer::setHaloValues(Vector3 localMpCellsBottom,int bottomLevel, double *bufferRec, +void UniformPseudoParticleContainer::setHaloValues(const Vector3 &localMpCellsBottom,int bottomLevel, std::vector &bufferRec, int xLow, int xHigh, int yLow, int yHigh, int zLow, int zHigh, bool doLocalExpansion){ #if defined(ENABLE_MPI) @@ -4319,10 +4318,10 @@ void UniformPseudoParticleContainer::communicateHalosOverlapPostProcessingStart( #endif } -void UniformPseudoParticleContainer::communicateHalosAlongAxis(double *lowerNeighbourBuffer, - double *higherNeighbourBuffer, - double *lowerNeighbourBufferRec, - double *higherNeighbourBufferRec, +void UniformPseudoParticleContainer::communicateHalosAlongAxis(std::vector &lowerNeighbourBuffer, + std::vector &higherNeighbourBuffer, + std::vector &lowerNeighbourBufferRec, + std::vector &higherNeighbourBufferRec, int lowerNeighbour, int higherNeighbour, int haloSize) { @@ -4331,13 +4330,13 @@ void UniformPseudoParticleContainer::communicateHalosAlongAxis(double *lowerNeig MPI_Status lowRecv,highRecv; - MPI_Isend(lowerNeighbourBuffer, haloSize, MPI_DOUBLE, lowerNeighbour, 1, + MPI_Isend(lowerNeighbourBuffer.data(), haloSize, MPI_DOUBLE, lowerNeighbour, 1, _comm, &low); - MPI_Isend(higherNeighbourBuffer, haloSize, MPI_DOUBLE, higherNeighbour, 3, + MPI_Isend(higherNeighbourBuffer.data(), haloSize, MPI_DOUBLE, higherNeighbour, 3, _comm, &high); - MPI_Recv(lowerNeighbourBufferRec, haloSize,MPI_DOUBLE, lowerNeighbour,3,_comm, &lowRecv); - MPI_Recv(higherNeighbourBufferRec, haloSize,MPI_DOUBLE, higherNeighbour,1,_comm, &highRecv); + MPI_Recv(lowerNeighbourBufferRec.data(), haloSize,MPI_DOUBLE, lowerNeighbour,3,_comm, &lowRecv); + MPI_Recv(higherNeighbourBufferRec.data(), haloSize,MPI_DOUBLE, higherNeighbour,1,_comm, &highRecv); #endif diff --git a/src/bhfmm/containers/UniformPseudoParticleContainer.h b/src/bhfmm/containers/UniformPseudoParticleContainer.h index cc4eb208ab..11c2cb1668 100644 --- a/src/bhfmm/containers/UniformPseudoParticleContainer.h +++ b/src/bhfmm/containers/UniformPseudoParticleContainer.h @@ -111,12 +111,12 @@ class UniformPseudoParticleContainer: public PseudoParticleContainer { int _globalNumCellsPerDim; Domain* _domain; int _globalNumCells; //total amount of cells - int* _occVector; // array for MPI allgather + std::vector _occVector; // array for MPI allgather int _coeffVectorLength; //size of MPI buffer for multipole coefficients int _expansionSize; //size of one local or multipole expansion in doubles - double* _coeffVector; // array for MPI allgather - double* _coeffVector_me; + std::vector _coeffVector; // array for MPI allgather + std::vector _coeffVector_me; #ifdef ENABLE_MPI HaloBufferNoOverlap * _multipoleRecBuffer, *_multipoleBuffer; //Buffer with use for non-overlapping communication HaloBufferOverlap * _multipoleRecBufferOverlap, * _multipoleBufferOverlap, * _multipoleBufferOverlapGlobal, * _multipoleRecBufferOverlapGlobal; //Buffers for receiving and sending of global and local tree halos @@ -199,7 +199,7 @@ class UniformPseudoParticleContainer: public PseudoParticleContainer { * @param bottomLevel: lowest level * @param buffer: buffer where values are should be stored */ - void getHaloValues(Vector3 localMpCellsBottom,int bottomLevel, double *buffer, + void getHaloValues(const Vector3 &localMpCellsBottom,int bottomLevel, std::vector &buffer, int xLow, int xHigh, int yLow, int yHigh, int zLow, int zHigh, bool doLocalExpansion); /** * Sets multipole or local expansion values in a defined area into a buffer for each level in local tree (e.g. halo values) @@ -211,7 +211,7 @@ class UniformPseudoParticleContainer: public PseudoParticleContainer { * @param bottomLevel: lowest level * @param buffer: buffer where values are stored in which should be written into the area */ - void setHaloValues(Vector3 localMpCellsBottom,int bottomLevel, double *bufferRec, + void setHaloValues(const Vector3 &localMpCellsBottom,int bottomLevel, std::vector &bufferRec, int xLow, int xHigh, int yLow, int yHigh, int zLow, int zHigh, bool doLocalExpansion); //for parallelization void communicateHalosNoOverlap(); @@ -235,8 +235,8 @@ class UniformPseudoParticleContainer: public PseudoParticleContainer { void communicateHalosX(); void communicateHalosY(); void communicateHalosZ(); - void communicateHalosAlongAxis(double * lowerNeighbourBuffer, double * higherNeighbourBuffer, - double * lowerNeighbourBufferRec, double * higherNeighbourBufferRec, + void communicateHalosAlongAxis(std::vector &lowerNeighbourBuffer, std::vector &higherNeighbourBuffer, + std::vector &lowerNeighbourBufferRec, std::vector &higherNeighbourBufferRec, int lowerNeighbour, int higherNeighbour, int haloSize ); bool _doNTLocal, _doNTGlobal; //indicate if NT method should be applied to the local tree part and/or the global tree part diff --git a/src/bhfmm/containers/UniformPseudoParticleContainer_old_Wigner_cpp.txt b/src/bhfmm/containers/UniformPseudoParticleContainer_old_Wigner_cpp.txt index 1f81735625..53b8427a75 100644 --- a/src/bhfmm/containers/UniformPseudoParticleContainer_old_Wigner_cpp.txt +++ b/src/bhfmm/containers/UniformPseudoParticleContainer_old_Wigner_cpp.txt @@ -45,7 +45,7 @@ UniformPseudoParticleContainer::UniformPseudoParticleContainer( #endif #if WIGNER == 1 //global_log->error() << "not supported yet" << std::endl; - mardyn_exit(-1); + MARDYN_EXIT(error_message.str()); #endif #ifdef ENABLE_MPI _timerProcessCells.set_sync(false); @@ -81,7 +81,7 @@ UniformPseudoParticleContainer::UniformPseudoParticleContainer( _globalLevel = log2(numProcessors)/3; if(_globalLevel > _maxLevel){ std::cout << "too many MPI ranks \n"; - mardyn_exit(-1); + MARDYN_EXIT(error_message.str()); } //numProcessers has to be a power of 8 mardyn_assert(log2(numProcessors) == _globalLevel * 3); @@ -778,7 +778,7 @@ void UniformPseudoParticleContainer::GatherWellSepLo_MPI(double *cellWid, int lo for (m2z = LoLim(2) + 2; m2z <= HiLim(2) + 2; m2z++) { if (m2z < 0 or m2z >= localMpCells) { std::cout << "Error \n"; - mardyn_exit(-1); + MARDYN_EXIT(error_message.str()); } @@ -786,7 +786,7 @@ void UniformPseudoParticleContainer::GatherWellSepLo_MPI(double *cellWid, int lo for (m2y = LoLim(1) + 2; m2y <= HiLim(1) + 2; m2y++) { if (m2y < 0 or m2y >= localMpCells) { std::cout << "Error \n"; - mardyn_exit(-1); + MARDYN_EXIT(error_message.str()); } @@ -794,7 +794,7 @@ void UniformPseudoParticleContainer::GatherWellSepLo_MPI(double *cellWid, int lo for (m2x = LoLim(0) + 2; m2x <= HiLim(0) + 2; m2x++) { if (m2x < 0 or m2x >= localMpCells) { std::cout << "Error \n"; - mardyn_exit(-1); + MARDYN_EXIT(error_message.str()); } m2v[0] = m2x; diff --git a/src/bhfmm/expansions/SolidHarmonicsExpansion.h b/src/bhfmm/expansions/SolidHarmonicsExpansion.h index a927d4190a..11707a0f8d 100644 --- a/src/bhfmm/expansions/SolidHarmonicsExpansion.h +++ b/src/bhfmm/expansions/SolidHarmonicsExpansion.h @@ -318,7 +318,7 @@ class SolidHarmonicsExpansion * @param buf buffer to write to * @param position index at which next entry should be written, note that it's value is updated! */ - void writeValuesToMPIBuffer(double * buf, int& position) const { + void writeValuesToMPIBuffer(std::vector &buf, int& position) const { const int end = _c.getTotalNumValues(); for (int i = 0; i < end; ++i) { buf[position++] = acc_c_C_seq(i); @@ -328,7 +328,7 @@ class SolidHarmonicsExpansion } } - void readValuesFromMPIBuffer(double * buf, int& position) { + void readValuesFromMPIBuffer(std::vector &buf, int& position) { const int end = _c.getTotalNumValues(); for (int i = 0; i < end; ++i) { acc_C_seq(i) = buf[position++]; @@ -337,7 +337,7 @@ class SolidHarmonicsExpansion acc_S_seq(i) = buf[position++]; } } - void addValuesFromMPIBuffer(double * buf, int& position) { + void addValuesFromMPIBuffer(std::vector &buf, int& position) { const int end = _c.getTotalNumValues(); for (int i = 0; i < end; ++i) { acc_C_seq(i) += buf[position++]; diff --git a/src/bhfmm/pseudoParticles/SHLocalParticle.h b/src/bhfmm/pseudoParticles/SHLocalParticle.h index a1a5bbece1..ed2121770f 100644 --- a/src/bhfmm/pseudoParticles/SHLocalParticle.h +++ b/src/bhfmm/pseudoParticles/SHLocalParticle.h @@ -84,14 +84,14 @@ class SHLocalParticle: public LocalParticle { return _expansionM; } - void writeValuesToMPIBuffer(double * buf, int& position) const { + void writeValuesToMPIBuffer(std::vector &buf, int& position) const { _expansionM.writeValuesToMPIBuffer(buf, position); } - void readValuesFromMPIBuffer(double * buf, int& position) { + void readValuesFromMPIBuffer(std::vector &buf, int& position) { _expansionM.readValuesFromMPIBuffer(buf,position); } - void addValuesFromMPIBuffer(double * buf, int& position) { + void addValuesFromMPIBuffer(std::vector &buf, int& position) { _expansionM.addValuesFromMPIBuffer(buf,position); } diff --git a/src/bhfmm/pseudoParticles/SHMultipoleParticle.h b/src/bhfmm/pseudoParticles/SHMultipoleParticle.h index a7a57d6512..5720c7d754 100644 --- a/src/bhfmm/pseudoParticles/SHMultipoleParticle.h +++ b/src/bhfmm/pseudoParticles/SHMultipoleParticle.h @@ -70,15 +70,15 @@ class SHMultipoleParticle: public MultipoleParticle { return _expansionL; } - void writeValuesToMPIBuffer(double * buf, int& position) const { + void writeValuesToMPIBuffer(std::vector &buf, int& position) const { _expansionL.writeValuesToMPIBuffer(buf, position); } - void readValuesFromMPIBuffer(double * buf, int& position) { + void readValuesFromMPIBuffer(std::vector &buf, int& position) { _expansionL.readValuesFromMPIBuffer(buf,position); } - void addValuesFromMPIBuffer(double * buf, int& position) { + void addValuesFromMPIBuffer(std::vector &buf, int& position) { _expansionL.addValuesFromMPIBuffer(buf,position); } diff --git a/src/ensemble/CanonicalEnsemble.cpp b/src/ensemble/CanonicalEnsemble.cpp index c79b31be4e..b7e536e613 100644 --- a/src/ensemble/CanonicalEnsemble.cpp +++ b/src/ensemble/CanonicalEnsemble.cpp @@ -195,8 +195,9 @@ void CanonicalEnsemble::readXML(XMLfileUnits& xmlconfig) { if("box" == domaintype) { _domain = new BoxDomain(); } else { - Log::global_log->error() << "Volume type not supported." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Volume type not supported." << std::endl; + MARDYN_EXIT(error_message.str()); } xmlconfig.changecurrentnode("domain"); _domain->readXML(xmlconfig); diff --git a/src/ensemble/CavityEnsemble.cpp b/src/ensemble/CavityEnsemble.cpp index bd65adeade..dafb7d55b0 100644 --- a/src/ensemble/CavityEnsemble.cpp +++ b/src/ensemble/CavityEnsemble.cpp @@ -93,10 +93,11 @@ void CavityEnsemble::setSubdomain(int rank, double x0, double x1, double y0, dou void CavityEnsemble::setControlVolume(double x0, double y0, double z0, double x1, double y1, double z1) { if ((x0 >= x1) || (y0 >= y1) || (z0 >= z1)) { - Log::global_log->error() << "\nInvalid control volume (" << x0 << " / " << y0 + std::ostringstream error_message; + error_message << "\nInvalid control volume (" << x0 << " / " << y0 << " / " << z0 << ") to (" << x1 << " / " << y1 << " / " << z1 << ")." << std::endl; - mardyn_exit(711); + MARDYN_EXIT(error_message.str()); } this->restrictedControlVolume = true; @@ -111,20 +112,24 @@ void CavityEnsemble::setControlVolume(double x0, double y0, double z0, double x1 void CavityEnsemble::init(Component *component, unsigned Nx, unsigned Ny, unsigned Nz) { if (this->ownrank < 0) { - Log::global_log->error() << "\nInvalid rank " << ownrank << ".\n"; - mardyn_exit(712); + std::ostringstream error_message; + error_message << "\nInvalid rank " << ownrank << ".\n"; + MARDYN_EXIT(error_message.str()); } if (this->initialized) { - Log::global_log->error() << "\nCavity ensemble initialized twice.\n"; - mardyn_exit(713); + std::ostringstream error_message; + error_message << "\nCavity ensemble initialized twice.\n"; + MARDYN_EXIT(error_message.str()); } if (0.0 >= this->T) { - Log::global_log->error() << "\nInvalid temperature T = " << T << ".\n"; - mardyn_exit(714); + std::ostringstream error_message; + error_message << "\nInvalid temperature T = " << T << ".\n"; + MARDYN_EXIT(error_message.str()); } if (0.0 >= this->globalV) { - Log::global_log->error() << "\nInvalid control volume V_ctrl = " << globalV << ".\n"; - mardyn_exit(715); + std::ostringstream error_message; + error_message << "\nInvalid control volume V_ctrl = " << globalV << ".\n"; + MARDYN_EXIT(error_message.str()); } this->componentid = component->ID(); diff --git a/src/ensemble/ChemicalPotential.cpp b/src/ensemble/ChemicalPotential.cpp index a535104e44..7475d741e0 100644 --- a/src/ensemble/ChemicalPotential.cpp +++ b/src/ensemble/ChemicalPotential.cpp @@ -284,8 +284,9 @@ bool ChemicalPotential::decideDeletion(double deltaUTilde) << "SEVERE WARNING: The Widom method is (erroneously) trying to carry out test deletions.\n"; return false; } - Log::global_log->error() << "No decision is possible." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "No decision is possible." << std::endl; + MARDYN_EXIT(error_message.str()); } float dec = *_remainingDecisions.begin(); _remainingDecisions.erase(_remainingDecisions.begin()); @@ -317,8 +318,9 @@ bool ChemicalPotential::decideInsertion(double deltaUTilde) << ": no decision is possible !!!\n"; return false; } - Log::global_log->error() << "No decision is possible." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "No decision is possible." << std::endl; + MARDYN_EXIT(error_message.str()); } double acc = _globalReducedVolume * exp(_muTilde - deltaUTilde) / (1.0 + (double) (_globalN)); @@ -373,10 +375,11 @@ void ChemicalPotential::setControlVolume(double x0, double y0, double z0, double x1, double y1, double z1) { if ((x0 >= x1) || (y0 >= y1) || (z0 >= z1)) { - Log::global_log->error() << "\nInvalid control volume (" << x0 << " / " << y0 + std::ostringstream error_message; + error_message << "\nInvalid control volume (" << x0 << " / " << y0 << " / " << z0 << ") to (" << x1 << " / " << y1 << " / " << z1 << ")." << std::endl; - mardyn_exit(611); + MARDYN_EXIT(error_message.str()); } _restrictedControlVolume = true; _globalV = (x1 - x0) * (y1 - y0) * (z1 - z0); diff --git a/src/ensemble/ChemicalPotential.h b/src/ensemble/ChemicalPotential.h index f24aaa8f16..3246226e9c 100644 --- a/src/ensemble/ChemicalPotential.h +++ b/src/ensemble/ChemicalPotential.h @@ -2,6 +2,7 @@ #pragma once #include +#include #include "utils/Random.h" #include "molecules/Molecule.h" @@ -43,9 +44,9 @@ class ChemicalPotential { #ifndef NDEBUG old.check(old.getID()); #endif - _reservoir = new Molecule(old); + _reservoir = std::make_unique(old); } - bool hasSample() { return _reservoir != NULL; } + bool hasSample() { return _reservoir != nullptr; } void setPlanckConstant(double h_in) { _h = h_in; } void submitTemperature(double T_in); @@ -128,7 +129,7 @@ class ChemicalPotential { // Using the widom method is just a way to determine the potential. This has nothing to do with actual insertions or // deletions! - Molecule* _reservoir; + std::unique_ptr _reservoir; /* Moved from LinkedCells! */ int _localInsertionsMinusDeletions; //!< balance of the grand canonical ensemble diff --git a/src/ensemble/EnsembleBase.cpp b/src/ensemble/EnsembleBase.cpp index d688d40471..e1fa33446d 100644 --- a/src/ensemble/EnsembleBase.cpp +++ b/src/ensemble/EnsembleBase.cpp @@ -23,8 +23,9 @@ void Ensemble::readXML(XMLfileUnits& xmlconfig) { numComponents = query.card(); Log::global_log->info() << "Number of components: " << numComponents << std::endl; if (numComponents == 0) { - Log::global_log->fatal() << "No components found. Please verify that you have input them correctly." << std::endl; - mardyn_exit(96123); + std::ostringstream error_message; + error_message << "No components found. Please verify that you have input them correctly." << std::endl; + MARDYN_EXIT(error_message.str()); } _components.resize(numComponents); XMLfile::Query::const_iterator componentIter; @@ -57,8 +58,9 @@ void Ensemble::readXML(XMLfileUnits& xmlconfig) { mixingrule = std::make_shared(); } else { - Log::global_log->error() << "Unknown mixing rule " << mixingruletype << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Unknown mixing rule " << mixingruletype << std::endl; + MARDYN_EXIT(error_message.str()); } mixingrule->readXML(xmlconfig); @@ -67,9 +69,10 @@ void Ensemble::readXML(XMLfileUnits& xmlconfig) { // Check if cid is larger than number of components // cid starts with 0 and cid2 is always larger than cid1 if (cid2 >= numComponents) { - Log::global_log->error() << "Mixing: cid=" << cid2+1 << " is larger than number of components (" - << numComponents << ")" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Mixing: cid=" << cid2+1 << " is larger than number of components (" + << numComponents << ")" << std::endl; + MARDYN_EXIT(error_message.str()); } _mixingrules[cid1][cid2] = mixingrule; } @@ -115,17 +118,20 @@ void Ensemble::setMixingrule(std::shared_ptr mixingrule) { // Check if cids are valid if (cid1 == cid2) { - Log::global_log->error() << "Mixing setMixingrule: cids must not be the same" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Mixing setMixingrule: cids must not be the same" << std::endl; + MARDYN_EXIT(error_message.str()); } if (std::min(cid1, cid2) < 0) { - Log::global_log->error() << "Mixing setMixingrule: cids must not be negative" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Mixing setMixingrule: cids must not be negative" << std::endl; + MARDYN_EXIT(error_message.str()); } if (std::max(cid1, cid2) >= _components.size()) { - Log::global_log->error() << "Mixing setMixingrule: cids must not exceed number of components (" - << _components.size() << ")" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Mixing setMixingrule: cids must not exceed number of components (" + << _components.size() << ")" << std::endl; + MARDYN_EXIT(error_message.str()); } _mixingrules[cid1][cid2] = mixingrule; diff --git a/src/ensemble/GrandCanonicalEnsemble.h b/src/ensemble/GrandCanonicalEnsemble.h index 2249cc0de7..03feb3d9dc 100644 --- a/src/ensemble/GrandCanonicalEnsemble.h +++ b/src/ensemble/GrandCanonicalEnsemble.h @@ -40,8 +40,9 @@ class GrandCanonicalEnsemble : public Ensemble { // TODO: Implement STUB void readXML(XMLfileUnits& xmlconfig) override { - Log::global_log->info() << "[GrandCanonicalEnsemble] readXML not implemented!" << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[GrandCanonicalEnsemble] readXML not implemented!" << std::endl; + MARDYN_EXIT(error_message.str()); }; unsigned long N() override { @@ -70,8 +71,9 @@ class GrandCanonicalEnsemble : public Ensemble { // TODO: Implement void updateGlobalVariable(ParticleContainer* particleContainer, GlobalVariable variable) override { - Log::global_log->info() << "[GrandCanonicalEnsemble] updateGlobalVariable not implemented!" << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[GrandCanonicalEnsemble] updateGlobalVariable not implemented!" << std::endl; + MARDYN_EXIT(error_message.str()); }; /*! Runs steps formerly in initConfigXML in simulation.cpp */ diff --git a/src/ensemble/PressureGradient.cpp b/src/ensemble/PressureGradient.cpp index 029a1a9e77..70f796847c 100644 --- a/src/ensemble/PressureGradient.cpp +++ b/src/ensemble/PressureGradient.cpp @@ -219,8 +219,9 @@ void PressureGradient::specifyTauPrime(double tauPrime, double dt) if(this->_localRank != 0) return; if(this->_universalConstantAccelerationTimesteps == 0) { - Log::global_log->error() << "SEVERE ERROR: unknown UCAT!\n"; - mardyn_exit(78); + std::ostringstream error_message; + error_message << "SEVERE ERROR: unknown UCAT!\n"; + MARDYN_EXIT(error_message.str()); } unsigned int vql = (unsigned int)ceil(tauPrime / (dt*this->_universalConstantAccelerationTimesteps)); std::map::iterator vqlit; diff --git a/src/io/ASCIIReader.cpp b/src/io/ASCIIReader.cpp index d0dd3cf7c1..4cd29cb517 100644 --- a/src/io/ASCIIReader.cpp +++ b/src/io/ASCIIReader.cpp @@ -56,21 +56,24 @@ void ASCIIReader::readPhaseSpaceHeader(Domain* domain, double timestep) { _phaseSpaceHeaderFileStream.open(_phaseSpaceHeaderFile.c_str()); _phaseSpaceHeaderFileStream >> token; if(token != "mardyn") { - Log::global_log->error() << _phaseSpaceHeaderFile << " not a valid mardyn input file." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << _phaseSpaceHeaderFile << " not a valid mardyn input file." << std::endl; + MARDYN_EXIT(error_message.str()); } std::string inputversion; _phaseSpaceHeaderFileStream >> token >> inputversion; // FIXME: remove tag trunk from file specification? if(token != "trunk") { - Log::global_log->error() << "Wrong input file specifier (\'" << token << "\' instead of \'trunk\')." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Wrong input file specifier (\'" << token << "\' instead of \'trunk\')." << std::endl; + MARDYN_EXIT(error_message.str()); } if(std::stoi(inputversion) < 20080701) { - Log::global_log->error() << "Input version too old (" << inputversion << ")" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Input version too old (" << inputversion << ")" << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "Reading phase space header from file " << _phaseSpaceHeaderFile << std::endl; @@ -163,9 +166,9 @@ void ASCIIReader::readPhaseSpaceHeader(Domain* domain, double timestep) { _phaseSpaceHeaderFileStream >> numljcenters >> numcharges >> numdipoles >> numquadrupoles >> numtersoff; if(numtersoff != 0) { - Log::global_log->error() << "tersoff no longer supported." - << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "tersoff no longer supported." << std::endl; + MARDYN_EXIT(error_message.str()); } double x, y, z, m; for(unsigned int j = 0; j < numljcenters; j++) { @@ -274,8 +277,9 @@ ASCIIReader::readPhaseSpace(ParticleContainer* particleContainer, Domain* domain Log::global_log->info() << "Opening phase space file " << _phaseSpaceFile << std::endl; _phaseSpaceFileStream.open(_phaseSpaceFile.c_str()); if(!_phaseSpaceFileStream.is_open()) { - Log::global_log->error() << "Could not open phaseSpaceFile " << _phaseSpaceFile << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Could not open phaseSpaceFile " << _phaseSpaceFile << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "Reading phase space file " << _phaseSpaceFile << std::endl; #ifdef ENABLE_MPI @@ -300,8 +304,9 @@ ASCIIReader::readPhaseSpace(ParticleContainer* particleContainer, Domain* domain _phaseSpaceFileStream >> token; } if((token != "NumberOfMolecules") && (token != "N")) { - Log::global_log->error() << "Expected the token 'NumberOfMolecules (N)' instead of '" << token << "'" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Expected the token 'NumberOfMolecules (N)' instead of '" << token << "'" << std::endl; + MARDYN_EXIT(error_message.str()); } _phaseSpaceFileStream >> nummolecules; #ifdef ENABLE_MPI @@ -327,8 +332,9 @@ ASCIIReader::readPhaseSpace(ParticleContainer* particleContainer, Domain* domain else if(ntypestring == "ICRV") ntype = Ndatatype::ICRV; else if(ntypestring == "IRV") ntype = Ndatatype::IRV; else { - Log::global_log->error() << "Unknown molecule format '" << ntypestring << "'" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Unknown molecule format '" << ntypestring << "'" << std::endl; + MARDYN_EXIT(error_message.str()); } } else { _phaseSpaceFileStream.seekg(spos); @@ -388,8 +394,9 @@ ASCIIReader::readPhaseSpace(ParticleContainer* particleContainer, Domain* domain componentid = 1; break; default: - Log::global_log->error() << "[ASCIIReader.cpp] Unknown ntype" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[ASCIIReader.cpp] Unknown ntype" << std::endl; + MARDYN_EXIT(error_message.str()); } if((x < 0.0 || x >= domain->getGlobalLength(0)) || (y < 0.0 || y >= domain->getGlobalLength(1)) @@ -398,12 +405,11 @@ ASCIIReader::readPhaseSpace(ParticleContainer* particleContainer, Domain* domain } if(componentid > numcomponents) { - Log::global_log->error() << "Molecule id " << id + std::ostringstream error_message; + error_message << "Molecule id " << id << " has a component ID greater than the existing number of components: " - << componentid - << ">" - << numcomponents << std::endl; - mardyn_exit(1); + << componentid << ">" << numcomponents << std::endl; + MARDYN_EXIT(error_message.str()); } // ComponentIDs are used as array IDs, hence need to start at 0. // In the input files they always start with 1 so we need to adapt that all the time. diff --git a/src/io/Adios2Reader.cpp b/src/io/Adios2Reader.cpp index 643fc4ba19..728f765802 100644 --- a/src/io/Adios2Reader.cpp +++ b/src/io/Adios2Reader.cpp @@ -88,7 +88,9 @@ unsigned long Adios2Reader::readPhaseSpace(ParticleContainer* particleContainer, } else if (_mode == "parallelRead") { parallelRead(particleContainer, domain, domainDecomp); } else { - Log::global_log->error() << "[Adios2Reader] Unknown _mode '" << _mode << "'" << std::endl; + std::ostringstream error_message; + error_message << "[Adios2Reader] Unknown _mode '" << _mode << "'" << std::endl; + MARDYN_EXIT(error_message.str()); } _simulation.setSimulationTime(_simtime); @@ -532,23 +534,20 @@ void Adios2Reader::initAdios2() { } } catch (std::invalid_argument& e) { - Log::global_log->fatal() - << "[Adios2Reader] Invalid argument exception, STOPPING PROGRAM from rank" - << domainDecomp.getRank() - << ": " << e.what() << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[Adios2Reader] Invalid argument exception, STOPPING PROGRAM from rank" + << domainDecomp.getRank() << ": " << e.what() << std::endl; + MARDYN_EXIT(error_message.str()); } catch (std::ios_base::failure& e) { - Log::global_log->fatal() - << "[Adios2Reader] IO System base failure exception, STOPPING PROGRAM from rank " - << domainDecomp.getRank() - << ": " << e.what() << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[Adios2Reader] IO System base failure exception, STOPPING PROGRAM from rank " + << domainDecomp.getRank() << ": " << e.what() << std::endl; + MARDYN_EXIT(error_message.str()); } catch (std::exception& e) { - Log::global_log->fatal() - << "[Adios2Reader] Exception, STOPPING PROGRAM from rank" - << domainDecomp.getRank() - << ": " << e.what() << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[Adios2Reader] Exception, STOPPING PROGRAM from rank" + << domainDecomp.getRank() << ": " << e.what() << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "[Adios2Reader] Init complete." << std::endl; }; diff --git a/src/io/Adios2Writer.cpp b/src/io/Adios2Writer.cpp index 12cad27dca..29b652e567 100644 --- a/src/io/Adios2Writer.cpp +++ b/src/io/Adios2Writer.cpp @@ -264,15 +264,20 @@ void Adios2Writer::initAdios2() { } resetContainers(); } catch (std::invalid_argument& e) { - Log::global_log->fatal() << "Invalid argument exception, STOPPING PROGRAM from rank: " << e.what() << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Invalid argument exception:" << std::endl; + error_message << e.what() << std::endl; + MARDYN_EXIT(error_message.str()); } catch (std::ios_base::failure& e) { - Log::global_log->fatal() << "IO System base failure exception, STOPPING PROGRAM from rank: " << e.what() << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "IO System base failure exception: " << std::endl; + error_message << e.what() << std::endl; + MARDYN_EXIT(error_message.str()); } catch (std::exception& e) { - Log::global_log->fatal() << "Exception, STOPPING PROGRAM from rank: " << e.what() - << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Exception: " << std::endl; + error_message << e.what() << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "[Adios2Writer] Init complete." << std::endl; } @@ -417,14 +422,20 @@ void Adios2Writer::endStep(ParticleContainer* particleContainer, DomainDecompBas clearContainers(); } catch (std::invalid_argument& e) { - Log::global_log->error() << "[Adios2Writer] Invalid argument exception, STOPPING PROGRAM"; - Log::global_log->error() << e.what(); + std::ostringstream error_message; + error_message << "[Adios2Writer] Invalid argument exception:" << std::endl; + error_message << e.what(); + MARDYN_EXIT(error_message.str()); } catch (std::ios_base::failure& e) { - Log::global_log->error() << "[Adios2Writer] IO System base failure exception, STOPPING PROGRAM"; - Log::global_log->error() << e.what(); + std::ostringstream error_message; + error_message << "[Adios2Writer] IO System base failure exception:" << std::endl; + error_message << e.what(); + MARDYN_EXIT(error_message.str()); } catch (std::exception& e) { - Log::global_log->error() << "[Adios2Writer] Exception, STOPPING PROGRAM"; - Log::global_log->error() << e.what(); + std::ostringstream error_message; + error_message << "[Adios2Writer] Exception:" << std::endl; + error_message << e.what(); + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "[Adios2Writer] endStep." << std::endl; } diff --git a/src/io/BinaryReader.cpp b/src/io/BinaryReader.cpp index 95c56fa418..891575908a 100644 --- a/src/io/BinaryReader.cpp +++ b/src/io/BinaryReader.cpp @@ -76,9 +76,10 @@ void BinaryReader::readPhaseSpaceHeader(Domain* domain, double timestep) { XMLfileUnits inp(_phaseSpaceHeaderFile); if(not inp.changecurrentnode("/mardyn")) { - Log::global_log->error() << "Could not find root node /mardyn in XML input file." << std::endl; - Log::global_log->fatal() << "Not a valid MarDyn XML input file." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Could not find root node /mardyn in XML input file." << std::endl; + error_message << "Not a valid MarDyn XML input file." << std::endl; + MARDYN_EXIT(error_message.str()); } bool bInputOk = true; @@ -95,8 +96,9 @@ void BinaryReader::readPhaseSpaceHeader(Domain* domain, double timestep) { bInputOk = bInputOk && inp.getNodeValue("format@type", strMoleculeFormat); if(not bInputOk) { - Log::global_log->error() << "Content of file: '" << _phaseSpaceHeaderFile << "' corrupted! Program exit ..." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Content of file: '" << _phaseSpaceHeaderFile << "' corrupted! Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } if("ICRVQD" == strMoleculeFormat) @@ -106,8 +108,9 @@ void BinaryReader::readPhaseSpaceHeader(Domain* domain, double timestep) { else if("ICRV" == strMoleculeFormat) _nMoleculeFormat = ICRV; else { - Log::global_log->error() << "Not a valid molecule format: " << strMoleculeFormat << ", program exit ..." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Not a valid molecule format: " << strMoleculeFormat << ", program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } // Set parameters of Domain and Simulation class @@ -132,9 +135,10 @@ BinaryReader::readPhaseSpace(ParticleContainer* particleContainer, Domain* domai _phaseSpaceFileStream.open(_phaseSpaceFile.c_str(), std::ios::binary | std::ios::in); if(!_phaseSpaceFileStream.is_open()) { - Log::global_log->error() << "Could not open phaseSpaceFile " + std::ostringstream error_message; + error_message << "Could not open phaseSpaceFile " << _phaseSpaceFile << std::endl; - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "Reading phase space file " << _phaseSpaceFile << std::endl; @@ -176,9 +180,10 @@ BinaryReader::readPhaseSpace(ParticleContainer* particleContainer, Domain* domai if (domainDecomp->getRank() == 0) { // Rank 0 only #endif if(_phaseSpaceFileStream.eof()) { - Log::global_log->error() << "End of file was hit before all " << numMolecules << " expected molecules were read." + std::ostringstream error_message; + error_message << "End of file was hit before all " << numMolecules << " expected molecules were read." << std::endl; - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); } _phaseSpaceFileStream.read(reinterpret_cast (&id), 8); switch (_nMoleculeFormat) { @@ -219,9 +224,10 @@ BinaryReader::readPhaseSpace(ParticleContainer* particleContainer, Domain* domai _phaseSpaceFileStream.read(reinterpret_cast (&vz), 8); break; default: - Log::global_log->error() << "BinaryReader: Unknown phase space format: " << _nMoleculeFormat << std::endl + std::ostringstream error_message; + error_message << "BinaryReader: Unknown phase space format: " << _nMoleculeFormat << std::endl << "Aborting simulation." << std::endl; - mardyn_exit(12); + MARDYN_EXIT(error_message.str()); } if ((x < 0.0 || x >= domain->getGlobalLength(0)) || (y < 0.0 || y >= domain->getGlobalLength(1)) || (z < 0.0 || z >= domain->getGlobalLength(2))) { @@ -229,17 +235,18 @@ BinaryReader::readPhaseSpace(ParticleContainer* particleContainer, Domain* domai } if(componentid > numcomponents) { - Log::global_log->error() << "Molecule id " << id + std::ostringstream error_message; + error_message << "Molecule id " << id << " has a component ID greater than the existing number of components: " << componentid << ">" << numcomponents << std::endl; - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); } if(componentid == 0) { - Log::global_log->error() << "Molecule id " << id - << " has componentID == 0." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Molecule id " << id << " has componentID == 0." << std::endl; + MARDYN_EXIT(error_message.str()); } // ComponentIDs are used as array IDs, hence need to start at 0. // In the input files they always start with 1 so we need to adapt that all the time. diff --git a/src/io/CavityWriter.cpp b/src/io/CavityWriter.cpp index 5c6d57601e..87c1ab8764 100644 --- a/src/io/CavityWriter.cpp +++ b/src/io/CavityWriter.cpp @@ -37,29 +37,34 @@ void CavityWriter::readXML(XMLfileUnits &xmlconfig) { xmlconfig.getNodeValue("maxNeighbours", _maxNeighbors); if (_maxNeighbors <= 0) { - Log::global_log->error() << "[CavityWriter] Invalid number of maxNeighbors: " << _maxNeighbors << std::endl; - mardyn_exit(999); + std::ostringstream error_message; + error_message << "[CavityWriter] Invalid number of maxNeighbors: " << _maxNeighbors << std::endl; + MARDYN_EXIT(error_message.str()); } xmlconfig.getNodeValue("radius", _radius); if (_radius <= 0.0f) { - Log::global_log->error() << "[CavityWriter] Invalid size of radius: " << _radius << std::endl; - mardyn_exit(999); + std::ostringstream error_message; + error_message << "[CavityWriter] Invalid size of radius: " << _radius << std::endl; + MARDYN_EXIT(error_message.str()); } xmlconfig.getNodeValue("Nx", _Nx); if (_Nx <= 0) { - Log::global_log->error() << "[CavityWriter] Invalid number of cells Nx: " << _Nx << std::endl; - mardyn_exit(999); + std::ostringstream error_message; + error_message << "[CavityWriter] Invalid number of cells Nx: " << _Nx << std::endl; + MARDYN_EXIT(error_message.str()); } xmlconfig.getNodeValue("Ny", _Ny); if (_Ny <= 0) { - Log::global_log->error() << "[CavityWriter] Invalid number of cells Ny: " << _Ny << std::endl; - mardyn_exit(999); + std::ostringstream error_message; + error_message << "[CavityWriter] Invalid number of cells Ny: " << _Ny << std::endl; + MARDYN_EXIT(error_message.str()); } xmlconfig.getNodeValue("Nz", _Nz); if (_Nz <= 0) { - Log::global_log->error() << "[CavityWriter] Invalid number of cells Nz: " << _Nz << std::endl; - mardyn_exit(999); + std::ostringstream error_message; + error_message << "[CavityWriter] Invalid number of cells Nz: " << _Nz << std::endl; + MARDYN_EXIT(error_message.str()); } // Default Control Volume is entire Domain @@ -75,15 +80,15 @@ void CavityWriter::readXML(XMLfileUnits &xmlconfig) { xmlconfig.getNodeValue("ControlVolume/z1", _controlVolume[5]); for (int d = 0; d < 3; d++) { if (_controlVolume[d * 2] > _controlVolume[d * 2 + 1]) { - Log::global_log->error() << "[CavityWriter] Lower Bound of Control Volume may not be larger than upper bound. " - << std::endl; - mardyn_exit(999); + std::ostringstream error_message; + error_message << "[CavityWriter] Lower Bound of Control Volume may not be larger than upper bound." << std::endl; + MARDYN_EXIT(error_message.str()); } if (_controlVolume[d * 2] < 0 || _controlVolume[d * 2 + 1] > global_simulation->getDomain()->getGlobalLength(d)) { - Log::global_log->error() << "[CavityWriter] Control volume bounds may not be outside of domain boundaries. " - << std::endl; - mardyn_exit(999); + std::ostringstream error_message; + error_message << "[CavityWriter] Control volume bounds may not be outside of domain boundaries." << std::endl; + MARDYN_EXIT(error_message.str()); } } diff --git a/src/io/CheckpointWriter.cpp b/src/io/CheckpointWriter.cpp index 6d8c4621c7..4685f518b4 100644 --- a/src/io/CheckpointWriter.cpp +++ b/src/io/CheckpointWriter.cpp @@ -19,8 +19,9 @@ void CheckpointWriter::readXML(XMLfileUnits& xmlconfig) { Log::global_log->info() << "Write frequency: " << _writeFrequency << std::endl; if(_writeFrequency == 0) { - Log::global_log->error() << "Write frequency must be a positive nonzero integer, but is " << _writeFrequency << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Write frequency must be a positive nonzero integer, but is " << _writeFrequency << std::endl; + MARDYN_EXIT(error_message.str()); } std::string checkpointType = "unknown"; @@ -32,8 +33,9 @@ void CheckpointWriter::readXML(XMLfileUnits& xmlconfig) { _useBinaryFormat = true; } else { - Log::global_log->error() << "Unknown CheckpointWriter type '" << checkpointType << "', expected: ASCII|binary." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Unknown CheckpointWriter type '" << checkpointType << "', expected: ASCII|binary." << std::endl; + MARDYN_EXIT(error_message.str()); } _outputPrefix = "mardyn"; diff --git a/src/io/CommunicationPartnerWriter.cpp b/src/io/CommunicationPartnerWriter.cpp index 1a280316e7..84d10bbb86 100644 --- a/src/io/CommunicationPartnerWriter.cpp +++ b/src/io/CommunicationPartnerWriter.cpp @@ -17,8 +17,9 @@ void CommunicationPartnerWriter::readXML(XMLfileUnits& xmlconfig) { Log::global_log->info() << "Write frequency: " << _writeFrequency << std::endl; if(_writeFrequency == 0) { - Log::global_log->error() << "Write frequency must be a positive nonzero integer, but is " << _writeFrequency << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Write frequency must be a positive nonzero integer, but is " << _writeFrequency << std::endl; + MARDYN_EXIT(error_message.str()); } std::string HaloParticleType = "unknown"; diff --git a/src/io/CubicGridGeneratorInternal.cpp b/src/io/CubicGridGeneratorInternal.cpp index 8c3e7e85c2..8ee1e5f396 100644 --- a/src/io/CubicGridGeneratorInternal.cpp +++ b/src/io/CubicGridGeneratorInternal.cpp @@ -40,17 +40,17 @@ void CubicGridGeneratorInternal::readXML(XMLfileUnits& xmlconfig) { Log::global_log->info() << "binaryMixture: " << _binaryMixture << std::endl; // setting both or none is not allowed! if((_numMolecules == 0 && density == -1.) || (_numMolecules != 0 && density != -1.) ){ - Log::global_log->error() << "Error in CubicGridGeneratorInternal: You have to set either density or numMolecules!" << std::endl; - mardyn_exit(2341); + std::ostringstream error_message; + error_message << "Error in CubicGridGeneratorInternal: You have to set either density or numMolecules!" << std::endl; + MARDYN_EXIT(error_message.str()); } if(density != -1.){ // density has been set if(density <= 0){ - Log::global_log->error() - << "Error in CubicGridGeneratorInternal: Density has to be positive and non-zero!" - << std::endl; - mardyn_exit(2342); + std::ostringstream error_message; + error_message << "Error in CubicGridGeneratorInternal: Density has to be positive and non-zero!" << std::endl; + MARDYN_EXIT(error_message.str()); } double vol = 1.0; for (int d = 0; d < 3; ++d) @@ -65,9 +65,10 @@ unsigned long CubicGridGeneratorInternal::readPhaseSpace(ParticleContainer *part Log::global_log->info() << "Reading phase space file (CubicGridGenerator)." << std::endl; if(_numMolecules == 0){ - Log::global_log->error() << "Error in CubicGridGeneratorInternal: numMolecules is not set!" + std::ostringstream error_message; + error_message << "Error in CubicGridGeneratorInternal: numMolecules is not set!" << std::endl << "Please make sure to run readXML()!" << std::endl; - mardyn_exit(2341); + MARDYN_EXIT(error_message.str()); } // create a body centered cubic layout, by creating by placing the molecules on the @@ -145,9 +146,10 @@ std::array CubicGridGeneratorInternal::determineMolsPerDimensi mardyn_assert(answer >= 1); if (answer < 1) { - Log::global_log->error() << "computed num Molecules along dimension " << d << ": " << answer << std::endl; - Log::global_log->error() << "Should be larger than 1. Exiting." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "computed num Molecules along dimension " << d << ": " << answer << std::endl; + error_message << "Should be larger than 1. Exiting." << std::endl; + MARDYN_EXIT(error_message.str()); } ret[d] = answer; diff --git a/src/io/FlopRateWriter.cpp b/src/io/FlopRateWriter.cpp index e438a724da..49e6ae40b7 100644 --- a/src/io/FlopRateWriter.cpp +++ b/src/io/FlopRateWriter.cpp @@ -26,7 +26,9 @@ void FlopRateWriter::readXML(XMLfileUnits& xmlconfig) { _writeToStdout = true; _writeToFile = true; } else { - Log::global_log->error() << "Unknown FlopRateOutputPlugin::mode. Choose \"stdout\", \"file\" or \"both\"." << std::endl; + std::ostringstream error_message; + error_message << "Unknown FlopRateOutputPlugin::mode. Choose \"stdout\", \"file\" or \"both\"." << std::endl; + MARDYN_EXIT(error_message.str()); } _writeFrequency = 1; @@ -35,8 +37,9 @@ void FlopRateWriter::readXML(XMLfileUnits& xmlconfig) { // TODO: if(_writeToFile) { - Log::global_log->error() << "TODO: file output not yet supported." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "TODO: file output not yet supported." << std::endl; + MARDYN_EXIT(error_message.str()); } if(_writeToFile) { diff --git a/src/io/FlopRateWriter.h b/src/io/FlopRateWriter.h index 9939da626c..48768f3489 100644 --- a/src/io/FlopRateWriter.h +++ b/src/io/FlopRateWriter.h @@ -11,6 +11,7 @@ #include "plugins/PluginBase.h" #include +#include class FlopCounter; diff --git a/src/io/HaloParticleWriter.cpp b/src/io/HaloParticleWriter.cpp index cd6f058252..a0db8de823 100644 --- a/src/io/HaloParticleWriter.cpp +++ b/src/io/HaloParticleWriter.cpp @@ -17,8 +17,9 @@ void HaloParticleWriter::readXML(XMLfileUnits& xmlconfig) { Log::global_log->info() << "Write frequency: " << _writeFrequency << std::endl; if(_writeFrequency == 0) { - Log::global_log->error() << "Write frequency must be a positive nonzero integer, but is " << _writeFrequency << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Write frequency must be a positive nonzero integer, but is " << _writeFrequency << std::endl; + MARDYN_EXIT(error_message.str()); } std::string HaloParticleType = "unknown"; diff --git a/src/io/KDTreePrinter.cpp b/src/io/KDTreePrinter.cpp index 132a7e1965..983fc2b938 100644 --- a/src/io/KDTreePrinter.cpp +++ b/src/io/KDTreePrinter.cpp @@ -18,9 +18,8 @@ void KDTreePrinter::readXML(XMLfileUnits &xmlconfig) { Log::global_log->info() << "Write frequency: " << _writeFrequency << std::endl; if (_writeFrequency == 0) { - Log::global_log->error() << "Write frequency must be a positive nonzero integer, but is " << _writeFrequency - << std::endl; - mardyn_exit(948947); + std::ostringstream error_message;error_message << "Write frequency must be a positive nonzero integer, but is " << _writeFrequency << std::endl; + MARDYN_EXIT(error_message.str()); } _outputPrefix = "mardyn"; diff --git a/src/io/MPI_IOCheckpointWriter.cpp b/src/io/MPI_IOCheckpointWriter.cpp index b160edd7e5..5148d3e90b 100644 --- a/src/io/MPI_IOCheckpointWriter.cpp +++ b/src/io/MPI_IOCheckpointWriter.cpp @@ -434,8 +434,9 @@ void MPI_IOCheckpointWriter::handle_error(int i) { MPI_Error_string(i, error_string, &length_of_error_string); - Log::global_log->error() << "Writing of file was not successfull " << " , " << i + std::ostringstream error_message; + error_message << "Writing of file was not successfull " << " , " << i << " , " << error_string << std::endl; - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); #endif } diff --git a/src/io/MPI_IOReader.cpp b/src/io/MPI_IOReader.cpp index 11a33ce58d..87be623061 100644 --- a/src/io/MPI_IOReader.cpp +++ b/src/io/MPI_IOReader.cpp @@ -58,21 +58,24 @@ void MPI_IOReader::readPhaseSpaceHeader(Domain* domain, double timestep) { _phaseSpaceHeaderFileStream.open(_phaseSpaceHeaderFile.c_str()); _phaseSpaceHeaderFileStream >> token; if(token != "mardyn") { - Log::global_log->error() << _phaseSpaceHeaderFile << " not a valid mardyn input file." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << _phaseSpaceHeaderFile << " not a valid mardyn input file." << std::endl; + MARDYN_EXIT(error_message.str()); } std::string inputversion; _phaseSpaceHeaderFileStream >> token >> inputversion; // FIXME: remove tag trunk from file specification? if(token != "trunk") { - Log::global_log->error() << "Wrong input file specifier (\'" << token << "\' instead of \'trunk\')." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Wrong input file specifier (\'" << token << "\' instead of \'trunk\')." << std::endl; + MARDYN_EXIT(error_message.str()); } if(strtoul(inputversion.c_str(), NULL, 0) < 20080701) { - Log::global_log->error() << "Input version tool old (" << inputversion << ")" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Input version tool old (" << inputversion << ")" << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "Reading phase space header from file " << _phaseSpaceHeaderFile << std::endl; @@ -115,9 +118,10 @@ void MPI_IOReader::readPhaseSpaceHeader(Domain* domain, double timestep) { if(!(ntypestring == "ICRVQD" || ntypestring == "ICRV" || ntypestring == "IRV")) { - Log::global_log->error() << "Unknown molecule format: '" + std::ostringstream error_message; + error_message << "Unknown molecule format: '" << ntypestring << "'" << std::endl; - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); } _moleculeFormat = ntypestring; Log::global_log->info() << " molecule format: " << ntypestring << std::endl; @@ -182,8 +186,9 @@ void MPI_IOReader::readPhaseSpaceHeader(Domain* domain, double timestep) { _phaseSpaceHeaderFileStream >> numljcenters >> numcharges >> numdipoles >> numquadrupoles >> numtersoff; if(numtersoff != 0) { - Log::global_log->error() << "tersoff no longer supported." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "tersoff no longer supported." << std::endl; + MARDYN_EXIT(error_message.str()); } double x, y, z, m; for(unsigned int j = 0; j < numljcenters; j++) { @@ -654,8 +659,9 @@ void MPI_IOReader::handle_error(int i) { MPI_Error_string(i, error_string, &length_of_error_string); - Log::global_log->error() << "Writing of file was not successfull " << " , " << i + std::ostringstream error_message; + error_message << "Writing of file was not successfull " << " , " << i << " , " << error_string << std::endl; - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); #endif } diff --git a/src/io/Mkesfera.cpp b/src/io/Mkesfera.cpp index c374fe6462..b478047539 100755 --- a/src/io/Mkesfera.cpp +++ b/src/io/Mkesfera.cpp @@ -175,8 +175,9 @@ MkesferaGenerator::readPhaseSpace(ParticleContainer* particleContainer, Domain* if(idx[0] - startx[0] >= fl_units_local[0] or idx[1] - startx[1] >= fl_units_local[1] or idx[2] - startx[2] >= fl_units_local[2] or startx[0] > idx[0] or startx[1] > idx[1] or startx[2] > idx[2]) { - Log::global_log->error() << "Error in calculation of start and end values! \n"; - mardyn_exit(0); + std::ostringstream error_message; + error_message << "Error in calculation of start and end values! \n"; + MARDYN_EXIT(error_message.str()); } fill[idx[0] - startx[0]][idx[1] - startx[1]][idx[2] - startx[2]][p] = tfill; if(tfill) { diff --git a/src/io/MmpldWriter.cpp b/src/io/MmpldWriter.cpp index 72defd987a..08bbc439c6 100644 --- a/src/io/MmpldWriter.cpp +++ b/src/io/MmpldWriter.cpp @@ -56,7 +56,9 @@ MmpldWriter::MmpldWriter(uint64_t startTimestep, uint64_t writeFrequency, uint64 _color_type(MMPLD_COLOR_NONE) { if (0 == _writeFrequency) { - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[MMPLD Writer] writefrequency must not be 0" << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -88,8 +90,9 @@ void MmpldWriter::readXML(XMLfileUnits& xmlconfig) case 102: break; default: - Log::global_log->error() << "Unsupported MMPLD version:" << _mmpldversion << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Unsupported MMPLD version:" << _mmpldversion << std::endl; + MARDYN_EXIT(error_message.str()); break; } xmlconfig.getNodeValue("outputprefix", _outputPrefix); @@ -101,8 +104,9 @@ void MmpldWriter::readXML(XMLfileUnits& xmlconfig) numSites = query.card(); Log::global_log->info() << "[MMPLD Writer] Number of sites: " << numSites << std::endl; if(numSites < 1) { - Log::global_log->fatal() << "[MMPLD Writer] No site parameters specified." << std::endl; - mardyn_exit(48973); + std::ostringstream error_message; + error_message << "[MMPLD Writer] No site parameters specified." << std::endl; + MARDYN_EXIT(error_message.str()); } std::string oldpath = xmlconfig.getcurrentnodepath(); XMLfile::Query::const_iterator outputSiteIter; @@ -143,8 +147,9 @@ void MmpldWriter::init(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) { if ( (htole32(1) != 1) || (htole64(1.0) != 1.0) ) { - Log::global_log->error() << "[MMPLD Writer] The MMPLD Writer currently only supports running on little endian systems." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[MMPLD Writer] The MMPLD Writer currently only supports running on little endian systems." << std::endl; + MARDYN_EXIT(error_message.str()); } // only executed once @@ -391,8 +396,9 @@ long MmpldWriter::get_data_frame_header_size() { data_frame_header_size = sizeof(float) + sizeof(uint32_t); break; default: - Log::global_log->error() << "[MMPLD Writer] Unsupported MMPLD version: " << _mmpldversion << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[MMPLD Writer] Unsupported MMPLD version: " << _mmpldversion << std::endl; + MARDYN_EXIT(error_message.str()); break; } return data_frame_header_size; diff --git a/src/io/ObjectGenerator.cpp b/src/io/ObjectGenerator.cpp index c342173c7f..312b5ed830 100644 --- a/src/io/ObjectGenerator.cpp +++ b/src/io/ObjectGenerator.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "utils/mardyn_assert.h" #include "ensemble/EnsembleBase.h" @@ -24,15 +25,17 @@ void ObjectGenerator::readXML(XMLfileUnits& xmlconfig) { ObjectFillerFactory objectFillerFactory; _filler = std::shared_ptr(objectFillerFactory.create(fillerType)); if(!_filler) { - Log::global_log->error() << "Object filler could not be created" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Object filler could not be created" << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->debug() << "Using object filler of type: " << _filler->getPluginName() << std::endl; _filler->readXML(xmlconfig); xmlconfig.changecurrentnode(".."); } else { - Log::global_log->error() << "No filler specified." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "No filler specified." << std::endl; + MARDYN_EXIT(error_message.str()); } if(xmlconfig.changecurrentnode("object")) { @@ -42,14 +45,17 @@ void ObjectGenerator::readXML(XMLfileUnits& xmlconfig) { ObjectFactory objectFactory; _object = std::shared_ptr(objectFactory.create(objectType)); if(!_object) { - Log::global_log->error() << "Unknown object type: " << objectType << std::endl; + std::ostringstream error_message; + error_message << "Unknown object type: " << objectType << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->debug() << "Created object of type: " << _object->getPluginName() << std::endl; _object->readXML(xmlconfig); xmlconfig.changecurrentnode(".."); } else { - Log::global_log->error() << "No object specified." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "No object specified." << std::endl; + MARDYN_EXIT(error_message.str()); } if(xmlconfig.changecurrentnode("velocityAssigner")) { @@ -78,8 +84,9 @@ void ObjectGenerator::readXML(XMLfileUnits& xmlconfig) { } else if(velocityAssignerName == "MaxwellVelocityDistribution") { _velocityAssigner = std::make_shared(0, seed); } else { - Log::global_log->error() << "Unknown velocity assigner specified." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Unknown velocity assigner specified." << std::endl; + MARDYN_EXIT(error_message.str()); } Ensemble* ensemble = _simulation.getEnsemble(); Log::global_log->info() << "Setting temperature for velocity assigner to " << ensemble->T() << std::endl; diff --git a/src/io/PerCellGenerator.cpp b/src/io/PerCellGenerator.cpp index e0631c6073..de643c18d7 100644 --- a/src/io/PerCellGenerator.cpp +++ b/src/io/PerCellGenerator.cpp @@ -42,16 +42,18 @@ void PerCellGenerator::readXML(XMLfileUnits &xmlconfig) { if (_numMoleculesPerCell != std::numeric_limits::max()) { Log::global_log->info() << "numMoleculesPerCell: " << _numMoleculesPerCell << std::endl; } else { - Log::global_log->error() << "Missing required field numMoleculesPerCell. Aborting!" << std::endl; - mardyn_exit(1949); + std::ostringstream error_message; + error_message << "Missing required field numMoleculesPerCell. Aborting!" << std::endl; + MARDYN_EXIT(error_message.str()); } xmlconfig.getNodeValue("initTemperature", _initTemperature); if (_initTemperature > 0.) { Log::global_log->info() << "initTemperature: " << _initTemperature << std::endl; } else { - Log::global_log->error() << "Missing required field initTemperature. Aborting!" << std::endl; - mardyn_exit(1949); + std::ostringstream error_message; + error_message << "Missing required field initTemperature. Aborting!" << std::endl; + MARDYN_EXIT(error_message.str()); } xmlconfig.getNodeValue("generateAtLeastTwoParticles", _generateAtLeastTwoParticles); diff --git a/src/io/RDF.cpp b/src/io/RDF.cpp index 732e869024..b4a21dcba5 100644 --- a/src/io/RDF.cpp +++ b/src/io/RDF.cpp @@ -33,8 +33,9 @@ RDF::RDF() : void RDF::init() { if(!_readConfig){ - Log::global_log->error() << "RDF initialized without reading the configuration, exiting" << std::endl; - mardyn_exit(25); + std::ostringstream error_message; + error_message << "RDF initialized without reading the configuration, exiting" << std::endl; + MARDYN_EXIT(error_message.str()); } _cellProcessor = new RDFCellProcessor(global_simulation->getcutoffRadius(), this); @@ -153,27 +154,27 @@ void RDF::init() { void RDF::readXML(XMLfileUnits& xmlconfig) { _writeFrequency = 1; xmlconfig.getNodeValue("writefrequency", _writeFrequency); - Log::global_log->info() << "Write frequency: " << _writeFrequency << std::endl; + Log::global_log->info() << "[RDF] Write frequency: " << _writeFrequency << std::endl; _samplingFrequency = 1; xmlconfig.getNodeValue("samplingfrequency", _samplingFrequency); - Log::global_log->info() << "Sampling frequency: " << _samplingFrequency << std::endl; + Log::global_log->info() << "[RDF] Sampling frequency: " << _samplingFrequency << std::endl; _outputPrefix = "mardyn"; xmlconfig.getNodeValue("outputprefix", _outputPrefix); - Log::global_log->info() << "Output prefix: " << _outputPrefix << std::endl; + Log::global_log->info() << "[RDF] Output prefix: " << _outputPrefix << std::endl; _bins = 1; xmlconfig.getNodeValue("bins", _bins); - Log::global_log->info() << "Number of bins: " << _bins << std::endl; + Log::global_log->info() << "[RDF] Number of bins: " << _bins << std::endl; _angularBins = 1; xmlconfig.getNodeValue("angularbins", _angularBins); - Log::global_log->info() << "Number of angular bins: " << _angularBins << std::endl; + Log::global_log->info() << "[RDF] Number of angular bins: " << _angularBins << std::endl; _intervalLength = 1; xmlconfig.getNodeValueReduced("intervallength", _intervalLength); - Log::global_log->info() << "Interval length: " << _intervalLength << std::endl; + Log::global_log->info() << "[RDF] Interval length: " << _intervalLength << std::endl; _readConfig = true; } diff --git a/src/io/ReplicaGenerator.cpp b/src/io/ReplicaGenerator.cpp index 41e7737f3e..4c8f2f6168 100755 --- a/src/io/ReplicaGenerator.cpp +++ b/src/io/ReplicaGenerator.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "Domain.h" #include "Simulation.h" @@ -56,9 +57,10 @@ void ReplicaGenerator::readReplicaPhaseSpaceHeader(SubDomain& subDomain) { XMLfileUnits inp(subDomain.strFilePathHeader); if(not inp.changecurrentnode("/mardyn")) { - Log::global_log->error() << "Could not find root node /mardyn in XML input file." << std::endl; - Log::global_log->fatal() << "Not a valid MarDyn XML input file." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Could not find root node /mardyn in XML input file." << std::endl; + error_message << "Not a valid MarDyn XML input file." << std::endl; + MARDYN_EXIT(error_message.str()); } bool bInputOk = true; @@ -80,9 +82,9 @@ void ReplicaGenerator::readReplicaPhaseSpaceHeader(SubDomain& subDomain) { subDomain.dDensity = subDomain.numParticles / subDomain.dVolume; if(not bInputOk) { - Log::global_log->error() << "Content of file: '" << subDomain.strFilePathHeader << "' corrupted! Program exit ..." - << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Content of file: '" << subDomain.strFilePathHeader << "' corrupted!" << std::endl; + MARDYN_EXIT(error_message.str()); } if("ICRVQD" == strMoleculeFormat) @@ -92,8 +94,9 @@ void ReplicaGenerator::readReplicaPhaseSpaceHeader(SubDomain& subDomain) { else if("ICRV" == strMoleculeFormat) _nMoleculeFormat = ICRV; else { - Log::global_log->error() << "Not a valid molecule format: " << strMoleculeFormat << ", program exit ..." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Not a valid molecule format: " << strMoleculeFormat << ", program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -106,8 +109,9 @@ void ReplicaGenerator::readReplicaPhaseSpaceData(SubDomain& subDomain, DomainDec std::ifstream ifs; ifs.open(subDomain.strFilePathData.c_str(), std::ios::binary | std::ios::in); if(!ifs.is_open()) { - Log::global_log->error() << "Could not open phaseSpaceFile " << subDomain.strFilePathData << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Could not open phaseSpaceFile " << subDomain.strFilePathData << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "Reading phase space file " << subDomain.strFilePathData << std::endl; @@ -117,13 +121,13 @@ void ReplicaGenerator::readReplicaPhaseSpaceData(SubDomain& subDomain, DomainDec // Select appropriate reader switch (_nMoleculeFormat) { case ICRVQD: - _moleculeDataReader = new MoleculeDataReaderICRVQD(); + _moleculeDataReader = std::make_unique(); break; case ICRV: - _moleculeDataReader = new MoleculeDataReaderICRV(); + _moleculeDataReader = std::make_unique(); break; case IRV: - _moleculeDataReader = new MoleculeDataReaderIRV(); + _moleculeDataReader = std::make_unique(); break; } @@ -188,9 +192,9 @@ void ReplicaGenerator::readXML(XMLfileUnits& xmlconfig) { } else if("heterogeneous_LV" == strType) { _nSystemType = ST_HETEROGENEOUS_LIQUID_VAPOR; } else { - Log::global_log->error() << "Specified wrong type at XML path: " << xmlconfig.getcurrentnodepath() << "/type" - << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Specified wrong type at XML path: " << xmlconfig.getcurrentnodepath() << "/type" << std::endl; + MARDYN_EXIT(error_message.str()); } SubDomain sd; @@ -240,8 +244,9 @@ void ReplicaGenerator::readXML(XMLfileUnits& xmlconfig) { numChanges = query.card(); Log::global_log->info() << "Number of components to change: " << (uint32_t) numChanges << std::endl; if(numChanges < 1) { - Log::global_log->error() << "No component change defined in XML-config file. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "No component change defined in XML-config file. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } XMLfile::Query::const_iterator changeIter; for(changeIter = query.begin(); changeIter; changeIter++) { @@ -263,8 +268,9 @@ void ReplicaGenerator::readXML(XMLfileUnits& xmlconfig) { numChanges = query.card(); Log::global_log->info() << "Number of components to change: " << (uint32_t) numChanges << std::endl; if(numChanges < 1) { - Log::global_log->error() << "No component change defined in XML-config file. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "No component change defined in XML-config file. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } XMLfile::Query::const_iterator changeIter; for(changeIter = query.begin(); changeIter; changeIter++) { @@ -528,11 +534,10 @@ ReplicaGenerator::readPhaseSpace(ParticleContainer* particleContainer, Domain* d << std::endl; if(domainDecomp->getRank() == 0 && numParticlesGlobal != _numParticlesTotal - numAddedParticlesFreespaceGlobal) { - Log::global_log->info() << "Number of particles: " << numParticlesGlobal << " (added)" - " != " - << (_numParticlesTotal - numAddedParticlesFreespaceGlobal) << " (expected). Program exit ..." - << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Number of particles: " << numParticlesGlobal << " (added) != " + << (_numParticlesTotal - numAddedParticlesFreespaceGlobal) << " (expected)." << std::endl; + MARDYN_EXIT(error_message.str()); } global_simulation->timers()->stop("REPLICA_GENERATOR_VLE_INPUT"); diff --git a/src/io/ReplicaGenerator.h b/src/io/ReplicaGenerator.h index c1994f7a78..a849173166 100755 --- a/src/io/ReplicaGenerator.h +++ b/src/io/ReplicaGenerator.h @@ -9,6 +9,7 @@ #include #include #include +#include enum SystemTypes : uint8_t { @@ -72,7 +73,7 @@ class ReplicaGenerator : public InputBase { uint32_t _nIndexLiqBeginY; uint32_t _nIndexLiqEndY; uint32_t _nMoleculeFormat; - MoleculeDataReader* _moleculeDataReader; + std::unique_ptr _moleculeDataReader; double _dMoleculeDiameter; double _fspY[6]; // free space positions uint8_t _nSystemType; diff --git a/src/io/ResultWriter.cpp b/src/io/ResultWriter.cpp index 7361191119..4a8d7ff899 100644 --- a/src/io/ResultWriter.cpp +++ b/src/io/ResultWriter.cpp @@ -14,8 +14,9 @@ void ResultWriter::readXML(XMLfileUnits& xmlconfig) { xmlconfig.getNodeValue("writefrequency", _writeFrequency); Log::global_log->info() << "[ResultWriter] Write frequency: " << _writeFrequency << std::endl; if (_writeFrequency <= 0) { - Log::global_log->error() << "[ResultWriter] Write frequency must be a positive nonzero integer, but is " << _writeFrequency << std::endl; - mardyn_exit(13831); + std::ostringstream error_message; + error_message << "[ResultWriter] Write frequency must be a positive nonzero integer, but is " << _writeFrequency << std::endl; + MARDYN_EXIT(error_message.str()); } xmlconfig.getNodeValue("outputprefix", _outputPrefix); diff --git a/src/io/TimerProfiler.cpp b/src/io/TimerProfiler.cpp index 373d701ba9..c8ec9d6803 100644 --- a/src/io/TimerProfiler.cpp +++ b/src/io/TimerProfiler.cpp @@ -7,11 +7,13 @@ #include #include +#include #include "TimerProfiler.h" #include "utils/Logger.h" #include "utils/String_utils.h" #include "utils/xmlfileUnits.h" +#include "utils/mardyn_assert.h" @@ -35,7 +37,9 @@ void TimerProfiler::readXML(XMLfileUnits& xmlconfig) { } else if (displayMode == "none") { setDisplayMode(Displaymode::NONE); } else { - Log::global_log->error() << "Unknown display mode: " << displayMode << std::endl; + std::ostringstream error_message; + error_message << "Unknown display mode: " << displayMode << std::endl; + MARDYN_EXIT(error_message.str()); } } } diff --git a/src/io/TimerWriter.cpp b/src/io/TimerWriter.cpp index 7521dd92c9..75ec55761e 100644 --- a/src/io/TimerWriter.cpp +++ b/src/io/TimerWriter.cpp @@ -34,8 +34,9 @@ void TimerWriter::readXML(XMLfileUnits& xmlconfig) { << std::endl; } if (_timerNames.empty()) { - Log::global_log->error() << "TimerWriter: no timers given. make sure you specify them correctly." << std::endl; - mardyn_exit(242367); + std::ostringstream error_message; + error_message << "TimerWriter: no timers given. make sure you specify them correctly." << std::endl; + MARDYN_EXIT(error_message.str()); } xmlconfig.changecurrentnode(oldpath); } diff --git a/src/io/vtk/VTKGridWriter.cpp b/src/io/vtk/VTKGridWriter.cpp index e31a1ede79..9872824611 100644 --- a/src/io/vtk/VTKGridWriter.cpp +++ b/src/io/vtk/VTKGridWriter.cpp @@ -34,7 +34,9 @@ void VTKGridWriter::readXML(XMLfileUnits& xmlconfig) { Log::global_log->info() << "VTKMoleculeWriter: Output prefix: " << _fileName << std::endl; if (_writeFrequency <= 0) { - Log::global_log->error() << "VTKMoleculeWriter: writeFrequency must be > 0!" << std::endl; + std::ostringstream error_message; + error_message << "VTKMoleculeWriter: writeFrequency must be > 0!" << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -47,8 +49,9 @@ void VTKGridWriter::endStep( LinkedCells* container = dynamic_cast(particleContainer); #ifndef NDEBUG if (container == NULL) { - Log::global_log->error() << "VTKGridWriter works only with plottable LinkedCells!" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "VTKGridWriter works only with plottable LinkedCells!" << std::endl; + MARDYN_EXIT(error_message.str()); } #endif @@ -113,8 +116,9 @@ void VTKGridWriter::init(ParticleContainer *particleContainer, DomainDecompBase * /*domainDecomposition*/, Domain * /*domain*/) { #ifndef NDEBUG if (dynamic_cast(particleContainer) == NULL) { - Log::global_log->error() << "VTKGridWriter works only with LinkCells!" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "VTKGridWriter works only with LinkCells!" << std::endl; + MARDYN_EXIT(error_message.str()); } #endif } diff --git a/src/io/vtk/VTKMoleculeWriter.cpp b/src/io/vtk/VTKMoleculeWriter.cpp index 98b64cd676..b2342a56f3 100644 --- a/src/io/vtk/VTKMoleculeWriter.cpp +++ b/src/io/vtk/VTKMoleculeWriter.cpp @@ -36,7 +36,9 @@ void VTKMoleculeWriter::readXML(XMLfileUnits& xmlconfig) { Log::global_log->info() << "VTKMoleculeWriter: Output prefix: " << _fileName << std::endl; if (_writeFrequency <= 0) { - Log::global_log->error() << "VTKMoleculeWriter: writeFrequency must be > 0!" << std::endl; + std::ostringstream error_message; + error_message << "VTKMoleculeWriter: writeFrequency must be > 0!" << std::endl; + MARDYN_EXIT(error_message.str()); } } diff --git a/src/longRange/Homogeneous.cpp b/src/longRange/Homogeneous.cpp index 8e25bfd89a..1b3e2238ed 100644 --- a/src/longRange/Homogeneous.cpp +++ b/src/longRange/Homogeneous.cpp @@ -81,8 +81,9 @@ void Homogeneous::init() { double zj = cj.ljcenter(sj).rz(); double tau2 = sqrt(xj * xj + yj * yj + zj * zj); if (tau1 + tau2 >= _cutoffLJ) { - Log::global_log->error() << "Error calculating cutoff corrections, rc too small" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Error calculating cutoff corrections, rc too small" << std::endl; + MARDYN_EXIT(error_message.str()); } double eps24; params >> eps24; diff --git a/src/longRange/Planar.cpp b/src/longRange/Planar.cpp index a75a38a8c5..db72d85477 100644 --- a/src/longRange/Planar.cpp +++ b/src/longRange/Planar.cpp @@ -149,8 +149,9 @@ void Planar::init() _subject->registerObserver(this); Log::global_log->info() << "Long Range Correction: Subject registered" << std::endl; } else { - Log::global_log->error() << "Long Range Correction: Initialization of plugin DistControl is needed before! Program exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Long Range Correction: Initialization of plugin DistControl is needed before! Program exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } } } @@ -194,13 +195,15 @@ void Planar::readXML(XMLfileUnits& xmlconfig) bool bRet3 = xmlconfig.getNodeValue("writecontrol/stop", _nStopWritingProfiles); if(_nWriteFreqProfiles < 1) { - Log::global_log->error() << "Long Range Correction: Write frequency < 1! Programm exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Long Range Correction: Write frequency < 1! Programm exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } if(_nStopWritingProfiles <= _nStartWritingProfiles) { - Log::global_log->error() << "Long Range Correction: Writing profiles 'stop' <= 'start'! Programm exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Long Range Correction: Writing profiles 'stop' <= 'start'! Programm exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } bool bInputIsValid = (bRet1 && bRet2 && bRet3); if(true == bInputIsValid) @@ -211,8 +214,9 @@ void Planar::readXML(XMLfileUnits& xmlconfig) } else { - Log::global_log->error() << "Long Range Correction: Write control parameters not valid! Programm exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Long Range Correction: Write control parameters not valid! Programm exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } } diff --git a/src/molecules/AutoPasSimpleMolecule.cpp b/src/molecules/AutoPasSimpleMolecule.cpp index 49150cd981..2968490833 100644 --- a/src/molecules/AutoPasSimpleMolecule.cpp +++ b/src/molecules/AutoPasSimpleMolecule.cpp @@ -20,7 +20,7 @@ AutoPasSimpleMolecule::AutoPasSimpleMolecule(unsigned long id, Component* compon } else if (_component != component and component != nullptr) { Log::global_log->warning() << "AutoPasSimpleMolecule can only handle one component" << std::endl; _component = component; - // mardyn_exit(32); + // MARDYN_EXIT(error_message.str()); } } diff --git a/src/molecules/Comp2Param.cpp b/src/molecules/Comp2Param.cpp index f32bdb3042..413e8b9d69 100644 --- a/src/molecules/Comp2Param.cpp +++ b/src/molecules/Comp2Param.cpp @@ -58,8 +58,9 @@ void Comp2Param::initialize( return {[=](double sigi, double sigj) { return eta * (sigi + sigj); }, // mixingSigma [=](double epsi, double epsj) { return xi * sqrt(epsi * epsj); }}; // mixingEpsilon } else { - Log::global_log->error() << "Mixing: Only LB rule supported" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Mixing: Only LB rule supported" << std::endl; + MARDYN_EXIT(error_message.str()); return {}; } }(); diff --git a/src/molecules/Component.cpp b/src/molecules/Component.cpp index fd1506a78b..ef3212f30f 100644 --- a/src/molecules/Component.cpp +++ b/src/molecules/Component.cpp @@ -76,11 +76,13 @@ void Component::readXML(XMLfileUnits& xmlconfig) { quadrupoleSite.readXML(xmlconfig); addQuadrupole(quadrupoleSite); } else if (siteType == "Tersoff") { - Log::global_log->error() << "Tersoff no longer supported:" << siteType << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Tersoff no longer supported:" << siteType << std::endl; + MARDYN_EXIT(error_message.str()); } else { - Log::global_log->error() << "Unknown site type:" << siteType << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Unknown site type:" << siteType << std::endl; + MARDYN_EXIT(error_message.str()); } // go back to initial level, to be consistent, even if no site information is found. xmlconfig.changecurrentnode(".."); diff --git a/src/molecules/MoleculeInterface.cpp b/src/molecules/MoleculeInterface.cpp index 4ba56e0dbc..f5b78b3cf3 100644 --- a/src/molecules/MoleculeInterface.cpp +++ b/src/molecules/MoleculeInterface.cpp @@ -30,8 +30,9 @@ bool MoleculeInterface::isLessThan(const MoleculeInterface& m2) const { else if (r(0) > m2.r(0)) return false; else { - Log::global_log->error() << "LinkedCells::isFirstParticle: both Particles have the same position" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "LinkedCells::isFirstParticle: both Particles have the same position" << std::endl; + MARDYN_EXIT(error_message.str()); } } } diff --git a/src/molecules/mixingrules/MixingRuleBase.cpp b/src/molecules/mixingrules/MixingRuleBase.cpp index f66d45322d..5ecfa4650d 100644 --- a/src/molecules/mixingrules/MixingRuleBase.cpp +++ b/src/molecules/mixingrules/MixingRuleBase.cpp @@ -15,11 +15,13 @@ void MixingRuleBase::readXML(const XMLfileUnits& xmlconfig) { // catch invalid inputs if (cid1 == cid2) { - Log::global_log->error() << "Mixing rules: cid1 and cid2 must not be the same but are both " << cid1 << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Mixing rules: cid1 and cid2 must not be the same but are both " << cid1 << std::endl; + MARDYN_EXIT(error_message.str()); } else if (std::min(cid1, cid2) < 0) { - Log::global_log->error() << "Mixing rules: cid1 and cid2 must be greater than zero" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Mixing rules: cid1 and cid2 must be greater than zero" << std::endl; + MARDYN_EXIT(error_message.str()); } // Symmetry for mixing rules is assumed diff --git a/src/parallel/CollectiveCommunication.h b/src/parallel/CollectiveCommunication.h index 7c390fa0ea..cf38274102 100644 --- a/src/parallel/CollectiveCommunication.h +++ b/src/parallel/CollectiveCommunication.h @@ -170,8 +170,9 @@ class CollectiveCommunication: public CollectiveCommBase, public CollectiveCommu commutative, &agglomeratedTypeAddOperator)); break; default: - Log::global_log->error()<<"invalid reducetype, aborting." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message<<"invalid reducetype, aborting." << std::endl; + MARDYN_EXIT(error_message.str()); } MPI_CHECK( @@ -192,8 +193,9 @@ class CollectiveCommunication: public CollectiveCommBase, public CollectiveCommu op = MPI_MAX; break; default: - Log::global_log->error()<<"invalid reducetype, aborting." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message<<"invalid reducetype, aborting." << std::endl; + MARDYN_EXIT(error_message.str()); } MPI_CHECK(MPI_Allreduce( MPI_IN_PLACE, &_values[i], 1, _types[i], op, _communicator )); } diff --git a/src/parallel/CollectiveCommunicationNonBlocking.h b/src/parallel/CollectiveCommunicationNonBlocking.h index d20e1818b7..b0b9966b13 100644 --- a/src/parallel/CollectiveCommunicationNonBlocking.h +++ b/src/parallel/CollectiveCommunicationNonBlocking.h @@ -39,9 +39,10 @@ class CollectiveCommunicationNonBlocking: public CollectiveCommunicationInterfac //! @param numValues number of values that shall be communicated void init(MPI_Comm communicator, int numValues, int key = 0) override { if (_currentKey != -1) { - Log::global_log->error() << "CollectiveCommunicationNonBlocking: previous communication with key " << _currentKey + std::ostringstream error_message; + error_message << "CollectiveCommunicationNonBlocking: previous communication with key " << _currentKey << " not yet finalized" << std::endl; - mardyn_exit(234); + MARDYN_EXIT(error_message.str()); } _currentKey = key; @@ -57,9 +58,10 @@ class CollectiveCommunicationNonBlocking: public CollectiveCommunicationInterfac // Creates the CollectiveCommunicationSingleNonBlocking object auto [_, inserted] = _comms.try_emplace(_currentKey); if (not inserted) { - Log::global_log->error() << "CollectiveCommunicationNonBlocking: key " << _currentKey + std::ostringstream error_message; + error_message << "CollectiveCommunicationNonBlocking: key " << _currentKey << " could not be inserted. Aborting!" << std::endl; - mardyn_exit(498789); + MARDYN_EXIT(error_message.str()); } } _comms.at(_currentKey).init(communicator, numValues, _currentKey); diff --git a/src/parallel/CommunicationPartner.cpp b/src/parallel/CommunicationPartner.cpp index 90d99e1ded..16f5efa8ac 100644 --- a/src/parallel/CommunicationPartner.cpp +++ b/src/parallel/CommunicationPartner.cpp @@ -195,8 +195,9 @@ void CommunicationPartner::initSend(ParticleContainer* moleculeContainer, const break; } default: - Log::global_log->error() << "[CommunicationPartner] MessageType unknown!" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[CommunicationPartner] MessageType unknown!" << std::endl; + MARDYN_EXIT(error_message.str()); } #ifndef NDEBUG @@ -599,8 +600,9 @@ void CommunicationPartner::collectLeavingMoleculesFromInvalidParticles(std::vect // it will add the given molecule to _sendBuf with the necessary shift. auto shiftAndAdd = [domain, lowCorner, highCorner, shift, this, &numMolsAlreadyIn](Molecule& m) { if (not m.inBox(lowCorner, highCorner)) { - Log::global_log->error() << "trying to remove a particle that is not in the halo region" << std::endl; - mardyn_exit(456); + std::ostringstream error_message; + error_message << "trying to remove a particle that is not in the halo region" << std::endl; + MARDYN_EXIT(error_message.str()); } for (int dim = 0; dim < 3; dim++) { if (shift[dim] != 0) { diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index bb1eb112e4..dd9b2af653 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -259,8 +259,9 @@ void DomainDecompBase::handleDomainLeavingParticlesDirect(const HaloRegion& halo auto shiftAndAdd = [&moleculeContainer, haloRegion, shift](Molecule& m) { if (not m.inBox(haloRegion.rmin, haloRegion.rmax)) { - Log::global_log->error() << "trying to remove a particle that is not in the halo region" << std::endl; - mardyn_exit(456); + std::ostringstream error_message; + error_message << "trying to remove a particle that is not in the halo region" << std::endl; + MARDYN_EXIT(error_message.str()); } for (int dim = 0; dim < 3; dim++) { if (shift[dim] != 0) { diff --git a/src/parallel/DomainDecompMPIBase.cpp b/src/parallel/DomainDecompMPIBase.cpp index cde084769c..0cb934df6a 100644 --- a/src/parallel/DomainDecompMPIBase.cpp +++ b/src/parallel/DomainDecompMPIBase.cpp @@ -6,6 +6,7 @@ */ #include #include +#include #include "DomainDecompMPIBase.h" #include "molecules/Molecule.h" @@ -149,9 +150,9 @@ void DomainDecompMPIBase::setCommunicationScheme(const std::string& scheme, cons } else if(zonalMethod=="nt") { zonalMethodP = new NeutralTerritory(); } else { - Log::global_log->error() << "DomainDecompMPIBase: invalid zonal method specified. Valid values are 'fs', 'es', 'hs', 'mp' and 'nt'" - << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "DomainDecompMPIBase: invalid zonal method specified. Valid values are 'fs', 'es', 'hs', 'mp' and 'nt'" << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "Using zonal method: " << zonalMethod << std::endl; @@ -165,9 +166,9 @@ void DomainDecompMPIBase::setCommunicationScheme(const std::string& scheme, cons Log::global_log->info() << "DomainDecompMPIBase: Using IndirectCommunicationScheme" << std::endl; _neighbourCommunicationScheme = std::make_unique(zonalMethodP); } else { - Log::global_log->error() << "DomainDecompMPIBase: invalid NeighbourCommunicationScheme specified. Valid values are 'direct' and 'indirect'" - << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "DomainDecompMPIBase: invalid NeighbourCommunicationScheme specified. Valid values are 'direct' and 'indirect'" << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -196,8 +197,10 @@ void DomainDecompMPIBase::assertIntIdentity(int IX) { for (int i = 1; i < _numProcs; i++) { MPI_CHECK(MPI_Recv(&recv, 1, MPI_INT, i, 2 * i + 17, _comm, &s)); if (recv != IX) { - Log::global_log->error() << "IX is " << IX << " for rank 0, but " << recv << " for rank " << i << ".\n"; - MPI_Abort(_comm, 911); + std::ostringstream error_message; + error_message << "[DomainDecompMPIBase] IX is " << IX << " for rank 0, " + << "but " << recv << " for rank " << i << "." << std::endl; + MARDYN_EXIT(error_message.str()); } } Log::global_log->info() << "IX = " << recv << " for all " << _numProcs << " ranks.\n"; @@ -224,8 +227,9 @@ void DomainDecompMPIBase::assertDisjunctivity(ParticleContainer* moleculeContain for (auto m = moleculeContainer->iterator(ParticleIterator::ONLY_INNER_AND_BOUNDARY); m.isValid(); ++m) { if(check.find(m->getID()) != check.end()){ - Log::global_log->error() << "Rank 0 contains a duplicated particle with id " << m->getID() << std::endl; - MPI_Abort(_comm, 1); + std::ostringstream error_message; + error_message << "Rank 0 contains a duplicated particle with id " << m->getID() << std::endl; + MARDYN_EXIT(error_message.str()); } check[m->getID()] = 0; } @@ -248,8 +252,9 @@ void DomainDecompMPIBase::assertDisjunctivity(ParticleContainer* moleculeContain } } if (not isOk) { - Log::global_log->error() << "Aborting because of duplicated particles." << std::endl; - MPI_Abort(_comm, 1); + std::ostringstream error_message; + error_message << "Aborting because of duplicated particles." << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "Data consistency checked: No duplicate IDs detected among " << check.size() diff --git a/src/parallel/DomainDecomposition.cpp b/src/parallel/DomainDecomposition.cpp index 4aa51be05a..67d4c8ce9c 100644 --- a/src/parallel/DomainDecomposition.cpp +++ b/src/parallel/DomainDecomposition.cpp @@ -1,10 +1,13 @@ #include "DomainDecomposition.h" +#include + #include "Domain.h" #include "molecules/Molecule.h" #include "particleContainer/ParticleContainer.h" #include "utils/xmlfileUnits.h" #include "utils/Logger.h" +#include "utils/mardyn_assert.h" #include "parallel/NeighbourCommunicationScheme.h" #include "parallel/HaloRegion.h" #include "ParticleData.h" @@ -23,12 +26,13 @@ void DomainDecomposition::initMPIGridDims() { { auto numProcsGridSize = _gridSize[0] * _gridSize[1] * _gridSize[2]; if (numProcsGridSize != _numProcs and numProcsGridSize != 0) { - Log::global_log->error() << "DomainDecomposition: Wrong grid size given!" << std::endl; - Log::global_log->error() << "\tnumProcs is " << _numProcs << "," << std::endl; - Log::global_log->error() << "\tbut grid is " << _gridSize[0] << " x " << _gridSize[1] << " x " << _gridSize[2] << std::endl; - Log::global_log->error() << "\tresulting in " << numProcsGridSize << " subdomains!" << std::endl; - Log::global_log->error() << "\tplease check your input file!" << std::endl; - mardyn_exit(2134); + std::ostringstream error_message; + error_message << "DomainDecomposition: Wrong grid size given!" << std::endl; + error_message << "\tnumProcs is " << _numProcs << "," << std::endl; + error_message << "\tbut grid is " << _gridSize[0] << " x " << _gridSize[1] << " x " << _gridSize[2] << std::endl; + error_message << "\tresulting in " << numProcsGridSize << " subdomains!" << std::endl; + error_message << "\tplease check your input file!" << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -59,10 +63,11 @@ void DomainDecomposition::prepareNonBlockingStage(bool /*forceRebalancing*/, Par LEAVING_AND_HALO_COPIES); } else { // Would first need to send leaving, then halo -> not good for overlapping! - Log::global_log->error() << "nonblocking P2P using separate messages for leaving and halo is currently not " + std::ostringstream error_message; + error_message << "nonblocking P2P using separate messages for leaving and halo is currently not " "supported. Please use the indirect neighbor communication scheme!" << std::endl; - mardyn_exit(235861); + MARDYN_EXIT(error_message.str()); } } @@ -73,9 +78,10 @@ void DomainDecomposition::finishNonBlockingStage(bool /*forceRebalancing*/, Part LEAVING_AND_HALO_COPIES); } else { // Would first need to send leaving, then halo -> not good for overlapping! - Log::global_log->error() + std::ostringstream error_message; + error_message << "nonblocking P2P using separate messages for leaving and halo is currently not supported." << std::endl; - mardyn_exit(235861); + MARDYN_EXIT(error_message.str()); } } diff --git a/src/parallel/ForceHelper.cpp b/src/parallel/ForceHelper.cpp index 86d19a8fff..3bf5177c48 100644 --- a/src/parallel/ForceHelper.cpp +++ b/src/parallel/ForceHelper.cpp @@ -1,6 +1,7 @@ #include "ForceHelper.h" +#include #include #include "utils/mardyn_assert.h" @@ -37,8 +38,9 @@ std::variant> addValuesAndGet [&](auto originalIter) { if (not originalIter.isValid()) { // This should not happen - std::cout << "Original molecule not usePreviousIterator"; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Original molecule not usePreviousIterator" << std::endl; + MARDYN_EXIT(error_message.str()); } mardyn_assert(originalIter->getID() == haloMolecule.getID()); diff --git a/src/parallel/GeneralDomainDecomposition.cpp b/src/parallel/GeneralDomainDecomposition.cpp index 2cbbf24573..46d14c60b1 100644 --- a/src/parallel/GeneralDomainDecomposition.cpp +++ b/src/parallel/GeneralDomainDecomposition.cpp @@ -21,6 +21,7 @@ #include #include #include +#include GeneralDomainDecomposition::GeneralDomainDecomposition(double interactionLength, Domain* domain, bool forceGrid) : _boxMin{0.}, @@ -58,8 +59,9 @@ void GeneralDomainDecomposition::initializeALL() { _loadBalancer = std::make_unique(_boxMin, _boxMax, 4 /*gamma*/, this->getCommunicator(), gridSize, gridCoords, minimalDomainSize); #else - Log::global_log->error() << "ALL load balancing library not enabled. Aborting." << std::endl; - mardyn_exit(24235); + std::ostringstream error_message; + error_message << "ALL load balancing library not enabled. Aborting." << std::endl; + MARDYN_EXIT(error_message.str()); #endif Log::global_log->info() << "GeneralDomainDecomposition initial box: [" << _boxMin[0] << ", " << _boxMax[0] << "] x [" << _boxMin[1] << ", " << _boxMax[1] << "] x [" << _boxMin[2] << ", " << _boxMax[2] << "]" @@ -186,7 +188,8 @@ void GeneralDomainDecomposition::migrateParticles(Domain* domain, ParticleContai ownMolecules.push_back(*iter); // TODO: This check should be in debug mode only if (not iter->inBox(newMin.data(), newMax.data())) { - Log::global_log->error_always_output() + std::ostringstream error_message; + error_message << "Particle still in domain that should have been migrated." << "BoxMin: " << particleContainer->getBoundingBoxMin(0) << ", " @@ -198,7 +201,7 @@ void GeneralDomainDecomposition::migrateParticles(Domain* domain, ParticleContai << particleContainer->getBoundingBoxMax(2) << "\n" << "Particle: \n" << *iter << std::endl; - mardyn_exit(2315); + MARDYN_EXIT(error_message.str()); } } particleContainer->clear(); @@ -289,10 +292,11 @@ void GeneralDomainDecomposition::readXML(XMLfileUnits& xmlconfig) { if (gridSizeString.find(',') != std::string::npos) { auto strings = string_utils::split(gridSizeString, ','); if (strings.size() != 3) { - Log::global_log->error() + std::ostringstream error_message; + error_message << "GeneralDomainDecomposition's gridSize should have three entries if a list is given, but has " << strings.size() << "!" << std::endl; - mardyn_exit(8134); + MARDYN_EXIT(error_message.str()); } _gridSize = {std::stod(strings[0]), std::stod(strings[1]), std::stod(strings[2])}; } else { @@ -301,10 +305,11 @@ void GeneralDomainDecomposition::readXML(XMLfileUnits& xmlconfig) { } for (auto gridSize : *_gridSize) { if (gridSize < _interactionLength) { - Log::global_log->error() << "GeneralDomainDecomposition's gridSize (" << gridSize + std::ostringstream error_message; + error_message << "GeneralDomainDecomposition's gridSize (" << gridSize << ") is smaller than the interactionLength (" << _interactionLength << "). This is forbidden, as it leads to errors! " << std::endl; - mardyn_exit(8136); + MARDYN_EXIT(error_message.str()); } } } @@ -319,14 +324,16 @@ void GeneralDomainDecomposition::readXML(XMLfileUnits& xmlconfig) { if (loadBalancerString.find("all") != std::string::npos) { initializeALL(); } else { - Log::global_log->error() << "GeneralDomainDecomposition: Unknown load balancer " << loadBalancerString + std::ostringstream error_message; + error_message << "GeneralDomainDecomposition: Unknown load balancer " << loadBalancerString << ". Aborting! Please select a valid option! Valid options: ALL"; - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); } _loadBalancer->readXML(xmlconfig); } else { - Log::global_log->error() << "loadBalancer section missing! Aborting!" << std::endl; - mardyn_exit(8466); + std::ostringstream error_message; + error_message << "loadBalancer section missing! Aborting!" << std::endl; + MARDYN_EXIT(error_message.str()); } xmlconfig.changecurrentnode(".."); } diff --git a/src/parallel/KDDecomposition.cpp b/src/parallel/KDDecomposition.cpp index 03fe4577a6..7a44ecd319 100644 --- a/src/parallel/KDDecomposition.cpp +++ b/src/parallel/KDDecomposition.cpp @@ -65,10 +65,11 @@ void KDDecomposition::init(Domain* domain){ _decompTree = new KDNode(_numProcs, lowCorner, highCorner, 0, 0, coversWholeDomain, 0); if (!_decompTree->isResolvable()) { auto minCellCountPerProc = std::pow(KDDStaticValues::minNumCellsPerDimension, 3); - Log::global_log->error() << "KDDecomposition not possible. Each process needs at least " << minCellCountPerProc - << " cells." << std::endl; - Log::global_log->error() << "The number of Cells is only sufficient for " << _decompTree->getNumMaxProcs() << " Procs!" << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "KDDecomposition not possible. Each process needs at least " + << minCellCountPerProc << " cells." << std::endl; + error_message << "The number of Cells is only sufficient for " << _decompTree->getNumMaxProcs() << " Procs!" << std::endl; + MARDYN_EXIT(error_message.str()); } _decompTree->buildKDTree(); _ownArea = _decompTree->findAreaForProcess(_rank); @@ -103,8 +104,9 @@ void KDDecomposition::readXML(XMLfileUnits& xmlconfig) { Log::global_log->info() << "KDDecomposition minNumCellsPerDimension: " << KDDStaticValues::minNumCellsPerDimension << std::endl; if(KDDStaticValues::minNumCellsPerDimension==0u){ - Log::global_log->error() << "KDDecomposition minNumCellsPerDimension has to be bigger than zero!" << std::endl; - mardyn_exit(43); + std::ostringstream error_message; + error_message << "KDDecomposition minNumCellsPerDimension has to be bigger than zero!" << std::endl; + MARDYN_EXIT(error_message.str()); } xmlconfig.getNodeValue("updateFrequency", _frequency); Log::global_log->info() << "KDDecomposition update frequency: " << _frequency << std::endl; @@ -124,9 +126,10 @@ void KDDecomposition::readXML(XMLfileUnits& xmlconfig) { } else if (deviationReductionOperation == "max") { _deviationReductionOperation = MPI_MAX; } else { - Log::global_log->fatal() << "Wrong deviationReductionOperation given: " << _deviationReductionOperation + std::ostringstream error_message; + error_message << "Wrong deviationReductionOperation given: " << _deviationReductionOperation << ". Should be 'max' or 'sum'." << std::endl; - mardyn_exit(45681); + MARDYN_EXIT(error_message.str()); } } Log::global_log->info() << "KDDecomposition uses " << deviationReductionOperation @@ -316,9 +319,10 @@ void KDDecomposition::balanceAndExchange(double lastTraversalTime, bool forceReb constructNewTree(newDecompRoot, newOwnLeaf, moleculeContainer); bool migrationSuccessful = migrateParticles(*newDecompRoot, *newOwnLeaf, moleculeContainer, domain); if (not migrationSuccessful) { - Log::global_log->error() << "A problem occurred during particle migration between old decomposition and new decomposition of the KDDecomposition." << std::endl; - Log::global_log->error() << "Aborting. Please save your input files and last available checkpoint and contact TUM SCCS." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "A problem occurred during particle migration between old decomposition and new decomposition of the KDDecomposition." << std::endl; + error_message << "Aborting. Please save your input files and last available checkpoint and contact TUM SCCS." << std::endl; + MARDYN_EXIT(error_message.str()); } delete _decompTree; _decompTree = newDecompRoot; @@ -559,8 +563,9 @@ bool KDDecomposition::migrateParticles(const KDNode& newRoot, const KDNode& newO void KDDecomposition::fillTimeVecs(CellProcessor **cellProc){ if(cellProc == nullptr){ - Log::global_log->error() << "The cellProcessor was not yet set! Please reorder fillTimeVecs, so that there won't be a problem!"; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "The cellProcessor was not yet set! Please reorder fillTimeVecs, so that there won't be a problem!" << std::endl; + MARDYN_EXIT(error_message.str()); } auto _tunerLoadCalc = dynamic_cast(_loadCalc); if(_tunerLoadCalc){ @@ -1029,8 +1034,9 @@ bool KDDecomposition::calculateAllPossibleSubdivisions(KDNode* node, std::listerror() << "no processor speeds given" << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "no processor speeds given" << std::endl; + MARDYN_EXIT(error_message.str()); } double optimalLoad = (_accumulatedProcessorSpeeds[node->_owningProc + node->_numProcs] - _accumulatedProcessorSpeeds[node->_owningProc]) * leftRightLoadRatio / (1. + leftRightLoadRatio); @@ -1092,8 +1098,9 @@ bool KDDecomposition::calculateAllPossibleSubdivisions(KDNode* node, std::list_child1->_numProcs <= 0 || clone->_child1->_numProcs >= node->_numProcs) || (clone->_child2->_numProcs <= 0 || clone->_child2->_numProcs >= node->_numProcs) ){ //continue; - Log::global_log->error_always_output() << "ERROR in calculateAllPossibleSubdivisions(), part of the domain was not assigned to a proc" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "ERROR in calculateAllPossibleSubdivisions(), part of the domain was not assigned to a proc" << std::endl; + MARDYN_EXIT(error_message.str()); } mardyn_assert( clone->_child1->isResolvable() && clone->_child2->isResolvable() ); @@ -1252,8 +1259,9 @@ void KDDecomposition::calculateCostsPar(KDNode* area, std::vectorerror() << "[KDDecomposition] zeroCounts too large!" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[KDDecomposition] zeroCounts too large!" << std::endl; + MARDYN_EXIT(error_message.str()); } } } @@ -1437,14 +1445,16 @@ void KDDecomposition::calcNumParticlesPerCell(ParticleContainer* moleculeContain } std::vector KDDecomposition::getNeighbourRanks() { - //global_log->error() << "not implemented \n"; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "KDDecomposition::getNeighbourRanks() not implemented" << std::endl; + MARDYN_EXIT(error_message.str()); return std::vector (0); } std::vector KDDecomposition::getNeighbourRanksFullShell() { - //global_log->error() << "not implemented \n"; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "KDDecomposition::getNeighbourRanksFullShell() not implemented" << std::endl; + MARDYN_EXIT(error_message.str()); return std::vector (0); } @@ -1777,8 +1787,9 @@ bool KDDecomposition::calculateHeteroSubdivision(KDNode* node, KDNode*& optimalN size_t biggestDim = maxInd; if (costsLeft[biggestDim].size()<=2){ - Log::global_log->error_always_output() << "The domain is far to small!"; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "The domain is far to small!" << std::endl; + MARDYN_EXIT(error_message.str()); } int startIndex = 1; @@ -1821,8 +1832,9 @@ bool KDDecomposition::calculateHeteroSubdivision(KDNode* node, KDNode*& optimalN optimalNode->split(biggestDim, node->_lowCorner[biggestDim] + i, numProcsLeft); if ( (unsigned int) (optimalNode->_child1->_numProcs + optimalNode->_child2->_numProcs) > (optimalNode->_child1->getNumMaxProcs() + optimalNode->_child2->getNumMaxProcs())) { - Log::global_log->error() << "Domain is not resolvable at all!" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Domain is not resolvable at all!" << std::endl; + MARDYN_EXIT(error_message.str()); } while ( (! optimalNode->_child1->isResolvable()) && optimalNode->_child2->isResolvable()) { @@ -1849,8 +1861,9 @@ bool KDDecomposition::calculateHeteroSubdivision(KDNode* node, KDNode*& optimalN if ((optimalNode->_child1->_numProcs <= 0 || optimalNode->_child1->_numProcs >= node->_numProcs) || (optimalNode->_child2->_numProcs <= 0 || optimalNode->_child2->_numProcs >= node->_numProcs) ){ //continue; - Log::global_log->error_always_output() << "ERROR in calculateHeteroSubdivision(), part of the domain was not assigned to a proc" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "ERROR in calculateHeteroSubdivision(), part of the domain was not assigned to a proc" << std::endl; + MARDYN_EXIT(error_message.str()); } mardyn_assert( optimalNode->_child1->isResolvable() && optimalNode->_child2->isResolvable() ); diff --git a/src/parallel/LoadCalc.cpp b/src/parallel/LoadCalc.cpp index abe0c2dc33..e02bf20276 100644 --- a/src/parallel/LoadCalc.cpp +++ b/src/parallel/LoadCalc.cpp @@ -40,13 +40,12 @@ std::vector TunerLoad::readVec(std::istream& in, int& count1, int& count tempCount2 = i; } else { if (i != tempCount2) { - Log::global_log->error_always_output() - << "The file contains data of 2D-vectors with a different amounts of elements in the second dimension!" - << std::endl; - Log::global_log->error_always_output() - << "This means the files is corrupted. Please remove it (or disallow the tuner to read from inputfiles) before restarting!" - << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "The file contains data of 2D-vectors" + << " with a different amounts of elements in the second dimension!" << std::endl; + error_message << "This means the files is corrupted. " + << "Please remove it (or disallow the tuner to read from inputfiles) before restarting!" << std::endl; + MARDYN_EXIT(error_message.str()); } } } @@ -122,23 +121,31 @@ TunerLoad::TunerLoad(int count1, int count2, std::vector&& ownTime, std: calcConsts(_cornerTime, false)) { if (_ownTime.size() != size_t(_count1 * _count2)) { - Log::global_log->error_always_output() << "_edgeTime was initialized with the wrong size of " << _ownTime.size() + std::ostringstream error_message; + error_message << "_edgeTime was initialized with the wrong size of " << _ownTime.size() << " expected: " << _count1 * _count2; + MARDYN_EXIT(error_message.str()); } if (_faceTime.size() != size_t(count1 * _count2)) { - Log::global_log->error_always_output() << "_edgeTime was initialized with the wrong size of " << _faceTime.size() + std::ostringstream error_message; + error_message << "_edgeTime was initialized with the wrong size of " << _faceTime.size() << " expected: " << _count1 * _count2; + MARDYN_EXIT(error_message.str()); } if (_edgeTime.size() != size_t(_count1 * _count2)) { - Log::global_log->error_always_output() << "_edgeTime was initialized with the wrong size of " << _edgeTime.size() + std::ostringstream error_message; + error_message << "_edgeTime was initialized with the wrong size of " << _edgeTime.size() << " expected: " << _count1 * _count2; + MARDYN_EXIT(error_message.str()); } if (_cornerTime.size() != size_t(_count1 * _count2)) { - Log::global_log->error_always_output() << "_edgeTime was initialized with the wrong size of " << _cornerTime.size() + std::ostringstream error_message; + error_message << "_edgeTime was initialized with the wrong size of " << _cornerTime.size() << " expected: " << _count1 * _count2; + MARDYN_EXIT(error_message.str()); } } @@ -146,9 +153,10 @@ TunerLoad TunerLoad::read(std::istream& stream) { std::string inStr { }; std::getline(stream, inStr); if (inStr != "Vectorization Tuner File") { - Log::global_log->error() << "The tunerfile is corrupted! Missing header \"Vectorization Tuner File\""; - Log::global_log->error() << "Please remove it or fix it before restarting!"; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "The tunerfile is corrupted! Missing header \"Vectorization Tuner File\""; + error_message << "Please remove it or fix it before restarting!"; + MARDYN_EXIT(error_message.str()); } int count1; @@ -156,33 +164,37 @@ TunerLoad TunerLoad::read(std::istream& stream) { std::getline(stream, inStr); if (inStr != "own") { - Log::global_log->error() << "The tunerfile is corrupted! Missing Section \"own\""; - Log::global_log->error() << "Please remove it or fix it before restarting!"; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "The tunerfile is corrupted! Missing Section \"own\""; + error_message << "Please remove it or fix it before restarting!"; + MARDYN_EXIT(error_message.str()); } auto ownTime = readVec(stream, count1, count2); std::getline(stream, inStr); if (inStr != "face") { - Log::global_log->error() << "The tunerfile is corrupted! Missing Section \"face\""; - Log::global_log->error() << "Please remove it or fix it before restarting!"; - mardyn_exit(1); + std::ostringstream error_message; + error_message<< "The tunerfile is corrupted! Missing Section \"face\""; + error_message << "Please remove it or fix it before restarting!"; + MARDYN_EXIT(error_message.str()); } auto faceTime = readVec(stream, count1, count2); std::getline(stream, inStr); if (inStr != "edge") { - Log::global_log->error() << "The tunerfile is corrupted! Missing Section \"edge\""; - Log::global_log->error() << "Please remove it or fix it before restarting!"; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "The tunerfile is corrupted! Missing Section \"edge\""; + error_message << "Please remove it or fix it before restarting!"; + MARDYN_EXIT(error_message.str()); } auto edgeTime = readVec(stream, count1, count2); std::getline(stream, inStr); if (inStr != "corner") { - Log::global_log->error() << "The tunerfile is corrupted! Missing Section \"corner\""; - Log::global_log->error() << "Please remove it or fix it before restarting!"; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "The tunerfile is corrupted! Missing Section \"corner\""; + error_message << "Please remove it or fix it before restarting!"; + MARDYN_EXIT(error_message.str()); } auto cornerTime = readVec(stream, count1, count2); return TunerLoad { count1, count2, std::move(ownTime), std::move(faceTime), std::move(edgeTime), std::move( diff --git a/src/parallel/NeighbourCommunicationScheme.cpp b/src/parallel/NeighbourCommunicationScheme.cpp index 7eaa8e94ea..6353fe5393 100644 --- a/src/parallel/NeighbourCommunicationScheme.cpp +++ b/src/parallel/NeighbourCommunicationScheme.cpp @@ -8,7 +8,9 @@ class NeighbourCommunicationScheme; class DirectNeighbourCommunicationScheme; class IndirectNeighbourCommunicationScheme; +#include #include + #include "NeighbourCommunicationScheme.h" #include "Domain.h" #include "Simulation.h" @@ -246,7 +248,8 @@ void DirectNeighbourCommunicationScheme::initExchangeMoleculesMPI(ParticleContai } } if(not invalidParticles.empty()){ - Log::global_log->error_always_output() << "NeighbourCommunicationScheme: Invalid particles that should have been " + std::ostringstream error_message; + error_message << "NeighbourCommunicationScheme: Invalid particles that should have been " "sent, are still existent. They would be lost. Aborting...\n" << "BoxMin: " << moleculeContainer->getBoundingBoxMin(0) << ", " @@ -258,15 +261,15 @@ void DirectNeighbourCommunicationScheme::initExchangeMoleculesMPI(ParticleContai << moleculeContainer->getBoundingBoxMax(2) << "\n" << "The particles:" << std::endl; for (auto& invalidParticle : invalidParticles) { - Log::global_log->error_always_output() << invalidParticle << std::endl; + error_message << invalidParticle << std::endl; } - Log::global_log->error_always_output() << "The leavingExportNeighbours:" << std::endl; + error_message << "The leavingExportNeighbours:" << std::endl; for (auto& neighbour : (*_leavingExportNeighbours)[0]) { std::stringstream ss; neighbour.print(ss); - Log::global_log->error_always_output() << ss.str() << std::endl; + error_message << ss.str() << std::endl; } - mardyn_exit(544); + MARDYN_EXIT(error_message.str()); } } @@ -377,7 +380,8 @@ void DirectNeighbourCommunicationScheme::finalizeExchangeMoleculesMPI(ParticleCo } if (waitingTime > deadlockTimeOut) { - Log::global_log->error() + std::ostringstream error_message; + error_message << "DirectNeighbourCommunicationScheme::finalizeExchangeMoleculesMPI1d: Deadlock error: Rank " << domainDecomp->getRank() << " is waiting for more than " << deadlockTimeOut << " seconds" << std::endl; @@ -396,7 +400,7 @@ void DirectNeighbourCommunicationScheme::finalizeExchangeMoleculesMPI(ParticleCo }); } - mardyn_exit(457); + MARDYN_EXIT(error_message.str()); } } // while not allDone @@ -422,10 +426,11 @@ void NeighbourCommunicationScheme::selectNeighbours(MessageType msgType, bool im else _neighbours = _haloImportForceExportNeighbours; break; case LEAVING_AND_HALO_COPIES: - Log::global_log->error() << "WRONG type in selectNeighbours - this should not be used for push-pull-partners " + std::ostringstream error_message; + error_message << "WRONG type in selectNeighbours - this should not be used for push-pull-partners " "selectNeighbours method" << std::endl; - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); break; } } @@ -587,14 +592,15 @@ void IndirectNeighbourCommunicationScheme::finalizeExchangeMoleculesMPI1D(Partic } if (waitingTime > deadlockTimeOut) { - Log::global_log->error() + std::ostringstream error_message; + error_message << "IndirectNeighbourCommunicationScheme::finalizeExchangeMoleculesMPI1d: Deadlock error: Rank " << domainDecomp->getRank() << " is waiting for more than " << deadlockTimeOut << " seconds" << std::endl; for (int i = 0; i < numNeighbours; ++i) { (*_neighbours)[d][i].deadlockDiagnosticSendRecv(); } - mardyn_exit(457); + MARDYN_EXIT(error_message.str()); } } // while not allDone diff --git a/src/parallel/ParticleDataRMM.cpp b/src/parallel/ParticleDataRMM.cpp index 9ab4094e93..943ad37e9e 100644 --- a/src/parallel/ParticleDataRMM.cpp +++ b/src/parallel/ParticleDataRMM.cpp @@ -29,8 +29,9 @@ void ParticleDataRMM::getMPIType(MPI_Datatype &sendPartType) { } else if (sizeof(pdata_dummy.r[0]) == 4) { // 4 bytes for single types[1] = MPI_FLOAT; } else { - Log::global_log->error() << "invalid size of vcp_real_calc"; - mardyn_exit(4852); + std::ostringstream error_message; + error_message << "invalid size of vcp_real_calc"; + MARDYN_EXIT(error_message.str()); } //if the following statement is not true, then the 6 double values do not follow one after the other. diff --git a/src/parallel/StaticIrregDomainDecomposition.cpp b/src/parallel/StaticIrregDomainDecomposition.cpp index 16e0ac5901..2da2b42af4 100644 --- a/src/parallel/StaticIrregDomainDecomposition.cpp +++ b/src/parallel/StaticIrregDomainDecomposition.cpp @@ -69,12 +69,13 @@ void StaticIrregDomainDecomposition::readXML(XMLfileUnits &xmlconfig) { // We check for this failure, and additionally check for positive // integer if (!(ss >> temp) || temp <= 0) { - Log::global_log->fatal() + std::ostringstream error_message; + error_message << "Weights in " << axes.at(i) << " axis have a non-natural number! Only integer weights > " "0 allowed, please check XML file!" << std::endl; - mardyn_exit(5003); + MARDYN_EXIT(error_message.str()); } _subdomainWeights[i].push_back(temp); if (ss.peek() == ',' || ss.peek() == ' ') // skip commas and spaces diff --git a/src/parallel/tests/KDDecompositionTest.cpp b/src/parallel/tests/KDDecompositionTest.cpp index af0f67dcba..c4bea90e23 100644 --- a/src/parallel/tests/KDDecompositionTest.cpp +++ b/src/parallel/tests/KDDecompositionTest.cpp @@ -13,6 +13,7 @@ #include "particleContainer/LinkedCells.h" #include "io/ASCIIReader.h" #include "parallel/NeighbourCommunicationScheme.h" +#include #include #include @@ -415,9 +416,11 @@ void KDDecompositionTest::testRebalancingDeadlocks() { kdd->barrier(); ASSERT_TRUE_MSG("Deadlock!", isOK); - if (not isOK) - MPI_Abort(MPI_COMM_WORLD, 1); - + if (not isOK) { + std::ostringstream error_message; + error_message << "[KDDecompositionTest] Deadlock detected." << std::endl; + MARDYN_EXIT(error_message.str()); + } delete kdd->_decompTree; kdd->_decompTree = newDecompRoot; kdd->_ownArea = newOwnLeaf; diff --git a/src/particleContainer/AutoPasContainer.cpp b/src/particleContainer/AutoPasContainer.cpp index b324cba507..b28bf3a668 100644 --- a/src/particleContainer/AutoPasContainer.cpp +++ b/src/particleContainer/AutoPasContainer.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "Domain.h" #include "Simulation.h" #include "utils/mardyn_assert.h" @@ -183,11 +184,12 @@ auto parseAutoPasOption(XMLfileUnits &xmlconfig, const std::string &xmlString, try { return OptionType::template parseOptions(stringInXml); } catch (const std::exception &e) { - Log::global_log->error() << "AutoPasContainer: error when parsing " << xmlString << ":" << std::endl; - Log::global_log->error() << e.what() << std::endl; - Log::global_log->error() << "Possible options: " + std::ostringstream error_message; + error_message << "AutoPasContainer: error when parsing " << xmlString << ":" << std::endl; + error_message << e.what() << std::endl; + error_message << "Possible options: " << autopas::utils::ArrayUtils::to_string(OptionType::getAllOptions()) << std::endl; - mardyn_exit(4432); + MARDYN_EXIT(error_message.str()); // dummy return return decltype(OptionType::template parseOptions(""))(); } @@ -240,7 +242,9 @@ void AutoPasContainer::readXML(XMLfileUnits &xmlconfig) { } else if (vlSkinPerTimestep == -1 ){ _verletSkin = vlSkin; } else { - Log::global_log->error() << "Input XML specifies skin AND skinPerTimestep. Please choose only one." << std::endl; + std::ostringstream error_message; + error_message << "Input XML specifies skin AND skinPerTimestep. Please choose only one." << std::endl; + MARDYN_EXIT(error_message.str()); } _relativeOptimumRange = xmlconfig.getNodeValue_double("optimumRange", _relativeOptimumRange); _relativeBlacklistRange = xmlconfig.getNodeValue_double("blacklistRange", _relativeBlacklistRange); @@ -394,12 +398,13 @@ bool AutoPasContainer::rebuild(double *bBoxMin, double *bBoxMax) { void AutoPasContainer::update() { // in case we update the container before handling the invalid particles, this might lead to lost particles. if (not _invalidParticles.empty()) { - Log::global_log->error() << "AutoPasContainer: trying to update container, even though invalidParticles still " + std::ostringstream error_message; + error_message << "AutoPasContainer: trying to update container, even though invalidParticles still " "exist. This would lead to lost particles => ERROR!\n" "Remaining invalid particles:\n" << autopas::utils::ArrayUtils::to_string(_invalidParticles, "\n", {"", ""}) << std::endl; - mardyn_exit(434); + MARDYN_EXIT(error_message.str()); } _invalidParticles = _autopasContainer.updateContainer(); diff --git a/src/particleContainer/LinkedCellTraversals/C08CellPairTraversal.h b/src/particleContainer/LinkedCellTraversals/C08CellPairTraversal.h index 0ef15dc14d..b9bc6bc30c 100644 --- a/src/particleContainer/LinkedCellTraversals/C08CellPairTraversal.h +++ b/src/particleContainer/LinkedCellTraversals/C08CellPairTraversal.h @@ -78,8 +78,9 @@ template void C08CellPairTraversal::traverseCellPairsOuter( CellProcessor& cellProcessor) { if(eighthShell){ - Log::global_log->error() << "eightshell + overlapping not yet supported." << std::endl; - mardyn_exit(-2); + std::ostringstream error_message; + error_message << "eightshell + overlapping not yet supported." << std::endl; + MARDYN_EXIT(error_message.str()); } using std::array; diff --git a/src/particleContainer/LinkedCellTraversals/NeutralTerritoryTraversal.h b/src/particleContainer/LinkedCellTraversals/NeutralTerritoryTraversal.h index f4428e7c52..7b7bcfb85f 100644 --- a/src/particleContainer/LinkedCellTraversals/NeutralTerritoryTraversal.h +++ b/src/particleContainer/LinkedCellTraversals/NeutralTerritoryTraversal.h @@ -124,15 +124,17 @@ void NeutralTerritoryTraversal::traverseCellPairs(CellProcessor& c template void NeutralTerritoryTraversal::traverseCellPairsOuter(CellProcessor& cellProcessor) { - Log::global_log->error() << "NT: overlapping Comm not implemented." << std::endl; - mardyn_exit(46); + std::ostringstream error_message; + error_message << "NT: overlapping Comm not implemented." << std::endl; + MARDYN_EXIT(error_message.str()); } template void NeutralTerritoryTraversal::traverseCellPairsInner(CellProcessor& cellProcessor, unsigned stage, unsigned stageCount) { - Log::global_log->error() << "NT: overlapping Comm not implemented." << std::endl; - mardyn_exit(47); + std::ostringstream error_message; + error_message << "NT: overlapping Comm not implemented." << std::endl; + MARDYN_EXIT(error_message.str()); } template diff --git a/src/particleContainer/LinkedCellTraversals/OriginalCellPairTraversal.h b/src/particleContainer/LinkedCellTraversals/OriginalCellPairTraversal.h index c54e9045fc..e54e67e461 100644 --- a/src/particleContainer/LinkedCellTraversals/OriginalCellPairTraversal.h +++ b/src/particleContainer/LinkedCellTraversals/OriginalCellPairTraversal.h @@ -74,8 +74,9 @@ void OriginalCellPairTraversal::rebuild(std::vector } } } else { - Log::global_log->error() << "OriginalCellPairTraversalDat::rebuild was called with incompatible Traversal data!" << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "OriginalCellPairTraversalDat::rebuild was called with incompatible Traversal data!" << std::endl; + MARDYN_EXIT(error_message.str()); } } diff --git a/src/particleContainer/LinkedCellTraversals/QuickschedTraversal.h b/src/particleContainer/LinkedCellTraversals/QuickschedTraversal.h index 0298d0142b..5c47f0e60f 100644 --- a/src/particleContainer/LinkedCellTraversals/QuickschedTraversal.h +++ b/src/particleContainer/LinkedCellTraversals/QuickschedTraversal.h @@ -108,10 +108,11 @@ void QuickschedTraversal::init() { // check that blocksize is within domain size for (int i = 0; i < 3; ++i) { if (_taskBlocksize[i] > this->_dims[i]) { - Log::global_log->error() << "Blocksize is bigger than number of cells in dimension " + std::ostringstream error_message; + error_message << "Blocksize is bigger than number of cells in dimension " << (char) ('x' + i) << ". (" << _taskBlocksize[i] << " > " << this->_dims[i] << ")" << std::endl; - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); } } @@ -175,8 +176,7 @@ void QuickschedTraversal::init() { break; } /* end case PackedAdjustable */ default: - Log::global_log->error() << "QuickschedHandler::init() received non existing task type!" - << std::endl; + Log::global_log->error() << "QuickschedHandler::init() received non existing task type!" << std::endl; } #endif // QUICKSCHED } diff --git a/src/particleContainer/LinkedCellTraversals/SlicedCellPairTraversal.h b/src/particleContainer/LinkedCellTraversals/SlicedCellPairTraversal.h index 1d5e484710..c22e8ea967 100644 --- a/src/particleContainer/LinkedCellTraversals/SlicedCellPairTraversal.h +++ b/src/particleContainer/LinkedCellTraversals/SlicedCellPairTraversal.h @@ -190,8 +190,9 @@ inline void SlicedCellPairTraversal::traverseCellPairsBackend( // Note: in the following we quasi-reimplement an OpenMP for-loop parallelisation with static scheduling if (not isApplicable(start, end) ) { - Log::global_log->error() << "The SlicedCellPairTraversal is not applicable. Aborting." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "The SlicedCellPairTraversal is not applicable. Aborting." << std::endl; + MARDYN_EXIT(error_message.str()); } std::array diff; diff --git a/src/particleContainer/LinkedCells.cpp b/src/particleContainer/LinkedCells.cpp index 67576d1bfe..eab3591bea 100644 --- a/src/particleContainer/LinkedCells.cpp +++ b/src/particleContainer/LinkedCells.cpp @@ -83,19 +83,19 @@ LinkedCells::LinkedCells(double bBoxMin[3], double bBoxMax[3], if (_boxWidthInNumCells[0] < 2 * _haloWidthInNumCells[0] || _boxWidthInNumCells[1] < 2 * _haloWidthInNumCells[1] || _boxWidthInNumCells[2] < 2 * _haloWidthInNumCells[2]) { - Log::global_log->error_always_output() - << "LinkedCells (constructor): bounding box too small for calculated cell length" + std::ostringstream error_message; + error_message << "LinkedCells (constructor): bounding box too small for calculated cell length" << std::endl; - Log::global_log->error_always_output() << "_cellsPerDimension: " << _cellsPerDimension[0] + error_message << "_cellsPerDimension: " << _cellsPerDimension[0] << " / " << _cellsPerDimension[1] << " / " << _cellsPerDimension[2] << std::endl; - Log::global_log->error_always_output() << "_haloWidthInNumCells: " + error_message << "_haloWidthInNumCells: " << _haloWidthInNumCells[0] << " / " << _haloWidthInNumCells[1] << " / " << _haloWidthInNumCells[2] << std::endl; - Log::global_log->error_always_output() << "_boxWidthInNumCells: " << _boxWidthInNumCells[0] + error_message << "_boxWidthInNumCells: " << _boxWidthInNumCells[0] << " / " << _boxWidthInNumCells[1] << " / " << _boxWidthInNumCells[2] << std::endl; - mardyn_exit(5); + MARDYN_EXIT(error_message.str()); } initializeCells(); @@ -155,8 +155,9 @@ bool LinkedCells::rebuild(double bBoxMin[3], double bBoxMax[3]) { // in each dimension at least one layer of (inner+boundary) cells necessary if (_cellsPerDimension[dim] == 2 * _haloWidthInNumCells[dim]) { - Log::global_log->error_always_output() << "LinkedCells::rebuild: region too small" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "LinkedCells::rebuild: region too small" << std::endl; + MARDYN_EXIT(error_message.str()); } numberOfCells *= _cellsPerDimension[dim]; @@ -224,16 +225,17 @@ void LinkedCells::check_molecules_in_box() { } if (numBadMolecules > 0) { - Log::global_log->error() << "Found " << numBadMolecules << " outside of bounding box:" << std::endl; + std::ostringstream error_message; + error_message << "Found " << numBadMolecules << " outside of bounding box:" << std::endl; for (auto & m : badMolecules) { - Log::global_log->error() << "Particle (id=" << m.getID() << "), (current position: x=" + error_message << "Particle (id=" << m.getID() << "), (current position: x=" << m.r(0) << ", y=" << m.r(1) << ", z=" << m.r(2) << ")" << std::endl; } - Log::global_log->error() << "The bounding box is: [" << _haloBoundingBoxMin[0] << ", " << _haloBoundingBoxMax[0] + error_message << "The bounding box is: [" << _haloBoundingBoxMin[0] << ", " << _haloBoundingBoxMax[0] << ") x [" << _haloBoundingBoxMin[1] << ", " << _haloBoundingBoxMax[1] << ") x [" << _haloBoundingBoxMin[2] << ", " << _haloBoundingBoxMax[2] << ")" << std::endl; - Log::global_log->error() << "Particles will be lost. Aborting simulation." << std::endl; - mardyn_exit(311); + error_message << "Particles will be lost. Aborting simulation." << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -292,8 +294,9 @@ void LinkedCells::update() { if (numBadMolecules > 0) { - Log::global_log->error() << "Found " << numBadMolecules << " outside of their correct cells. Aborting." << std::endl; - mardyn_exit(311); + std::ostringstream error_message; + error_message << "Found " << numBadMolecules << " outside of their correct cells. Aborting." << std::endl; + MARDYN_EXIT(error_message.str()); } #endif } @@ -542,8 +545,9 @@ void LinkedCells::addParticles(std::vector& particles, bool checkWheth void LinkedCells::traverseNonInnermostCells(CellProcessor& cellProcessor) { if (not _cellsValid) { - Log::global_log->error() << "Cell structure in LinkedCells (traverseNonInnermostCells) invalid, call update first" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Cell structure in LinkedCells (traverseNonInnermostCells) invalid, call update first" << std::endl; + MARDYN_EXIT(error_message.str()); } _traversalTuner->traverseCellPairsOuter(cellProcessor); @@ -551,8 +555,9 @@ void LinkedCells::traverseNonInnermostCells(CellProcessor& cellProcessor) { void LinkedCells::traversePartialInnermostCells(CellProcessor& cellProcessor, unsigned int stage, int stageCount) { if (not _cellsValid) { - Log::global_log->error() << "Cell structure in LinkedCells (traversePartialInnermostCells) invalid, call update first" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Cell structure in LinkedCells (traversePartialInnermostCells) invalid, call update first" << std::endl; + MARDYN_EXIT(error_message.str()); } _traversalTuner->traverseCellPairsInner(cellProcessor, stage, stageCount); @@ -560,10 +565,9 @@ void LinkedCells::traversePartialInnermostCells(CellProcessor& cellProcessor, un void LinkedCells::traverseCells(CellProcessor& cellProcessor) { if (not _cellsValid) { - Log::global_log->error() - << "Cell structure in LinkedCells (traversePairs) invalid, call update first" - << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Cell structure in LinkedCells (traversePairs) invalid, call update first" << std::endl; + MARDYN_EXIT(error_message.str()); } cellProcessor.initTraversal(); @@ -609,10 +613,9 @@ void LinkedCells::deleteParticlesOutsideBox(double boxMin[3], double boxMax[3]) void LinkedCells::deleteOuterParticles() { /*if (_cellsValid == false) { - Log::global_log->error() - << "Cell structure in LinkedCells (deleteOuterParticles) invalid, call update first" - << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Cell structure in LinkedCells (deleteOuterParticles) invalid, call update first" << std::endl; + MARDYN_EXIT(error_message.str()); }*/ const size_t numHaloCells = _haloCellIndices.size(); @@ -641,7 +644,7 @@ RegionParticleIterator LinkedCells::regionIterator(const double startRegion[3], const auto &localBoxOfInterestMin = type == ParticleIterator::ALL_CELLS ? _haloBoundingBoxMin : _boundingBoxMin; const auto &localBoxOfInterestMax = type == ParticleIterator::ALL_CELLS ? _haloBoundingBoxMax : _boundingBoxMax; - // clamp iterated region to local MPI subdomain + // clamp iterated region to local MPI subdomain const std::array startRegionClamped = { std::clamp(startRegion[0], localBoxOfInterestMin[0], localBoxOfInterestMax[0]), std::clamp(startRegion[1], localBoxOfInterestMin[1], localBoxOfInterestMax[1]), @@ -833,11 +836,12 @@ unsigned long int LinkedCells::getCellIndexOfMolecule(Molecule* molecule) const for (int dim = 0; dim < 3; dim++) { #ifndef NDEBUG if (molecule->r(dim) < _haloBoundingBoxMin[dim] || molecule->r(dim) >= _haloBoundingBoxMax[dim]) { - Log::global_log->error() << "Molecule is outside of bounding box" << std::endl; - Log::global_log->error() << "Molecule:\n" << *molecule << std::endl; - Log::global_log->error() << "_haloBoundingBoxMin = (" << _haloBoundingBoxMin[0] << ", " << _haloBoundingBoxMin[1] << ", " << _haloBoundingBoxMin[2] << ")" << std::endl; - Log::global_log->error() << "_haloBoundingBoxMax = (" << _haloBoundingBoxMax[0] << ", " << _haloBoundingBoxMax[1] << ", " << _haloBoundingBoxMax[2] << ")" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Molecule is outside of bounding box" << std::endl; + error_message << "Molecule:\n" << *molecule << std::endl; + error_message << "_haloBoundingBoxMin = (" << _haloBoundingBoxMin[0] << ", " << _haloBoundingBoxMin[1] << ", " << _haloBoundingBoxMin[2] << ")" << std::endl; + error_message << "_haloBoundingBoxMax = (" << _haloBoundingBoxMax[0] << ", " << _haloBoundingBoxMax[1] << ", " << _haloBoundingBoxMax[2] << ")" << std::endl; + MARDYN_EXIT(error_message.str()); } #endif //this version is sensitive to roundoffs, if we have molecules (initialized) precisely at position 0.0: @@ -882,11 +886,12 @@ unsigned long int LinkedCells::getCellIndexOfPoint(const double point[3]) const #ifndef NDEBUG //this should never ever happen! if (localPoint[dim] < _haloBoundingBoxMin[dim] || localPoint[dim] >= _haloBoundingBoxMax[dim]) { - Log::global_log->error() << "Point is outside of halo bounding box" << std::endl; - Log::global_log->error() << "Point p = (" << localPoint[0] << ", " << localPoint[1] << ", " << localPoint[2] << ")" << std::endl; - Log::global_log->error() << "_haloBoundingBoxMin = (" << _haloBoundingBoxMin[0] << ", " << _haloBoundingBoxMin[1] << ", " << _haloBoundingBoxMin[2] << ")" << std::endl; - Log::global_log->error() << "_haloBoundingBoxMax = (" << _haloBoundingBoxMax[0] << ", " << _haloBoundingBoxMax[1] << ", " << _haloBoundingBoxMax[2] << ")" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Point is outside of halo bounding box" << std::endl; + error_message << "Point p = (" << localPoint[0] << ", " << localPoint[1] << ", " << localPoint[2] << ")" << std::endl; + error_message << "_haloBoundingBoxMin = (" << _haloBoundingBoxMin[0] << ", " << _haloBoundingBoxMin[1] << ", " << _haloBoundingBoxMin[2] << ")" << std::endl; + error_message << "_haloBoundingBoxMax = (" << _haloBoundingBoxMax[0] << ", " << _haloBoundingBoxMax[1] << ", " << _haloBoundingBoxMax[2] << ")" << std::endl; + MARDYN_EXIT(error_message.str()); } #endif @@ -1003,14 +1008,13 @@ void LinkedCells::deleteMolecule(ParticleIterator &moleculeIter, const bool& reb moleculeIter.deleteCurrentParticle(); - if (rebuildCaches) { - auto cellid = getCellIndexOfMolecule(&*moleculeIter); - if (cellid >= _cells.size()) { - Log::global_log->error_always_output() - << "coordinates for atom deletion lie outside bounding box." - << std::endl; - mardyn_exit(1); - } + if (rebuildCaches) { + auto cellid = getCellIndexOfMolecule(&*moleculeIter); + if (cellid >= _cells.size()) { + std::ostringstream error_message; + error_message << "coordinates for atom deletion lie outside bounding box." << std::endl; + MARDYN_EXIT(error_message.str()); + } _cells[cellid].buildSoACaches(); } } @@ -1066,7 +1070,7 @@ double LinkedCells::getEnergy(ParticlePairsHandler* particlePairsHandler, Molecu delete cellProcessor; } - mardyn_assert(not std::isnan(u)); // catches NaN + mardyn_assert(not std::isnan(u)); // catches NaN return u; } diff --git a/src/particleContainer/TraversalTuner.h b/src/particleContainer/TraversalTuner.h index b4f0f27a65..93e501a4f4 100644 --- a/src/particleContainer/TraversalTuner.h +++ b/src/particleContainer/TraversalTuner.h @@ -154,8 +154,9 @@ void TraversalTuner::findOptimalTraversal() { else if (dynamic_cast *>(_optimalTraversal)) { Log::global_log->info() << "Using QuickschedTraversal." << std::endl; #ifndef QUICKSCHED - Log::global_log->error() << "MarDyn was compiled without Quicksched Support. Aborting!" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "MarDyn was compiled without Quicksched Support. Aborting!" << std::endl; + MARDYN_EXIT(error_message.str()); #endif } else if (dynamic_cast *>(_optimalTraversal)) Log::global_log->info() << "Using SlicedCellPairTraversal." << std::endl; @@ -163,9 +164,10 @@ void TraversalTuner::findOptimalTraversal() { Log::global_log->warning() << "Using unknown traversal." << std::endl; if (_cellsInCutoff > _optimalTraversal->maxCellsInCutoff()) { - Log::global_log->error() << "Traversal supports up to " << _optimalTraversal->maxCellsInCutoff() + std::ostringstream error_message; + error_message << "Traversal supports up to " << _optimalTraversal->maxCellsInCutoff() << " cells in cutoff, but value is chosen as " << _cellsInCutoff << std::endl; - mardyn_exit(45); + MARDYN_EXIT(error_message.str()); } } @@ -240,12 +242,13 @@ void TraversalTuner::readXML(XMLfileUnits &xmlconfig) { tag += (dimension + j); xmlconfig.getNodeValue(tag, quiData->taskBlockSize[j]); if (quiData->taskBlockSize[j] < 2) { - Log::global_log->error() << "Task block size in " + std::ostringstream error_message; + error_message << "Task block size in " << (char) (dimension + j) << " direction is <2 and thereby invalid! (" << quiData->taskBlockSize[j] << ")" << std::endl; - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); } } break; @@ -306,8 +309,9 @@ void TraversalTuner::rebuild(std::vector &cells, con traversalPointerReference = new QuickschedTraversal(cells, dims, quiData->taskBlockSize); } break; default: - Log::global_log->error() << "Unknown traversal data found in TraversalTuner._traversals!" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Unknown traversal data found in TraversalTuner._traversals!" << std::endl; + MARDYN_EXIT(error_message.str()); } } traversalPointerReference->rebuild(cells, dims, cellLength, cutoff, traversalData); @@ -335,8 +339,9 @@ inline void TraversalTuner::traverseCellPairs(traversalNames name, slicedTraversal.traverseCellPairs(cellProcessor); break; default: - Log::global_log->error()<< "Calling traverseCellPairs(traversalName, CellProcessor&) for something else than the Sliced Traversal is disabled for now. Aborting." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message<< "Calling traverseCellPairs(traversalName, CellProcessor&) for something else than the Sliced Traversal is disabled for now. Aborting." << std::endl; + MARDYN_EXIT(error_message.str()); break; } } diff --git a/src/particleContainer/adapter/ParticlePairs2PotForceAdapter.h b/src/particleContainer/adapter/ParticlePairs2PotForceAdapter.h index df57c1bf6d..e21ecac19c 100644 --- a/src/particleContainer/adapter/ParticlePairs2PotForceAdapter.h +++ b/src/particleContainer/adapter/ParticlePairs2PotForceAdapter.h @@ -175,7 +175,9 @@ class ParticlePairs2PotForceAdapter : public ParticlePairsHandler { FluidPot(molecule1, molecule2, params, distanceVector, dummy1, dummy2, dummy3, calculateLJ); return dummy1 / 6.0 + dummy2 + dummy3; default: - mardyn_exit(666); + std::ostringstream error_message; + error_message << "[ParticlePairs2PotForceAdapter9] pairType is unknown" << std::endl; + MARDYN_EXIT(error_message.str()); } return 0.0; } diff --git a/src/plugins/COMaligner.cpp b/src/plugins/COMaligner.cpp index 48f784c59e..21fda4be2f 100755 --- a/src/plugins/COMaligner.cpp +++ b/src/plugins/COMaligner.cpp @@ -7,6 +7,10 @@ #include "COMaligner.h" +#include + +#include "utils/mardyn_assert.h" + //! @brief will be called to read configuration //! //! All values have defaults and are not mandatory to be supplied
@@ -27,11 +31,12 @@ void COMaligner::readXML(XMLfileUnits& xmlconfig){ // SANITY CHECK if(_interval < 1 || _alignmentCorrection < 0 || _alignmentCorrection > 1){ - Log::global_log -> error() << "[COMaligner] INVALID CONFIGURATION!!! DISABLED!" << std::endl; - Log::global_log -> error() << "[COMaligner] HALTING SIMULATION" << std::endl; + std::ostringstream error_message; + error_message << "[COMaligner] INVALID CONFIGURATION!!! DISABLED!" << std::endl; + error_message << "[COMaligner] HALTING SIMULATION" << std::endl; _enabled = false; // HALT SIM - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); return; } diff --git a/src/plugins/DirectedPM.cpp b/src/plugins/DirectedPM.cpp index 0c37d09842..9ba0c95884 100644 --- a/src/plugins/DirectedPM.cpp +++ b/src/plugins/DirectedPM.cpp @@ -100,19 +100,20 @@ void DirectedPM::beforeForces(ParticleContainer* particleContainer, DomainDecomp (phiUN < _phiIncrements)) { unID = (hUN * _rIncrements * _phiIncrements) + (rUN * _phiIncrements) + phiUN; } else { - Log::global_log->error() + std::ostringstream error_message; + error_message << "INV PROFILE UNITS " << _universalInvProfileUnit[0] << " " << _universalInvProfileUnit[1] << " " << _universalInvProfileUnit[2] << "\n"; - Log::global_log->error() << "PROFILE UNITS " << _rIncrements << " " << _hIncrements << " " + error_message << "PROFILE UNITS " << _rIncrements << " " << _hIncrements << " " << _phiIncrements << "\n"; - Log::global_log->error() << "Severe error!! Invalid profile ID (" << rUN << " / " << hUN << " / " + error_message << "Severe error!! Invalid profile ID (" << rUN << " / " << hUN << " / " << phiUN << ").\n\n"; - Log::global_log->error() << "Severe error!! Invalid profile unit (" << R2 << " / " << yc << " / " + error_message << "Severe error!! Invalid profile unit (" << R2 << " / " << yc << " / " << phi << ").\n\n"; - Log::global_log->error() + error_message << "Coordinates off center (" << xc << " / " << yc << " / " << zc << ").\n"; - Log::global_log->error() << "unID = " << unID << "\n"; - mardyn_exit(707); + error_message << "unID = " << unID << "\n"; + MARDYN_EXIT(error_message.str()); } // ADD VELOCITCY AND VIRIAL TO RESPECTIVE BIN _localnumberOfParticles[unID] += 1.; diff --git a/src/plugins/Dropaccelerator.cpp b/src/plugins/Dropaccelerator.cpp index e0d5d7e4ef..26fe0d6cf3 100644 --- a/src/plugins/Dropaccelerator.cpp +++ b/src/plugins/Dropaccelerator.cpp @@ -31,11 +31,12 @@ void Dropaccelerator::readXML(XMLfileUnits& xmlconfig) { // SANITY CHECK if (_interval < 1 || _steps <= 0 || _startSimStep < 0 || _xPosition <= 0. || _yPosition <= 0. || _zPosition <= 0. || _dropRadius <= 0) { - Log::global_log->error() << "[Dropaccelerator] INVALID CONFIGURATION!!! DISABLED!" << std::endl; - Log::global_log->error() << "[Dropaccelerator] HALTING SIMULATION" << std::endl; + std::ostringstream error_message; + error_message << "[Dropaccelerator] INVALID CONFIGURATION!!! DISABLED!" << std::endl; + error_message << "[Dropaccelerator] HALTING SIMULATION" << std::endl; _enabled = false; // HALT SIM - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); return; } diff --git a/src/plugins/Dropaligner.cpp b/src/plugins/Dropaligner.cpp index 085add8594..9402bbdb48 100644 --- a/src/plugins/Dropaligner.cpp +++ b/src/plugins/Dropaligner.cpp @@ -23,11 +23,12 @@ void Dropaligner::readXML(XMLfileUnits& xmlconfig) { // SANITY CHECK if (_interval < 1 || _alignmentCorrection < 0 || _alignmentCorrection > 1 || _xPos <= 0. || _yPos <= 0. || _zPos <= 0. || _radius <= 0) { - Log::global_log->error() << "[Dropaligner] INVALID CONFIGURATION!!! DISABLED!" << std::endl; - Log::global_log->error() << "[Dropaligner] HALTING SIMULATION" << std::endl; + std::ostringstream error_message; + error_message << "[Dropaligner] INVALID CONFIGURATION!!! DISABLED!" << std::endl; + error_message << "[Dropaligner] HALTING SIMULATION" << std::endl; _enabled = false; // HALT SIM - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); return; } diff --git a/src/plugins/ExamplePlugin.cpp b/src/plugins/ExamplePlugin.cpp index f08e926a30..5b6420a3e0 100644 --- a/src/plugins/ExamplePlugin.cpp +++ b/src/plugins/ExamplePlugin.cpp @@ -54,13 +54,13 @@ void ExamplePlugin::readXML(XMLfileUnits& xmlconfig) { _displaySelector = WhereToDisplay::AT_FINISH; Log::global_log->info() << "Displaying at finish." << std::endl; } else { - Log::global_log->error() - << "Unknown option specified to ExamplePlugin::where_to_display." - << std::endl; - Log::global_log->error() + std::ostringstream error_message; + error_message + << "Unknown option specified to ExamplePlugin::where_to_display." << std::endl; + error_message << "Valid options are: all, beforeEventNewTimestep, beforeForces, afterForces, endStep, init, finish." << std::endl; - mardyn_exit(11); + MARDYN_EXIT(error_message.str()); } } diff --git a/src/plugins/FixRegion.cpp b/src/plugins/FixRegion.cpp index 1d11c42c70..e67ad58228 100644 --- a/src/plugins/FixRegion.cpp +++ b/src/plugins/FixRegion.cpp @@ -29,10 +29,11 @@ void FixRegion::init(ParticleContainer* particleContainer, DomainDecompBase* dom // SANITY CHECK if (_xMin < 0. || _yMin < 0. || _zMin < 0. || _xMax > _boxLength[0] || _yMax > _boxLength[1] || _zMax > _boxLength[2]) { - Log::global_log->error() << "[FixRegion] INVALID INPUT!!! DISABLED!" << std::endl; - Log::global_log->error() << "[FixRegion] HALTING SIMULATION" << std::endl; + std::ostringstream error_message; + error_message << "[FixRegion] INVALID INPUT!!! DISABLED!" << std::endl; + error_message << "[FixRegion] HALTING SIMULATION" << std::endl; // HALT SIM - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); return; } diff --git a/src/plugins/MaxCheck.cpp b/src/plugins/MaxCheck.cpp index f61deed1a8..e7e56a2997 100644 --- a/src/plugins/MaxCheck.cpp +++ b/src/plugins/MaxCheck.cpp @@ -16,6 +16,7 @@ #include "utils/mardyn_assert.h" #include +#include MaxCheck::MaxCheck() { @@ -75,8 +76,9 @@ void MaxCheck::readXML(XMLfileUnits& xmlconfig) { numTargets = query.card(); Log::global_log->info() << "[MaxCheck] Number of component targets: " << numTargets << std::endl; if (numTargets < 1) { - Log::global_log->warning() << "[MaxCheck] No target parameters specified. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[MaxCheck] No target parameters specified. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } std::string oldpath = xmlconfig.getcurrentnodepath(); XMLfile::Query::const_iterator nodeIter; diff --git a/src/plugins/Mirror.cpp b/src/plugins/Mirror.cpp index f13855e1c7..c820b1bd10 100644 --- a/src/plugins/Mirror.cpp +++ b/src/plugins/Mirror.cpp @@ -85,8 +85,9 @@ void Mirror::readXML(XMLfileUnits& xmlconfig) if(nullptr != subject) subject->registerObserver(this); else { - Log::global_log->error() << "[Mirror] Initialization of plugin DistControl is needed before! Program exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[Mirror] Initialization of plugin DistControl is needed before! Program exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } } Log::global_log->info() << "[Mirror] Enabled at position: y = " << _position.coord << std::endl; @@ -124,15 +125,17 @@ void Mirror::readXML(XMLfileUnits& xmlconfig) /** zero gradient */ if(MT_ZERO_GRADIENT == _type) { - Log::global_log->error() << "[Mirror] Method 3 (MT_ZERO_GRADIENT) is deprecated. Use 5 (MT_MELAND_2004) instead. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[Mirror] Method 3 (MT_ZERO_GRADIENT) is deprecated. Use 5 (MT_MELAND_2004) instead. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } /** normal distributions */ if(MT_NORMDISTR_MB == _type) { - Log::global_log->error() << "[Mirror] Method 4 (MT_NORMDISTR_MB) is deprecated. Use 5 (MT_MELAND_2004) instead. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[Mirror] Method 4 (MT_NORMDISTR_MB) is deprecated. Use 5 (MT_MELAND_2004) instead. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } /** Meland2004 */ @@ -142,8 +145,9 @@ void Mirror::readXML(XMLfileUnits& xmlconfig) if(!xmlconfig.getNodeValue("meland/velo_target", _melandParams.velo_target)) { - Log::global_log->error() << "[Mirror] Meland: Parameters for method 5 (MT_MELAND_2004) provided in config-file *.xml corrupted/incomplete. Program exit ..." << std::endl; - mardyn_exit(-2004); + std::ostringstream error_message; + error_message << "[Mirror] Meland: Parameters for method 5 (MT_MELAND_2004) provided in config-file *.xml corrupted/incomplete. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } else { Log::global_log->info() << "[Mirror] Meland: target velocity = " << _melandParams.velo_target << std::endl; @@ -168,13 +172,15 @@ void Mirror::readXML(XMLfileUnits& xmlconfig) bRet = bRet && xmlconfig.getNodeValue("ramping/treatment", _rampingParams.treatment); if (not bRet) { - Log::global_log->error() << "[Mirror] Ramping: Parameters for method 5 (MT_RAMPING) provided in config-file *.xml corrupted/incomplete. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[Mirror] Ramping: Parameters for method 5 (MT_RAMPING) provided in config-file *.xml corrupted/incomplete. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } else { if(_rampingParams.startStep > _rampingParams.stopStep) { - Log::global_log->error() << "[Mirror] Ramping: Start > Stop. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[Mirror] Ramping: Start > Stop. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } else { Log::global_log->info() << "[Mirror] Ramping from " << _rampingParams.startStep << " to " << _rampingParams.stopStep << std::endl; @@ -185,8 +191,9 @@ void Mirror::readXML(XMLfileUnits& xmlconfig) case 1 : treatmentStr = "Transmission"; break; default: - Log::global_log->error() << "[Mirror] Ramping: No proper treatment was set. Use 0 (Deletion) or 1 (Transmission). Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[Mirror] Ramping: No proper treatment was set. Use 0 (Deletion) or 1 (Transmission). Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "[Mirror] Ramping: Treatment for non-reflected particles: " << _rampingParams.treatment << " ( " << treatmentStr << " ) " << std::endl; } diff --git a/src/plugins/NEMD/DensityControl.cpp b/src/plugins/NEMD/DensityControl.cpp index 0cd8dd582c..7d39ac3ed8 100644 --- a/src/plugins/NEMD/DensityControl.cpp +++ b/src/plugins/NEMD/DensityControl.cpp @@ -84,10 +84,11 @@ void DensityControl::readXML(XMLfileUnits& xmlconfig) { _vecPriority.push_back(0); const uint32_t nRet = this->tokenize_int_list(_vecPriority, strPrio); if (nRet != numComponents) { - Log::global_log->error() << "[DensityControl] Number of component IDs specified in element ..." + std::ostringstream error_message; + error_message << "[DensityControl] Number of component IDs specified in element ..." << " does not match the number of components in the simulation. Programm exit ..." << std::endl; - mardyn_exit(-1); + MARDYN_EXIT(error_message.str()); } // targets @@ -111,8 +112,9 @@ void DensityControl::readXML(XMLfileUnits& xmlconfig) { numTargets = query.card(); Log::global_log->info() << "[DensityControl] Number of component targets: " << numTargets << std::endl; if (numTargets < 1) { - Log::global_log->error() << "[DensityControl] No target parameters specified. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[DensityControl] No target parameters specified. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } const std::string oldpath = xmlconfig.getcurrentnodepath(); XMLfile::Query::const_iterator nodeIter; diff --git a/src/plugins/NEMD/DistControl.cpp b/src/plugins/NEMD/DistControl.cpp index 0dff820093..f6b461c721 100644 --- a/src/plugins/NEMD/DistControl.cpp +++ b/src/plugins/NEMD/DistControl.cpp @@ -79,16 +79,18 @@ void DistControl::readXML(XMLfileUnits& xmlconfig) std::string strSubdivisionType; if( !xmlconfig.getNodeValue("subdivision@type", strSubdivisionType) ) { - Log::global_log->error() << "[DistControl] Missing attribute \"subdivision@type\"! Programm exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[DistControl] Missing attribute \"subdivision@type\"! Programm exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } if("number" == strSubdivisionType) { unsigned int nNumSlabs = 0; if( !xmlconfig.getNodeValue("subdivision/number", nNumSlabs) ) { - Log::global_log->error() << "[DistControl] Missing element \"subdivision/number\"! Programm exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[DistControl] Missing element \"subdivision/number\"! Programm exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } else this->SetSubdivision(nNumSlabs); @@ -98,16 +100,18 @@ void DistControl::readXML(XMLfileUnits& xmlconfig) double dSlabWidth = 0.; if( !xmlconfig.getNodeValue("subdivision/width", dSlabWidth) ) { - Log::global_log->error() << "[DistControl] Missing element \"subdivision/width\"! Programm exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[DistControl] Missing element \"subdivision/width\"! Programm exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } else this->SetSubdivision(dSlabWidth); } else { - Log::global_log->error() << "[DistControl] Wrong attribute \"subdivision@type\". Expected: type=\"number|width\"! Programm exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[DistControl] Wrong attribute \"subdivision@type\". Expected: type=\"number|width\"! Programm exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } // init method @@ -137,8 +141,9 @@ void DistControl::readXML(XMLfileUnits& xmlconfig) } else { - Log::global_log->error() << "[DistControl] Missing elements \"init/values/left\" or \"init/values/right\" or both! Programm exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[DistControl] Missing elements \"init/values/left\" or \"init/values/right\" or both! Programm exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } } else if("file" == strInitMethodType) @@ -154,15 +159,17 @@ void DistControl::readXML(XMLfileUnits& xmlconfig) } else { - Log::global_log->error() << "[DistControl] Missing elements \"init/file\" or \"init/simstep\" or both! Programm exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[DistControl] Missing elements \"init/file\" or \"init/simstep\" or both! Programm exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } } else { - Log::global_log->error() << "[DistControl] Wrong attribute \"init@type\", type = " << strInitMethodType << ", " + std::ostringstream error_message; + error_message << "[DistControl] Wrong attribute \"init@type\", type = " << strInitMethodType << ", " "expected: type=\"startconfig|values|file\"! Programm exit..." << std::endl; - mardyn_exit(-1); + MARDYN_EXIT(error_message.str()); } // update method @@ -189,8 +196,9 @@ void DistControl::readXML(XMLfileUnits& xmlconfig) } else { - Log::global_log->error() << "[DistControl] Missing elements \"method/componentID\" or \"method/density\" or both! Programm exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[DistControl] Missing elements \"method/componentID\" or \"method/density\" or both! Programm exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } } else if("denderiv" == strUpdateMethodType) @@ -213,15 +221,17 @@ void DistControl::readXML(XMLfileUnits& xmlconfig) } else { - Log::global_log->error() << "[DistControl] Missing elements \"method/componentID\" or \"method/density\" or both! Programm exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[DistControl] Missing elements \"method/componentID\" or \"method/density\" or both! Programm exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } } else { - Log::global_log->error() << "[DistControl] Wrong attribute \"method@type\", type = " << strUpdateMethodType << ", " + std::ostringstream error_message; + error_message << "[DistControl] Wrong attribute \"method@type\", type = " << strUpdateMethodType << ", " "expected: type=\"density|denderiv\"! Programm exit..." << std::endl; - mardyn_exit(-1); + MARDYN_EXIT(error_message.str()); } } @@ -266,8 +276,9 @@ void DistControl::PrepareSubdivision() break; case SDOPT_UNKNOWN: default: - Log::global_log->error() << "[DistControl] PrepareSubdivision(): Neither _binParams.width nor _binParams.count was set correctly! Programm exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[DistControl] PrepareSubdivision(): Neither _binParams.width nor _binParams.count was set correctly! Programm exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } _binParams.invWidth = 1. / _binParams.width; @@ -702,13 +713,14 @@ void DistControl::UpdatePositionsInit(ParticleContainer* particleContainer) } case DCIM_UNKNOWN: default: - Log::global_log->error() << "[DistControl] Wrong Init Method! Programm exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[DistControl] Wrong Init Method! Programm exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } #ifndef NDEBUG - Log::global_log->error() << "[DistControl] _dInterfaceMidLeft = " << _dInterfaceMidLeft << std::endl; - Log::global_log->error() << "[DistControl] _dInterfaceMidRight = " << _dInterfaceMidRight << std::endl; + Log::global_log->debug() << "[DistControl] _dInterfaceMidLeft = " << _dInterfaceMidLeft << std::endl; + Log::global_log->debug() << "[DistControl] _dInterfaceMidRight = " << _dInterfaceMidRight << std::endl; #endif // update positions @@ -738,8 +750,9 @@ void DistControl::UpdatePositions(const uint64_t& simstep) break; case DCUM_UNKNOWN: default: - Log::global_log->error() << "[DistControl] UpdatePositions() Corrupted code!!! Programm exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[DistControl] UpdatePositions() Corrupted code!!! Programm exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } // update positions diff --git a/src/plugins/NEMD/MettDeamon.cpp b/src/plugins/NEMD/MettDeamon.cpp index ec9ed8c18d..0585fbf4c9 100644 --- a/src/plugins/NEMD/MettDeamon.cpp +++ b/src/plugins/NEMD/MettDeamon.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -416,8 +417,9 @@ void MettDeamon::readXML(XMLfileUnits& xmlconfig) numChanges = query.card(); Log::global_log->info() << "[MettDeamon] Number of fixed molecules components: " << numChanges << std::endl; if(numChanges < 1) { - Log::global_log->error() << "[MettDeamon] No component change defined in XML-config file. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[MettDeamon] No component change defined in XML-config file. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } std::string oldpath = xmlconfig.getcurrentnodepath(); XMLfile::Query::const_iterator changeIter; @@ -434,8 +436,9 @@ void MettDeamon::readXML(XMLfileUnits& xmlconfig) xmlconfig.changecurrentnode(".."); } else { - Log::global_log->error() << "[MettDeamon] No component changes defined in XML-config file. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[MettDeamon] No component changes defined in XML-config file. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -1188,8 +1191,9 @@ void MettDeamon::InsertReservoirSlab(ParticleContainer* particleContainer) } _feedrate.feed.sum -= _reservoir->getBinWidth(); // reset feed sum if(not _reservoir->nextBin(_nMaxMoleculeID.global) ) { - Log::global_log->error() << "[MettDeamon] Failed to activate new bin of particle Reservoir's BinQueue => Program exit." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[MettDeamon] Failed to activate new bin of particle Reservoir's BinQueue => Program exit." << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->debug() << "[" << nRank << "]: ADDED " << numAdded.local << "/" << numParticlesCurrentSlab.local << " particles (" << numAdded.local/static_cast(numParticlesCurrentSlab.local)*100 << ")%." << std::endl; // calc global values @@ -1208,8 +1212,9 @@ void MettDeamon::initRestart() bool bRet = _reservoir->activateBin(_restartInfo.nBindindex); if(not bRet) { - Log::global_log->info() << "[MettDeamon] Failed to activate reservoir bin after restart! Program exit ... " << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[MettDeamon] Failed to activate reservoir bin after restart! Program exit ... " << std::endl; + MARDYN_EXIT(error_message.str()); } _feedrate.feed.sum = _restartInfo.dYsum; } @@ -1225,8 +1230,9 @@ void MettDeamon::readNormDistr() //check to see that the file was opened correctly: if (!ifs.vxz.is_open() || !ifs.vy.is_open() ) { - std::cerr << "[MettDeamon] There was a problem opening the input file!\n"; - mardyn_exit(-1);//exit or do additional error checking + std::ostringstream error_message; + error_message << "[MettDeamon] There was a problem opening the input file!\n"; + MARDYN_EXIT(error_message.str());//exit or do additional error checking } double dVal = 0.0; @@ -1235,12 +1241,17 @@ void MettDeamon::readNormDistr() _norm.vxz.push_back(dVal); } while (ifs.vy >> dVal) { - if(MD_LEFT_TO_RIGHT == _nMovingDirection) + if (MD_LEFT_TO_RIGHT == _nMovingDirection) { _norm.vy.push_back( abs(dVal) ); - else if (MD_RIGHT_TO_LEFT == _nMovingDirection) + } + else if (MD_RIGHT_TO_LEFT == _nMovingDirection) { _norm.vy.push_back( abs(dVal) * (-1.) ); - else - mardyn_exit(-1); + } + else { + std::ostringstream error_message; + error_message << "[MettDeamon] Something went wrong with the direction." << std::endl; + MARDYN_EXIT(error_message.str()); + } } // close files ifs.vxz.close(); @@ -1308,8 +1319,9 @@ void Reservoir::readXML(XMLfileUnits& xmlconfig) xmlconfig.getNodeValue("file/data", _filepath.data); } else { - Log::global_log->error() << "[MettDeamon] Reservoir file type not specified or unknown. Programm exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[MettDeamon] Reservoir file type not specified or unknown. Programm exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } // Possibly change component IDs @@ -1318,8 +1330,9 @@ void Reservoir::readXML(XMLfileUnits& xmlconfig) XMLfile::Query query = xmlconfig.query("change"); numChanges = query.card(); if(numChanges < 1) { - Log::global_log->error() << "[MettDeamon] No component change defined in XML-config file. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[MettDeamon] No component change defined in XML-config file. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } std::string oldpath = xmlconfig.getcurrentnodepath(); XMLfile::Query::const_iterator changeIter; @@ -1347,8 +1360,9 @@ void Reservoir::readParticleData(DomainDecompBase* domainDecomp, ParticleContain this->readFromFileBinary(domainDecomp, particleContainer); break; default: - Log::global_log->error() << "[MettDeamon] Unknown (or ambiguous) method to read reservoir for feature MettDeamon. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[MettDeamon] Unknown (or ambiguous) method to read reservoir for feature MettDeamon. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } // sort particles into bins @@ -1476,7 +1490,9 @@ void Reservoir::sortParticlesToBins(DomainDecompBase* domainDecomp, ParticleCont mol.setr(1, y - nBinIndex*_dBinWidth + (domain->getGlobalLength(1) - _dBinWidth) ); break; default: - Log::global_log->error() << "[MettDeamon] Unknown moving direction" << std::endl; + std::ostringstream error_message; + error_message << "[MettDeamon] Unknown moving direction" << std::endl; + MARDYN_EXIT(error_message.str()); } // check if molecule is in bounding box of the process domain bool bIsInsideBB = domainDecomp->procOwnsPos(mol.r(0), mol.r(1), mol.r(2), domain); @@ -1506,7 +1522,9 @@ void Reservoir::sortParticlesToBins(DomainDecompBase* domainDecomp, ParticleCont } break; default: - Log::global_log->error() << "[MettDeamon] Unknown moving direction" << std::endl; + std::ostringstream error_message; + error_message << "[MettDeamon] Unknown moving direction" << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -1518,8 +1536,9 @@ void Reservoir::readFromFile(DomainDecompBase* domainDecomp, ParticleContainer* Log::global_log->info() << "[MettDeamon] Opening Reservoirfile " << _filepath.data << std::endl; ifs.open( _filepath.data.c_str() ); if (!ifs.is_open()) { - Log::global_log->error() << "[MettDeamon] Could not open Mettdeamon Reservoirfile " << _filepath.data << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[MettDeamon] Could not open Mettdeamon Reservoirfile " << _filepath.data << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "[MettDeamon] Reading Mettdeamon Reservoirfile " << _filepath.data << std::endl; @@ -1547,8 +1566,9 @@ void Reservoir::readFromFile(DomainDecompBase* domainDecomp, ParticleContainer* } if((token != "NumberOfMolecules") && (token != "N")) { - Log::global_log->error() << "[MettDeamon] Expected the token 'NumberOfMolecules (N)' instead of '" << token << "'" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[MettDeamon] Expected the token 'NumberOfMolecules (N)' instead of '" << token << "'" << std::endl; + MARDYN_EXIT(error_message.str()); } ifs >> _numMoleculesRead; @@ -1567,8 +1587,9 @@ void Reservoir::readFromFile(DomainDecompBase* domainDecomp, ParticleContainer* else if (ntypestring == "ICRV") ntype = ICRV; else if (ntypestring == "IRV") ntype = IRV; else { - Log::global_log->error() << "[MettDeamon] Unknown molecule format '" << ntypestring << "'" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[MettDeamon] Unknown molecule format '" << ntypestring << "'" << std::endl; + MARDYN_EXIT(error_message.str()); } } else { ifs.seekg(spos); @@ -1609,16 +1630,19 @@ void Reservoir::readFromFile(DomainDecompBase* domainDecomp, ParticleContainer* ifs >> id >> x >> y >> z >> vx >> vy >> vz; break; default: - Log::global_log->error() << "[MettDeamon] Unknown molecule format" << std::endl; + std::ostringstream error_message; + error_message << "[MettDeamon] Unknown molecule format" << std::endl; + MARDYN_EXIT(error_message.str()); } if( componentid > numcomponents ) { - Log::global_log->error() << "[MettDeamon] Molecule id " << id + std::ostringstream error_message; + error_message << "[MettDeamon] Molecule id " << id << " has a component ID greater than the existing number of components: " << componentid << ">" << numcomponents << std::endl; - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); } // ComponentIDs are used as array IDs, hence need to start at 0. // In the input files they always start with 1 so we need to adapt that all the time. @@ -1645,9 +1669,10 @@ void Reservoir::readFromFileBinaryHeader() XMLfileUnits inp(_filepath.header); if(not inp.changecurrentnode("/mardyn")) { - Log::global_log->error() << "[MettDeamon] Could not find root node /mardyn in XML header file or file itself." << std::endl; - Log::global_log->fatal() << "[MettDeamon] Not a valid MarDyn XML header file." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[MettDeamon] Could not find root node /mardyn in XML header file or file itself." << std::endl; + error_message << "[MettDeamon] Not a valid MarDyn XML header file." << std::endl; + MARDYN_EXIT(error_message.str()); } bool bInputOk = true; @@ -1674,8 +1699,9 @@ void Reservoir::readFromFileBinaryHeader() if(not bInputOk) { - Log::global_log->error() << "[MettDeamon] Content of file: '" << _filepath.header << "' corrupted! Program exit ..." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[MettDeamon] Content of file: '" << _filepath.header << "' corrupted! Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } if("ICRVQD" == strMoleculeFormat) @@ -1686,8 +1712,9 @@ void Reservoir::readFromFileBinaryHeader() _nMoleculeFormat = ICRV; else { - Log::global_log->error() << "[MettDeamon] Not a valid molecule format: " << strMoleculeFormat << ", program exit ..." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[MettDeamon] Not a valid molecule format: " << strMoleculeFormat << ", program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -1705,8 +1732,9 @@ void Reservoir::readFromFileBinary(DomainDecompBase* domainDecomp, ParticleConta std::ifstream ifs; ifs.open(_filepath.data.c_str(), std::ios::binary | std::ios::in); if (!ifs.is_open()) { - Log::global_log->error() << "[MettDeamon] Could not open reservoir phaseSpaceFile " << _filepath.data << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[MettDeamon] Could not open reservoir phaseSpaceFile " << _filepath.data << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "[MettDeamon] Reading phase space file " << _filepath.data << std::endl; @@ -1724,7 +1752,10 @@ void Reservoir::readFromFileBinary(DomainDecompBase* domainDecomp, ParticleConta case IRV: _moleculeDataReader = std::make_unique(); break; - default: Log::global_log->error() << "[MettDeamon] Unknown molecule format" << std::endl; + default: + std::ostringstream error_message; + error_message << "[MettDeamon] Unknown molecule format" << std::endl; + MARDYN_EXIT(error_message.str()); } for (uint64_t pi=0; pi<_numMoleculesRead; pi++) { @@ -1807,7 +1838,9 @@ bool Reservoir::isRelevant(DomainDecompBase* domainDecomp, Domain* domain, Molec dOffset = nBinIndex*_dBinWidth + (domain->getGlobalLength(1) - _dBinWidth); break; default: - Log::global_log->error() << "[MettDeamon] Unknown moving direction" << std::endl; + std::ostringstream error_message; + error_message << "[MettDeamon] Unknown moving direction" << std::endl; + MARDYN_EXIT(error_message.str()); } return domainDecomp->procOwnsPos(mol.r(0), y-dOffset, mol.r(2), domain); } diff --git a/src/plugins/NEMD/MettDeamonFeedrateDirector.cpp b/src/plugins/NEMD/MettDeamonFeedrateDirector.cpp index 62a136d275..ea7f39e152 100644 --- a/src/plugins/NEMD/MettDeamonFeedrateDirector.cpp +++ b/src/plugins/NEMD/MettDeamonFeedrateDirector.cpp @@ -134,12 +134,14 @@ void MettDeamonFeedrateDirector::beforeForces( // Check if other plugins were found if(nullptr == mirror) { - Log::global_log->error() << "[MettDeamonFeedrateDirector] No Mirror plugin found in plugin list. Program exit ..." << std::endl; - mardyn_exit(-2004); + std::ostringstream error_message; + error_message << "[MettDeamonFeedrateDirector] No Mirror plugin found in plugin list. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } if(nullptr == mettDeamon) { - Log::global_log->error() << "[MettDeamonFeedrateDirector] No MettDeamon plugin found in plugin list. Program exit ..." << std::endl; - mardyn_exit(-2004); + std::ostringstream error_message; + error_message << "[MettDeamonFeedrateDirector] No MettDeamon plugin found in plugin list. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } // Get number of deleted/reflected particles from Mirror plugin diff --git a/src/plugins/NEMD/RegionSampling.cpp b/src/plugins/NEMD/RegionSampling.cpp index 26f7c94062..9f6484436a 100644 --- a/src/plugins/NEMD/RegionSampling.cpp +++ b/src/plugins/NEMD/RegionSampling.cpp @@ -171,8 +171,9 @@ void SampleRegion::readXML(XMLfileUnits& xmlconfig) distControl->registerObserver(this); else { - Log::global_log->error() << "RegionSampling->region["<GetID()<<"]: Initialization of plugin DistControl is needed before! Program exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "RegionSampling->region["<GetID()<<"]: Initialization of plugin DistControl is needed before! Program exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -183,8 +184,9 @@ void SampleRegion::readXML(XMLfileUnits& xmlconfig) numSamplingModules = query.card(); Log::global_log->info() << "RegionSampling->region["<GetID()-1<<"]: Number of sampling modules: " << numSamplingModules << std::endl; if(numSamplingModules < 1) { - Log::global_log->error() << "RegionSampling->region["<GetID()-1<<"]: No sampling module parameters specified. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "RegionSampling->region["<GetID()-1<<"]: No sampling module parameters specified. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } XMLfile::Query::const_iterator outputSamplingIter; @@ -219,16 +221,18 @@ void SampleRegion::readXML(XMLfileUnits& xmlconfig) std::string strSubdivisionType; if( !xmlconfig.getNodeValue("subdivision@type", strSubdivisionType) ) { - Log::global_log->error() << "RegionSampling->region["<GetID()-1<<"]->sampling('"<region["<GetID()-1<<"]->sampling('"<error() << "RegionSampling->region["<GetID()-1<<"]->sampling('"<region["<GetID()-1<<"]->sampling('"<error() << "RegionSampling->region["<GetID()-1<<"]->sampling('"<region["<GetID()-1<<"]->sampling('"<error() << "RegionSampling->region["<GetID()-1<<"]->sampling('"<region["<GetID()-1<<"]->sampling('"<info() << "RegionSampling->region["<GetID()-1<<"]: Number of velocity discretizations: " << numDiscretizations << std::endl; if(numDiscretizations < 1) { - Log::global_log->error() << "RegionSampling->region["<GetID()-1<<"]: No velocity discretizations specified for VDF sampling. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "RegionSampling->region["<GetID()-1<<"]: No velocity discretizations specified for VDF sampling. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } XMLfile::Query::const_iterator nodeIter; for( nodeIter = query_vd.begin(); nodeIter != query_vd.end(); nodeIter++ ) @@ -306,8 +313,9 @@ void SampleRegion::readXML(XMLfileUnits& xmlconfig) uint32_t cid = 0; bool bVal = xmlconfig.getNodeValue("@cid", cid); if( (cid > _numComponents) || ((not bVal) && (not _boolSingleComp)) ){ - Log::global_log->error() << "RegionSampling->region["<GetID()-1<<"]: VDF velocity discretization corrupted. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "RegionSampling->region["<GetID()-1<<"]: VDF velocity discretization corrupted. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } if(_boolSingleComp){ @@ -333,16 +341,18 @@ void SampleRegion::readXML(XMLfileUnits& xmlconfig) std::string strSubdivisionType; if( !xmlconfig.getNodeValue("subdivision@type", strSubdivisionType) ) { - Log::global_log->error() << "RegionSampling->region["<GetID()-1<<"]->sampling('"<region["<GetID()-1<<"]->sampling('"<error() << "RegionSampling->region["<GetID()-1<<"]->sampling('"<region["<GetID()-1<<"]->sampling('"<error() << "RegionSampling->region["<GetID()-1<<"]->sampling('"<region["<GetID()-1<<"]->sampling('"<error() << "RegionSampling->region["<GetID()-1<<"]->sampling('"<region["<GetID()-1<<"]->sampling('"<error() << "RegionSampling->region["<GetID()-1<<"]->sampling('"<region["<GetID()-1<<"]->sampling('"<error() << "RegionSampling->region["<GetID()-1<<"]->sampling('"<region["<GetID()-1<<"]->sampling('"<error() << "RegionSampling->region["<GetID()-1<<"]: Found " << numSubdivisions << " 'subdivision' elements, " + std::ostringstream error_message; + error_message << "RegionSampling->region["<GetID()-1<<"]: Found " << numSubdivisions << " 'subdivision' elements, " "expected: 2. Program exit ..." << std::endl; - mardyn_exit(-1); + MARDYN_EXIT(error_message.str()); } std::string oldpath = xmlconfig.getcurrentnodepath(); XMLfile::Query::const_iterator outputSubdivisionIter; @@ -473,16 +488,18 @@ void SampleRegion::readXML(XMLfileUnits& xmlconfig) if(not bInputIsValid) { - Log::global_log->error() << "RegionSampling->region["<GetID()-1<<"]->sampling('"<region["<GetID()-1<<"]->sampling('"<error() << "RegionSampling->region["<GetID()-1<<"]: Wrong attribute 'sampling@type', expected type='profiles|VDF|fieldYR'! Program exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "RegionSampling->region["<GetID()-1<<"]: Wrong attribute 'sampling@type', expected type='profiles|VDF|fieldYR'! Program exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } } // for( outputSamplingIter = query.begin(); outputSamplingIter; outputSamplingIter++ ) } @@ -506,8 +523,9 @@ void SampleRegion::prepareSubdivisionProfiles() break; case SDOPT_UNKNOWN: default: - Log::global_log->error() << "tec::ControlRegion::PrepareSubdivisionProfiles(): Unknown subdivision type! Program exit..." << std::endl; - exit(-1); + std::ostringstream error_message; + error_message << "tec::ControlRegion::PrepareSubdivisionProfiles(): Unknown subdivision type! Program exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -530,8 +548,9 @@ void SampleRegion::prepareSubdivisionVDF() break; case SDOPT_UNKNOWN: default: - Log::global_log->error() << "ERROR in SampleRegion::PrepareSubdivisionVDF(): Unknown subdivision type! Program exit..." << std::endl; - exit(-1); + std::ostringstream error_message; + error_message << "ERROR in SampleRegion::PrepareSubdivisionVDF(): Unknown subdivision type! Program exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -554,8 +573,9 @@ void SampleRegion::prepareSubdivisionFieldYR() break; case SDOPT_UNKNOWN: default: - Log::global_log->error() << "SampleRegion::PrepareSubdivisionFieldYR(): Unknown subdivision type! Program exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "SampleRegion::PrepareSubdivisionFieldYR(): Unknown subdivision type! Program exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } dWidth = (this->GetWidth(0) < this->GetWidth(2) ) ? this->GetWidth(0) : this->GetWidth(2); @@ -573,8 +593,9 @@ void SampleRegion::prepareSubdivisionFieldYR() break; case SDOPT_UNKNOWN: default: - Log::global_log->error() << "SampleRegion::PrepareSubdivisionFieldYR(): Unknown subdivision type! Program exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "SampleRegion::PrepareSubdivisionFieldYR(): Unknown subdivision type! Program exit..." << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -2047,8 +2068,9 @@ void RegionSampling::readXML(XMLfileUnits& xmlconfig) numRegions = query.card(); Log::global_log->info() << "RegionSampling: Number of sampling regions: " << numRegions << std::endl; if(numRegions < 1) { - Log::global_log->warning() << "RegionSampling: No region parameters specified. Program exit ..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "RegionSampling: No region parameters specified. Program exit ..." << std::endl; + MARDYN_EXIT(error_message.str()); } std::string oldpath = xmlconfig.getcurrentnodepath(); XMLfile::Query::const_iterator outputRegionIter; diff --git a/src/plugins/Permittivity.cpp b/src/plugins/Permittivity.cpp index be6e1c54f6..84b60e439f 100644 --- a/src/plugins/Permittivity.cpp +++ b/src/plugins/Permittivity.cpp @@ -10,6 +10,9 @@ // If a simulation is resumed from a restart file, then the existing running average file is ammended but the computation of the running averages starts anew at the time step of the restart file #include "Permittivity.h" +#include + +#include "utils/mardyn_assert.h" #include "Simulation.h" void Permittivity::readXML(XMLfileUnits& xmlconfig) { @@ -74,7 +77,9 @@ void Permittivity::init(ParticleContainer* particleContainer, DomainDecompBase* bool orientationIsCorrect = ci.dipole(0).e() == std::array{0,0,1}; _myAbs[i] = ci.dipole(0).abs(); if(not orientationIsCorrect){ - Log::global_log->error() << "Wrong dipole vector chosen! Please always choose [eMyx eMyy eMyz] = [0 0 1] when using the permittivity plugin" << std::endl; + std::ostringstream error_message; + error_message << "Wrong dipole vector chosen! Please always choose [eMyx eMyy eMyz] = [0 0 1] when using the permittivity plugin" << std::endl; + MARDYN_EXIT(error_message.str()); } } } diff --git a/src/plugins/PluginFactory.cpp b/src/plugins/PluginFactory.cpp index 0927e4b9da..2c1041455e 100644 --- a/src/plugins/PluginFactory.cpp +++ b/src/plugins/PluginFactory.cpp @@ -192,9 +192,9 @@ long PluginFactory::enablePlugins(std::list& _plugins, } else if ("multi" == sphere_representation) { plugin = new MmpldWriterMultiSphere(); } else { - Log::global_log->error() << "[MMPLD Writer] Unknown sphere representation type: " << sphere_representation - << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[MMPLD Writer] Unknown sphere representation type: " << sphere_representation << std::endl; + MARDYN_EXIT(error_message.str()); } } else if (pluginname == "DomainProfiles") { plugin = this->create("DensityProfileWriter"); diff --git a/src/plugins/SpatialProfile.cpp b/src/plugins/SpatialProfile.cpp index 07ca7397fc..a549cdcfa6 100644 --- a/src/plugins/SpatialProfile.cpp +++ b/src/plugins/SpatialProfile.cpp @@ -45,8 +45,9 @@ void SpatialProfile::readXML(XMLfileUnits& xmlconfig) { xmlconfig.getNodeValue("z", samplInfo.universalProfileUnit[2]); samplInfo.cylinder = false; } else { - Log::global_log->error() << "[SpatialProfile] Invalid mode. cylinder/cartesian" << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[SpatialProfile] Invalid mode. cylinder/cartesian" << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "[SpatialProfile] Binning units: " << samplInfo.universalProfileUnit[0] << " " @@ -394,17 +395,18 @@ long SpatialProfile::getCylUID(ParticleIterator& thismol) { unID = (long) (hUn * samplInfo.universalProfileUnit[0] * samplInfo.universalProfileUnit[2] + rUn * samplInfo.universalProfileUnit[2] + phiUn); } else { - Log::global_log->error() << "INV PROFILE UNITS " << samplInfo.universalInvProfileUnit[0] << " " + std::ostringstream error_message; + error_message << "INV PROFILE UNITS " << samplInfo.universalInvProfileUnit[0] << " " << samplInfo.universalInvProfileUnit[1] << " " << samplInfo.universalInvProfileUnit[2] << "\n"; - Log::global_log->error() << "PROFILE UNITS " << samplInfo.universalProfileUnit[0] << " " + error_message << "PROFILE UNITS " << samplInfo.universalProfileUnit[0] << " " << samplInfo.universalProfileUnit[1] << " " << samplInfo.universalProfileUnit[2] << "\n"; - Log::global_log->error() << "Severe error!! Invalid profile ID (" << rUn << " / " << hUn << " / " << phiUn + error_message << "Severe error!! Invalid profile ID (" << rUn << " / " << hUn << " / " << phiUn << ").\n\n"; - Log::global_log->error() << "Severe error!! Invalid profile unit (" << R2 << " / " << yc << " / " << phi << ").\n\n"; - Log::global_log->error() << "Coordinates off center (" << xc << " / " << yc << " / " << zc << ").\n"; - Log::global_log->error() << "unID = " << unID << "\n"; - mardyn_exit(707); + error_message << "Severe error!! Invalid profile unit (" << R2 << " / " << yc << " / " << phi << ").\n\n"; + error_message << "Coordinates off center (" << xc << " / " << yc << " / " << zc << ").\n"; + error_message << "unID = " << unID << "\n"; + MARDYN_EXIT(error_message.str()); } return unID; } diff --git a/src/plugins/VectorizationTuner.cpp b/src/plugins/VectorizationTuner.cpp index 6174b59301..bcc3ad011a 100644 --- a/src/plugins/VectorizationTuner.cpp +++ b/src/plugins/VectorizationTuner.cpp @@ -34,8 +34,9 @@ void VectorizationTuner::readXML(XMLfileUnits& xmlconfig) { } else if (mode == "file") { vtWriter.reset(new VTWriter()); } else { - Log::global_log->error() << R"(Unknown FlopRateOutputPlugin::mode. Choose "stdout" or "file".)" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << R"(Unknown FlopRateOutputPlugin::mode. Choose "stdout" or "file".)" << std::endl; + MARDYN_EXIT(error_message.str()); } _outputPrefix = "mardyn"; @@ -61,10 +62,11 @@ void VectorizationTuner::readXML(XMLfileUnits& xmlconfig) { } else if (incTypeStr == "both") { _moleculeCntIncreaseType = MoleculeCntIncreaseTypeEnum::both; } else { - Log::global_log->error() + std::ostringstream error_message; + error_message << R"(Unknown FlopRateOutputPlugin::moleculecntincreasetype. Choose "linear" or "exponential" or "both".)" << std::endl; - mardyn_exit(798123); + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "Molecule count increase type: " << incTypeStr << std::endl; @@ -282,8 +284,9 @@ void VectorizationTuner::tune(std::vector& componentList, TunerLoad& mardyn_assert(componentList.size() == particleNums.size()); if(componentList.size() > 2){ - Log::global_log->error_always_output() << "The tuner currently supports only two different particle types!" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "The tuner currently supports only two different particle types!" << std::endl; + MARDYN_EXIT(error_message.str()); } int maxMols = particleNums.at(0); diff --git a/src/plugins/WallPotential.cpp b/src/plugins/WallPotential.cpp index 2d9bda387a..45161c0e14 100755 --- a/src/plugins/WallPotential.cpp +++ b/src/plugins/WallPotential.cpp @@ -5,6 +5,8 @@ #include "WallPotential.h" +#include + #include "Simulation.h" #include "utils/mardyn_assert.h" @@ -40,7 +42,7 @@ void WallPotential::readXML(XMLfileUnits &xmlconfig) { _potential = LJ9_3; // TODO: is this allowed or should simulation be halted // HALT SIM - //mardyn_exit(1); + //MARDYN_EXIT(error_message.str()); } XMLfile::Query query = xmlconfig.query("component"); @@ -87,8 +89,9 @@ void WallPotential::readXML(XMLfileUnits &xmlconfig) { Log::global_log->info() << "[WallPotential] LJ10_4 initialized." << std::endl; } else{ - Log::global_log -> error() << "[WallPotential] UNKNOWN WALL POTENTIAL! EXITING!" << std::endl; - mardyn_exit(11); + std::ostringstream error_message; + error_message << "[WallPotential] Unknown wall potential" << std::endl; + MARDYN_EXIT(error_message.str()); } } diff --git a/src/plugins/profiles/ProfileBase.cpp b/src/plugins/profiles/ProfileBase.cpp index 3f685c23d5..f0ec2cc639 100644 --- a/src/plugins/profiles/ProfileBase.cpp +++ b/src/plugins/profiles/ProfileBase.cpp @@ -2,8 +2,11 @@ // Created by Kruegener on 10/25/2018. // +#include + #include "ProfileBase.h" #include "plugins/SpatialProfile.h" +#include "utils/mardyn_assert.h" void ProfileBase::writeMatrix (std::ofstream& outfile) { if (_samplInfo.cylinder) { @@ -43,7 +46,9 @@ void ProfileBase::writeKartMatrix (std::ofstream& outfile) { } void ProfileBase::writeSimpleMatrix (std::ofstream& outfile) { - Log::global_log->error() << "SIMPLE MATRIX OUTPUT NOT IMPLEMENTED!\n"; + std::ostringstream error_message; + error_message << "SIMPLE MATRIX OUTPUT NOT IMPLEMENTED!\n"; + MARDYN_EXIT(error_message.str()); } void ProfileBase::writeCylMatrix (std::ofstream& outfile) { diff --git a/src/thermostats/TemperatureControl.cpp b/src/thermostats/TemperatureControl.cpp index d6156f1e17..0946e9146b 100644 --- a/src/thermostats/TemperatureControl.cpp +++ b/src/thermostats/TemperatureControl.cpp @@ -167,8 +167,9 @@ void ControlRegionT::readXML(XMLfileUnits& xmlconfig) { _timestep = global_simulation->getIntegrator()->getTimestepLength(); _nuDt = _nuAndersen * _timestep; } else { - Log::global_log->error() << "[TemperatureControl] REGION: Invalid 'method' param: " << methods << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[TemperatureControl] REGION: Invalid 'method' param: " << methods << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "[TemperatureControl] REGION 'method' param: " << methods << std::endl; } @@ -191,8 +192,9 @@ void ControlRegionT::VelocityScalingInit(XMLfileUnits& xmlconfig, std::string st // settings xmlconfig.getNodeValue("settings/numslabs", _nNumSlabs); if (_nNumSlabs < 1) { - Log::global_log->fatal() << "TemperatureControl: need at least one slab! (settings/numslabs)"; - mardyn_exit(932); + std::ostringstream error_message; + error_message << "TemperatureControl: need at least one slab! (settings/numslabs)"; + MARDYN_EXIT(error_message.str()); } xmlconfig.getNodeValue("settings/exponent", _dTemperatureExponent); xmlconfig.getNodeValue("settings/directions", strDirections); @@ -417,8 +419,9 @@ void ControlRegionT::ControlTemperature(Molecule* mol) { } } } else { - Log::global_log->error() << "[TemperatureControl] Invalid localMethod param: " << _localMethod << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "[TemperatureControl] Invalid localMethod param: " << _localMethod << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -504,9 +507,10 @@ void ControlRegionT::registerAsObserver() { if (distControl != nullptr) distControl->registerObserver(this); else { - Log::global_log->error() << "TemperatureControl->region[" << this->GetID() - << "]: Initialization of plugin DistControl is needed before! Program exit..." << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "TemperatureControl->region[" << this->GetID() + << "]: Initialization of plugin DistControl is needed before!" << std::endl; + MARDYN_EXIT(error_message.str()); } } } diff --git a/src/utils/Logger.cpp b/src/utils/Logger.cpp index fe44547c1c..6a694fd3df 100644 --- a/src/utils/Logger.cpp +++ b/src/utils/Logger.cpp @@ -2,13 +2,21 @@ #include "Logger.h" +#include + namespace Log { -Logger *global_log; +std::unique_ptr global_log; +// Write to stream Logger::Logger(logLevel level, std::ostream *os) : _log_level(level), _msg_log_level(Log::Error), - _do_output(true), _filename(""),_log_stream(os), + _do_output(true), _filename(""), + // std::cout is managed globally, + // so do nothing when _log_stream goes out of scope + // --> any passed ostream other than std::cout needs to be + // deleted manually! + _log_stream(os, [](std::ostream*){/* no-op deleter */}), logLevelNames(), _starttime(), _rank(0) { init_starting_time(); @@ -19,10 +27,10 @@ Logger::Logger(logLevel level, std::ostream *os) : *_log_stream << std::boolalpha; // Print boolean as true/false } - +// Write to file Logger::Logger(logLevel level, std::string prefix) : _log_level(level), _msg_log_level(Log::Error), - _do_output(true), _filename(""), _log_stream(0), + _do_output(true), _filename(""), _log_stream(nullptr), logLevelNames(), _starttime(), _rank(0) { init_starting_time(); @@ -35,17 +43,11 @@ Logger::Logger(logLevel level, std::string prefix) : #endif filenamestream << ".log"; _filename = filenamestream.str(); - _log_stream = new std::ofstream(_filename.c_str()); + + _log_stream = std::make_shared(_filename.c_str()); *_log_stream << std::boolalpha; // Print boolean as true/false } -Logger::~Logger() { - *_log_stream << std::flush; - if (_filename != "") - (static_cast (_log_stream))->close(); -} - - /// allow logging only for a single process void Logger::set_mpi_output_root(int root) { if (_rank != root) diff --git a/src/utils/Logger.h b/src/utils/Logger.h index 5cabb95f15..5afa8b0b98 100644 --- a/src/utils/Logger.h +++ b/src/utils/Logger.h @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef USE_GETTIMEOFDAY #include @@ -46,12 +47,12 @@ namespace Log { class Logger; /** - * Gobal logger variable for use in the entire program. - * Must be initialized with constructor e.g. new Log::Logger(). + * Global logger variable for use in the entire program. + * Must be initialized with constructor * Namespace visibility: - * */ + */ #ifndef LOGGER_SRC -extern Log::Logger *global_log; +extern std::unique_ptr global_log; #endif /** @@ -72,8 +73,12 @@ typedef enum { * * Provides easy interface to handle log messages. Initialize either with * output level and stream or output level and filename or use default constructor - * values (Error, &(std::cout)). With a given file basename and MPI Support each rank will - * create and write to his own file. + * values (Error, &(std::cout)). + * Note: Due to the default argument (std::cout), the passed ostream pointer + * will not be deleted automatically! Any passed ostream pointer other than + * std::cout must be deleted manually! + * With a given file basename and MPI Support each rank will create + * and write to its own file. * For writing log messages use fatal(), error(), warning(), info() or debug() as * with normal streams, e.g. * > log.error() << "Wrong parameter." << std::endl; @@ -92,7 +97,7 @@ class Logger { logLevel _msg_log_level; bool _do_output; std::string _filename; - std::ostream *_log_stream; + std::shared_ptr _log_stream; std::map logLevelNames; #ifdef USE_GETTIMEOFDAY timeval _starttime; @@ -115,21 +120,32 @@ class Logger { // don't allow copy-construction Logger(const Logger&) : _log_level(Log::Error), _msg_log_level(Log::Error), _do_output(true), - _filename(""), _log_stream(0), logLevelNames(), _starttime(), _rank(0) + _filename(""), _log_stream(nullptr), logLevelNames(), _starttime(), _rank(0) { } // don't allow assignment Logger& operator=(const Logger&) { return *this; } public: - /** Initializes the log level, log stream and the list of log level names. - * If ENABLE_MPI is enabled by default all process perform logging output. */ + /** + * Constructor for a logger to a stream. + * + * Initializes the log level, log stream and the list of log level names. + * If ENABLE_MPI is enabled by default, all process perform logging output. + * Note: Due to the default argument (std::cout), the passed ostream pointer + * will not be deleted automatically! Any passed ostream pointer other than + * std::cout must be deleted manually! + */ Logger(logLevel level = Log::Error, std::ostream *os = &(std::cout)); - + /** + * Constructor for a logger to a file. + * + * Initializes the log level, log stream and the list of log level names. + * If ENABLE_MPI is enabled by default, all process perform logging output. + */ Logger(logLevel level, std::string prefix); - /// Destructor flushes stream - ~Logger(); + ~Logger() = default; /// General output template for variables, strings, etc. template diff --git a/src/utils/OptionParser.cpp b/src/utils/OptionParser.cpp index 80e8baa9e2..de5d01c144 100644 --- a/src/utils/OptionParser.cpp +++ b/src/utils/OptionParser.cpp @@ -12,6 +12,11 @@ #include #include #include +#include + +#ifdef ENABLE_MPI +#include // For MPI_Finalize() +#endif #if defined(ENABLE_NLS) && ENABLE_NLS # include @@ -345,11 +350,17 @@ void OptionParser::process_opt(const Option& o, const std::string& opt, const st } else if (o.action() == "help") { print_help(); - mardyn_exit(0); + #ifdef ENABLE_MPI + MPI_Finalize(); + #endif + std::exit(EXIT_SUCCESS); } else if (o.action() == "version") { print_version(); - mardyn_exit(0); + #ifdef ENABLE_MPI + MPI_Finalize(); + #endif + std::exit(EXIT_SUCCESS); } else if (o.action() == "callback" && o.callback()) { (*o.callback())(o, opt, value, *this); @@ -437,12 +448,15 @@ void OptionParser::print_version() const { } void OptionParser::exit() const { - mardyn_exit(2); + std::ostringstream error_message; + error_message << "OptionParser::exit() called" << std::endl; + MARDYN_EXIT(error_message.str()); } void OptionParser::error(const std::string& msg) const { print_usage(std::cerr); - std::cerr << prog() << ": " << _("error") << ": " << msg << std::endl; - mardyn_exit(-4); + std::ostringstream error_message; + error_message << prog() << ": " << _("error") << ": " << msg << std::endl; + MARDYN_EXIT(error_message.str()); } ////////// } class OptionParser ////////// diff --git a/src/utils/SigsegvHandler.h b/src/utils/SigsegvHandler.h index f6bcf7c823..6dc345228f 100644 --- a/src/utils/SigsegvHandler.h +++ b/src/utils/SigsegvHandler.h @@ -28,7 +28,7 @@ void handler(int sig) { // print out all the frames to stderr fprintf(stderr, "Error: signal %d:\n", sig); backtrace_symbols_fd(array, size, STDERR_FILENO); - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); } void registerSigsegvHandler() { diff --git a/src/utils/Testing.cpp b/src/utils/Testing.cpp index 3899af516d..c50c2d49ee 100644 --- a/src/utils/Testing.cpp +++ b/src/utils/Testing.cpp @@ -6,11 +6,14 @@ */ #include "utils/Testing.h" + +#include + #include "utils/Logger.h" #include "utils/FileUtils.h" #include "utils/mardyn_assert.h" -Log::Logger* test_log; +std::shared_ptr test_log; #ifdef UNIT_TESTS #ifdef USE_CPPUNIT @@ -30,7 +33,7 @@ Log::Logger* test_log; int runTests(Log::logLevel testLogLevel, std::string& testDataDirectory, const std::string& testcases) { Log::logLevel globalLogLevel = Log::global_log->get_log_level(); - test_log = new Log::Logger(testLogLevel); + test_log = std::make_shared(testLogLevel); test_log->set_do_output(Log::global_log->get_do_output()); if (testLogLevel > Log::Info) { Log::global_log->set_log_level(Log::Debug); @@ -93,8 +96,9 @@ utils::Test::~Test() { } void utils::Test::setTestDataDirectory(std::string& testDataDir) { if (!fileExists(testDataDir.c_str())) { - test_log->error() << "Directory '" << testDataDirectory << "' for test input data does not exist!" << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "Directory '" << testDataDir.c_str() << "' for test input data does not exist!" << std::endl; + MARDYN_EXIT(error_message.str()); } testDataDirectory = testDataDir; } @@ -104,8 +108,9 @@ std::string utils::Test::getTestDataFilename(const std::string& file, bool check std::string fullPath = testDataDirectory +"/"+ file; if (!fileExists(fullPath.c_str()) and checkExistence) { - test_log->error() << "File " << fullPath << " for test input data does not exist!" << std::endl; - mardyn_exit(-1); + std::ostringstream error_message; + error_message << "File " << fullPath << " for test input data does not exist!" << std::endl; + MARDYN_EXIT(error_message.str()); } return fullPath; } diff --git a/src/utils/Testing.h b/src/utils/Testing.h index 1243c03528..5e02feff8d 100644 --- a/src/utils/Testing.h +++ b/src/utils/Testing.h @@ -36,7 +36,7 @@ void setTestDataDirectory(std::string& testDataDirectory); * Gobal logger variable for use in the test cases. * Is initialized in runTests(). */ -extern Log::Logger* test_log; +extern std::shared_ptr test_log; #ifdef UNIT_TESTS diff --git a/src/utils/generator/ReplicaFiller.cpp b/src/utils/generator/ReplicaFiller.cpp index 58dd7584fc..eb7d054943 100644 --- a/src/utils/generator/ReplicaFiller.cpp +++ b/src/utils/generator/ReplicaFiller.cpp @@ -146,19 +146,22 @@ void ReplicaFiller::readXML(XMLfileUnits& xmlconfig) { std::string inputPluginName; xmlconfig.getNodeValue("@type", inputPluginName); if (inputPluginName != "BinaryReader") { - Log::global_log->error() << "[ReplicaFiller] ReplicaFiller only works with inputPlugins: BinaryReader at the moment" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[ReplicaFiller] ReplicaFiller only works with inputPlugins: BinaryReader at the moment" << std::endl; + MARDYN_EXIT(error_message.str()); } setInputReader(std::make_shared()); _inputReader->readXML(xmlconfig); if (_inputReader == nullptr) { - Log::global_log->error() << "[ReplicaFiller] Could not create input reader " << inputPluginName << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[ReplicaFiller] Could not create input reader " << inputPluginName << std::endl; + MARDYN_EXIT(error_message.str()); } xmlconfig.changecurrentnode(".."); } else { - Log::global_log->error() << "[ReplicaFiller] Input reader for original not specified." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[ReplicaFiller] Input reader for original not specified." << std::endl; + MARDYN_EXIT(error_message.str()); } if (xmlconfig.changecurrentnode("origin")) { Coordinate3D origin; @@ -176,8 +179,9 @@ void ReplicaFiller::readXML(XMLfileUnits& xmlconfig) { if (xmlconfig.getNodeValue("componentid", componentid)) { const size_t numComps = global_simulation->getEnsemble()->getComponents()->size(); if ((componentid < 1) || (componentid > numComps)) { - Log::global_log->error() << "[ReplicaFiller] Specified componentid is invalid. Valid range: 1 <= componentid <= " << numComps << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[ReplicaFiller] Specified componentid is invalid. Valid range: 1 <= componentid <= " << numComps << std::endl; + MARDYN_EXIT(error_message.str()); } _componentid = componentid - 1; // Internally stored in array starting at index 0 _keepComponent = false; @@ -205,8 +209,9 @@ void ReplicaFiller::init() { Log::global_log->info() << "[ReplicaFiller] Number of molecules in the replica: " << numberOfParticles << std::endl; if (numberOfParticles == 0) { - Log::global_log->error_always_output() << "[ReplicaFiller] No molecules in replica, aborting! " << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "[ReplicaFiller] No molecules in replica, aborting! " << std::endl; + MARDYN_EXIT(error_message.str()); } Log::global_log->info() << "[ReplicaFiller] Setting simulation time to 0.0" << std::endl; diff --git a/src/utils/mardyn_assert.h b/src/utils/mardyn_assert.h index fec2f2510c..08ad520e73 100644 --- a/src/utils/mardyn_assert.h +++ b/src/utils/mardyn_assert.h @@ -8,22 +8,64 @@ #ifndef SRC_UTILS_MARDYN_ASSERT_H_ #define SRC_UTILS_MARDYN_ASSERT_H_ +#include +#include +#include +#include +#include +#include + #include "Logger.h" -inline void mardyn_exit(int code) { +// Macro to wrap mardyn_exit and pass the caller file and line +#define MARDYN_EXIT(exit_message) mardyn_exit(exit_message, __func__, __FILE__, __LINE__) + +inline void mardyn_exit(const std::string & exit_message, + const char* function, const char* filepath, const int line) { + + // Only print the file path relative to the "/src/" directory + // The following code extracts this relative path from "filepath" + // Search until last "/src/" was found to avoid user-specific "src" dirs + const char* filepath_truncated = nullptr; + const char* temp = filepath; + while ((temp = std::strstr(temp, "/src/")) != nullptr) { + filepath_truncated = temp; + temp++; + } + if (filepath_truncated == nullptr) { + // Print absolute path if "/src/" not found + filepath_truncated = filepath; + } else { + filepath_truncated++; // +1 to ignore the first "/" + } + + // Print code location from which MARDYN_EXIT() was called + Log::global_log->error_always_output() + << "Exit called from function `" << function << "`" + << " in file `" << filepath_truncated << ":" << line + << "` with message:" << std::endl; + + // Print exit message line by line to always have Logger output + std::stringstream ss(exit_message); + std::string exit_message_line; + // Split exit message by "\n" and print via Logger + while (std::getline(ss, exit_message_line, '\n')) { + Log::global_log->error_always_output() << exit_message_line << std::endl; + } + #ifdef ENABLE_MPI // terminate all mpi processes and return exitcode - MPI_Abort(MPI_COMM_WORLD, code); + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); #else // call global abort - this stops the debugger at the right spot. - Log::global_log->error_always_output() << "Exit code would have been " << code << std::endl; ::abort(); #endif } inline void __mardyn_assert__(const char * expr, const char* file, int line) { - Log::global_log->error_always_output() << "Assertion \"" << expr << "\" failed at " << file << ":" << line << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Assertion \"" << expr << "\" failed at " << file << ":" << line << std::endl; + MARDYN_EXIT(error_message.str()); } #ifdef NDEBUG diff --git a/src/utils/xmlfile.cpp b/src/utils/xmlfile.cpp index c781575251..acedd95cb2 100644 --- a/src/utils/xmlfile.cpp +++ b/src/utils/xmlfile.cpp @@ -193,9 +193,10 @@ bool XMLfile::initfile_local(const std::string& filepath) { //version using ifstream std::ifstream fstrm(filepathTrimmed.c_str(),std::ifstream::binary|std::ifstream::ate); if(!fstrm) { - std::cerr << "ERROR opening " << filepathTrimmed << std::endl; + std::ostringstream error_message; + error_message << "ERROR opening " << filepathTrimmed << std::endl; clear(); - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); } std::ifstream::pos_type filesize=fstrm.tellg(); fstrm.close(); fstrm.clear(); @@ -538,17 +539,19 @@ template bool XMLfile::Node::getValue(T& value) const // Check if input has correct sign if (std::is_unsigned_v) { if (ss.str().find_first_of("-") != std::string::npos) { - std::cerr << "ERROR parsing \"" << ss.str() << "\" to data type " << typeid(T).name() << " from tag \"<" << name() << ">\" in xml file" << std::endl; - std::cerr << "The tag contains a negative value but an unsigned value was expected." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "ERROR parsing \"" << ss.str() << "\" to data type " << typeid(T).name() << " from tag \"<" << name() << ">\" in xml file" << std::endl; + error_message << "The tag contains a negative value but an unsigned value was expected." << std::endl; + MARDYN_EXIT(error_message.str()); } } ss >> value; // Check if the entire string was consumed if (!ss.eof() || ss.fail()) { - std::cerr << "ERROR parsing all chars of \"" << ss.str() << "\" from tag \"<" << name() << ">\" in xml file" << std::endl; - std::cerr << "This might be the result of using a float while an integer is expected." << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "ERROR parsing all chars of \"" << ss.str() << "\" from tag \"<" << name() << ">\" in xml file" << std::endl; + error_message << "This might be the result of using a float while an integer is expected." << std::endl; + MARDYN_EXIT(error_message.str()); } return true; } @@ -582,9 +585,10 @@ template<> bool XMLfile::Node::getValue(bool& value) const } else if (v == "FALSE" || v == "NO" || v == "OFF") { value = false; } else { - std::cerr << "ERROR parsing \"" << v << "\" to boolean from tag \"" << name() << "\" in xml file." + std::ostringstream error_message; + error_message << "ERROR parsing \"" << v << "\" to boolean from tag \"" << name() << "\" in xml file." << " Valid values are: true, false, yes, no, on, off. " << std::endl; - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); } } return found; diff --git a/tools/gui/generators/MDGenerator.cpp b/tools/gui/generators/MDGenerator.cpp index 0e871f345a..cd6ad19a86 100644 --- a/tools/gui/generators/MDGenerator.cpp +++ b/tools/gui/generators/MDGenerator.cpp @@ -7,6 +7,8 @@ #include "MDGenerator.h" +#include + #include "parallel/DomainDecompBase.h" #include "io/CheckpointWriter.h" #include "particleContainer/LinkedCells.h" @@ -42,30 +44,19 @@ const double MDGenerator::abogadro_constant = 6.02214078e23; const double MDGenerator::boltzmann_constant_kB = 1.38065e-23; MDGenerator::MDGenerator(std::string name) : -Generator(name), _deleteLogger(true) { +Generator(name) { // initialize monolithic Mardyn's global_log and silence it... #ifndef MARDYN // if mardyn is not the main program, silence it's logger; - Log::global_log = new Log::Logger(Log::Warning, &(std::cout)); - _logger = new Log::Logger(Log::Debug, &ScenarioGeneratorApplication::getInstance()->getTextMessageStream()); + Log::global_log = std::make_shared(Log::Warning, &(std::cout)); + _logger = std::make_shared(Log::Debug, &ScenarioGeneratorApplication::getInstance()->getTextMessageStream()); #else - _logger = new Log::Logger(Log::Debug, &(std::cout)); + _logger = std::make_shared(Log::Debug, &(std::cout)); #endif } -MDGenerator::~MDGenerator() { - if (_deleteLogger) { - delete _logger; - } -} - -void MDGenerator::setLogger(Log::Logger* logger) { - if (_logger != NULL && _deleteLogger) { - delete _logger; - } - +void MDGenerator::setLogger(std::shared_ptr logger) { _logger = logger; - _deleteLogger = false; } void MDGenerator::createSampleObject() const { diff --git a/tools/gui/generators/MDGenerator.h b/tools/gui/generators/MDGenerator.h index 76a3e9f98d..221a534ce6 100644 --- a/tools/gui/generators/MDGenerator.h +++ b/tools/gui/generators/MDGenerator.h @@ -18,6 +18,7 @@ #include #include #include +#include class Domain; class DomainDecompBase; @@ -72,12 +73,11 @@ class MDGenerator: public Generator, public InputBase { static const double kelvin_2_mardyn; protected: - Log::Logger* _logger; - bool _deleteLogger; + std::shared_ptr _logger; MDGenerator(std::string name); - virtual ~MDGenerator(); + virtual ~MDGenerator() = default; /** * determine the velocity according to the temperature. @@ -91,7 +91,7 @@ class MDGenerator: public Generator, public InputBase { public: - virtual void setLogger(Log::Logger* logger); + virtual void setLogger(std::shared_ptr logger); //! NOP void setPhaseSpaceFile(std::string /*filename*/) {} diff --git a/tools/gui/generators/common/DropletPlacement.cpp b/tools/gui/generators/common/DropletPlacement.cpp index fe55fb123e..ca1b7c1893 100644 --- a/tools/gui/generators/common/DropletPlacement.cpp +++ b/tools/gui/generators/common/DropletPlacement.cpp @@ -7,10 +7,14 @@ #include "DropletPlacement.h" #include +#include + +#include "utils/Logger.h" + #define SIZE 100 -DropletPlacement::DropletPlacement(double fluidVolume, double maxSphereVolume, int numSphereSizes, Log::Logger* logger) +DropletPlacement::DropletPlacement(double fluidVolume, double maxSphereVolume, int numSphereSizes, std::shared_ptr logger) : _fluidVolume(fluidVolume / 100.), _maxSphereRadius(pow((3.0*maxSphereVolume / 100.)/(4.0 * M_PI), 1.0/3.0)), _numSphereSizes(numSphereSizes), _numOccupied(0), _logger(logger) { diff --git a/tools/gui/generators/common/DropletPlacement.h b/tools/gui/generators/common/DropletPlacement.h index c65ffbd739..1caba0d6dc 100644 --- a/tools/gui/generators/common/DropletPlacement.h +++ b/tools/gui/generators/common/DropletPlacement.h @@ -10,6 +10,7 @@ #include "utils/Logger.h" #include +#include /** * Places drops of different sizes in the domain, so that a given percentage @@ -41,7 +42,7 @@ class DropletPlacement { * - each class covering the same volume in total * - the size of a sphere is determined by pow(0.9, i) * maxSphereRadius; i in [1,maxSphereSize] */ - DropletPlacement(double fluidVolume, double maxSphereVolume, int numSphereSizes, Log::Logger* logger); + DropletPlacement(double fluidVolume, double maxSphereVolume, int numSphereSizes, std::shared_ptr logger); /** * Generates droplets with sizes as specified by numSphereSizes, fluidVolume @@ -59,7 +60,7 @@ class DropletPlacement { int _numOccupied; std::vector > > _occupiedFields; - Log::Logger* _logger; + std::shared_ptr _logger; /** * Initialize vector _occupiedFields