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, Teuchos::RCP<ostream> os = Teuchos::rcp(&std::cout,false) ); 00066 00068 virtual ~BasicOutputManager() {}; 00070 00072 00073 00075 void setOStream( Teuchos::RCP<ostream> os ); 00076 00078 Teuchos::RCP<ostream> getOStream(); 00079 00081 00083 00084 00086 00089 bool isVerbosity( MsgType type ) const; 00090 00092 void print( MsgType type, const std::string output ); 00093 00095 ostream &stream( MsgType type ); 00096 00098 00099 private: 00100 00102 00103 00105 BasicOutputManager( const OutputManager<ScalarType>& OM ); 00106 00108 BasicOutputManager<ScalarType>& operator=( const OutputManager<ScalarType>& OM ); 00109 00111 00112 Teuchos::RCP<ostream> myOS_; 00113 Teuchos::oblackholestream myBHS_; 00114 bool iPrint_; 00115 }; 00116 00117 template<class ScalarType> 00118 BasicOutputManager<ScalarType>::BasicOutputManager(int vb, Teuchos::RCP<ostream> os) 00119 : OutputManager<ScalarType>(vb), myOS_(os) { 00120 int MyPID; 00121 #ifdef HAVE_MPI 00122 // Initialize MPI 00123 int mpiStarted = 0; 00124 MPI_Initialized(&mpiStarted); 00125 if (mpiStarted) MPI_Comm_rank(MPI_COMM_WORLD, &MyPID); 00126 else MyPID=0; 00127 #else 00128 MyPID = 0; 00129 #endif 00130 iPrint_ = (MyPID == 0); 00131 } 00132 00133 template<class ScalarType> 00134 void BasicOutputManager<ScalarType>::setOStream( Teuchos::RCP<ostream> os ) { 00135 myOS_ = os; 00136 } 00137 00138 template<class ScalarType> 00139 Teuchos::RCP<ostream> BasicOutputManager<ScalarType>::getOStream() { 00140 return myOS_; 00141 } 00142 00143 template<class ScalarType> 00144 bool BasicOutputManager<ScalarType>::isVerbosity( MsgType type ) const { 00145 if ( (type & this->vb_) == type ) { 00146 return true; 00147 } 00148 return false; 00149 } 00150 00151 template<class ScalarType> 00152 void BasicOutputManager<ScalarType>::print( MsgType type, const std::string output ) { 00153 if ( (type & this->vb_) == type && iPrint_ ) { 00154 *myOS_ << output; 00155 } 00156 } 00157 00158 template<class ScalarType> 00159 ostream & BasicOutputManager<ScalarType>::stream( MsgType type ) { 00160 if ( (type & this->vb_) == type && iPrint_ ) { 00161 return *myOS_; 00162 } 00163 return myBHS_; 00164 } 00165 00166 } // end Anasazi namespace 00167 00168 #endif 00169 00170 // end of file AnasaziOutputManager.hpp
1.4.7