Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Teuchos_DefaultSerialComm.hpp
Go to the documentation of this file.
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef TEUCHOS_SERIAL_COMM_HPP
00043 #define TEUCHOS_SERIAL_COMM_HPP
00044 
00045 #include "Teuchos_Comm.hpp"
00046 #include "Teuchos_OrdinalTraits.hpp"
00047 
00048 
00049 namespace Teuchos {
00050 
00051 
00056 template<typename Ordinal>
00057 class SerialComm : public Comm<Ordinal> {
00058 public:
00059 
00061 
00062 
00064   SerialComm();
00065 
00067 
00069 
00070 
00072   virtual int getRank() const;
00074   virtual int getSize() const;
00076   virtual void barrier() const;
00078   virtual void broadcast(
00079     const int rootRank, const Ordinal bytes, char buffer[]
00080     ) const;
00082   virtual void gatherAll(
00083     const Ordinal sendBytes, const char sendBuffer[]
00084     ,const Ordinal recvBytes, char recvBuffer[]
00085     ) const;
00087   virtual void reduceAll(
00088     const ValueTypeReductionOp<Ordinal,char> &reductOp
00089     ,const Ordinal bytes, const char sendBuffer[], char globalReducts[]
00090     ) const;
00092   virtual void reduceAllAndScatter(
00093     const ValueTypeReductionOp<Ordinal,char> &reductOp
00094     ,const Ordinal sendBytes, const char sendBuffer[]
00095     ,const Ordinal recvCounts[], char myGlobalReducts[]
00096     ) const;
00098   virtual void scan(
00099     const ValueTypeReductionOp<Ordinal,char> &reductOp
00100     ,const Ordinal bytes, const char sendBuffer[], char scanReducts[]
00101     ) const;
00103   virtual void send(
00104     const Ordinal bytes, const char sendBuffer[], const int destRank
00105     ) const;
00107   virtual int receive(
00108     const int sourceRank, const Ordinal bytes, char recvBuffer[]
00109     ) const;
00111   virtual void readySend(
00112     const ArrayView<const char> &sendBuffer,
00113     const int destRank
00114     ) const;
00116   virtual RCP<CommRequest> isend(
00117     const ArrayView<const char> &sendBuffer,
00118     const int destRank
00119     ) const;
00121   virtual RCP<CommRequest> ireceive(
00122     const ArrayView<char> &Buffer,
00123     const int sourceRank
00124     ) const;
00126   virtual void waitAll(
00127     const ArrayView<RCP<CommRequest> > &requests
00128     ) const;
00130   virtual void wait(
00131     const Ptr<RCP<CommRequest> > &request
00132     ) const;
00133 
00135 
00137 
00138 
00140   std::string description() const;
00141 
00143   
00144 };
00145 
00146 
00151 template<typename Ordinal>
00152 RCP<SerialComm<Ordinal> > createSerialComm()
00153 {
00154   return Teuchos::rcp(new SerialComm<Ordinal>);
00155 }
00156 
00157 
00158 // ////////////////////////
00159 // Implementations
00160 
00161 
00162 // Constructors
00163 
00164 
00165 template<typename Ordinal>
00166 SerialComm<Ordinal>::SerialComm()
00167 {}
00168 
00169 
00170 // Overridden from Comm
00171 
00172   
00173 template<typename Ordinal>
00174 int SerialComm<Ordinal>::getRank() const
00175 {
00176   return 0;
00177 }
00178 
00179   
00180 template<typename Ordinal>
00181 int SerialComm<Ordinal>::getSize() const
00182 {
00183   return 1;
00184 }
00185 
00186   
00187 template<typename Ordinal>
00188 void SerialComm<Ordinal>::barrier() const
00189 {
00190   // Nothing to do
00191 }
00192 
00193   
00194 template<typename Ordinal>
00195 void SerialComm<Ordinal>::broadcast(
00196   const int /*rootRank*/, const Ordinal /*bytes*/, char []/*buffer*/
00197   ) const
00198 {
00199   // Nothing to do
00200 }
00201 
00202   
00203 template<typename Ordinal>
00204 void SerialComm<Ordinal>::gatherAll(
00205   const Ordinal sendBytes, const char sendBuffer[]
00206   ,const Ordinal recvBytes, char recvBuffer[]
00207   ) const
00208 {
00209   (void)sendBytes;  // to remove "unused parameter" warning
00210   (void)recvBytes;
00211   (void)sendBuffer;
00212   (void)recvBuffer;
00213 #ifdef TEUCHOS_DEBUG
00214   TEST_FOR_EXCEPT(!(sendBytes==recvBytes));
00215 #endif
00216   std::copy(sendBuffer,sendBuffer+sendBytes,recvBuffer);
00217 }
00218 
00219   
00220 template<typename Ordinal>
00221 void SerialComm<Ordinal>::reduceAll(
00222   const ValueTypeReductionOp<Ordinal,char> &reductOp
00223   ,const Ordinal bytes, const char sendBuffer[], char globalReducts[]
00224   ) const
00225 {
00226   (void)reductOp;
00227   std::copy(sendBuffer,sendBuffer+bytes,globalReducts);
00228 }
00229 
00230   
00231 template<typename Ordinal>
00232 void SerialComm<Ordinal>::reduceAllAndScatter(
00233   const ValueTypeReductionOp<Ordinal,char> &reductOp
00234   ,const Ordinal sendBytes, const char sendBuffer[]
00235   ,const Ordinal recvCounts[], char myGlobalReducts[]
00236   ) const
00237 {
00238   // Ignore unused arguments
00239   (void)reductOp;
00240   (void)sendBytes;
00241   (void)sendBuffer;
00242   (void)recvCounts;
00243   (void)myGlobalReducts;
00244 
00245 #ifdef TEUCHOS_DEBUG
00246   TEST_FOR_EXCEPT( recvCounts==NULL || recvCounts[0] != sendBytes ); 
00247 #endif
00248   std::copy(sendBuffer,sendBuffer+sendBytes,myGlobalReducts);
00249 }
00250 
00251   
00252 template<typename Ordinal>
00253 void SerialComm<Ordinal>::scan(
00254   const ValueTypeReductionOp<Ordinal,char> &reductOp
00255   ,const Ordinal bytes, const char sendBuffer[], char scanReducts[]
00256   ) const
00257 {
00258   (void)reductOp;
00259   std::copy(sendBuffer,sendBuffer+bytes,scanReducts);
00260 }
00261 
00262   
00263 template<typename Ordinal>
00264 void SerialComm<Ordinal>::send(
00265   const Ordinal /*bytes*/, const char []/*sendBuffer*/, const int /*destRank*/
00266   ) const
00267 {
00268   TEST_FOR_EXCEPTION(
00269     true, std::logic_error
00270     ,"SerialComm<Ordinal>::send(...): Error, you can not call send(...) when you"
00271     " only have one process!"
00272     );
00273 }
00274 
00275   
00276 template<typename Ordinal>
00277 int SerialComm<Ordinal>::receive(
00278   const int /*sourceRank*/, const Ordinal /*bytes*/, char []/*recvBuffer*/
00279   ) const
00280 {
00281   TEST_FOR_EXCEPTION(
00282     true, std::logic_error
00283     ,"SerialComm<Ordinal>::receive(...): Error, you can not call receive(...) when you"
00284     " only have one process!"
00285     );
00286   // The next line will never be reached, but a return is required on some platforms
00287   return 0; 
00288 }
00289 
00290 
00291 template<typename Ordinal>
00292 void SerialComm<Ordinal>::readySend(
00293   const ArrayView<const char> &/*sendBuffer*/,
00294   const int /*destRank*/
00295   ) const
00296 {
00297   TEST_FOR_EXCEPTION(
00298     true, std::logic_error
00299     ,"SerialComm<Ordinal>::readySend(...): Error, you can not call readySend(...) when you"
00300     " only have one process!"
00301     );
00302 }
00303 
00304 
00305 template<typename Ordinal>
00306 RCP<CommRequest> SerialComm<Ordinal>::isend(
00307   const ArrayView<const char> &/*sendBuffer*/,
00308   const int /*destRank*/
00309   ) const
00310 {
00311   TEST_FOR_EXCEPT(true);
00312   return null;
00313 }
00314 
00315 
00316 template<typename Ordinal>
00317 RCP<CommRequest> SerialComm<Ordinal>::ireceive(
00318   const ArrayView<char> &/*Buffer*/,
00319   const int /*sourceRank*/
00320   ) const
00321 {
00322   TEST_FOR_EXCEPT(true);
00323   return null;
00324 }
00325 
00326 
00327 template<typename Ordinal>
00328 void SerialComm<Ordinal>::waitAll(
00329   const ArrayView<RCP<CommRequest> > &/*requests*/
00330   ) const
00331 {
00332   TEST_FOR_EXCEPT(true);
00333 }
00334 
00335 
00336 template<typename Ordinal>
00337 void SerialComm<Ordinal>::wait(
00338   const Ptr<RCP<CommRequest> > &/*request*/
00339   ) const
00340 {
00341   TEST_FOR_EXCEPT(true);
00342 }
00343 
00344 
00345 // Overridden from Describable
00346 
00347 
00348 template<typename Ordinal>
00349 std::string SerialComm<Ordinal>::description() const
00350 {
00351   std::ostringstream oss;
00352   oss << "Teuchos::SerialComm<"<<OrdinalTraits<Ordinal>::name()<<">";
00353   return oss.str();
00354 }
00355 
00356 
00357 } // namespace Teuchos
00358 
00359 
00360 #endif // TEUCHOS_SERIAL_COMM_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines