BelosOutputManager.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                 Belos: Block Linear Solvers 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 BELOS_OUTPUT_MANAGER_HPP
00030 #define BELOS_OUTPUT_MANAGER_HPP
00031 
00036 #include "BelosConfigDefs.hpp"
00037 #include "BelosTypes.hpp"
00038 #include "Teuchos_oblackholestream.hpp" 
00039 
00040 #ifdef HAVE_MPI
00041 #include <mpi.h>
00042 #endif
00043 
00056 namespace Belos {
00057   
00058   template <class ScalarType>
00059   class OutputManager {
00060     
00061   public:
00062     
00064 
00065     
00067     OutputManager( int vb = Belos::Errors, const Teuchos::RCP<std::ostream> &os = Teuchos::rcp(&std::cout,false) );
00068     
00070     virtual ~OutputManager() {};
00072     
00074 
00075     
00077     void setOStream( const Teuchos::RCP<std::ostream> &os ) { myOS_ = os; };
00078     
00080     void setVerbosity( int vb ) { vb_ = vb; }; 
00081     
00083     
00085 
00086 
00088     std::ostream& stream( MsgType type ) 
00089     {
00090       if ( (type & vb_) && iPrint_ ) {
00091   return *myOS_;
00092       }
00093       return myBHS_;
00094     }
00095  
00097     Teuchos::RCP<std::ostream> getOStream() { return myOS_; };
00098     
00100     
00102 
00103     
00105 
00108     bool isVerbosity( MsgType type ) const { return (( type == Belos::Errors ) || ( vb_ & type )); }; 
00109     
00111 
00113 
00114     
00116     void print( MsgType type, const std::string output );
00117 
00119 
00120   private:
00121     
00123 
00124     
00126     OutputManager( const OutputManager<ScalarType>& OM );
00127     
00129     OutputManager<ScalarType>& operator=( const OutputManager<ScalarType>& OM );
00130     
00132     
00133     int vb_;
00134     Teuchos::RCP<std::ostream> myOS_; 
00135     Teuchos::oblackholestream myBHS_;  
00136     bool iPrint_;
00137   };
00138   
00139   template<class ScalarType>
00140   OutputManager<ScalarType>::OutputManager( int vb, const Teuchos::RCP<std::ostream> &os ) :
00141     vb_(vb),
00142     myOS_(os)
00143   {
00144     int MyPID;
00145 #ifdef HAVE_MPI
00146     // Initialize MPI
00147     int mpiStarted = 0;
00148     MPI_Initialized(&mpiStarted);
00149     if (mpiStarted) MPI_Comm_rank(MPI_COMM_WORLD, &MyPID);
00150     else MyPID=0;
00151 #else 
00152     MyPID = 0;
00153 #endif
00154     iPrint_ = (MyPID == 0);
00155   }
00156  
00157   template<class ScalarType>
00158   void OutputManager<ScalarType>::print( MsgType type, const std::string output ) {
00159   if ( (type & vb_) && iPrint_ ) {
00160     *myOS_ << output;
00161   }
00162 }
00163  
00164 } // end Belos namespace
00165 
00166 #endif
00167 
00168 // end of file BelosOutputManager.hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:05:06 2011 for Belos by  doxygen 1.6.3