|
Teuchos - Trilinos Tools Package Version of the Day
|
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 00036 namespace Teuchos { 00037 00038 00043 template<typename Ordinal> 00044 class SerialComm : public Comm<Ordinal> { 00045 public: 00046 00048 00049 00051 SerialComm(); 00052 00054 00056 00057 00059 virtual int getRank() const; 00061 virtual int getSize() const; 00063 virtual void barrier() const; 00065 virtual void broadcast( 00066 const int rootRank, const Ordinal bytes, char buffer[] 00067 ) const; 00069 virtual void gatherAll( 00070 const Ordinal sendBytes, const char sendBuffer[] 00071 ,const Ordinal recvBytes, char recvBuffer[] 00072 ) const; 00074 virtual void reduceAll( 00075 const ValueTypeReductionOp<Ordinal,char> &reductOp 00076 ,const Ordinal bytes, const char sendBuffer[], char globalReducts[] 00077 ) const; 00079 virtual void reduceAllAndScatter( 00080 const ValueTypeReductionOp<Ordinal,char> &reductOp 00081 ,const Ordinal sendBytes, const char sendBuffer[] 00082 ,const Ordinal recvCounts[], char myGlobalReducts[] 00083 ) const; 00085 virtual void scan( 00086 const ValueTypeReductionOp<Ordinal,char> &reductOp 00087 ,const Ordinal bytes, const char sendBuffer[], char scanReducts[] 00088 ) const; 00090 virtual void send( 00091 const Ordinal bytes, const char sendBuffer[], const int destRank 00092 ) const; 00094 virtual int receive( 00095 const int sourceRank, const Ordinal bytes, char recvBuffer[] 00096 ) const; 00098 virtual void readySend( 00099 const ArrayView<const char> &sendBuffer, 00100 const int destRank 00101 ) const; 00103 virtual RCP<CommRequest> isend( 00104 const ArrayView<const char> &sendBuffer, 00105 const int destRank 00106 ) const; 00108 virtual RCP<CommRequest> ireceive( 00109 const ArrayView<char> &Buffer, 00110 const int sourceRank 00111 ) const; 00113 virtual void waitAll( 00114 const ArrayView<RCP<CommRequest> > &requests 00115 ) const; 00117 virtual void wait( 00118 const Ptr<RCP<CommRequest> > &request 00119 ) const; 00120 00122 00124 00125 00127 std::string description() const; 00128 00130 00131 }; 00132 00133 00138 template<typename Ordinal> 00139 RCP<SerialComm<Ordinal> > createSerialComm() 00140 { 00141 return Teuchos::rcp(new SerialComm<Ordinal>); 00142 } 00143 00144 00145 // //////////////////////// 00146 // Implementations 00147 00148 00149 // Constructors 00150 00151 00152 template<typename Ordinal> 00153 SerialComm<Ordinal>::SerialComm() 00154 {} 00155 00156 00157 // Overridden from Comm 00158 00159 00160 template<typename Ordinal> 00161 int SerialComm<Ordinal>::getRank() const 00162 { 00163 return 0; 00164 } 00165 00166 00167 template<typename Ordinal> 00168 int SerialComm<Ordinal>::getSize() const 00169 { 00170 return 1; 00171 } 00172 00173 00174 template<typename Ordinal> 00175 void SerialComm<Ordinal>::barrier() const 00176 { 00177 // Nothing to do 00178 } 00179 00180 00181 template<typename Ordinal> 00182 void SerialComm<Ordinal>::broadcast( 00183 const int /*rootRank*/, const Ordinal /*bytes*/, char []/*buffer*/ 00184 ) const 00185 { 00186 // Nothing to do 00187 } 00188 00189 00190 template<typename Ordinal> 00191 void SerialComm<Ordinal>::gatherAll( 00192 const Ordinal sendBytes, const char sendBuffer[] 00193 ,const Ordinal recvBytes, char recvBuffer[] 00194 ) const 00195 { 00196 (void)sendBytes; // to remove "unused parameter" warning 00197 (void)recvBytes; 00198 (void)sendBuffer; 00199 (void)recvBuffer; 00200 #ifdef TEUCHOS_DEBUG 00201 TEST_FOR_EXCEPT(!(sendBytes==recvBytes)); 00202 #endif 00203 std::copy(sendBuffer,sendBuffer+sendBytes,recvBuffer); 00204 } 00205 00206 00207 template<typename Ordinal> 00208 void SerialComm<Ordinal>::reduceAll( 00209 const ValueTypeReductionOp<Ordinal,char> &reductOp 00210 ,const Ordinal bytes, const char sendBuffer[], char globalReducts[] 00211 ) const 00212 { 00213 (void)reductOp; 00214 std::copy(sendBuffer,sendBuffer+bytes,globalReducts); 00215 } 00216 00217 00218 template<typename Ordinal> 00219 void SerialComm<Ordinal>::reduceAllAndScatter( 00220 const ValueTypeReductionOp<Ordinal,char> &reductOp 00221 ,const Ordinal sendBytes, const char sendBuffer[] 00222 ,const Ordinal recvCounts[], char myGlobalReducts[] 00223 ) const 00224 { 00225 // Ignore unused arguments 00226 (void)reductOp; 00227 (void)sendBytes; 00228 (void)sendBuffer; 00229 (void)recvCounts; 00230 (void)myGlobalReducts; 00231 00232 #ifdef TEUCHOS_DEBUG 00233 TEST_FOR_EXCEPT( recvCounts==NULL || recvCounts[0] != sendBytes ); 00234 #endif 00235 std::copy(sendBuffer,sendBuffer+sendBytes,myGlobalReducts); 00236 } 00237 00238 00239 template<typename Ordinal> 00240 void SerialComm<Ordinal>::scan( 00241 const ValueTypeReductionOp<Ordinal,char> &reductOp 00242 ,const Ordinal bytes, const char sendBuffer[], char scanReducts[] 00243 ) const 00244 { 00245 (void)reductOp; 00246 std::copy(sendBuffer,sendBuffer+bytes,scanReducts); 00247 } 00248 00249 00250 template<typename Ordinal> 00251 void SerialComm<Ordinal>::send( 00252 const Ordinal /*bytes*/, const char []/*sendBuffer*/, const int /*destRank*/ 00253 ) const 00254 { 00255 TEST_FOR_EXCEPTION( 00256 true, std::logic_error 00257 ,"SerialComm<Ordinal>::send(...): Error, you can not call send(...) when you" 00258 " only have one process!" 00259 ); 00260 } 00261 00262 00263 template<typename Ordinal> 00264 int SerialComm<Ordinal>::receive( 00265 const int /*sourceRank*/, const Ordinal /*bytes*/, char []/*recvBuffer*/ 00266 ) const 00267 { 00268 TEST_FOR_EXCEPTION( 00269 true, std::logic_error 00270 ,"SerialComm<Ordinal>::receive(...): Error, you can not call receive(...) when you" 00271 " only have one process!" 00272 ); 00273 // The next line will never be reached, but a return is required on some platforms 00274 return 0; 00275 } 00276 00277 00278 template<typename Ordinal> 00279 void SerialComm<Ordinal>::readySend( 00280 const ArrayView<const char> &/*sendBuffer*/, 00281 const int /*destRank*/ 00282 ) const 00283 { 00284 TEST_FOR_EXCEPTION( 00285 true, std::logic_error 00286 ,"SerialComm<Ordinal>::readySend(...): Error, you can not call readySend(...) when you" 00287 " only have one process!" 00288 ); 00289 } 00290 00291 00292 template<typename Ordinal> 00293 RCP<CommRequest> SerialComm<Ordinal>::isend( 00294 const ArrayView<const char> &/*sendBuffer*/, 00295 const int /*destRank*/ 00296 ) const 00297 { 00298 TEST_FOR_EXCEPT(true); 00299 return null; 00300 } 00301 00302 00303 template<typename Ordinal> 00304 RCP<CommRequest> SerialComm<Ordinal>::ireceive( 00305 const ArrayView<char> &/*Buffer*/, 00306 const int /*sourceRank*/ 00307 ) const 00308 { 00309 TEST_FOR_EXCEPT(true); 00310 return null; 00311 } 00312 00313 00314 template<typename Ordinal> 00315 void SerialComm<Ordinal>::waitAll( 00316 const ArrayView<RCP<CommRequest> > &/*requests*/ 00317 ) const 00318 { 00319 TEST_FOR_EXCEPT(true); 00320 } 00321 00322 00323 template<typename Ordinal> 00324 void SerialComm<Ordinal>::wait( 00325 const Ptr<RCP<CommRequest> > &/*request*/ 00326 ) const 00327 { 00328 TEST_FOR_EXCEPT(true); 00329 } 00330 00331 00332 // Overridden from Describable 00333 00334 00335 template<typename Ordinal> 00336 std::string SerialComm<Ordinal>::description() const 00337 { 00338 std::ostringstream oss; 00339 oss << "Teuchos::SerialComm<"<<OrdinalTraits<Ordinal>::name()<<">"; 00340 return oss.str(); 00341 } 00342 00343 00344 } // namespace Teuchos 00345 00346 00347 #endif // TEUCHOS_SERIAL_COMM_HPP
1.7.4