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 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 ANASAZI_BASIC_OUTPUT_MANAGER_HPP
43 #define ANASAZI_BASIC_OUTPUT_MANAGER_HPP
44 
49 #include "AnasaziConfigDefs.hpp"
50 #include "AnasaziOutputManager.hpp"
51 #include "Teuchos_oblackholestream.hpp"
52 
53 #ifdef HAVE_MPI
54 #include <mpi.h>
55 #endif
56 
65 namespace Anasazi {
66 
67  using std::ostream;
68 
69  template <class ScalarType>
70  class BasicOutputManager : public OutputManager<ScalarType> {
71 
72  public:
73 
75 
76 
79  Teuchos::RCP<ostream> os = Teuchos::rcpFromRef(std::cout),
80  int printingRank = 0);
81 
83  virtual ~BasicOutputManager() {};
85 
87 
88 
90  void setOStream( Teuchos::RCP<ostream> os );
91 
93  Teuchos::RCP<ostream> getOStream();
94 
96 
98 
99 
101 
104  bool isVerbosity( MsgType type ) const;
105 
107  void print( MsgType type, const std::string output );
108 
110  ostream &stream( MsgType type );
111 
113 
114  private:
115 
117 
118 
121 
124 
126 
127  Teuchos::RCP<ostream> myOS_;
128  Teuchos::oblackholestream myBHS_;
129  bool iPrint_;
130  };
131 
132  template<class ScalarType>
133  BasicOutputManager<ScalarType>::BasicOutputManager(int vb, Teuchos::RCP<ostream> os, int printingRank)
134  : OutputManager<ScalarType>(vb), myOS_(os) {
135  // print only on proc 0
136  int MyPID;
137 #ifdef HAVE_MPI
138  // Initialize MPI
139  int mpiStarted = 0;
140  MPI_Initialized(&mpiStarted);
141  if (mpiStarted) MPI_Comm_rank(MPI_COMM_WORLD, &MyPID);
142  else MyPID=0;
143 #else
144  MyPID = 0;
145 #endif
146  iPrint_ = (MyPID == printingRank);
147  }
148 
149  template<class ScalarType>
150  void BasicOutputManager<ScalarType>::setOStream( Teuchos::RCP<ostream> os ) {
151  myOS_ = os;
152  }
153 
154  template<class ScalarType>
156  return myOS_;
157  }
158 
159  template<class ScalarType>
161  if ( (type & this->vb_) == type ) {
162  return true;
163  }
164  return false;
165  }
166 
167  template<class ScalarType>
168  void BasicOutputManager<ScalarType>::print( MsgType type, const std::string output ) {
169  if ( (type & this->vb_) == type && iPrint_ ) {
170  *myOS_ << output;
171  }
172  }
173 
174  template<class ScalarType>
176  if ( (type & this->vb_) == type && iPrint_ ) {
177  return *myOS_;
178  }
179  return myBHS_;
180  }
181 
182 } // end Anasazi namespace
183 
184 #endif
185 
186 // 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.