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   virtual int getRank() const;
00059   virtual int getSize() const;
00061   virtual void barrier() const;
00063   virtual void broadcast(
00064     const int rootRank, const Ordinal bytes, char buffer[]
00065     ) const;
00067   virtual void gatherAll(
00068     const Ordinal sendBytes, const char sendBuffer[]
00069     ,const Ordinal recvBytes, char recvBuffer[]
00070     ) const;
00072   virtual void reduceAll(
00073     const ValueTypeReductionOp<Ordinal,char> &reductOp
00074     ,const Ordinal bytes, const char sendBuffer[], char globalReducts[]
00075     ) const;
00077   virtual void reduceAllAndScatter(
00078     const ValueTypeReductionOp<Ordinal,char> &reductOp
00079     ,const Ordinal sendBytes, const char sendBuffer[]
00080     ,const Ordinal recvCounts[], char myGlobalReducts[]
00081     ) const;
00083   virtual void scan(
00084     const ValueTypeReductionOp<Ordinal,char> &reductOp
00085     ,const Ordinal bytes, const char sendBuffer[], char scanReducts[]
00086     ) const;
00088   virtual void send(
00089     const Ordinal bytes, const char sendBuffer[], const int destRank
00090     ) const;
00092   virtual int receive(
00093     const int sourceRank, const Ordinal bytes, char recvBuffer[]
00094     ) const;
00096   virtual void readySend(
00097     const ArrayView<const char> &sendBuffer,
00098     const int destRank
00099     ) const;
00101   virtual RCP<CommRequest> isend(
00102     const ArrayView<const char> &sendBuffer,
00103     const int destRank
00104     ) const;
00106   virtual RCP<CommRequest> ireceive(
00107     const ArrayView<char> &Buffer,
00108     const int sourceRank
00109     ) const;
00111   virtual void waitAll(
00112     const ArrayView<RCP<CommRequest> > &requests
00113     ) const;
00115   virtual void wait(
00116     const Ptr<RCP<CommRequest> > &request
00117     ) const;
00118 
00120 
00122 
00123 
00125   std::string description() const;
00126 
00128   
00129 };
00130 
00131 // ////////////////////////
00132 // Implementations
00133 
00134 // Constructors
00135 
00136 template<typename Ordinal>
00137 SerialComm<Ordinal>::SerialComm()
00138 {}
00139 
00140 // Overridden from Comm
00141   
00142 template<typename Ordinal>
00143 int SerialComm<Ordinal>::getRank() const
00144 {
00145   return 0;
00146 }
00147   
00148 template<typename Ordinal>
00149 int SerialComm<Ordinal>::getSize() const
00150 {
00151   return 1;
00152 }
00153   
00154 template<typename Ordinal>
00155 void SerialComm<Ordinal>::barrier() const
00156 {
00157   // Nothing to do
00158 }
00159   
00160 template<typename Ordinal>
00161 void SerialComm<Ordinal>::broadcast(
00162   const int /*rootRank*/, const Ordinal /*bytes*/, char []/*buffer*/
00163   ) const
00164 {
00165   // Nothing to do
00166 }
00167   
00168 template<typename Ordinal>
00169 void SerialComm<Ordinal>::gatherAll(
00170   const Ordinal sendBytes, const char sendBuffer[]
00171   ,const Ordinal recvBytes, char recvBuffer[]
00172   ) const
00173 {
00174   (void)sendBytes;  // to remove "unused parameter" warning
00175   (void)recvBytes;
00176   (void)sendBuffer;
00177   (void)recvBuffer;
00178 #ifdef TEUCHOS_DEBUG
00179   TEST_FOR_EXCEPT(!(sendBytes==recvBytes));
00180 #endif
00181   std::copy(sendBuffer,sendBuffer+sendBytes,recvBuffer);
00182 }
00183   
00184 template<typename Ordinal>
00185 void SerialComm<Ordinal>::reduceAll(
00186   const ValueTypeReductionOp<Ordinal,char> &reductOp
00187   ,const Ordinal bytes, const char sendBuffer[], char globalReducts[]
00188   ) const
00189 {
00190   (void)reductOp;
00191   std::copy(sendBuffer,sendBuffer+bytes,globalReducts);
00192 }
00193   
00194 template<typename Ordinal>
00195 void SerialComm<Ordinal>::reduceAllAndScatter(
00196   const ValueTypeReductionOp<Ordinal,char> &reductOp
00197   ,const Ordinal sendBytes, const char sendBuffer[]
00198   ,const Ordinal recvCounts[], char myGlobalReducts[]
00199   ) const
00200 {
00201   // Ignore unused arguments
00202   (void)reductOp;
00203   (void)sendBytes;
00204   (void)sendBuffer;
00205   (void)recvCounts;
00206   (void)myGlobalReducts;
00207 
00208 #ifdef TEUCHOS_DEBUG
00209   TEST_FOR_EXCEPT( recvCounts==NULL || recvCounts[0] != sendBytes ); 
00210 #endif
00211   std::copy(sendBuffer,sendBuffer+sendBytes,myGlobalReducts);
00212 }
00213   
00214 template<typename Ordinal>
00215 void SerialComm<Ordinal>::scan(
00216   const ValueTypeReductionOp<Ordinal,char> &reductOp
00217   ,const Ordinal bytes, const char sendBuffer[], char scanReducts[]
00218   ) const
00219 {
00220   (void)reductOp;
00221   std::copy(sendBuffer,sendBuffer+bytes,scanReducts);
00222 }
00223   
00224 template<typename Ordinal>
00225 void SerialComm<Ordinal>::send(
00226   const Ordinal /*bytes*/, const char []/*sendBuffer*/, const int /*destRank*/
00227   ) const
00228 {
00229   TEST_FOR_EXCEPTION(
00230     true, std::logic_error
00231     ,"SerialComm<Ordinal>::send(...): Error, you can not call send(...) when you"
00232     " only have one process!"
00233     );
00234 }
00235   
00236 template<typename Ordinal>
00237 int SerialComm<Ordinal>::receive(
00238   const int /*sourceRank*/, const Ordinal /*bytes*/, char []/*recvBuffer*/
00239   ) const
00240 {
00241   TEST_FOR_EXCEPTION(
00242     true, std::logic_error
00243     ,"SerialComm<Ordinal>::receive(...): Error, you can not call receive(...) when you"
00244     " only have one process!"
00245     );
00246   // The next line will never be reached, but a return is required on some platforms
00247   return 0; 
00248 }
00249 
00250 template<typename Ordinal>
00251 void SerialComm<Ordinal>::readySend(
00252   const ArrayView<const char> &/*sendBuffer*/,
00253   const int /*destRank*/
00254   ) const
00255 {
00256   TEST_FOR_EXCEPTION(
00257     true, std::logic_error
00258     ,"SerialComm<Ordinal>::readySend(...): Error, you can not call readySend(...) when you"
00259     " only have one process!"
00260     );
00261 }
00262 
00263 
00264 
00265 template<typename Ordinal>
00266 RCP<CommRequest> SerialComm<Ordinal>::isend(
00267   const ArrayView<const char> &/*sendBuffer*/,
00268   const int /*destRank*/
00269   ) const
00270 {
00271   TEST_FOR_EXCEPT(true);
00272   return null;
00273 }
00274 
00275 
00276 template<typename Ordinal>
00277 RCP<CommRequest> SerialComm<Ordinal>::ireceive(
00278   const ArrayView<char> &/*Buffer*/,
00279   const int /*sourceRank*/
00280   ) const
00281 {
00282   TEST_FOR_EXCEPT(true);
00283   return null;
00284 }
00285 
00286 
00287 template<typename Ordinal>
00288 void SerialComm<Ordinal>::waitAll(
00289   const ArrayView<RCP<CommRequest> > &/*requests*/
00290   ) const
00291 {
00292   TEST_FOR_EXCEPT(true);
00293 }
00294 
00295 
00296 template<typename Ordinal>
00297 void SerialComm<Ordinal>::wait(
00298   const Ptr<RCP<CommRequest> > &/*request*/
00299   ) const
00300 {
00301   TEST_FOR_EXCEPT(true);
00302 }
00303 
00304 
00305 // Overridden from Describable
00306 
00307 template<typename Ordinal>
00308 std::string SerialComm<Ordinal>::description() const
00309 {
00310   std::ostringstream oss;
00311   oss << "Teuchos::SerialComm<"<<OrdinalTraits<Ordinal>::name()<<">";
00312   return oss.str();
00313 }
00314 
00315 } // namespace Teuchos
00316 
00317 #endif // TEUCHOS_SERIAL_COMM_HPP

Generated on Tue Jul 13 09:22:59 2010 for Teuchos - Trilinos Tools Package by  doxygen 1.4.7