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 //
4 // Belos: Block Linear Solvers Package
5 // Copyright 2004 Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 //@HEADER
41 
42 #ifndef BELOS_OUTPUT_MANAGER_HPP
43 #define BELOS_OUTPUT_MANAGER_HPP
44 
49 #include "BelosConfigDefs.hpp"
50 #include "BelosTypes.hpp"
51 #include "Teuchos_oblackholestream.hpp"
52 #include "Teuchos_RCP.hpp"
53 
54 #ifdef HAVE_MPI
55 #include <mpi.h>
56 #include "BelosGlobalComm.hpp"
57 #endif
58 
71 namespace Belos {
72 
73  template <class ScalarType>
74  class OutputManager {
75 
76  public:
77 
79 
80 
82  OutputManager( int vb = Belos::Errors, const Teuchos::RCP< std::ostream > &os = Teuchos::rcp(&std::cout,false) );
83 
85  virtual ~OutputManager() {};
87 
89 
90 
92  void setOStream( const Teuchos::RCP<std::ostream> &os ) { myOS_ = os; };
93 
95  void setVerbosity( int vb ) { vb_ = vb; };
96 
98 
100 
101 
103  std::ostream& stream( MsgType type )
104  {
105  if ( (type & vb_) && iPrint_ ) {
106  return *myOS_;
107  }
108  return myBHS_;
109  }
110 
113 
115 
117 
118 
120 
123  bool isVerbosity( MsgType type ) const { return (( type == Belos::Errors ) || ( vb_ & type )); };
124 
126 
128 
129 
131  void print( MsgType type, const std::string output );
132 
134 
135  private:
136 
138 
139 
142 
145 
147 
148  int vb_;
151  bool iPrint_;
152  };
153 
154  template<class ScalarType>
156  vb_(vb),
157  myOS_(os)
158  {
159  int MyPID;
160 #ifdef HAVE_MPI
161  // Initialize MPI
162  int mpiStarted = 0;
163  MPI_Initialized(&mpiStarted);
164  if (mpiStarted) MPI_Comm_rank(Belos::get_global_comm(), &MyPID);
165  else MyPID=0;
166 #else
167  MyPID = 0;
168 #endif
169  iPrint_ = (MyPID == 0);
170  }
171 
172  template<class ScalarType>
173  void OutputManager<ScalarType>::print( MsgType type, const std::string output ) {
174  if ( (type & vb_) && iPrint_ ) {
175  *myOS_ << output;
176  }
177 }
178 
179 } // end Belos namespace
180 
181 #endif
182 
183 // 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:254
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 Wed Apr 24 2024 09:25:57 for Belos by doxygen 1.8.5