Zoltan2
Loading...
Searching...
No Matches
Zoltan2_DebugManager.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Zoltan2: A package of combinatorial algorithms for scientific computing
4//
5// Copyright 2012 NTESS and the Zoltan2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
14#ifndef ZOLTAN2_DEBUGMANAGER_HPP
15#define ZOLTAN2_DEBUGMANAGER_HPP
16
18#include <string>
19#include <iostream>
20#include <fstream>
21
22namespace Zoltan2
23{
44
46{
47 public:
48
59 DebugManager ( int rank, bool doPrinting, std::ofstream &debugOs,
60 MessageOutputLevel debugLevel, bool ownsFileOS = false) : myPID_(rank), debugLevel_(debugLevel),
61 myOS_(static_cast<std::ostream *>(&debugOs)), fileOS_(&debugOs),
62 iPrint_(doPrinting), ownsFileOS_(ownsFileOS) {}
63
71 DebugManager ( int rank, bool doPrinting, std::ostream &debugOs,
72 MessageOutputLevel debugLevel) : myPID_(rank), debugLevel_(debugLevel),
73 myOS_(&debugOs), fileOS_(NULL), iPrint_(doPrinting), ownsFileOS_(false) {}
74
77 virtual ~DebugManager()
78 {
79 myOS_->flush();
80 if (fileOS_) {
81 fileOS_->close();
82 if (ownsFileOS_)
83 delete fileOS_;
84 }
85 }
86
89 inline std::ostream *getOStream() const { return myOS_; };
90
93 inline MessageOutputLevel getDebugLevel() const { return debugLevel_; };
94
103 inline void print(MessageOutputLevel debugLevel, const std::string &output){
104#ifndef Z2_OMIT_ALL_STATUS_MESSAGES
105 if (debugLevel <= debugLevel_ && iPrint_)
106 *myOS_ << myPID_ << ": " << output << std::endl;
107#endif
108 }
109
119 inline void printInAllTasks(MessageOutputLevel debugLevel, const std::string &output){
120#ifndef Z2_OMIT_ALL_STATUS_MESSAGES
121 if (debugLevel <= debugLevel_)
122 *myOS_ << myPID_ << ": " << output << std::endl;
123#endif
124 }
125
134 inline void print(MessageOutputLevel debugLevel, const char *output){
135#ifndef Z2_OMIT_ALL_STATUS_MESSAGES
136 if (debugLevel <= debugLevel_ && iPrint_)
137 *myOS_ << myPID_ << ": " << output << std::endl;
138#endif
139 }
140
149 inline void printInAllTasks(MessageOutputLevel debugLevel, const char *output) {
150#ifndef Z2_OMIT_ALL_STATUS_MESSAGES
151 if (debugLevel <= debugLevel_)
152 *myOS_ << "PID =" << myPID_ << " " << output << std::endl;
153#endif
154 }
155
156 private:
157
158 int myPID_;
159 MessageOutputLevel debugLevel_;
160 std::ostream *myOS_;
161 std::ofstream *fileOS_;
162 bool iPrint_;
163 bool ownsFileOS_;
164};
165
166} //namespace Zoltan2
167
168#endif
Defines Parameter related enumerators, declares functions.
DebugManager(int rank, bool doPrinting, std::ofstream &debugOs, MessageOutputLevel debugLevel, bool ownsFileOS=false)
Constructor for output to an ofstream.
void print(MessageOutputLevel debugLevel, const std::string &output)
Print a debug or status message, if this process is one of those that is supposed to be doing output.
DebugManager(int rank, bool doPrinting, std::ofstream &debugOs, MessageOutputLevel debugLevel, bool ownsFileOS=false)
Constructor for output to an ofstream.
virtual ~DebugManager()
Destructor.
void printInAllTasks(MessageOutputLevel debugLevel, const std::string &output)
Print a debug or status message regardless of whether this process is one of those that is supposed t...
MessageOutputLevel getDebugLevel() const
Return the highest level of message that will be printed.
void print(MessageOutputLevel debugLevel, const char *output)
The const char * versions of print functions are needed to avoid the expensive conversion to string.
std::ostream * getOStream() const
Return the output stream for debug/status messages.
DebugManager(int rank, bool doPrinting, std::ostream &debugOs, MessageOutputLevel debugLevel)
Constructor for output to an iostream.
void printInAllTasks(MessageOutputLevel debugLevel, const char *output)
The const char * versions of print functions are needed to avoid the expensive conversion to string.
Created by mbenlioglu on Aug 31, 2020.
MessageOutputLevel
The amount of debugging or status output to print.