Anasazi  Version of the Day
AnasaziBasicOutputManager.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Anasazi: Block Eigensolvers Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
25 //
26 // ***********************************************************************
27 // @HEADER
28 
29 #ifndef ANASAZI_BASIC_OUTPUT_MANAGER_HPP
30 #define ANASAZI_BASIC_OUTPUT_MANAGER_HPP
31 
36 #include "AnasaziConfigDefs.hpp"
37 #include "AnasaziOutputManager.hpp"
38 #include "Teuchos_oblackholestream.hpp"
39 
40 #ifdef HAVE_MPI
41 #include <mpi.h>
42 #endif
43 
52 namespace Anasazi {
53 
54  using std::ostream;
55 
56  template <class ScalarType>
57  class BasicOutputManager : public OutputManager<ScalarType> {
58 
59  public:
60 
62 
63 
66  Teuchos::RCP<ostream> os = Teuchos::rcpFromRef(std::cout),
67  int printingRank = 0);
68 
70  virtual ~BasicOutputManager() {};
72 
74 
75 
77  void setOStream( Teuchos::RCP<ostream> os );
78 
80  Teuchos::RCP<ostream> getOStream();
81 
83 
85 
86 
88 
91  bool isVerbosity( MsgType type ) const;
92 
94  void print( MsgType type, const std::string output );
95 
97  ostream &stream( MsgType type );
98 
100 
101  private:
102 
104 
105 
108 
111 
113 
114  Teuchos::RCP<ostream> myOS_;
115  Teuchos::oblackholestream myBHS_;
116  bool iPrint_;
117  };
118 
119  template<class ScalarType>
120  BasicOutputManager<ScalarType>::BasicOutputManager(int vb, Teuchos::RCP<ostream> os, int printingRank)
121  : OutputManager<ScalarType>(vb), myOS_(os) {
122  // print only on proc 0
123  int MyPID;
124 #ifdef HAVE_MPI
125  // Initialize MPI
126  int mpiStarted = 0;
127  MPI_Initialized(&mpiStarted);
128  if (mpiStarted) MPI_Comm_rank(MPI_COMM_WORLD, &MyPID);
129  else MyPID=0;
130 #else
131  MyPID = 0;
132 #endif
133  iPrint_ = (MyPID == printingRank);
134  }
135 
136  template<class ScalarType>
137  void BasicOutputManager<ScalarType>::setOStream( Teuchos::RCP<ostream> os ) {
138  myOS_ = os;
139  }
140 
141  template<class ScalarType>
143  return myOS_;
144  }
145 
146  template<class ScalarType>
148  if ( (type & this->vb_) == type ) {
149  return true;
150  }
151  return false;
152  }
153 
154  template<class ScalarType>
155  void BasicOutputManager<ScalarType>::print( MsgType type, const std::string output ) {
156  if ( (type & this->vb_) == type && iPrint_ ) {
157  *myOS_ << output;
158  }
159  }
160 
161  template<class ScalarType>
163  if ( (type & this->vb_) == type && iPrint_ ) {
164  return *myOS_;
165  }
166  return myBHS_;
167  }
168 
169 } // end Anasazi namespace
170 
171 #endif
172 
173 // end of file AnasaziOutputManager.hpp
void print(MsgType type, const std::string output)
Send some output to this output stream.
ostream & stream(MsgType type)
Return a stream for outputting to.
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package...
Abstract class definition for Anasazi Output Managers.
Anasazi&#39;s basic output manager for sending information of select verbosity levels to the appropriate ...
Output managers remove the need for the eigensolver to know any information about the required output...
bool isVerbosity(MsgType type) const
Find out whether we need to print out information for this message type.
Anasazi header file which uses auto-configuration information to include necessary C++ headers...
Teuchos::RCP< ostream > getOStream()
Get the output stream for this manager.
BasicOutputManager(int vb=Anasazi::Errors, Teuchos::RCP< ostream > os=Teuchos::rcpFromRef(std::cout), int printingRank=0)
Default constructor.
MsgType
Enumerated list of available message types recognized by the eigensolvers.
void setOStream(Teuchos::RCP< ostream > os)
Set the output stream for this manager.