Belos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BelosOutputManager.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Belos: Block Linear Solvers Package
4 //
5 // Copyright 2004-2016 NTESS and the Belos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef BELOS_OUTPUT_MANAGER_HPP
11 #define BELOS_OUTPUT_MANAGER_HPP
12 
17 #include "BelosConfigDefs.hpp"
18 #include "BelosTypes.hpp"
19 #include "Teuchos_oblackholestream.hpp"
20 #include "Teuchos_RCP.hpp"
21 
22 #ifdef HAVE_MPI
23 #include <mpi.h>
24 #include "BelosGlobalComm.hpp"
25 #endif
26 
39 namespace Belos {
40 
41  template <class ScalarType>
42  class OutputManager {
43 
44  public:
45 
47 
48 
50  OutputManager( int vb = Belos::Errors, const Teuchos::RCP< std::ostream > &os = Teuchos::rcp(&std::cout,false) );
51 
53  virtual ~OutputManager() {};
55 
57 
58 
60  void setOStream( const Teuchos::RCP<std::ostream> &os ) { myOS_ = os; };
61 
63  void setVerbosity( int vb ) { vb_ = vb; };
64 
66 
68 
69 
71  std::ostream& stream( MsgType type )
72  {
73  if ( (type & vb_) && iPrint_ ) {
74  return *myOS_;
75  }
76  return myBHS_;
77  }
78 
81 
83 
85 
86 
88 
91  bool isVerbosity( MsgType type ) const { return (( type == Belos::Errors ) || ( vb_ & type )); };
92 
94 
96 
97 
99  void print( MsgType type, const std::string output );
100 
102 
103  private:
104 
106 
107 
110 
113 
115 
116  int vb_;
119  bool iPrint_;
120  };
121 
122  template<class ScalarType>
124  vb_(vb),
125  myOS_(os)
126  {
127  int MyPID;
128 #ifdef HAVE_MPI
129  // Initialize MPI
130  int mpiStarted = 0;
131  MPI_Initialized(&mpiStarted);
132  if (mpiStarted) MPI_Comm_rank(Belos::get_global_comm(), &MyPID);
133  else MyPID=0;
134 #else
135  MyPID = 0;
136 #endif
137  iPrint_ = (MyPID == 0);
138  }
139 
140  template<class ScalarType>
141  void OutputManager<ScalarType>::print( MsgType type, const std::string output ) {
142  if ( (type & vb_) && iPrint_ ) {
143  *myOS_ << output;
144  }
145 }
146 
147 } // end Belos namespace
148 
149 #endif
150 
151 // end of file BelosOutputManager.hpp
Collection of types and exceptions used within the Belos solvers.
Belos&#39;s basic output manager for sending information of select verbosity levels to the appropriate ou...
void setVerbosity(int vb)
Set the verbosity level for this manager.
MsgType
Available message types recognized by the linear solvers.
Definition: BelosTypes.hpp:222
std::ostream & stream(MsgType type)
Get an output stream for outputting the input message type.
OutputManager(int vb=Belos::Errors, const Teuchos::RCP< std::ostream > &os=Teuchos::rcp(&std::cout, false))
Basic constructor.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool isVerbosity(MsgType type) const
Find out whether we need to print out information for this message type.
void print(MsgType type, const std::string output)
@ name Print methods
Belos header file which uses auto-configuration information to include necessary C++ headers...
virtual ~OutputManager()
Destructor.
Teuchos::RCP< std::ostream > getOStream()
Get the output stream for this manager.
void setOStream(const Teuchos::RCP< std::ostream > &os)
Set the output stream for this manager.

Generated on Fri Nov 1 2024 09:23:45 for Belos by doxygen 1.8.5