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   using std::ostream;
00055 
00056   template <class ScalarType>
00057   class BasicOutputManager : public OutputManager<ScalarType> {
00058 
00059     public:
00060 
00062 
00063 
00065       BasicOutputManager(int vb = Anasazi::Errors, 
00066                          Teuchos::RCP<ostream> os = Teuchos::rcpFromRef(std::cout),
00067                          int printingRank = 0);
00068 
00070       virtual ~BasicOutputManager() {};
00072 
00074 
00075 
00077       void setOStream( Teuchos::RCP<ostream> os );
00078 
00080       Teuchos::RCP<ostream> getOStream();
00081 
00083 
00085 
00086 
00088 
00091       bool isVerbosity( MsgType type ) const;
00092 
00094       void print( MsgType type, const std::string output );
00095 
00097       ostream &stream( MsgType type );
00098 
00100 
00101     private:
00102 
00104 
00105 
00107       BasicOutputManager( const OutputManager<ScalarType>& OM );
00108 
00110       BasicOutputManager<ScalarType>& operator=( const OutputManager<ScalarType>& OM );
00111 
00113 
00114       Teuchos::RCP<ostream> myOS_;
00115       Teuchos::oblackholestream myBHS_;
00116       bool iPrint_;
00117   };
00118 
00119   template<class ScalarType>
00120   BasicOutputManager<ScalarType>::BasicOutputManager(int vb, Teuchos::RCP<ostream> os, int printingRank)
00121   : OutputManager<ScalarType>(vb), myOS_(os) {
00122     // print only on proc 0
00123     int MyPID;
00124 #ifdef HAVE_MPI
00125     // Initialize MPI
00126     int mpiStarted = 0;
00127     MPI_Initialized(&mpiStarted);
00128     if (mpiStarted) MPI_Comm_rank(MPI_COMM_WORLD, &MyPID);
00129     else MyPID=0;
00130 #else 
00131     MyPID = 0;
00132 #endif
00133     iPrint_ = (MyPID == printingRank);
00134   }
00135 
00136   template<class ScalarType>
00137   void BasicOutputManager<ScalarType>::setOStream( Teuchos::RCP<ostream> os ) { 
00138     myOS_ = os; 
00139   }
00140 
00141   template<class ScalarType>
00142   Teuchos::RCP<ostream> BasicOutputManager<ScalarType>::getOStream() { 
00143     return myOS_; 
00144   }
00145 
00146   template<class ScalarType>
00147   bool BasicOutputManager<ScalarType>::isVerbosity( MsgType type ) const {
00148     if ( (type & this->vb_) == type ) {
00149       return true;
00150     }
00151     return false;
00152   }
00153 
00154   template<class ScalarType>
00155   void BasicOutputManager<ScalarType>::print( MsgType type, const std::string output ) {
00156     if ( (type & this->vb_) == type && iPrint_ ) {
00157       *myOS_ << output;
00158     }
00159   }
00160 
00161   template<class ScalarType>
00162   ostream & BasicOutputManager<ScalarType>::stream( MsgType type ) {
00163     if ( (type & this->vb_) == type && iPrint_ ) {
00164       return *myOS_;
00165     }
00166     return myBHS_;
00167   }
00168 
00169 } // end Anasazi namespace
00170 
00171 #endif
00172 
00173 // end of file AnasaziOutputManager.hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Generated on Wed Apr 13 09:56:58 2011 for Anasazi by  doxygen 1.6.3