WarpX
Loading...
Searching...
No Matches
WarnManager.H
Go to the documentation of this file.
1/* Copyright 2022 Luca Fedeli
2 *
3 * This file is part of WarpX.
4 *
5 * License: BSD-3-Clause-LBNL
6 */
7
8#ifndef ABLASTR_WARN_MANAGER_H_
9#define ABLASTR_WARN_MANAGER_H_
10
12
13#include <AMReX_BaseFwd.H>
14
15#include <memory>
16#include <optional>
17#include <string>
18
20{
21
26 enum class WarnPriority
27 {
41 };
42
49 {
50 public:
51
55 WarnManager( const WarnManager& ) = delete;
56
60 WarnManager( WarnManager&& ) = delete;
61
65 WarnManager& operator=( const WarnManager & ) = delete;
66
70 WarnManager& operator=( const WarnManager&& ) = delete;
71
75 ~WarnManager() = default;
76
77 static WarnManager& GetInstance();
78
86 void RecordWarning(
87 const std::string& topic,
88 const std::string& text,
89 const WarnPriority& priority = WarnPriority::medium);
90
98 [[nodiscard]] std::string PrintLocalWarnings(
99 const std::string& when) const;
100
108 [[nodiscard]] std::string PrintGlobalWarnings(
109 const std::string& when) const;
110
116 void SetAlwaysWarnImmediately(bool always_warn_immediately);
117
123 [[nodiscard]] bool GetAlwaysWarnImmediatelyFlag() const;
124
131 void SetAbortThreshold(std::optional<WarnPriority> abort_threshold);
132
138 [[nodiscard]] std::optional<WarnPriority> GetAbortThreshold() const;
139
147
148 static const int warn_line_size = 80 ;
149 static const int warn_tab_size = 5 ;
150
151 private:
152
156 WarnManager();
157
166 [[nodiscard]] std::string PrintWarnMsg(
167 const ablastr::utils::msg_logger::MsgWithCounter& msg_with_counter) const;
168
177 [[nodiscard]] std::string PrintWarnMsg(
178 const ablastr::utils::msg_logger::MsgWithCounterAndRanks& msg_with_counter_and_ranks) const;
179
188 static std::string GetHeader(
189 const std::string& when,
190 int line_size,
191 bool is_global);
192
201 static std::string MsgFormatter(
202 const std::string& msg,
203 int line_size,
204 int tab_size);
205
206 int m_rank = 0 ;
207 std::unique_ptr<ablastr::utils::msg_logger::Logger> m_p_logger ;
209 std::optional<WarnPriority> m_abort_on_warning_threshold = std::nullopt ;
210 };
211
218
227 void WMRecordWarning(
228 const std::string& topic,
229 const std::string& text,
230 const WarnPriority& priority = WarnPriority::medium);
231}
232
233#endif //ABLASTR_WARN_MANAGER_H_
Definition WarnManager.H:49
std::string PrintWarnMsg(const ablastr::utils::msg_logger::MsgWithCounter &msg_with_counter) const
This function generates a string for a single entry of the warning list for a MessageWithCounter stru...
Definition WarnManager.cpp:221
static std::string GetHeader(const std::string &when, int line_size, bool is_global)
This function generates the header of the warning messages list.
Definition WarnManager.cpp:271
void SetAlwaysWarnImmediately(bool always_warn_immediately)
Setter for the m_always_warn_immediately.
Definition WarnManager.cpp:165
std::unique_ptr< ablastr::utils::msg_logger::Logger > m_p_logger
Definition WarnManager.H:207
std::string PrintLocalWarnings(const std::string &when) const
This function prints all the warning messages collected on the present MPI rank (i....
Definition WarnManager.cpp:108
WarnManager(const WarnManager &)=delete
bool GetAlwaysWarnImmediatelyFlag() const
Getter for the m_always_warn_immediately.
Definition WarnManager.cpp:170
static const int warn_tab_size
Definition WarnManager.H:149
void debug_read_warnings_from_input(const amrex::ParmParse &params)
This function reads warning messages from the inputfile. It is intended for debug&testing purposes.
Definition WarnManager.cpp:185
WarnManager & operator=(const WarnManager &)=delete
std::optional< WarnPriority > m_abort_on_warning_threshold
Definition WarnManager.H:209
WarnManager & operator=(const WarnManager &&)=delete
int m_rank
Definition WarnManager.H:206
std::optional< WarnPriority > GetAbortThreshold() const
Getter for the m_abort_on_warning_threshold flag.
Definition WarnManager.cpp:180
WarnManager(WarnManager &&)=delete
static std::string MsgFormatter(const std::string &msg, int line_size, int tab_size)
This function formats each line of a warning message text.
Definition WarnManager.cpp:296
bool m_always_warn_immediately
Definition WarnManager.H:208
void RecordWarning(const std::string &topic, const std::string &text, const WarnPriority &priority=WarnPriority::medium)
This function records a warning message (recording a warning message is thread-safe)
Definition WarnManager.cpp:57
WarnManager()
Definition WarnManager.cpp:52
static WarnManager & GetInstance()
Definition WarnManager.cpp:47
static const int warn_line_size
Definition WarnManager.H:148
void SetAbortThreshold(std::optional< WarnPriority > abort_threshold)
Setter for the m_abort_on_warning_threshold flag (pass std::nullopt in order to never abort)
Definition WarnManager.cpp:175
std::string PrintGlobalWarnings(const std::string &when) const
This function prints all the warning messages collected by all the MPI ranks (i.e....
Definition WarnManager.cpp:133
Definition WarnManager.H:20
void WMRecordWarning(const std::string &topic, const std::string &text, const WarnPriority &priority=WarnPriority::medium)
Helper function to abbreviate the call to WarnManager::GetInstance().RecordWarning (recording a warni...
Definition WarnManager.cpp:320
WarnManager & GetWMInstance()
Helper function to abbreviate the call to get a WarnManager instance.
Definition WarnManager.cpp:315
WarnPriority
Definition WarnManager.H:27
@ medium
Definition WarnManager.H:35
@ low
Definition WarnManager.H:31
@ high
Definition WarnManager.H:40