diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index ca96635a0..9684dc969 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -39,6 +39,7 @@ list (APPEND MAIN_SOURCE_FILES opm/simulators/timestepping/gatherConvergenceReport.cpp opm/simulators/utils/DeferredLogger.cpp opm/simulators/utils/gatherDeferredLogger.cpp + opm/simulators/utils/ParallelFileMerger.cpp opm/simulators/utils/ParallelRestart.cpp opm/simulators/wells/GroupState.cpp opm/simulators/wells/WGState.cpp diff --git a/opm/simulators/utils/ParallelFileMerger.cpp b/opm/simulators/utils/ParallelFileMerger.cpp new file mode 100644 index 000000000..7e9268f27 --- /dev/null +++ b/opm/simulators/utils/ParallelFileMerger.cpp @@ -0,0 +1,113 @@ +/* + Copyright 2016 Dr. Blatt - HPC-Simulation-Software & Services + Copyright 2016 STATOIL AS. + + This file is part of the Open Porous Media project (OPM). + + OPM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OPM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . +*/ + +#include +#include + +namespace Opm +{ +namespace detail +{ + +ParallelFileMerger::ParallelFileMerger(const fs::path& output_dir, + const std::string& deckname, + bool show_fallout) + : debugFileRegex_(deckname+"\\.\\d+\\.DBG"), + logFileRegex_(deckname+"\\.\\d+\\.PRT"), + fileWarningRegex_(deckname+"\\.(\\d+)\\.[^.]+"), + show_fallout_(show_fallout) +{ + if ( show_fallout_ ) + { + auto debugPath = output_dir; + debugPath /= (deckname + ".DBG"); + debugStream_.reset(new std::ofstream(debugPath, + std::ofstream::app)); + auto logPath = output_dir; + logPath /= ( deckname + ".PRT"); + logStream_.reset(new std::ofstream(logPath, + std::ofstream::app)); + } +} + +void ParallelFileMerger::operator()(const fs::path& file) +{ + std::smatch matches; + std::string filename = file.filename().native(); + + if ( std::regex_match(filename, matches, fileWarningRegex_) ) + { + std::string rank = std::regex_replace(filename, fileWarningRegex_, "\\1"); + + if( std::regex_match(filename, logFileRegex_) ) + { + if ( show_fallout_ ){ + appendFile(*logStream_, file, rank); + }else{ + fs::remove(file); + } + } + else + { + if (std::regex_match(filename, debugFileRegex_) ) + { + if ( show_fallout_ ){ + appendFile(*debugStream_, file, rank); + }else{ + fs::remove(file); + } + } + else + { + if ( show_fallout_ ){ + std::cerr << "WARNING: Unrecognized file with name " + << filename + << " that might stem from a parallel run." + << std::endl; + } + } + } + } +} + +void ParallelFileMerger::appendFile(std::ofstream& of, const fs::path& file, const std::string& rank) +{ + if( fs::file_size(file) ) + { + std::cerr << "WARNING: There has been logging to file " + << file.string() <<" by process " + << rank << std::endl; + + std::ifstream in(file); + of< #include -#include +#include +#include #include -#include + namespace Opm { @@ -45,93 +47,19 @@ class ParallelFileMerger public: /// \brief Constructor /// \param output_dir The output directory to use for reading/Writing. - /// \param deckanme The name of the deck. + /// \param deckname The name of the deck. ParallelFileMerger(const fs::path& output_dir, const std::string& deckname, - bool show_fallout = false) - : debugFileRegex_(deckname+"\\.\\d+\\.DBG"), - logFileRegex_(deckname+"\\.\\d+\\.PRT"), - fileWarningRegex_(deckname+"\\.(\\d+)\\.[^.]+"), - show_fallout_(show_fallout) - { - if ( show_fallout_ ) - { - auto debugPath = output_dir; - debugPath /= (deckname + ".DBG"); - debugStream_.reset(new std::ofstream(debugPath, - std::ofstream::app)); - auto logPath = output_dir; - logPath /= ( deckname + ".PRT"); - logStream_.reset(new std::ofstream(logPath, - std::ofstream::app)); - } - } + bool show_fallout = false); - void operator()(const fs::path& file) - { - std::smatch matches; - std::string filename = file.filename().native(); + void operator()(const fs::path& file); - if ( std::regex_match(filename, matches, fileWarningRegex_) ) - { - std::string rank = std::regex_replace(filename, fileWarningRegex_, "\\1"); - - if( std::regex_match(filename, logFileRegex_) ) - { - if ( show_fallout_ ){ - appendFile(*logStream_, file, rank); - }else{ - fs::remove(file); - } - } - else - { - if (std::regex_match(filename, debugFileRegex_) ) - { - if ( show_fallout_ ){ - appendFile(*debugStream_, file, rank); - }else{ - fs::remove(file); - } - } - else - { - if ( show_fallout_ ){ - std::cerr << "WARNING: Unrecognized file with name " - << filename - << " that might stem from a parallel run." - << std::endl; - } - } - } - } - } private: /// \brief Append contents of a file to a stream /// \brief of The output stream to use. /// \brief file The file whose content to append. /// \brief rank The rank that wrote the file. - void appendFile(std::ofstream& of, const fs::path& file, const std::string& rank) - { - if( fs::file_size(file) ) - { - std::cerr << "WARNING: There has been logging to file " - << file.string() <<" by process " - << rank << std::endl; - - std::ifstream in(file); - of<