diff options
Diffstat (limited to 'Source/Utils')
-rw-r--r-- | Source/Utils/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Source/Utils/MPIInitHelpers.cpp | 8 | ||||
-rw-r--r-- | Source/Utils/Make.package | 1 | ||||
-rw-r--r-- | Source/Utils/WarnManager.H | 135 | ||||
-rw-r--r-- | Source/Utils/WarnManager.cpp | 217 | ||||
-rw-r--r-- | Source/Utils/WarnManager_fwd.H | 16 |
6 files changed, 5 insertions, 373 deletions
diff --git a/Source/Utils/CMakeLists.txt b/Source/Utils/CMakeLists.txt index 4121ee84a..b2754cdaf 100644 --- a/Source/Utils/CMakeLists.txt +++ b/Source/Utils/CMakeLists.txt @@ -7,7 +7,6 @@ target_sources(WarpX MPIInitHelpers.cpp ParticleUtils.cpp RelativeCellPosition.cpp - WarnManager.cpp WarpXAlgorithmSelection.cpp WarpXMovingWindow.cpp WarpXTagging.cpp diff --git a/Source/Utils/MPIInitHelpers.cpp b/Source/Utils/MPIInitHelpers.cpp index 4dc5b9ae8..374165296 100644 --- a/Source/Utils/MPIInitHelpers.cpp +++ b/Source/Utils/MPIInitHelpers.cpp @@ -6,7 +6,7 @@ */ #include "MPIInitHelpers.H" -#include "WarpX.H" +#include <ablastr/warn_manager/WarnManager.H> #include <AMReX_Config.H> #include <AMReX_ParallelDescriptor.H> @@ -66,14 +66,16 @@ namespace utils << mtn(thread_provided) << ") is LOWER than requested " << mtn(thread_required) << "). This might lead to undefined " << "results in asynchronous operations (e.g. async_io)."; - WarpX::GetInstance().RecordWarning("MPI", ss.str(), WarnPriority::high); + ablastr::warn_manager::WMRecordWarning( + "MPI", ss.str(), ablastr::warn_manager::WarnPriority::high); } if( thread_provided > thread_required ){ ss << "NOTE: Provided MPI thread safety level (" << mtn(thread_provided) << ") is stricter than requested " << mtn(thread_required) << "). This might reduce multi-node " << "communication performance."; - WarpX::GetInstance().RecordWarning("MPI", ss.str()); + ablastr::warn_manager::WMRecordWarning( + "MPI", ss.str()); } #endif } diff --git a/Source/Utils/Make.package b/Source/Utils/Make.package index bdd4b61b9..c37715083 100644 --- a/Source/Utils/Make.package +++ b/Source/Utils/Make.package @@ -8,7 +8,6 @@ CEXE_sources += CoarsenMR.cpp CEXE_sources += Interpolate.cpp CEXE_sources += IntervalsParser.cpp CEXE_sources += MPIInitHelpers.cpp -CEXE_sources += WarnManager.cpp CEXE_sources += RelativeCellPosition.cpp CEXE_sources += ParticleUtils.cpp diff --git a/Source/Utils/WarnManager.H b/Source/Utils/WarnManager.H deleted file mode 100644 index 243a00ace..000000000 --- a/Source/Utils/WarnManager.H +++ /dev/null @@ -1,135 +0,0 @@ -/* Copyright 2021 Luca Fedeli - * - * This file is part of WarpX. - * - * License: BSD-3-Clause-LBNL - */ - -#ifndef WARPX_WARN_MANAGER_H_ -#define WARPX_WARN_MANAGER_H_ - -#include "WarnManager_fwd.H" - -#include <ablastr/utils/msg_logger/MsgLogger_fwd.H> - -#include <AMReX_ParmParse.H> - -#include <memory> -#include <string> -#include <vector> - -namespace Utils -{ - /** - * The class WarnManager manages warning messages in WarpX, - * providing methods to record warnings, and print warning - * lists. - */ - class WarnManager - { - public: - - /** - * The constructor. - */ - WarnManager(); - - /** - * \brief This function records a warning message. - * - * @param[in] topic a string to identify the topic of the warning (e.g., "parallelization", "pbc", "particles"...) - * @param[in] text the text of the warning message - * @param[in] priority priority of the warning message ("medium" by default) - */ - void record_warning( - std::string topic, - std::string text, - ablastr::utils::msg_logger::Priority priority); - - /** - * \brief This function prints all the warning messages collected on the present MPI rank - * (i.e., this is not a collective call). This function is mainly intended for debug purposes. - * - * @param[in] when a string to mark when the warnings are printed out (it appears in the warning list) - * @return a string containing the "local" warning list - */ - std::string print_local_warnings( - const std::string& when) const; - - /** - * \brief This function prints all the warning messages collected by all the MPI ranks - * (i.e., this is a collective call). Only the I/O rank prints the message. - * - * @param[in] when a string to mark when the warnings are printed out (it appears in the warning list) - * @return a string containing the "global" warning list - */ - std::string print_global_warnings( - const std::string& when) const; - - /** - * \brief This function reads warning messages from the inputfile. It is intended for - * debug&testing purposes - * - * @param[in, out] params the inputfile parser - */ - void debug_read_warnings_from_input(amrex::ParmParse& params); - - static const int warn_line_size = 80 /*! Maximum line length to be used in formatting warning list*/; - static const int warn_tab_size = 5 /*! Tabulation size to be used in formatting warning list*/; - - private: - - /** - * \brief This function generates a string for a single entry of the warning list - * for a MessageWithCounter struct (i.e., a warning message paired with a counter storing - * how many times the warning has been raised) - * - * @param[in] msg_with_counter a MessageWithCounter - * @return a string containing the warning message - */ - std::string print_warn_msg( - const ablastr::utils::msg_logger::MsgWithCounter& msg_with_counter) const; - - /** - * \brief This function generates a string for a single entry of the warning list - * for a MsgWithCounterAndRanks struct (i.e., a warning message paired with a counter storing - * how many times the warning has been raised and info on which ranks have raised the warning) - * - * @param[in] msg_with_counter_and_ranks a MsgWithCounterAndRanks - * @return a string containing the warning message - */ - std::string print_warn_msg( - const ablastr::utils::msg_logger::MsgWithCounterAndRanks& msg_with_counter_and_ranks) const; - - /** - * \brief This function generates the header of the warning messages list - * - * @param[in] when a string to mark when the warnings are printed out (it appears in the warning list) - * @param[in] line_size maximum line length to be used in formatting warning list - * @param[in] is_global flag: true if the header is for a global warning list, false otherwise - * @return a string containing the header of the warning list - */ - static std::string get_header( - const std::string& when, - const int line_size, - const bool is_global); - - /** - * \brief This function formats each line of a warning message text - * - * @param[in] msg the warning message text - * @param[in] line_size maximum line length to be used in formatting warning list - * @param[in] tab_size tabulation size to be used in formatting warning list - * @return a string containing the formatted warning message text - */ - static std::string msg_formatter( - const std::string& msg, - const int line_size, - const int tab_size); - - int m_rank = 0 /*! MPI rank (appears in the warning list)*/; - std::unique_ptr<ablastr::utils::msg_logger::Logger> m_p_logger /*! The Logger stores all the warning messages*/; - }; -} - -#endif //WARPX_WARN_MANAGER_H_ diff --git a/Source/Utils/WarnManager.cpp b/Source/Utils/WarnManager.cpp deleted file mode 100644 index 18f065ab7..000000000 --- a/Source/Utils/WarnManager.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/* Copyright 2021 Luca Fedeli - * - * This file is part of WarpX. - * - * License: BSD-3-Clause-LBNL - */ - -#include "WarnManager.H" - -#include "WarpXUtil.H" - -#include <ablastr/utils/TextMsg.H> -#include <ablastr/utils/msg_logger/MsgLogger.H> - -#include <AMReX_ParallelDescriptor.H> - -#include <algorithm> -#include <sstream> - -using namespace Utils; - -namespace abl_msg_logger = ablastr::utils::msg_logger; - -WarnManager::WarnManager(): - m_rank{amrex::ParallelDescriptor::MyProc()}, - m_p_logger{std::make_unique<abl_msg_logger::Logger>()} -{} - -void WarnManager::record_warning( - std::string topic, - std::string text, - abl_msg_logger::Priority priority) -{ - m_p_logger->record_msg(abl_msg_logger::Msg{topic, text, priority}); -} - -std::string WarnManager::print_local_warnings(const std::string& when) const -{ - auto all_warnings = m_p_logger->get_msgs_with_counter(); - std::sort(all_warnings.begin(), all_warnings.end(), - [](const auto& a, const auto& b){return a.msg < b.msg;}); - - std::stringstream ss; - - ss << "\n" << WarnManager::get_header(when, warn_line_size, false); - - if(all_warnings.empty()){ - ss << "* No recorded warnings.\n"; - } - else{ - for(const auto& warn_msg : all_warnings){ - ss << print_warn_msg(warn_msg); - ss << "*\n"; - } - } - - ss << std::string(warn_line_size, '*') << "\n\n" ; - - return ss.str(); -} - -std::string WarnManager::print_global_warnings(const std::string& when) const -{ - auto all_warnings = - m_p_logger->collective_gather_msgs_with_counter_and_ranks(); - - if(m_rank != amrex::ParallelDescriptor::IOProcessorNumber()) - return "[see I/O rank message]"; - - std::sort(all_warnings.begin(), all_warnings.end(), - [](const auto& a, const auto& b){ - return a.msg_with_counter.msg < b.msg_with_counter.msg;}); - - std::stringstream ss; - - ss << "\n" << WarnManager::get_header(when, warn_line_size, true); - - if(all_warnings.empty()){ - ss << "* No recorded warnings.\n"; - } - else{ - for(const auto& warn_msg : all_warnings){ - ss << print_warn_msg(warn_msg); - ss << "*\n"; - } - } - - ss << std::string(warn_line_size, '*') << "\n\n" ; - - return ss.str(); -} - -void WarnManager::debug_read_warnings_from_input(amrex::ParmParse& params) -{ - std::vector<std::string> warnings; - params.queryarr("test_warnings", warnings); - - for (const auto& warn : warnings){ - amrex::ParmParse pp_warn(warn); - - std::string topic; - pp_warn.query("topic", topic); - - std::string msg; - pp_warn.query("msg", msg); - - std::string spriority; - pp_warn.query("priority", spriority); - abl_msg_logger::Priority priority = - abl_msg_logger::StringToPriority(spriority); - - int all_involved = 0; - pp_warn.query("all_involved", all_involved); - if(all_involved != 0){ - this->record_warning(topic, msg, priority); - } - else{ - std::vector<int> who_involved; - pp_warn.queryarr("who_involved", who_involved); - if(std::find (who_involved.begin(), who_involved.end(), m_rank) - != who_involved.end()){ - this->record_warning(topic, msg, priority); - } - } - } - -} - -std::string WarnManager::print_warn_msg( - const abl_msg_logger::MsgWithCounter& msg_with_counter) const -{ - std::stringstream ss; - ss << "* --> "; - if (msg_with_counter.msg.priority == abl_msg_logger::Priority::high) - ss << "[!!!]"; - else if (msg_with_counter.msg.priority == abl_msg_logger::Priority::medium) - ss << "[!! ]"; - else if (msg_with_counter.msg.priority == abl_msg_logger::Priority::low) - ss << "[! ]"; - else - ss << "[???]"; - - ss << " [" + msg_with_counter.msg.topic << "] "; - - if(msg_with_counter.counter == 2) - ss << "[raised twice]\n"; - else if(msg_with_counter.counter == 1) - ss << "[raised once]\n"; - else - ss << "[raised " << msg_with_counter.counter << " times]\n"; - - ss << msg_formatter(msg_with_counter.msg.text, warn_line_size, warn_tab_size); - - return ss.str(); -} - -std::string WarnManager::print_warn_msg( - const abl_msg_logger::MsgWithCounterAndRanks& msg_with_counter_and_ranks) const -{ - std::stringstream ss; - ss << this->print_warn_msg(msg_with_counter_and_ranks.msg_with_counter); - - std::string raised_by = "@ Raised by: "; - if (!msg_with_counter_and_ranks.all_ranks){ - for (const auto rr : msg_with_counter_and_ranks.ranks) - raised_by += " " + std::to_string(rr); - } - else{ - raised_by += "ALL\n"; - } - ss << WarnManager::msg_formatter(raised_by, warn_line_size, warn_tab_size); - - return ss.str(); -} - -std::string WarnManager::get_header( - const std::string& when, - const int line_size, - const bool is_global) -{ - const std::string warn_header{"**** WARNINGS "}; - - std::stringstream ss; - - ss << warn_header << - std::string(line_size - static_cast<int>(warn_header.length()), '*') << "\n" ; - - if(is_global){ - ss << "* GLOBAL warning list after " << " [ " << when << " ]\n*\n"; - } - else{ - auto const mpi_rank = amrex::ParallelDescriptor::MyProc(); - ss << "* LOCAL" << " ( rank # " << mpi_rank << " ) " - << " warning list after " << when << "\n*\n"; - } - - return ss.str(); -} - -std::string -WarnManager::msg_formatter( - const std::string& msg, - const int line_size, - const int tab_size) -{ - const auto prefix = "*" + std::string(tab_size, ' '); - const auto prefix_length = static_cast<int>(prefix.length()); - - const auto wrapped_text = ablastr::utils::automatic_text_wrap( - msg, line_size-prefix_length); - - std::stringstream ss_out; - for (const auto& line : wrapped_text) - ss_out << prefix << line << "\n"; - - return ss_out.str(); -} diff --git a/Source/Utils/WarnManager_fwd.H b/Source/Utils/WarnManager_fwd.H deleted file mode 100644 index e12cf7910..000000000 --- a/Source/Utils/WarnManager_fwd.H +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright 2021 Luca Fedeli - * - * This file is part of WarpX. - * - * License: BSD-3-Clause-LBNL - */ - -#ifndef WARPX_WARN_MANAGER_FWD_H -#define WARPX_WARN_MANAGER_FWD_H - -namespace Utils -{ - class WarnManager; -} - -#endif //WARPX_WARN_MANAGER_FWD_H |