Teuchos_DefaultSerialComm.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_SERIAL_COMM_HPP
00030 #define TEUCHOS_SERIAL_COMM_HPP
00031 
00032 #include "Teuchos_Comm.hpp"
00033 #include "Teuchos_OrdinalTraits.hpp"
00034 
00035 namespace Teuchos {
00036 
00041 template<typename Ordinal>
00042 class SerialComm : public Comm<Ordinal> {
00043 public:
00044 
00046 
00047 
00049   SerialComm();
00050 
00052 
00054 
00055 
00057   int getRank() const;
00059   int getSize() const;
00061   void barrier() const;
00063   void broadcast(
00064     const int rootRank, const Ordinal bytes, char buffer[]
00065     ) const;
00067   void gatherAll(
00068     const Ordinal sendBytes, const char sendBuffer[]
00069     ,const Ordinal recvBytes, char recvBuffer[]
00070     ) const;
00072   void reduceAll(
00073     const ValueTypeReductionOp<Ordinal,char> &reductOp
00074     ,const Ordinal bytes, const char sendBuffer[], char globalReducts[]
00075     ) const;
00077   void reduceAllAndScatter(
00078     const ValueTypeReductionOp<Ordinal,char> &reductOp
00079     ,const Ordinal sendBytes, const char sendBuffer[]
00080     ,const Ordinal recvCounts[], const Ordinal blockSize, char myGlobalReducts[]
00081     ) const;
00083   void scan(
00084     const ValueTypeReductionOp<Ordinal,char> &reductOp
00085     ,const Ordinal bytes, const char sendBuffer[], char scanReducts[]
00086     ) const;
00088   void send(
00089     const Ordinal bytes, const char sendBuffer[], const int destRank
00090     ) const;
00092   int receive(
00093     const int sourceRank, const Ordinal bytes, char recvBuffer[]
00094     ) const;
00095 
00097 
00099 
00100 
00102   std::string description() const;
00103 
00105   
00106 };
00107 
00108 // ////////////////////////
00109 // Implementations
00110 
00111 // Constructors
00112 
00113 template<typename Ordinal>
00114 SerialComm<Ordinal>::SerialComm()
00115 {}
00116 
00117 // Overridden from Comm
00118   
00119 template<typename Ordinal>
00120 int SerialComm<Ordinal>::getRank() const
00121 {
00122   return 0;
00123 }
00124   
00125 template<typename Ordinal>
00126 int SerialComm<Ordinal>::getSize() const
00127 {
00128   return 1;
00129 }
00130   
00131 template<typename Ordinal>
00132 void SerialComm<Ordinal>::barrier() const
00133 {
00134   // Nothing to do
00135 }
00136   
00137 template<typename Ordinal>
00138 void SerialComm<Ordinal>::broadcast(
00139   const int rootRank, const Ordinal bytes, char buffer[]
00140   ) const
00141 {
00142   // Nothing to do
00143 }
00144   
00145 template<typename Ordinal>
00146 void SerialComm<Ordinal>::gatherAll(
00147   const Ordinal sendBytes, const char sendBuffer[]
00148   ,const Ordinal recvBytes, char recvBuffer[]
00149   ) const
00150 {
00151 #ifdef TEUCHOS_DEBUG
00152   TEST_FOR_EXCEPT(!(sendBytes==recvBytes));
00153 #endif
00154   std::copy(sendBuffer,sendBuffer+sendBytes,recvBuffer);
00155 }
00156   
00157 template<typename Ordinal>
00158 void SerialComm<Ordinal>::reduceAll(
00159   const ValueTypeReductionOp<Ordinal,char> &reductOp
00160   ,const Ordinal bytes, const char sendBuffer[], char globalReducts[]
00161   ) const
00162 {
00163   std::copy(sendBuffer,sendBuffer+bytes,globalReducts);
00164 }
00165   
00166 template<typename Ordinal>
00167 void SerialComm<Ordinal>::reduceAllAndScatter(
00168   const ValueTypeReductionOp<Ordinal,char> &reductOp
00169   ,const Ordinal sendBytes, const char sendBuffer[]
00170   ,const Ordinal recvCounts[], const Ordinal blockSize, char myGlobalReducts[]
00171   ) const
00172 {
00173 #ifdef TEUCHOS_DEBUG
00174   TEST_FOR_EXCEPT( recvCounts==NULL || blockSize*recvCounts[0] != sendBytes ); 
00175 #endif
00176   std::copy(sendBuffer,sendBuffer+sendBytes,myGlobalReducts);
00177 }
00178   
00179 template<typename Ordinal>
00180 void SerialComm<Ordinal>::scan(
00181   const ValueTypeReductionOp<Ordinal,char> &reductOp
00182   ,const Ordinal bytes, const char sendBuffer[], char scanReducts[]
00183   ) const
00184 {
00185   std::copy(sendBuffer,sendBuffer+bytes,scanReducts);
00186 }
00187   
00188 template<typename Ordinal>
00189 void SerialComm<Ordinal>::send(
00190   const Ordinal bytes, const char sendBuffer[], const int destRank
00191   ) const
00192 {
00193   TEST_FOR_EXCEPTION(
00194     true, std::logic_error
00195     ,"SerialComm<Ordinal>::send(...): Error, you can not call send(...) when you"
00196     " only have one process!"
00197     );
00198 }
00199   
00200 template<typename Ordinal>
00201 int SerialComm<Ordinal>::receive(
00202   const int sourceRank, const Ordinal bytes, char recvBuffer[]
00203   ) const
00204 {
00205   TEST_FOR_EXCEPTION(
00206     true, std::logic_error
00207     ,"SerialComm<Ordinal>::receive(...): Error, you can not call receive(...) when you"
00208     " only have one process!"
00209     );
00210   // The next line will never be reached, but a return is required on some platforms
00211   return 0; 
00212 }
00213 
00214 // Overridden from Describable
00215 
00216 template<typename Ordinal>
00217 std::string SerialComm<Ordinal>::description() const
00218 {
00219   std::ostringstream oss;
00220   oss << "Teuchos::SerialComm<"<<OrdinalTraits<Ordinal>::name()<<">";
00221   return oss.str();
00222 }
00223 
00224 } // namespace Teuchos
00225 
00226 #endif // TEUCHOS_SERIAL_COMM_HPP

Generated on Tue Oct 20 12:45:25 2009 for Teuchos - Trilinos Tools Package by doxygen 1.4.7