Belos Version of the Day
Loading...
Searching...
No Matches
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#endif
57
70namespace Belos {
71
72 template <class ScalarType>
74
75 public:
76
78
79
81 OutputManager( int vb = Belos::Errors, const Teuchos::RCP< std::ostream > &os = Teuchos::rcp(&std::cout,false) );
82
84 virtual ~OutputManager() {};
86
88
89
91 void setOStream( const Teuchos::RCP<std::ostream> &os ) { myOS_ = os; };
92
94 void setVerbosity( int vb ) { vb_ = vb; };
95
97
99
100
102 std::ostream& stream( MsgType type )
103 {
104 if ( (type & vb_) && iPrint_ ) {
105 return *myOS_;
106 }
107 return myBHS_;
108 }
109
111 Teuchos::RCP<std::ostream> getOStream() { return myOS_; };
112
114
116
117
119
122 bool isVerbosity( MsgType type ) const { return (( type == Belos::Errors ) || ( vb_ & type )); };
123
125
127
128
130 void print( MsgType type, const std::string output );
131
133
134 private:
135
137
138
141
144
146
147 int vb_;
148 Teuchos::RCP<std::ostream> myOS_;
149 Teuchos::oblackholestream myBHS_;
150 bool iPrint_;
151 };
152
153 template<class ScalarType>
154 OutputManager<ScalarType>::OutputManager( int vb, const Teuchos::RCP<std::ostream> &os ) :
155 vb_(vb),
156 myOS_(os)
157 {
158 int MyPID;
159#ifdef HAVE_MPI
160 // Initialize MPI
161 int mpiStarted = 0;
162 MPI_Initialized(&mpiStarted);
163 if (mpiStarted) MPI_Comm_rank(MPI_COMM_WORLD, &MyPID);
164 else MyPID=0;
165#else
166 MyPID = 0;
167#endif
168 iPrint_ = (MyPID == 0);
169 }
170
171 template<class ScalarType>
172 void OutputManager<ScalarType>::print( MsgType type, const std::string output ) {
173 if ( (type & vb_) && iPrint_ ) {
174 *myOS_ << output;
175 }
176}
177
178} // end Belos namespace
179
180#endif
181
182// end of file BelosOutputManager.hpp
Belos header file which uses auto-configuration information to include necessary C++ headers.
Collection of types and exceptions used within the Belos solvers.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
void print(MsgType type, const std::string output)
@ name Print methods
void setVerbosity(int vb)
Set the verbosity level for this manager.
void setOStream(const Teuchos::RCP< std::ostream > &os)
Set the output stream for this manager.
Teuchos::RCP< std::ostream > getOStream()
Get the output stream for this manager.
virtual ~OutputManager()
Destructor.
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.
bool isVerbosity(MsgType type) const
Find out whether we need to print out information for this message type.
MsgType
Available message types recognized by the linear solvers.

Generated for Belos by doxygen 1.10.0