AnasaziBasicOutputManager.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                 Anasazi: Block Eigensolvers Package
00005 //                 Copyright (2004) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef ANASAZI_BASIC_OUTPUT_MANAGER_HPP
00030 #define ANASAZI_BASIC_OUTPUT_MANAGER_HPP
00031 
00036 #include "AnasaziConfigDefs.hpp"
00037 #include "AnasaziOutputManager.hpp"
00038 #include "Teuchos_oblackholestream.hpp"
00039 
00040 #ifdef HAVE_MPI
00041 #include <mpi.h>
00042 #endif
00043 
00052 namespace Anasazi {
00053 
00054 template <class ScalarType>
00055 class BasicOutputManager : public OutputManager<ScalarType> {
00056 
00057   public:
00058 
00060 
00061 
00063   BasicOutputManager( int vb = Anasazi::Errors, Teuchos::RefCountPtr<ostream> os = Teuchos::rcp(&std::cout,false) );
00064 
00066   virtual ~BasicOutputManager() {};
00068   
00070 
00071 
00073   void setOStream( Teuchos::RefCountPtr<ostream> os );
00074 
00076   Teuchos::RefCountPtr<ostream> getOStream();
00077 
00079 
00081 
00082 
00084 
00087   bool isVerbosity( MsgType type );
00088 
00090   void print( MsgType type, const string output );
00091 
00093   ostream &stream( MsgType type );
00094 
00096 
00097   private:
00098 
00100 
00101 
00103   BasicOutputManager( const OutputManager<ScalarType>& OM );
00104 
00106   BasicOutputManager<ScalarType>& operator=( const OutputManager<ScalarType>& OM );
00107 
00109 
00110   Teuchos::RefCountPtr<ostream> myOS_;
00111   Teuchos::oblackholestream myBHS_;
00112   bool iPrint_;
00113 };
00114 
00115 template<class ScalarType>
00116 BasicOutputManager<ScalarType>::BasicOutputManager(int vb, Teuchos::RefCountPtr<ostream> os)
00117     : OutputManager<ScalarType>(vb), myOS_(os) {
00118   int MyPID;
00119 #ifdef HAVE_MPI
00120   // Initialize MPI
00121   int mpiStarted = 0;
00122   MPI_Initialized(&mpiStarted);
00123   if (mpiStarted) MPI_Comm_rank(MPI_COMM_WORLD, &MyPID);
00124   else MyPID=0;
00125 #else 
00126   MyPID = 0;
00127 #endif
00128   iPrint_ = (MyPID == 0);
00129 } 
00130 
00131 template<class ScalarType>
00132 void BasicOutputManager<ScalarType>::setOStream( Teuchos::RefCountPtr<ostream> os ) { 
00133   myOS_ = os; 
00134 }
00135 
00136 template<class ScalarType>
00137 Teuchos::RefCountPtr<ostream> BasicOutputManager<ScalarType>::getOStream() { 
00138   return myOS_; 
00139 }
00140 
00141 template<class ScalarType>
00142 bool BasicOutputManager<ScalarType>::isVerbosity( MsgType type ) {
00143   if ( (type & this->vb_) == type ) {
00144     return true;
00145   }
00146   return false;
00147 }
00148 
00149 template<class ScalarType>
00150 void BasicOutputManager<ScalarType>::print( MsgType type, const string output ) {
00151   if ( (type & this->vb_) == type && iPrint_ ) {
00152     *myOS_ << output;
00153   }
00154 }
00155 
00156 template<class ScalarType>
00157 ostream & BasicOutputManager<ScalarType>::stream( MsgType type ) {
00158   if ( (type & this->vb_) == type && iPrint_ ) {
00159     return *myOS_;
00160   }
00161   return myBHS_;
00162 }
00163 
00164 } // end Anasazi namespace
00165 
00166 #endif
00167 
00168 // end of file AnasaziOutputManager.hpp

Generated on Thu Sep 18 12:31:33 2008 for Anasazi by doxygen 1.3.9.1