Teuchos_DefaultComm.hpp

00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //                    Teuchos: Common Tools 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 TEUCHOS_DEFAULT_COMM_HPP
00030 #define TEUCHOS_DEFAULT_COMM_HPP
00031 
00032 #include "Teuchos_RCP.hpp"
00033 #include "Teuchos_DefaultSerialComm.hpp"
00034 #ifdef HAVE_MPI
00035 #  include "Teuchos_DefaultMpiComm.hpp"
00036 #endif
00037 
00038 namespace Teuchos {
00039 
00047 template<typename Ordinal>
00048 class DefaultComm {
00049 public:
00050 
00056   static Teuchos::RCP<const Comm<Ordinal> > getComm();
00057 
00060   static Teuchos::RCP<const Comm<Ordinal> >
00061   getDefaultSerialComm( const Teuchos::RCP<const Comm<Ordinal> > &comm );
00062 
00063 private:
00064 
00065   static Teuchos::RCP<const Comm<Ordinal> > comm_;
00066   static Teuchos::RCP<const Comm<Ordinal> > defaultSerialComm_;
00067 
00068 };
00069 
00070 // ///////////////////////////
00071 // Template Implementations
00072 
00073 template<typename Ordinal>
00074 Teuchos::RCP<const Teuchos::Comm<Ordinal> >
00075 DefaultComm<Ordinal>::getComm()
00076 {
00077   if(!comm_.get()) {
00078 #ifdef HAVE_MPI
00079     comm_ = rcp(new MpiComm<Ordinal>(opaqueWrapper((MPI_Comm)MPI_COMM_WORLD)));
00080 #else // HAVE_MPI    
00081     comm_ = rcp(new SerialComm<Ordinal>());
00082 #endif // HAVE_MPI    
00083   }
00084   return comm_;
00085 }
00086 
00087 template<typename Ordinal>
00088 Teuchos::RCP<const Teuchos::Comm<Ordinal> >
00089 DefaultComm<Ordinal>::getDefaultSerialComm(
00090   const Teuchos::RCP<const Comm<Ordinal> > &comm
00091   )
00092 {
00093   if( comm.get() )
00094     return comm;
00095   else
00096     return defaultSerialComm_;
00097 }
00098 
00099 template<typename Ordinal>
00100 Teuchos::RCP<const Teuchos::Comm<Ordinal> >
00101 DefaultComm<Ordinal>::comm_ = Teuchos::null;
00102 
00103 template<typename Ordinal>
00104 Teuchos::RCP<const Teuchos::Comm<Ordinal> >
00105 DefaultComm<Ordinal>::defaultSerialComm_
00106 = Teuchos::rcp(new Teuchos::SerialComm<Ordinal>());
00107 
00108 } // namespace Teuchos
00109 
00110 #endif // TEUCHOS_DEFAULT_COMM_HPP

Generated on Wed May 12 21:24:40 2010 for Teuchos - Trilinos Tools Package by  doxygen 1.4.7