2016-10-05 03:32:55 -05:00
|
|
|
/*
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OPM_PARALLELFILEMERGER_HEADER_INCLUDED
|
|
|
|
#define OPM_PARALLELFILEMERGER_HEADER_INCLUDED
|
|
|
|
|
2021-11-01 06:31:40 -05:00
|
|
|
#include <filesystem>
|
2021-04-29 02:01:03 -05:00
|
|
|
#include <fstream>
|
2016-10-05 03:32:55 -05:00
|
|
|
#include <memory>
|
2021-04-29 02:01:03 -05:00
|
|
|
#include <regex>
|
|
|
|
#include <string>
|
2016-10-05 03:32:55 -05:00
|
|
|
|
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
|
2021-11-01 06:31:40 -05:00
|
|
|
namespace fs = ::std::filesystem;
|
2016-10-05 03:32:55 -05:00
|
|
|
|
|
|
|
/// \brief A functor that merges multiple files of a parallel run to one file.
|
|
|
|
///
|
|
|
|
/// Without care multiple processes might log messages in a parallel run.
|
|
|
|
/// Non-root processes will do that to seperate files
|
|
|
|
/// <basename>.<rank>.<extension. This functor will append those file
|
|
|
|
/// to usual ones and delete the other files.
|
|
|
|
class ParallelFileMerger
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// \brief Constructor
|
|
|
|
/// \param output_dir The output directory to use for reading/Writing.
|
2021-04-29 02:01:03 -05:00
|
|
|
/// \param deckname The name of the deck.
|
2016-10-05 03:40:52 -05:00
|
|
|
ParallelFileMerger(const fs::path& output_dir,
|
2019-01-14 06:06:21 -06:00
|
|
|
const std::string& deckname,
|
2021-04-29 02:01:03 -05:00
|
|
|
bool show_fallout = false);
|
2016-10-05 03:32:55 -05:00
|
|
|
|
2021-04-29 02:01:03 -05:00
|
|
|
void operator()(const fs::path& file);
|
2016-10-05 03:32:55 -05:00
|
|
|
|
|
|
|
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.
|
2021-04-29 02:01:03 -05:00
|
|
|
void appendFile(std::ofstream& of, const fs::path& file, const std::string& rank);
|
2016-10-05 03:32:55 -05:00
|
|
|
|
2018-06-25 15:22:29 -05:00
|
|
|
/// \brief Regex to capture *.DBG
|
2019-09-18 07:55:04 -05:00
|
|
|
std::regex debugFileRegex_;
|
2016-10-05 03:32:55 -05:00
|
|
|
/// \brief Regex to capture *.PRT
|
2019-09-18 07:55:04 -05:00
|
|
|
std::regex logFileRegex_;
|
2018-09-05 09:03:51 -05:00
|
|
|
/// \brief Regex to capture CASENAME.[0-9]+.[A-Z]+
|
2019-09-18 07:55:04 -05:00
|
|
|
std::regex fileWarningRegex_;
|
2018-06-25 15:22:29 -05:00
|
|
|
/// \brief Stream to *.DBG file
|
2020-02-18 01:54:20 -06:00
|
|
|
std::unique_ptr<std::ofstream> debugStream_;
|
2016-10-05 03:32:55 -05:00
|
|
|
/// \brief Stream to *.PRT file
|
2020-02-18 01:54:20 -06:00
|
|
|
std::unique_ptr<std::ofstream> logStream_;
|
2019-01-14 06:06:21 -06:00
|
|
|
/// \brief Whether to show any logging fallout
|
|
|
|
bool show_fallout_;
|
2016-10-05 03:32:55 -05:00
|
|
|
};
|
|
|
|
} // end namespace detail
|
2021-04-29 02:01:03 -05:00
|
|
|
} // end namespace Opm
|
2016-10-05 03:32:55 -05:00
|
|
|
#endif // end header guard
|