Zoltan2
Zoltan2_DebugManager.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Zoltan2: A package of combinatorial algorithms for scientific computing
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Karen Devine (kddevin@sandia.gov)
39 // Erik Boman (egboman@sandia.gov)
40 // Siva Rajamanickam (srajama@sandia.gov)
41 //
42 // ***********************************************************************
43 //
44 // @HEADER
45 
50 #ifndef ZOLTAN2_DEBUGMANAGER_HPP
51 #define ZOLTAN2_DEBUGMANAGER_HPP
52 
53 #include <Zoltan2_Parameters.hpp>
54 #include <string>
55 #include <iostream>
56 #include <fstream>
57 
58 namespace Zoltan2
59 {
82 {
83  public:
84 
95  DebugManager ( int rank, bool doPrinting, std::ofstream &debugOs,
96  MessageOutputLevel debugLevel) : myPID_(rank), debugLevel_(debugLevel),
97  myOS_(static_cast<std::ostream *>(&debugOs)), fileOS_(&debugOs),
98  iPrint_(doPrinting) {}
99 
107  DebugManager ( int rank, bool doPrinting, std::ostream &debugOs,
108  MessageOutputLevel debugLevel) : myPID_(rank), debugLevel_(debugLevel),
109  myOS_(&debugOs), fileOS_(NULL), iPrint_(doPrinting) {}
110 
113  virtual ~DebugManager()
114  {
115  myOS_->flush();
116  if (fileOS_)
117  fileOS_->close();
118  }
119 
122  inline std::ostream *getOStream() const { return myOS_; };
123 
126  inline MessageOutputLevel getDebugLevel() const { return debugLevel_; };
127 
136  inline void print(MessageOutputLevel debugLevel, const std::string &output){
137 #ifndef Z2_OMIT_ALL_STATUS_MESSAGES
138  if (debugLevel <= debugLevel_ && iPrint_)
139  *myOS_ << myPID_ << ": " << output << std::endl;
140 #endif
141  }
142 
152  inline void printInAllTasks(MessageOutputLevel debugLevel, const std::string &output){
153 #ifndef Z2_OMIT_ALL_STATUS_MESSAGES
154  if (debugLevel <= debugLevel_)
155  *myOS_ << myPID_ << ": " << output << std::endl;
156 #endif
157  }
158 
167  inline void print(MessageOutputLevel debugLevel, const char *output){
168 #ifndef Z2_OMIT_ALL_STATUS_MESSAGES
169  if (debugLevel <= debugLevel_ && iPrint_)
170  *myOS_ << myPID_ << ": " << output << std::endl;
171 #endif
172  }
173 
182  inline void printInAllTasks(MessageOutputLevel debugLevel, const char *output) {
183 #ifndef Z2_OMIT_ALL_STATUS_MESSAGES
184  if (debugLevel <= debugLevel_)
185  *myOS_ << "PID =" << myPID_ << " " << output << std::endl;
186 #endif
187  }
188 
189  private:
190 
191  int myPID_;
192  MessageOutputLevel debugLevel_;
193  std::ostream *myOS_;
194  std::ofstream *fileOS_;
195  bool iPrint_;
196 };
197 
198 } //namespace Zoltan2
199 
200 #endif
Zoltan2::DebugManager::print
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.
Definition: Zoltan2_DebugManager.hpp:136
Zoltan2::DebugManager::DebugManager
DebugManager(int rank, bool doPrinting, std::ofstream &debugOs, MessageOutputLevel debugLevel)
Constructor for output to an ofstream.
Definition: Zoltan2_DebugManager.hpp:95
Zoltan2::DebugManager::getDebugLevel
MessageOutputLevel getDebugLevel() const
Return the highest level of message that will be printed.
Definition: Zoltan2_DebugManager.hpp:126
Zoltan2::DebugManager::printInAllTasks
void printInAllTasks(MessageOutputLevel debugLevel, const char *output)
The const char * versions of print functions are needed to avoid the expensive conversion to string.
Definition: Zoltan2_DebugManager.hpp:182
Zoltan2::DebugManager::print
void print(MessageOutputLevel debugLevel, const char *output)
The const char * versions of print functions are needed to avoid the expensive conversion to string.
Definition: Zoltan2_DebugManager.hpp:167
Zoltan2::DebugManager
DebugManager contains the methods that perform output of debug and status messages.
Definition: Zoltan2_DebugManager.hpp:81
Zoltan2::DebugManager::~DebugManager
virtual ~DebugManager()
Destructor.
Definition: Zoltan2_DebugManager.hpp:113
Zoltan2::DebugManager::printInAllTasks
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...
Definition: Zoltan2_DebugManager.hpp:152
Zoltan2::DebugManager::getOStream
std::ostream * getOStream() const
Return the output stream for debug/status messages.
Definition: Zoltan2_DebugManager.hpp:122
Zoltan2::MessageOutputLevel
MessageOutputLevel
The amount of debugging or status output to print.
Definition: Zoltan2_Parameters.hpp:98
Zoltan2::DebugManager::DebugManager
DebugManager(int rank, bool doPrinting, std::ostream &debugOs, MessageOutputLevel debugLevel)
Constructor for output to an iostream.
Definition: Zoltan2_DebugManager.hpp:107
Zoltan2
Definition: Zoltan2_AlgSerialGreedy.hpp:56
Zoltan2_Parameters.hpp
Defines Parameter related enumerators, declares functions.