Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Teuchos_CommHelpers.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_COMM_HELPERS_HPP
00043 #define TEUCHOS_COMM_HELPERS_HPP
00044 
00045 #include "Teuchos_Comm.hpp"
00046 #include "Teuchos_CommUtilities.hpp"
00047 #include "Teuchos_SerializationTraitsHelpers.hpp"
00048 #include "Teuchos_ReductionOpHelpers.hpp"
00049 #include "Teuchos_SerializerHelpers.hpp"
00050 #include "Teuchos_ScalarTraits.hpp"
00051 #include "Teuchos_OrdinalTraits.hpp"
00052 #include "Teuchos_Array.hpp"
00053 #include "Teuchos_TypeNameTraits.hpp"
00054 #include "Teuchos_Workspace.hpp"
00055 #include "Teuchos_as.hpp"
00056 
00057 #ifdef HAVE_MPI
00058 #  include "Teuchos_DefaultMpiComm.hpp"
00059 #endif // HAVE_MPI
00060 #include "Teuchos_DefaultSerialComm.hpp"
00061 
00062 
00063 namespace Teuchos {
00064 
00065 
00066 //
00067 // Teuchos::Comm Helper Functions
00068 //
00069 
00075 enum EReductionType {
00076   REDUCE_SUM, 
00077   REDUCE_MIN, 
00078   REDUCE_MAX, 
00079   REDUCE_AND 
00080 };
00081 
00086 const char* toString (const EReductionType reductType);
00087 
00092 template<typename Ordinal>
00093 int rank(const Comm<Ordinal>& comm);
00094 
00099 template<typename Ordinal>
00100 int size(const Comm<Ordinal>& comm);
00101 
00106 template<typename Ordinal>
00107 void barrier(const Comm<Ordinal>& comm);
00108 
00113 template<typename Ordinal, typename Packet>
00114 void broadcast(
00115   const Comm<Ordinal>& comm,
00116   const int rootRank,
00117   const Ordinal count, Packet buffer[]
00118   );
00119 
00124 template<typename Ordinal, typename Packet>
00125 void broadcast(
00126   const Comm<Ordinal>& comm,
00127   const int rootRank,
00128   const ArrayView<Packet> &buffer
00129   );
00130 
00135 template<typename Ordinal, typename Packet>
00136 void broadcast(
00137   const Comm<Ordinal>& comm,
00138   const int rootRank, Packet *object
00139   );
00140 
00145 template<typename Ordinal, typename Packet>
00146 void broadcast(
00147   const Comm<Ordinal>& comm,
00148   const int rootRank, const Ptr<Packet> &object
00149   );
00150 
00155 template<typename Ordinal, typename Packet>
00156 void broadcast(
00157   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00158   const int rootRank, const Ordinal count, Packet*const buffer[]
00159   );
00160 
00165 template<typename Ordinal, typename Packet>
00166 void broadcast(
00167   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00168   const int rootRank, const ArrayView<const Ptr<Packet> > &buffer
00169   );
00170 
00176 template<typename Ordinal, typename Packet, typename Serializer>
00177 void broadcast(
00178   const Comm<Ordinal>& comm,
00179   const Serializer& serializer,
00180   const int rootRank,
00181   const Ordinal count, Packet buffer[]
00182   );
00183 
00188 template<typename Ordinal, typename Packet>
00189 void
00190 gather (const Packet sendBuf[],
00191         const Ordinal sendCount,
00192         Packet recvBuf[],
00193         const Ordinal recvCount,
00194         const int root,
00195         const Comm<Ordinal>& comm);
00196 
00201 template<typename Ordinal, typename Packet>
00202 void
00203 gatherv (const Packet sendBuf[],
00204          const Ordinal sendCount,
00205          Packet recvBuf[],
00206          const Ordinal recvCounts[],
00207          const Ordinal displs[],
00208          const int root,
00209          const Comm<Ordinal>& comm);
00210 
00216 template<typename Ordinal, typename Packet>
00217 void gatherAll(
00218   const Comm<Ordinal>& comm,
00219   const Ordinal sendCount, const Packet sendBuffer[],
00220   const Ordinal recvCount, Packet recvBuffer[]
00221   );
00222 
00228 template<typename Ordinal, typename Packet>
00229 void gatherAll(
00230   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00231   const Ordinal sendCount, const Packet*const sendBuffer[],
00232   const Ordinal recvCount, Packet*const recvBuffer[]
00233   );
00234 
00240 template<typename Ordinal, typename Packet, typename Serializer>
00241 void gatherAll(
00242   const Comm<Ordinal>& comm,
00243   const Serializer& serializer,
00244   const Ordinal sendCount, const Packet sendBuffer[],
00245   const Ordinal recvCount, Packet recvBuffer[]
00246   );
00247 
00253 template<typename Ordinal, typename Packet>
00254 void reduceAll(
00255   const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
00256   const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
00257   );
00258 
00264 template<typename Ordinal, typename Packet>
00265 void reduceAll(
00266   const Comm<Ordinal>& comm, const EReductionType reductType,
00267   const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
00268   );
00269 
00275 template<typename Ordinal, typename Packet>
00276 void reduceAll(
00277   const Comm<Ordinal>& comm, const EReductionType reductType,
00278   const Packet &send, const Ptr<Packet> &globalReduct
00279   );
00280 
00282 template<typename Ordinal, typename Packet>
00283 TEUCHOS_DEPRECATED void reduceAll(
00284   const Comm<Ordinal>& comm, const EReductionType reductType,
00285   const Packet &send, Packet *globalReduct
00286   )
00287 {
00288   reduceAll<Ordinal,Packet>(comm, reductType, send, ptr(globalReduct));
00289 }
00290 
00296 template<typename Ordinal, typename Packet>
00297 void reduceAll(
00298   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00299   const ReferenceTypeReductionOp<Ordinal,Packet> &reductOp,
00300   const Ordinal count, const Packet*const sendBuffer[], Packet*const globalReducts[]
00301   );
00302 
00308 template<typename Ordinal, typename Packet, typename Serializer>
00309 void reduceAll(
00310   const Comm<Ordinal>& comm,
00311   const Serializer& serializer,
00312   const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
00313   const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
00314   );
00315 
00321 template<typename Ordinal, typename Packet, typename Serializer>
00322 void reduceAll(
00323   const Comm<Ordinal>& comm,
00324   const Serializer& serializer,
00325   const EReductionType reductType,
00326   const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
00327   );
00328 
00334 template<typename Ordinal, typename Packet>
00335 void reduceAllAndScatter(
00336   const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
00337   const Ordinal sendCount, const Packet sendBuffer[] ,
00338   const Ordinal recvCounts[], Packet myGlobalReducts[]
00339   );
00340 
00346 template<typename Ordinal, typename Packet>
00347 void reduceAllAndScatter(
00348   const Comm<Ordinal>& comm, const EReductionType reductType,
00349   const Ordinal sendCount, const Packet sendBuffer[] ,
00350   const Ordinal recvCounts[], Packet myGlobalReducts[]
00351   );
00352 
00358 template<typename Ordinal, typename Packet>
00359 void reduceAllAndScatter(
00360   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00361   const ReferenceTypeReductionOp<Ordinal,Packet> &reductOp,
00362   const Ordinal sendCount, const Packet*const sendBuffer[] ,
00363   const Ordinal recvCounts[], Packet*const myGlobalReducts[]
00364   );
00365 
00371 template<typename Ordinal, typename Packet>
00372 void scan(
00373   const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
00374   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
00375   );
00376 
00382 template<typename Ordinal, typename Packet, typename Serializer>
00383 void reduceAllAndScatter(
00384   const Comm<Ordinal>& comm,
00385   const Serializer& serializer,
00386   const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
00387   const Ordinal sendCount, const Packet sendBuffer[],
00388   const Ordinal recvCounts[], Packet myGlobalReducts[]
00389   );
00390 
00396 template<typename Ordinal, typename Packet, typename Serializer>
00397 void reduceAllAndScatter(
00398   const Comm<Ordinal>& comm,
00399   const Serializer& serializer,
00400   const EReductionType reductType,
00401   const Ordinal sendCount, const Packet sendBuffer[] ,
00402   const Ordinal recvCounts[], Packet myGlobalReducts[]
00403   );
00404 
00410 template<typename Ordinal, typename Packet>
00411 void scan(
00412   const Comm<Ordinal>& comm, const EReductionType reductType,
00413   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
00414   );
00415 
00421 template<typename Ordinal, typename Packet>
00422 void scan(
00423   const Comm<Ordinal>& comm, const EReductionType reductType,
00424   const Packet &send, const Ptr<Packet> &scanReduct
00425   );
00426 
00428 template<typename Ordinal, typename Packet>
00429 TEUCHOS_DEPRECATED void scan(
00430   const Comm<Ordinal>& comm, const EReductionType reductType,
00431   const Packet &send, Packet *scanReduct
00432   )
00433 {
00434   scan(comm, reductType, send, ptr(scanReduct));
00435 }
00436 
00442 template<typename Ordinal, typename Packet>
00443 void scan(
00444   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00445   const ReferenceTypeReductionOp<Ordinal,Packet> &reductOp,
00446   const Ordinal count, const Packet*const sendBuffer[], Packet*const scanReducts[]
00447   );
00448 
00454 template<typename Ordinal, typename Packet, typename Serializer>
00455 void scan(
00456   const Comm<Ordinal>& comm,
00457   const Serializer& serializer,
00458   const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
00459   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
00460   );
00461 
00467 template<typename Ordinal, typename Packet, typename Serializer>
00468 void scan(
00469   const Comm<Ordinal>& comm,
00470   const Serializer& serializer,
00471   const EReductionType reductType,
00472   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
00473   );
00474 
00479 template<typename Ordinal, typename Packet>
00480 void send(
00481   const Comm<Ordinal>& comm,
00482   const Ordinal count, const Packet sendBuffer[], const int destRank
00483   );
00484 
00486 template<typename Ordinal, typename Packet>
00487 void
00488 send (const Packet sendBuffer[],
00489       const Ordinal count,
00490       const int destRank,
00491       const int tag,
00492       const Comm<Ordinal>& comm);
00493 
00498 template<typename Ordinal, typename Packet>
00499 void ssend(
00500   const Comm<Ordinal>& comm,
00501   const Ordinal count, const Packet sendBuffer[], const int destRank
00502   );
00503 
00505 template<typename Ordinal, typename Packet>
00506 void
00507 ssend (const Packet sendBuffer[],
00508        const Ordinal count,
00509        const int destRank,
00510        const int tag,
00511        const Comm<Ordinal>& comm);
00512 
00517 template<typename Ordinal, typename Packet>
00518 void send(
00519   const Comm<Ordinal>& comm,
00520   const Packet &send, const int destRank
00521   );
00522 
00527 template<typename Ordinal, typename Packet>
00528 void ssend(
00529   const Comm<Ordinal>& comm,
00530   const Packet &send, const int destRank
00531   );
00532 
00539 template<typename Ordinal, typename Packet>
00540 void send(
00541   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00542   const Ordinal count, const Packet*const sendBuffer[], const int destRank
00543   );
00544 
00550 template<typename Ordinal, typename Packet, typename Serializer>
00551 void send(
00552   const Comm<Ordinal>& comm,
00553   const Serializer& serializer,
00554   const Ordinal count, const Packet sendBuffer[], const int destRank
00555   );
00556 
00561 template<typename Ordinal, typename Packet>
00562 int receive(
00563   const Comm<Ordinal>& comm,
00564   const int sourceRank, const Ordinal count, Packet recvBuffer[]
00565   );
00566 
00571 template<typename Ordinal, typename Packet>
00572 int receive(
00573   const Comm<Ordinal>& comm,
00574   const int sourceRank, Packet *recv
00575   );
00576 
00581 template<typename Ordinal, typename Packet>
00582 int receive(
00583   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00584   const int sourceRank, const Ordinal count, Packet*const recvBuffer[]
00585   );
00586 
00592 template<typename Ordinal, typename Packet, typename Serializer>
00593 int receive(
00594   const Comm<Ordinal>& comm,
00595   const Serializer& serializer,
00596   const int sourceRank, const Ordinal count, Packet recvBuffer[]
00597   );
00598 
00604 template<typename Ordinal, typename Packet>
00605 void readySend(
00606   const Comm<Ordinal>& comm,
00607   const ArrayView<const Packet> &sendBuffer,
00608   const int destRank
00609   );
00610 
00612 template<typename Ordinal, typename Packet>
00613 void
00614 readySend (const Packet sendBuffer[],
00615            const Ordinal count,
00616            const int destRank,
00617            const int tag,
00618            const Comm<Ordinal>& comm);
00619 
00624 template<typename Ordinal, typename Packet>
00625 void readySend(
00626   const Comm<Ordinal>& comm,
00627   const Packet &send,
00628   const int destRank
00629   );
00630 
00636 template<typename Ordinal, typename Packet, typename Serializer>
00637 void readySend(
00638   const Comm<Ordinal>& comm,
00639   const Serializer& serializer,
00640   const ArrayView<const Packet> &sendBuffer,
00641   const int destRank
00642   );
00643 
00648 template<typename Ordinal, typename Packet>
00649 RCP<CommRequest<Ordinal> > isend(
00650   const Comm<Ordinal>& comm,
00651   const ArrayRCP<const Packet> &sendBuffer,
00652   const int destRank
00653   );
00654 
00656 template<typename Ordinal, typename Packet>
00657 RCP<CommRequest<Ordinal> >
00658 isend (const ArrayRCP<const Packet>& sendBuffer,
00659        const int destRank,
00660        const int tag,
00661        const Comm<Ordinal>& comm);
00662 
00667 template<typename Ordinal, typename Packet>
00668 RCP<CommRequest<Ordinal> > isend(
00669   const Comm<Ordinal>& comm,
00670   const RCP<const Packet> &send,
00671   const int destRank
00672   );
00673 
00679 template<typename Ordinal, typename Packet, typename Serializer>
00680 RCP<CommRequest<Ordinal> > isend(
00681   const Comm<Ordinal>& comm,
00682   const Serializer& serializer,
00683   const ArrayRCP<const Packet> &sendBuffer,
00684   const int destRank
00685   );
00686 
00687 
00688 // 2008/07/29: rabartl: ToDo: Add reference semantics version of isend!
00689 
00690 
00700 template<typename Ordinal, typename Packet>
00701 RCP<CommRequest<Ordinal> > ireceive(
00702   const Comm<Ordinal>& comm,
00703   const ArrayRCP<Packet> &recvBuffer,
00704   const int sourceRank
00705   );
00706 
00708 template<typename Ordinal, typename Packet>
00709 RCP<CommRequest<Ordinal> >
00710 ireceive (const ArrayRCP<Packet> &recvBuffer,
00711           const int sourceRank,
00712           const int tag,
00713           const Comm<Ordinal>& comm);
00714 
00726 template<typename Ordinal, typename Packet>
00727 RCP<CommRequest<Ordinal> > ireceive(
00728   const Comm<Ordinal>& comm,
00729   const RCP<Packet> &recv,
00730   const int sourceRank
00731   );
00732 
00738 template<typename Ordinal, typename Packet, typename Serializer>
00739 RCP<CommRequest<Ordinal> > ireceive(
00740   const Comm<Ordinal>& comm,
00741   const Serializer& serializer,
00742   const ArrayRCP<Packet> &recvBuffer,
00743   const int sourceRank
00744   );
00745 
00746 
00747 // 2008/07/29: rabartl: ToDo: Add reference semantics version of ireceive!
00748 
00749 
00757 template<typename Ordinal>
00758 void waitAll(
00759   const Comm<Ordinal>& comm,
00760   const ArrayView<RCP<CommRequest<Ordinal> > > &requests
00761   );
00762 
00792 template<typename Ordinal>
00793 void
00794 waitAll (const Comm<Ordinal>& comm,
00795          const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
00796          const ArrayView<RCP<CommStatus<Ordinal> > >& statuses);
00797 
00821 template<typename Ordinal>
00822 RCP<CommStatus<Ordinal> >
00823 wait (const Comm<Ordinal>& comm, const Ptr<RCP<CommRequest<Ordinal> > >& request);
00824 
00825 //
00826 // Standard reduction subclasses for objects that use value semantics
00827 //
00828 
00829 
00834 template<typename Ordinal, typename Packet>
00835 class SumValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
00836 {
00837 public:
00839   void reduce(
00840     const Ordinal count,
00841     const Packet inBuffer[],
00842     Packet inoutBuffer[]
00843     ) const;
00844 };
00845 
00846 
00855 template<typename Ordinal, typename Packet>
00856 class MinValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
00857 {
00858 public:
00860   void reduce(
00861     const Ordinal count,
00862     const Packet inBuffer[],
00863     Packet inoutBuffer[]
00864     ) const;
00865 };
00866 
00867 
00876 template<typename Ordinal, typename Packet>
00877 class MaxValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
00878 {
00879 public:
00881   void reduce(
00882     const Ordinal count,
00883     const Packet inBuffer[],
00884     Packet inoutBuffer[]
00885     ) const;
00886 };
00887 
00888 
00893 template<typename Ordinal, typename Packet>
00894 class ANDValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
00895 {
00896 public:
00898   void reduce(
00899     const Ordinal count,
00900     const Packet inBuffer[],
00901     Packet inoutBuffer[]
00902     ) const;
00903 };
00904 
00905 
00906 // ////////////////////////////////////////////////////////////
00907 // Implementation details (not for geneal users to mess with)
00908 
00909 
00910 //
00911 // ReductionOp Utilities
00912 //
00913 
00914 
00915 namespace MixMaxUtilities {
00916 
00917 
00918 template<bool isComparable, typename Ordinal, typename Packet>
00919 class Min {};
00920 
00921 
00922 template<typename Ordinal, typename Packet>
00923 class Min<true,Ordinal,Packet> {
00924 public:
00925   static void min(
00926     const Ordinal count,
00927     const Packet inBuffer[],
00928     Packet inoutBuffer[]
00929     )
00930     {
00931       for( int i = 0; i < count; ++i )
00932         inoutBuffer[i] = TEUCHOS_MIN(inoutBuffer[i],inBuffer[i]);
00933     }
00934 };
00935 
00936 
00937 template<typename Ordinal, typename Packet>
00938 class Min<false,Ordinal,Packet> {
00939 public:
00940   static void min(
00941     const Ordinal,
00942     const Packet[],
00943     Packet[]
00944     )
00945     {
00946       TEUCHOS_TEST_FOR_EXCEPTION(
00947         true,std::logic_error,
00948         "Error, the type "<<TypeNameTraits<Packet>::name()
00949         <<" does not support comparison operations!"
00950         );
00951     }
00952 };
00953 
00954 
00955 template<bool isComparable, typename Ordinal, typename Packet>
00956 class Max {};
00957 
00958 
00959 template<typename Ordinal, typename Packet>
00960 class Max<true,Ordinal,Packet> {
00961 public:
00962   static void max(
00963     const Ordinal count,
00964     const Packet inBuffer[],
00965     Packet inoutBuffer[]
00966     )
00967     {
00968       for( int i = 0; i < count; ++i )
00969         inoutBuffer[i] = TEUCHOS_MAX(inoutBuffer[i],inBuffer[i]);
00970     }
00971 };
00972 
00973 
00974 template<typename Ordinal, typename Packet>
00975 class Max<false,Ordinal,Packet> {
00976 public:
00977   static void max(
00978     const Ordinal,
00979     const Packet[],
00980     Packet[]
00981     )
00982     {
00983       TEUCHOS_TEST_FOR_EXCEPTION(
00984         true,std::logic_error,
00985         "Error, the type "<<TypeNameTraits<Packet>::name()
00986         <<" does not support comparison operations!"
00987         );
00988     }
00989 };
00990 
00991 
00992 template<bool isComparable, typename Ordinal, typename Packet>
00993 class AND {};
00994 
00995 
00996 template<typename Ordinal, typename Packet>
00997 class AND<true,Ordinal,Packet> {
00998 public:
00999   static void andOp(
01000     const Ordinal count,
01001     const Packet inBuffer[],
01002     Packet inoutBuffer[]
01003     )
01004     {
01005       for( int i = 0; i < count; ++i )
01006         inoutBuffer[i] = inoutBuffer[i] && inBuffer[i];
01007     }
01008 };
01009 
01010 
01011 template<typename Ordinal, typename Packet>
01012 class AND<false,Ordinal,Packet> {
01013 public:
01014   static void andOp(
01015     const Ordinal,
01016     const Packet[],
01017     Packet[]
01018     )
01019     {
01020       TEUCHOS_TEST_FOR_EXCEPTION(
01021         true,std::logic_error,
01022         "Error, the type "<<TypeNameTraits<Packet>::name()
01023         <<" does not support logical AND operations!"
01024         );
01025     }
01026 };
01027 
01028 
01029 } // namespace MixMaxUtilities
01030 
01031 
01032 template<typename Ordinal, typename Packet>
01033 void SumValueReductionOp<Ordinal,Packet>::reduce(
01034   const Ordinal count,
01035   const Packet inBuffer[],
01036   Packet inoutBuffer[]
01037   ) const
01038 {
01039   for( int i = 0; i < count; ++i )
01040     inoutBuffer[i] += inBuffer[i];
01041 }
01042 
01043 
01044 template<typename Ordinal, typename Packet>
01045 void MinValueReductionOp<Ordinal,Packet>::reduce(
01046   const Ordinal count,
01047   const Packet inBuffer[],
01048   Packet inoutBuffer[]
01049   ) const
01050 {
01051   typedef MixMaxUtilities::Min<ScalarTraits<Packet>::isComparable, Ordinal, Packet> min_type;
01052   min_type::min (count, inBuffer, inoutBuffer);
01053 }
01054 
01055 
01056 template<typename Ordinal, typename Packet>
01057 void MaxValueReductionOp<Ordinal,Packet>::reduce(
01058   const Ordinal count,
01059   const Packet inBuffer[],
01060   Packet inoutBuffer[]
01061   ) const
01062 {
01063   typedef MixMaxUtilities::Max<ScalarTraits<Packet>::isComparable, Ordinal, Packet> max_type;
01064   max_type::max (count,inBuffer,inoutBuffer);
01065 }
01066 
01067 
01068 template<typename Ordinal, typename Packet>
01069 void ANDValueReductionOp<Ordinal,Packet>::reduce(
01070   const Ordinal count,
01071   const Packet inBuffer[],
01072   Packet inoutBuffer[]
01073   ) const
01074 {
01075   typedef MixMaxUtilities::AND<ScalarTraits<Packet>::isComparable, Ordinal, Packet> and_type;
01076   and_type::andOp (count, inBuffer, inoutBuffer);
01077 }
01078 
01079 
01080 } // namespace Teuchos
01081 
01082 
01083 // //////////////////////////
01084 // Template implemenations
01085 
01086 
01087 //
01088 // ReductionOp utilities
01089 //
01090 
01091 
01092 namespace Teuchos {
01093 
01094 
01095 // Not for the general user to use! I am returning a raw ReducionOp* pointer
01096 // to avoid the overhead of using RCP. However, given the use case
01097 // this is just fine since I can just use std::auto_ptr to make sure things
01098 // are deleted correctly.
01099 template<typename Ordinal, typename Packet>
01100 ValueTypeReductionOp<Ordinal,Packet>*
01101 createOp (const EReductionType reductType)
01102 {
01103   typedef ScalarTraits<Packet> ST;
01104   switch (reductType) {
01105     case REDUCE_SUM: {
01106       return new SumValueReductionOp<Ordinal,Packet> ();
01107     }
01108     case REDUCE_MIN: {
01109       TEUCHOS_TEST_FOR_EXCEPTION(
01110         ! ST::isComparable, std::invalid_argument, "Teuchos::createOp"
01111         "(EReductionType): The Packet type " << TypeNameTraits<Packet>::name ()
01112         << " is not less-than comparable, so it does not make sense to do a "
01113         "MIN reduction with it.");
01114       return new MinValueReductionOp<Ordinal,Packet> ();
01115     }
01116     case REDUCE_MAX: {
01117       TEUCHOS_TEST_FOR_EXCEPTION(
01118         ! ST::isComparable, std::invalid_argument, "Teuchos::createOp"
01119         "(EReductionType): The Packet type " << TypeNameTraits<Packet>::name ()
01120         << " is not less-than comparable, so it does not make sense to do a "
01121         "MAX reduction with it.");
01122       return new MaxValueReductionOp<Ordinal,Packet> ();
01123     }
01124     case REDUCE_AND: {
01125       return new ANDValueReductionOp<Ordinal, Packet> ();
01126     }
01127     default:
01128       TEUCHOS_TEST_FOR_EXCEPTION(
01129         true, std::invalid_argument, "Teuchos::createOp(EReductionType): "
01130         "Invalid EReductionType value " << reductType << ".  Valid values "
01131         "include REDUCE_SUM, REDUCE_MIN, REDUCE_MAX, and REDUCE_AND.");
01132   }
01133 }
01134 
01135 
01136 } // namespace Teuchos
01137 
01138 
01139 //
01140 // Teuchos::Comm wrapper functions
01141 //
01142 
01143 
01144 template<typename Ordinal>
01145 int Teuchos::rank(const Comm<Ordinal>& comm)
01146 {
01147   return comm.getRank();
01148 }
01149 
01150 
01151 template<typename Ordinal>
01152 int Teuchos::size(const Comm<Ordinal>& comm)
01153 {
01154   return comm.getSize();
01155 }
01156 
01157 
01158 template<typename Ordinal>
01159 void Teuchos::barrier(const Comm<Ordinal>& comm)
01160 {
01161   TEUCHOS_COMM_TIME_MONITOR(
01162     "Teuchos::CommHelpers: barrier<"
01163     <<OrdinalTraits<Ordinal>::name()
01164     <<">()"
01165     );
01166   comm.barrier();
01167 }
01168 
01169 
01170 template<typename Ordinal, typename Packet>
01171 void Teuchos::broadcast(
01172   const Comm<Ordinal>& comm,
01173   const int rootRank, const Ordinal count, Packet buffer[]
01174   )
01175 {
01176   TEUCHOS_COMM_TIME_MONITOR(
01177     "Teuchos::CommHelpers: broadcast<"
01178     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01179     <<">( value type )"
01180     );
01181   ValueTypeSerializationBuffer<Ordinal,Packet>
01182     charBuffer(count,buffer);
01183   comm.broadcast(
01184     rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
01185     );
01186 }
01187 
01188 
01189 template<typename Ordinal, typename Packet>
01190 void Teuchos::broadcast(
01191   const Comm<Ordinal>& comm,
01192   const int rootRank,
01193   const ArrayView<Packet> &buffer
01194   )
01195 {
01196   broadcast<Ordinal, Packet>(comm, rootRank, buffer.size(), buffer.getRawPtr() );
01197 }
01198 
01199 
01200 template<typename Ordinal, typename Packet>
01201 void Teuchos::broadcast(
01202   const Comm<Ordinal>& comm,
01203   const int rootRank, Packet *object
01204   )
01205 {
01206   broadcast<Ordinal,Packet>(comm,rootRank,1,object);
01207 }
01208 
01209 
01210 template<typename Ordinal, typename Packet>
01211 void Teuchos::broadcast(
01212   const Comm<Ordinal>& comm,
01213   const int rootRank, const Ptr<Packet> &object
01214   )
01215 {
01216   broadcast<Ordinal,Packet>(comm,rootRank,1,object.getRawPtr());
01217 }
01218 
01219 
01220 template<typename Ordinal, typename Packet>
01221 void Teuchos::broadcast(
01222   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
01223   const int rootRank, const Ordinal count, Packet*const buffer[]
01224   )
01225 {
01226   TEUCHOS_COMM_TIME_MONITOR(
01227     "Teuchos::CommHelpers: broadcast<"
01228     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01229     <<">( reference type )"
01230     );
01231   ReferenceTypeSerializationBuffer<Ordinal,Packet>
01232     charBuffer(serializer, count, buffer);
01233   comm.broadcast(
01234     rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
01235     );
01236 }
01237 
01238 
01239 template<typename Ordinal, typename Packet>
01240 void Teuchos::broadcast(
01241   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
01242   const int rootRank, const ArrayView<const Ptr<Packet> > &buffer
01243   )
01244 {
01245   Array<Packet*> bufferPtrArray;
01246   for (int i = 0; i < buffer.size(); ++i) {
01247     bufferPtrArray.push_back(buffer[i].getRawPtr());
01248   }
01249   broadcast<Ordinal,Packet>(comm, serializer, rootRank,
01250     buffer.size(), bufferPtrArray.getRawPtr());
01251 }
01252 
01253 template<typename Ordinal, typename Packet, typename Serializer>
01254 void Teuchos::broadcast(
01255   const Comm<Ordinal>& comm,
01256   const Serializer& serializer,
01257   const int rootRank, const Ordinal count, Packet buffer[]
01258   )
01259 {
01260   TEUCHOS_COMM_TIME_MONITOR(
01261     "Teuchos::CommHelpers: broadcast<"
01262     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01263     <<">( value type )"
01264     );
01265   ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
01266     charBuffer(count,buffer,rcp(&serializer,false));
01267   comm.broadcast(
01268     rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
01269     );
01270 }
01271 
01272 
01273 template<typename Ordinal, typename Packet>
01274 void Teuchos::gatherAll(
01275   const Comm<Ordinal>& comm,
01276   const Ordinal sendCount, const Packet sendBuffer[],
01277   const Ordinal recvCount, Packet recvBuffer[]
01278   )
01279 {
01280   TEUCHOS_COMM_TIME_MONITOR(
01281     "Teuchos::CommHelpers: gatherAll<"
01282     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01283     <<">( value type )"
01284     );
01285   ConstValueTypeSerializationBuffer<Ordinal,Packet>
01286     charSendBuffer(sendCount,sendBuffer);
01287   ValueTypeSerializationBuffer<Ordinal,Packet>
01288     charRecvBuffer(recvCount,recvBuffer);
01289   comm.gatherAll(
01290     charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
01291     ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
01292     );
01293 }
01294 
01295 template<typename Ordinal, typename Packet>
01296 void
01297 Teuchos::gather (const Packet sendBuf[],
01298                  const Ordinal sendCount,
01299                  Packet recvBuf[],
01300                  const Ordinal recvCount,
01301                  const int root,
01302                  const Comm<Ordinal>& comm)
01303 {
01304   TEUCHOS_COMM_TIME_MONITOR(
01305     "Teuchos::CommHelpers: gather<"
01306     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01307     <<">( value type )"
01308     );
01309   ConstValueTypeSerializationBuffer<Ordinal,Packet>
01310     charSendBuffer (sendCount, sendBuf);
01311   ValueTypeSerializationBuffer<Ordinal,Packet>
01312     charRecvBuffer (recvCount, recvBuf);
01313   comm.gather (charSendBuffer.getBytes (),
01314                charSendBuffer.getCharBuffer (),
01315                charRecvBuffer.getBytes (),
01316                charRecvBuffer.getCharBuffer (),
01317                root);
01318 }
01319 
01320 template<typename Ordinal, typename Packet>
01321 void
01322 Teuchos::gatherv (const Packet sendBuf[],
01323                   const Ordinal sendCount,
01324                   Packet recvBuf[],
01325                   const Ordinal recvCounts[],
01326                   const Ordinal displs[],
01327                   const int root,
01328                   const Comm<Ordinal>& comm)
01329 {
01330   // Ordinal totalRecvCount = 0;
01331 
01332   // // In order to get the right output buffer length, we have to sum
01333   // // the receive counts from all the processes in the communicator.
01334   // const Ordinal numProcs = as<Ordinal> (comm->getSize ());
01335   // for (Ordinal k = 0; k < as<Ordinal> (numProcs); ++k) {
01336   //   totalRecvCount += recvCounts[k];
01337   // }
01338 
01339   // // FIXME (mfh 16 Apr 2013) We also have to redo the displacements.
01340 
01341   // ConstValueTypeSerializationBuffer<Ordinal,Packet>
01342   //   charSendBuffer (sendCount, sendBuf);
01343   // ValueTypeSerializationBuffer<Ordinal,Packet>
01344   //   charRecvBuffer (totalRecvCount, recvBuf);
01345   // comm.gatherv (charSendBuffer.getBytes (),
01346   //               charSendBuffer.getCharBuffer (),
01347   //               charRecvBuffer.getBytes (),
01348   //               charRecvBuffer.getCharBuffer (),
01349   //               root);
01350   TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
01351     "Teuchos::gatherv: The general case is not implemented.");
01352 }
01353 
01354 template<typename Ordinal, typename Packet>
01355 void Teuchos::gatherAll(
01356   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
01357   const Ordinal sendCount, const Packet*const sendBuffer[],
01358   const Ordinal recvCount, Packet*const recvBuffer[]
01359   )
01360 {
01361   TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
01362 }
01363 
01364 template<typename Ordinal, typename Packet, typename Serializer>
01365 void Teuchos::gatherAll(
01366   const Comm<Ordinal>& comm,
01367   const Serializer& serializer,
01368   const Ordinal sendCount, const Packet sendBuffer[],
01369   const Ordinal recvCount, Packet recvBuffer[]
01370   )
01371 {
01372   TEUCHOS_COMM_TIME_MONITOR(
01373     "Teuchos::CommHelpers: gatherAll<"
01374     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01375     <<">( value type )"
01376     );
01377   ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
01378     charSendBuffer(sendCount,sendBuffer,rcp(&serializer,false));
01379   ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
01380     charRecvBuffer(recvCount,recvBuffer,rcp(&serializer,false));
01381   comm.gatherAll(
01382     charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
01383     ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
01384     );
01385 }
01386 
01387 
01388 template<typename Ordinal, typename Packet>
01389 void Teuchos::reduceAll(
01390   const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp
01391   ,const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
01392   )
01393 {
01394   TEUCHOS_COMM_TIME_MONITOR(
01395     "Teuchos::CommHelpers: reduceAll<"
01396     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01397     <<">( value type, user-defined op )"
01398     );
01399   ConstValueTypeSerializationBuffer<Ordinal,Packet>
01400     charSendBuffer(count,sendBuffer);
01401   ValueTypeSerializationBuffer<Ordinal,Packet>
01402     charGlobalReducts(count,globalReducts);
01403   CharToValueTypeReductionOp<Ordinal,Packet>
01404     charReductOp(rcp(&reductOp,false));
01405   comm.reduceAll(
01406     charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
01407     ,charGlobalReducts.getCharBuffer()
01408     );
01409 }
01410 
01411 
01412 template<typename Ordinal, typename Packet>
01413 void Teuchos::reduceAll(
01414   const Comm<Ordinal>& comm, const EReductionType reductType,
01415   const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
01416   )
01417 {
01418   TEUCHOS_COMM_TIME_MONITOR(
01419     "Teuchos::CommHelpers: reduceAll<"
01420     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01421     <<">( value type, "<<toString(reductType)<<" )"
01422     );
01423   std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
01424     reductOp(createOp<Ordinal,Packet>(reductType));
01425   reduceAll(comm,*reductOp,count,sendBuffer,globalReducts);
01426 }
01427 
01428 
01429 namespace Teuchos {
01430 
01431 #ifdef TEUCHOS_HAVE_COMPLEX
01432 // Specialization for Ordinal=int and Packet=std::complex<double>.
01433 template<>
01434 TEUCHOSCOMM_LIB_DLL_EXPORT void
01435 reduceAll<int, std::complex<double> > (const Comm<int>& comm,
01436                                        const EReductionType reductType,
01437                                        const int count,
01438                                        const std::complex<double> sendBuffer[],
01439                                        std::complex<double> globalReducts[]);
01440 template<>
01441 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01442 ireceive<int, std::complex<double> > (const Comm<int>& comm,
01443                                       const ArrayRCP<std::complex<double> >& recvBuffer,
01444                                       const int sourceRank);
01445 template<>
01446 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01447 ireceive<int, std::complex<double> > (const ArrayRCP<std::complex<double> > &recvBuffer,
01448                                       const int sourceRank,
01449                                       const int tag,
01450                                       const Comm<int>& comm);
01451 template<>
01452 TEUCHOSCOMM_LIB_DLL_EXPORT void
01453 send<int, std::complex<double> > (const Comm<int>& comm,
01454                                   const int count,
01455                                   const std::complex<double> sendBuffer[],
01456                                   const int destRank);
01457 template<>
01458 TEUCHOSCOMM_LIB_DLL_EXPORT void
01459 send<int, std::complex<double> > (const std::complex<double> sendBuffer[],
01460                                   const int count,
01461                                   const int destRank,
01462                                   const int tag,
01463                                   const Comm<int>& comm);
01464 template<>
01465 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01466 isend<int, std::complex<double> > (const ArrayRCP<const std::complex<double> >& sendBuffer,
01467                                    const int destRank,
01468                                    const int tag,
01469                                    const Comm<int>& comm);
01470 
01471 // Specialization for Ordinal=int and Packet=std::complex<float>.
01472 template<>
01473 TEUCHOSCOMM_LIB_DLL_EXPORT void
01474 reduceAll<int, std::complex<float> > (const Comm<int>& comm,
01475                                       const EReductionType reductType,
01476                                       const int count,
01477                                       const std::complex<float> sendBuffer[],
01478                                       std::complex<float> globalReducts[]);
01479 template<>
01480 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01481 ireceive<int, std::complex<float> > (const Comm<int>& comm,
01482                                      const ArrayRCP<std::complex<float> >& recvBuffer,
01483                                      const int sourceRank);
01484 template<>
01485 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01486 ireceive<int, std::complex<float> > (const ArrayRCP<std::complex<float> > &recvBuffer,
01487                                      const int sourceRank,
01488                                      const int tag,
01489                                      const Comm<int>& comm);
01490 template<>
01491 TEUCHOSCOMM_LIB_DLL_EXPORT void
01492 send<int, std::complex<float> > (const Comm<int>& comm,
01493                                  const int count,
01494                                  const std::complex<float> sendBuffer[],
01495                                  const int destRank);
01496 template<>
01497 TEUCHOSCOMM_LIB_DLL_EXPORT void
01498 send<int, std::complex<float> > (const std::complex<float> sendBuffer[],
01499                                  const int count,
01500                                  const int destRank,
01501                                  const int tag,
01502                                  const Comm<int>& comm);
01503 template<>
01504 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01505 isend<int, std::complex<float> > (const ArrayRCP<const std::complex<float> >& sendBuffer,
01506                                   const int destRank,
01507                                   const int tag,
01508                                   const Comm<int>& comm);
01509 #endif // TEUCHOS_HAVE_COMPLEX
01510 
01511 // Specialization for Ordinal=int and Packet=double.
01512 template<>
01513 TEUCHOSCOMM_LIB_DLL_EXPORT void
01514 reduceAll<int, double> (const Comm<int>& comm,
01515                         const EReductionType reductType,
01516                         const int count,
01517                         const double sendBuffer[],
01518                         double globalReducts[]);
01519 template<>
01520 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01521 ireceive<int, double> (const Comm<int>& comm,
01522                        const ArrayRCP<double>& recvBuffer,
01523                        const int sourceRank);
01524 template<>
01525 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01526 ireceive<int, double> (const ArrayRCP<double> &recvBuffer,
01527                        const int sourceRank,
01528                        const int tag,
01529                        const Comm<int>& comm);
01530 template<>
01531 TEUCHOSCOMM_LIB_DLL_EXPORT void
01532 send<int, double> (const Comm<int>& comm,
01533                    const int count,
01534                    const double sendBuffer[],
01535                    const int destRank);
01536 template<>
01537 TEUCHOSCOMM_LIB_DLL_EXPORT void
01538 send<int, double> (const double sendBuffer[],
01539                    const int count,
01540                    const int destRank,
01541                    const int tag,
01542                    const Comm<int>& comm);
01543 template<>
01544 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01545 isend<int, double> (const ArrayRCP<const double>& sendBuffer,
01546                     const int destRank,
01547                     const int tag,
01548                     const Comm<int>& comm);
01549 
01550 // Specialization for Ordinal=int and Packet=float.
01551 template<>
01552 TEUCHOSCOMM_LIB_DLL_EXPORT void
01553 reduceAll<int, float> (const Comm<int>& comm,
01554                        const EReductionType reductType,
01555                        const int count,
01556                        const float sendBuffer[],
01557                        float globalReducts[]);
01558 template<>
01559 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01560 ireceive<int, float> (const Comm<int>& comm,
01561                       const ArrayRCP<float>& recvBuffer,
01562                       const int sourceRank);
01563 template<>
01564 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01565 ireceive<int, float> (const ArrayRCP<float> &recvBuffer,
01566                       const int sourceRank,
01567                       const int tag,
01568                       const Comm<int>& comm);
01569 template<>
01570 TEUCHOSCOMM_LIB_DLL_EXPORT void
01571 send<int, float> (const Comm<int>& comm,
01572                   const int count,
01573                   const float sendBuffer[],
01574                   const int destRank);
01575 template<>
01576 TEUCHOSCOMM_LIB_DLL_EXPORT void
01577 send<int, float> (const float sendBuffer[],
01578                   const int count,
01579                   const int destRank,
01580                   const int tag,
01581                   const Comm<int>& comm);
01582 template<>
01583 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01584 isend<int, float> (const ArrayRCP<const float>& sendBuffer,
01585                    const int destRank,
01586                    const int tag,
01587                    const Comm<int>& comm);
01588 
01589 #ifdef TEUCHOS_HAVE_LONG_LONG_INT
01590 // Specialization for Ordinal=int and Packet=long long.
01591 template<>
01592 TEUCHOSCOMM_LIB_DLL_EXPORT void
01593 gather<int, long long> (const long long sendBuf[],
01594                         const int sendCount,
01595                         long long recvBuf[],
01596                         const int recvCount,
01597                         const int root,
01598                         const Comm<int>& comm);
01599 template<>
01600 TEUCHOSCOMM_LIB_DLL_EXPORT void
01601 gatherv<int, long long> (const long long sendBuf[],
01602                          const int sendCount,
01603                          long long recvBuf[],
01604                          const int recvCounts[],
01605                          const int displs[],
01606                          const int root,
01607                          const Comm<int>& comm);
01608 template<>
01609 TEUCHOSCOMM_LIB_DLL_EXPORT void
01610 reduceAll<int, long long> (const Comm<int>& comm,
01611                            const EReductionType reductType,
01612                            const int count,
01613                            const long long sendBuffer[],
01614                            long long globalReducts[]);
01615 template<>
01616 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01617 ireceive<int, long long> (const Comm<int>& comm,
01618                           const ArrayRCP<long long>& recvBuffer,
01619                           const int sourceRank);
01620 template<>
01621 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01622 ireceive<int, long long> (const ArrayRCP<long long> &recvBuffer,
01623                           const int sourceRank,
01624                           const int tag,
01625                           const Comm<int>& comm);
01626 template<>
01627 TEUCHOSCOMM_LIB_DLL_EXPORT void
01628 send<int, long long> (const Comm<int>& comm,
01629                       const int count,
01630                       const long long sendBuffer[],
01631                       const int destRank);
01632 template<>
01633 TEUCHOSCOMM_LIB_DLL_EXPORT void
01634 send<int, long long> (const long long sendBuffer[],
01635                       const int count,
01636                       const int destRank,
01637                       const int tag,
01638                       const Comm<int>& comm);
01639 template<>
01640 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01641 isend<int, long long> (const ArrayRCP<const long long>& sendBuffer,
01642                        const int destRank,
01643                        const int tag,
01644                        const Comm<int>& comm);
01645 
01646 // Specialization for Ordinal=int and Packet=unsigned long long.
01647 template<>
01648 TEUCHOSCOMM_LIB_DLL_EXPORT void
01649 gather<int, unsigned long long> (const unsigned long long sendBuf[],
01650                                  const int sendCount,
01651                                  unsigned long long recvBuf[],
01652                                  const int recvCount,
01653                                  const int root,
01654                                  const Comm<int>& comm);
01655 template<>
01656 TEUCHOSCOMM_LIB_DLL_EXPORT void
01657 gatherv<int, unsigned long long> (const unsigned long long sendBuf[],
01658                                   const int sendCount,
01659                                   unsigned long long recvBuf[],
01660                                   const int recvCounts[],
01661                                   const int displs[],
01662                                   const int root,
01663                                   const Comm<int>& comm);
01664 template<>
01665 TEUCHOSCOMM_LIB_DLL_EXPORT void
01666 reduceAll<int, unsigned long long> (const Comm<int>& comm,
01667                                     const EReductionType reductType,
01668                                     const int count,
01669                                     const unsigned long long sendBuffer[],
01670                                     unsigned long long globalReducts[]);
01671 template<>
01672 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01673 ireceive<int, unsigned long long> (const Comm<int>& comm,
01674                                    const ArrayRCP<unsigned long long>& recvBuffer,
01675                                    const int sourceRank);
01676 template<>
01677 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01678 ireceive<int, unsigned long long> (const ArrayRCP<unsigned long long> &recvBuffer,
01679                                    const int sourceRank,
01680                                    const int tag,
01681                                    const Comm<int>& comm);
01682 template<>
01683 TEUCHOSCOMM_LIB_DLL_EXPORT void
01684 send<int, unsigned long long> (const Comm<int>& comm,
01685                                const int count,
01686                                const unsigned long long sendBuffer[],
01687                                const int destRank);
01688 template<>
01689 TEUCHOSCOMM_LIB_DLL_EXPORT void
01690 send<int, unsigned long long> (const unsigned long long sendBuffer[],
01691                                const int count,
01692                                const int destRank,
01693                                const int tag,
01694                                const Comm<int>& comm);
01695 template<>
01696 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01697 isend<int, unsigned long long> (const ArrayRCP<const unsigned long long>& sendBuffer,
01698                                 const int destRank,
01699                                 const int tag,
01700                                 const Comm<int>& comm);
01701 #endif // TEUCHOS_HAVE_LONG_LONG_INT
01702 
01703 // Specialization for Ordinal=int and Packet=long.
01704 template<>
01705 TEUCHOSCOMM_LIB_DLL_EXPORT void
01706 gather<int, long> (const long sendBuf[],
01707                    const int sendCount,
01708                    long recvBuf[],
01709                    const int recvCount,
01710                    const int root,
01711                    const Comm<int>& comm);
01712 template<>
01713 TEUCHOSCOMM_LIB_DLL_EXPORT void
01714 gatherv<int, long> (const long sendBuf[],
01715                     const int sendCount,
01716                     long recvBuf[],
01717                     const int recvCounts[],
01718                     const int displs[],
01719                     const int root,
01720                     const Comm<int>& comm);
01721 template<>
01722 TEUCHOSCOMM_LIB_DLL_EXPORT void
01723 reduceAll<int, long> (const Comm<int>& comm,
01724                       const EReductionType reductType,
01725                       const int count,
01726                       const long sendBuffer[],
01727                       long globalReducts[]);
01728 template<>
01729 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01730 ireceive<int, long> (const Comm<int>& comm,
01731                      const ArrayRCP<long>& recvBuffer,
01732                      const int sourceRank);
01733 template<>
01734 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01735 ireceive<int, long> (const ArrayRCP<long> &recvBuffer,
01736                      const int sourceRank,
01737                      const int tag,
01738                      const Comm<int>& comm);
01739 template<>
01740 TEUCHOSCOMM_LIB_DLL_EXPORT void
01741 send<int, long> (const Comm<int>& comm,
01742                  const int count,
01743                  const long sendBuffer[],
01744                  const int destRank);
01745 template<>
01746 TEUCHOSCOMM_LIB_DLL_EXPORT void
01747 send<int, long> (const long sendBuffer[],
01748                  const int count,
01749                  const int destRank,
01750                  const int tag,
01751                  const Comm<int>& comm);
01752 template<>
01753 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01754 isend<int, long> (const ArrayRCP<const long>& sendBuffer,
01755                   const int destRank,
01756                   const int tag,
01757                   const Comm<int>& comm);
01758 
01759 // Specialization for Ordinal=int and Packet=unsigned long.
01760 template<>
01761 TEUCHOSCOMM_LIB_DLL_EXPORT void
01762 gather<int, unsigned long> (const unsigned long sendBuf[],
01763                             const int sendCount,
01764                             unsigned long recvBuf[],
01765                             const int recvCount,
01766                             const int root,
01767                             const Comm<int>& comm);
01768 template<>
01769 TEUCHOSCOMM_LIB_DLL_EXPORT void
01770 gatherv<int, unsigned long> (const unsigned long sendBuf[],
01771                              const int sendCount,
01772                              unsigned long recvBuf[],
01773                              const int recvCounts[],
01774                              const int displs[],
01775                              const int root,
01776                              const Comm<int>& comm);
01777 template<>
01778 TEUCHOSCOMM_LIB_DLL_EXPORT void
01779 reduceAll<int, unsigned long> (const Comm<int>& comm,
01780                                const EReductionType reductType,
01781                                const int count,
01782                                const unsigned long sendBuffer[],
01783                                unsigned long globalReducts[]);
01784 template<>
01785 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01786 ireceive<int, unsigned long> (const Comm<int>& comm,
01787                               const ArrayRCP<unsigned long>& recvBuffer,
01788                               const int sourceRank);
01789 template<>
01790 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01791 ireceive<int, unsigned long> (const ArrayRCP<unsigned long> &recvBuffer,
01792                               const int sourceRank,
01793                               const int tag,
01794                               const Comm<int>& comm);
01795 template<>
01796 TEUCHOSCOMM_LIB_DLL_EXPORT void
01797 send<int, unsigned long> (const Comm<int>& comm,
01798                           const int count,
01799                           const unsigned long sendBuffer[],
01800                           const int destRank);
01801 template<>
01802 TEUCHOSCOMM_LIB_DLL_EXPORT void
01803 send<int, unsigned long> (const unsigned long sendBuffer[],
01804                           const int count,
01805                           const int destRank,
01806                           const int tag,
01807                           const Comm<int>& comm);
01808 template<>
01809 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01810 isend<int, unsigned long> (const ArrayRCP<const unsigned long>& sendBuffer,
01811                            const int destRank,
01812                            const int tag,
01813                            const Comm<int>& comm);
01814 
01815 // Specialization for Ordinal=int and Packet=int.
01816 template<>
01817 TEUCHOSCOMM_LIB_DLL_EXPORT void
01818 gather<int, int> (const int sendBuf[],
01819                   const int sendCount,
01820                   int recvBuf[],
01821                   const int recvCount,
01822                   const int root,
01823                   const Comm<int>& comm);
01824 template<>
01825 TEUCHOSCOMM_LIB_DLL_EXPORT void
01826 gatherv<int, int> (const int sendBuf[],
01827                    const int sendCount,
01828                    int recvBuf[],
01829                    const int recvCounts[],
01830                    const int displs[],
01831                    const int root,
01832                    const Comm<int>& comm);
01833 template<>
01834 TEUCHOSCOMM_LIB_DLL_EXPORT void
01835 reduceAll<int, int> (const Comm<int>& comm,
01836                      const EReductionType reductType,
01837                      const int count,
01838                      const int sendBuffer[],
01839                      int globalReducts[]);
01840 // mfh 09 Apr 2013: We provide a full specialization of
01841 // reduceAllAndScatter, because it is an important part of
01842 // Tpetra::Distributor initialization.
01843 template<>
01844 TEUCHOSCOMM_LIB_DLL_EXPORT void
01845 reduceAllAndScatter<int, int> (const Comm<int>& comm,
01846                                const EReductionType reductType,
01847                                const int sendCount,
01848                                const int sendBuffer[],
01849                                const int recvCounts[],
01850                                int myGlobalReducts[]);
01851 template<>
01852 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01853 ireceive<int, int> (const Comm<int>& comm,
01854                     const ArrayRCP<int>& recvBuffer,
01855                     const int sourceRank);
01856 template<>
01857 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01858 ireceive<int, int> (const ArrayRCP<int> &recvBuffer,
01859                     const int sourceRank,
01860                     const int tag,
01861                     const Comm<int>& comm);
01862 template<>
01863 TEUCHOSCOMM_LIB_DLL_EXPORT void
01864 send<int, int> (const Comm<int>& comm,
01865                 const int count,
01866                 const int sendBuffer[],
01867                 const int destRank);
01868 template<>
01869 TEUCHOSCOMM_LIB_DLL_EXPORT void
01870 send<int, int> (const int sendBuffer[],
01871                 const int count,
01872                 const int destRank,
01873                 const int tag,
01874                 const Comm<int>& comm);
01875 template<>
01876 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01877 isend<int, int> (const ArrayRCP<const int>& sendBuffer,
01878                  const int destRank,
01879                  const int tag,
01880                  const Comm<int>& comm);
01881 
01882 // Specialization for Ordinal=int and Packet=unsigned int.
01883 template<>
01884 TEUCHOSCOMM_LIB_DLL_EXPORT void
01885 gather<int, unsigned int> (const unsigned int sendBuf[],
01886                            const int sendCount,
01887                            unsigned int recvBuf[],
01888                            const int recvCount,
01889                            const int root,
01890                            const Comm<int>& comm);
01891 template<>
01892 TEUCHOSCOMM_LIB_DLL_EXPORT void
01893 gatherv<int, unsigned int> (const unsigned int sendBuf[],
01894                             const int sendCount,
01895                             unsigned int recvBuf[],
01896                             const int recvCounts[],
01897                             const int displs[],
01898                             const int root,
01899                             const Comm<int>& comm);
01900 template<>
01901 TEUCHOSCOMM_LIB_DLL_EXPORT void
01902 reduceAll<int, unsigned int> (const Comm<int>& comm,
01903                               const EReductionType reductType,
01904                               const int count,
01905                               const unsigned int sendBuffer[],
01906                               unsigned int globalReducts[]);
01907 template<>
01908 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01909 ireceive<int, unsigned int> (const Comm<int>& comm,
01910                              const ArrayRCP<unsigned int>& recvBuffer,
01911                              const int sourceRank);
01912 template<>
01913 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01914 ireceive<int, unsigned int> (const ArrayRCP<unsigned int> &recvBuffer,
01915                              const int sourceRank,
01916                              const int tag,
01917                              const Comm<int>& comm);
01918 template<>
01919 TEUCHOSCOMM_LIB_DLL_EXPORT void
01920 send<int, unsigned int> (const Comm<int>& comm,
01921                          const int count,
01922                          const unsigned int sendBuffer[],
01923                          const int destRank);
01924 template<>
01925 TEUCHOSCOMM_LIB_DLL_EXPORT void
01926 send<int, unsigned int> (const unsigned int sendBuffer[],
01927                          const int count,
01928                          const int destRank,
01929                          const int tag,
01930                          const Comm<int>& comm);
01931 template<>
01932 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01933 isend<int, unsigned int> (const ArrayRCP<const unsigned int>& sendBuffer,
01934                           const int destRank,
01935                           const int tag,
01936                           const Comm<int>& comm);
01937 
01938 // Specialization for Ordinal=int and Packet=short.
01939 template<>
01940 TEUCHOSCOMM_LIB_DLL_EXPORT void
01941 gather<int, short> (const short sendBuf[],
01942                     const int sendCount,
01943                     short recvBuf[],
01944                     const int recvCount,
01945                     const int root,
01946                     const Comm<int>& comm);
01947 template<>
01948 TEUCHOSCOMM_LIB_DLL_EXPORT void
01949 gatherv<int, short> (const short sendBuf[],
01950                      const int sendCount,
01951                      short recvBuf[],
01952                      const int recvCounts[],
01953                      const int displs[],
01954                      const int root,
01955                      const Comm<int>& comm);
01956 template<>
01957 TEUCHOSCOMM_LIB_DLL_EXPORT void
01958 reduceAll<int, short> (const Comm<int>& comm,
01959                        const EReductionType reductType,
01960                        const int count,
01961                        const short sendBuffer[],
01962                        short globalReducts[]);
01963 template<>
01964 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01965 ireceive<int, short> (const Comm<int>& comm,
01966                       const ArrayRCP<short>& recvBuffer,
01967                       const int sourceRank);
01968 template<>
01969 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01970 ireceive<int, short> (const ArrayRCP<short> &recvBuffer,
01971                       const int sourceRank,
01972                       const int tag,
01973                       const Comm<int>& comm);
01974 template<>
01975 TEUCHOSCOMM_LIB_DLL_EXPORT void
01976 send<int, short> (const Comm<int>& comm,
01977                   const int count,
01978                   const short sendBuffer[],
01979                   const int destRank);
01980 template<>
01981 TEUCHOSCOMM_LIB_DLL_EXPORT void
01982 send<int, short> (const short sendBuffer[],
01983                   const int count,
01984                   const int destRank,
01985                   const int tag,
01986                   const Comm<int>& comm);
01987 template<>
01988 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01989 isend<int, short> (const ArrayRCP<const short>& sendBuffer,
01990                    const int destRank,
01991                    const int tag,
01992                    const Comm<int>& comm);
01993 
01994 // mfh 18 Oct 2012: The specialization for Packet=char seems to be
01995 // causing problems such as the following:
01996 //
01997 // http://testing.sandia.gov/cdash/testDetails.php?test=9909246&build=747699
01998 //
01999 // I am disabling it for now.  This should revert back to the old
02000 // behavior for Packet=char.  That should fix the Tpetra errors, since
02001 // many Tpetra objects inherit from DistObject<char, ...>.
02002 #if 0
02003 // Specialization for Ordinal=int and Packet=char.
02004 template<>
02005 TEUCHOSCOMM_LIB_DLL_EXPORT void
02006 reduceAll<int, char> (const Comm<int>& comm,
02007                       const EReductionType reductType,
02008                       const int count,
02009                       const char sendBuffer[],
02010                       char globalReducts[]);
02011 #endif // 0
02012 } // namespace Teuchos
02013 
02014 
02015 template<typename Ordinal, typename Packet>
02016 void Teuchos::reduceAll(
02017   const Comm<Ordinal>& comm, const EReductionType reductType
02018   ,const Packet &send, const Ptr<Packet> &globalReduct
02019   )
02020 {
02021   // mfh 17 Oct 2012: This will invoke the above specializations for
02022   // general count, so we don't need to specialize this function.
02023   reduceAll<Ordinal,Packet>(comm, reductType, 1, &send, &*globalReduct);
02024 }
02025 
02026 
02027 template<typename Ordinal, typename Packet>
02028 void Teuchos::reduceAll(
02029   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
02030   const ReferenceTypeReductionOp<Ordinal,Packet> &reductOp,
02031   const Ordinal count, const Packet*const sendBuffer[], Packet*const globalReducts[]
02032   )
02033 {
02034   TEUCHOS_COMM_TIME_MONITOR(
02035     "Teuchos::CommHelpers: reduceAll<"
02036     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02037     <<">( reference type )"
02038     );
02039   ConstReferenceTypeSerializationBuffer<Ordinal,Packet>
02040     charSendBuffer(serializer,count,sendBuffer);
02041   ReferenceTypeSerializationBuffer<Ordinal,Packet>
02042     charGlobalReducts(serializer,count,globalReducts);
02043   CharToReferenceTypeReductionOp<Ordinal,Packet>
02044     charReductOp(rcp(&serializer,false),rcp(&reductOp,false));
02045   comm.reduceAll(
02046     charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
02047     ,charGlobalReducts.getCharBuffer()
02048     );
02049 }
02050 
02051 template<typename Ordinal, typename Packet, typename Serializer>
02052 void Teuchos::reduceAll(
02053   const Comm<Ordinal>& comm,
02054   const Serializer& serializer,
02055   const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
02056   const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
02057   )
02058 {
02059   TEUCHOS_COMM_TIME_MONITOR(
02060     "Teuchos::CommHelpers: reduceAll<"
02061     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02062     <<">( value type, user-defined op )"
02063     );
02064   ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
02065     charSendBuffer(count,sendBuffer,rcp(&serializer,false));
02066   ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
02067     charGlobalReducts(count,globalReducts,rcp(&serializer,false));
02068   CharToValueTypeReductionOp<Ordinal,Packet,Serializer>
02069     charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
02070   comm.reduceAll(
02071     charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
02072     ,charGlobalReducts.getCharBuffer()
02073     );
02074 }
02075 
02076 
02077 template<typename Ordinal, typename Packet, typename Serializer>
02078 void Teuchos::reduceAll(
02079   const Comm<Ordinal>& comm,
02080   const Serializer& serializer,
02081   const EReductionType reductType,
02082   const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
02083   )
02084 {
02085   TEUCHOS_COMM_TIME_MONITOR(
02086     "Teuchos::CommHelpers: reduceAll<"
02087     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02088     <<">( value type, "<<toString(reductType)<<" )"
02089     );
02090   std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
02091     reductOp(createOp<Ordinal,Packet>(reductType));
02092   reduceAll(comm,serializer,*reductOp,count,sendBuffer,globalReducts);
02093 }
02094 
02095 
02096 template<typename Ordinal, typename Packet>
02097 void Teuchos::reduceAllAndScatter(
02098   const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
02099   const Ordinal sendCount, const Packet sendBuffer[] ,
02100   const Ordinal recvCounts[], Packet myGlobalReducts[]
02101   )
02102 {
02103 
02104   TEUCHOS_COMM_TIME_MONITOR(
02105     "Teuchos::CommHelpers: reduceAllAndScatter<"
02106     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02107     <<">( value type, user-defined op )"
02108     );
02109 
02110   const Ordinal size = Teuchos::size(comm);
02111   const Ordinal rank = Teuchos::rank(comm);
02112 
02113 #ifdef TEUCHOS_DEBUG
02114   Ordinal sumRecvCounts = 0;
02115   for( Ordinal i = 0; i < size; ++i )
02116     sumRecvCounts += recvCounts[static_cast<ptrdiff_t>(i)];
02117   TEUCHOS_TEST_FOR_EXCEPT(!(sumRecvCounts==sendCount));
02118 #endif
02119 
02120   ConstValueTypeSerializationBuffer<Ordinal,Packet>
02121     charSendBuffer(sendCount,sendBuffer);
02122   ValueTypeSerializationBuffer<Ordinal,Packet>
02123     charMyGlobalReducts(recvCounts[static_cast<ptrdiff_t>(rank)], myGlobalReducts);
02124   CharToValueTypeReductionOp<Ordinal,Packet>
02125     charReductOp(rcp(&reductOp,false));
02126 
02127   const Ordinal
02128     packetSize = charSendBuffer.getBytes()/sendCount;
02129 
02130   WorkspaceStore* wss = get_default_workspace_store().get();
02131   Workspace<Ordinal> charRecvCounts(wss, size);
02132   for (Ordinal k = 0; k < size; ++k) {
02133     charRecvCounts[k] = as<Ordinal>(recvCounts[static_cast<ptrdiff_t>(k)] * packetSize);
02134   }
02135 
02136   comm.reduceAllAndScatter(
02137     charReductOp, charSendBuffer.getBytes(), charSendBuffer.getCharBuffer(),
02138     &charRecvCounts[0], charMyGlobalReducts.getCharBuffer()
02139     );
02140 
02141 }
02142 
02143 
02144 template<typename Ordinal, typename Packet>
02145 void Teuchos::reduceAllAndScatter(
02146   const Comm<Ordinal>& comm, const EReductionType reductType,
02147   const Ordinal sendCount, const Packet sendBuffer[] ,
02148   const Ordinal recvCounts[], Packet myGlobalReducts[]
02149   )
02150 {
02151   TEUCHOS_COMM_TIME_MONITOR(
02152     "Teuchos::CommHelpers: reduceAllAndScatter<"
02153     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02154     <<">( value type, "<<toString(reductType)<<" )"
02155     );
02156   std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
02157     reductOp(createOp<Ordinal,Packet>(reductType));
02158   reduceAllAndScatter(
02159     comm, *reductOp, sendCount, sendBuffer, recvCounts, myGlobalReducts
02160     );
02161 }
02162 
02163 
02164 template<typename Ordinal, typename Packet>
02165 void Teuchos::reduceAllAndScatter(
02166   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
02167   const ReferenceTypeReductionOp<Ordinal,Packet> &reductOp,
02168   const Ordinal sendCount, const Packet*const sendBuffer[],
02169   const Ordinal recvCounts[], Packet*const myGlobalReducts[]
02170   )
02171 {
02172   TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
02173 }
02174 
02175 template<typename Ordinal, typename Packet, typename Serializer>
02176 void Teuchos::reduceAllAndScatter(
02177   const Comm<Ordinal>& comm,
02178   const Serializer& serializer,
02179   const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
02180   const Ordinal sendCount, const Packet sendBuffer[] ,
02181   const Ordinal recvCounts[], Packet myGlobalReducts[]
02182   )
02183 {
02184 
02185   TEUCHOS_COMM_TIME_MONITOR(
02186     "Teuchos::CommHelpers: reduceAllAndScatter<"
02187     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02188     <<">( value type, user-defined op )"
02189     );
02190 
02191   const Ordinal size = Teuchos::size(comm);
02192   const Ordinal rank = Teuchos::rank(comm);
02193 
02194 #ifdef TEUCHOS_DEBUG
02195   Ordinal sumRecvCounts = 0;
02196   for( Ordinal i = 0; i < size; ++i )
02197     sumRecvCounts += recvCounts[static_cast<ptrdiff_t>(i)];
02198   TEUCHOS_TEST_FOR_EXCEPT(!(sumRecvCounts==sendCount));
02199 #endif
02200 
02201   ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
02202     charSendBuffer(sendCount,sendBuffer,rcp(&serializer,false));
02203   ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
02204     charMyGlobalReducts(recvCounts[static_cast<ptrdiff_t>(rank)], myGlobalReducts,rcp(&serializer,false));
02205   CharToValueTypeReductionOp<Ordinal,Packet,Serializer>
02206     charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
02207 
02208   const Ordinal
02209     packetSize = charSendBuffer.getBytes()/sendCount;
02210 
02211   WorkspaceStore* wss = get_default_workspace_store().get();
02212   Workspace<Ordinal> charRecvCounts(wss, size);
02213   for (Ordinal k = 0; k < size; ++k) {
02214     charRecvCounts[k] = as<Ordinal>(recvCounts[static_cast<ptrdiff_t>(k)] * packetSize);
02215   }
02216 
02217   comm.reduceAllAndScatter(
02218     charReductOp, charSendBuffer.getBytes(), charSendBuffer.getCharBuffer(),
02219     &charRecvCounts[0], charMyGlobalReducts.getCharBuffer()
02220     );
02221 
02222 }
02223 
02224 template<typename Ordinal, typename Packet, typename Serializer>
02225 void Teuchos::reduceAllAndScatter(
02226   const Comm<Ordinal>& comm,
02227   const Serializer& serializer,
02228   const EReductionType reductType,
02229   const Ordinal sendCount, const Packet sendBuffer[] ,
02230   const Ordinal recvCounts[], Packet myGlobalReducts[]
02231   )
02232 {
02233   TEUCHOS_COMM_TIME_MONITOR(
02234     "Teuchos::CommHelpers: reduceAllAndScatter<"
02235     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02236     <<">( value type, "<<toString(reductType)<<" )"
02237     );
02238   std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
02239     reductOp(createOp<Ordinal,Packet>(reductType));
02240   reduceAllAndScatter(
02241     comm, serializer, *reductOp, sendCount, sendBuffer, recvCounts,
02242     myGlobalReducts
02243     );
02244 }
02245 
02246 
02247 template<typename Ordinal, typename Packet>
02248 void Teuchos::scan(
02249   const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
02250   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
02251   )
02252 {
02253   TEUCHOS_COMM_TIME_MONITOR(
02254     "Teuchos::CommHelpers: scan<"
02255     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02256     <<">( value type, user-defined op )"
02257     );
02258   ConstValueTypeSerializationBuffer<Ordinal,Packet>
02259     charSendBuffer(count,sendBuffer);
02260   ValueTypeSerializationBuffer<Ordinal,Packet>
02261     charScanReducts(count,scanReducts);
02262   CharToValueTypeReductionOp<Ordinal,Packet>
02263     charReductOp(rcp(&reductOp,false));
02264   comm.scan(
02265     charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
02266     ,charScanReducts.getCharBuffer()
02267     );
02268 }
02269 
02270 
02271 template<typename Ordinal, typename Packet>
02272 void Teuchos::scan(
02273   const Comm<Ordinal>& comm, const EReductionType reductType,
02274   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
02275   )
02276 {
02277   TEUCHOS_COMM_TIME_MONITOR(
02278     "Teuchos::CommHelpers: scan<"
02279     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02280     <<">( value type, "<<toString(reductType)<<" )"
02281     );
02282   std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
02283     reductOp(createOp<Ordinal,Packet>(reductType));
02284   scan(comm,*reductOp,count,sendBuffer,scanReducts);
02285 }
02286 
02287 
02288 template<typename Ordinal, typename Packet>
02289 void Teuchos::scan(
02290   const Comm<Ordinal>& comm, const EReductionType reductType,
02291   const Packet &send, const Ptr<Packet> &scanReduct
02292   )
02293 {
02294   scan<Ordinal,Packet>(comm, reductType, 1, &send, &*scanReduct);
02295 }
02296 
02297 
02298 template<typename Ordinal, typename Packet>
02299 void Teuchos::scan(
02300   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
02301   const ReferenceTypeReductionOp<Ordinal,Packet> &reductOp,
02302   const Ordinal count, const Packet*const sendBuffer[], Packet*const scanReducts[]
02303   )
02304 {
02305   TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
02306 }
02307 
02308 template<typename Ordinal, typename Packet, typename Serializer>
02309 void Teuchos::scan(
02310   const Comm<Ordinal>& comm,
02311   const Serializer& serializer,
02312   const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
02313   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
02314   )
02315 {
02316   TEUCHOS_COMM_TIME_MONITOR(
02317     "Teuchos::CommHelpers: scan<"
02318     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02319     <<">( value type, user-defined op )"
02320     );
02321   ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
02322     charSendBuffer(count,sendBuffer,rcp(&serializer,false));
02323   ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
02324     charScanReducts(count,scanReducts,rcp(&serializer,false));
02325   CharToValueTypeReductionOp<Ordinal,Packet,Serializer>
02326     charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
02327   comm.scan(
02328     charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
02329     ,charScanReducts.getCharBuffer()
02330     );
02331 }
02332 
02333 
02334 template<typename Ordinal, typename Packet, typename Serializer>
02335 void Teuchos::scan(
02336   const Comm<Ordinal>& comm,
02337   const Serializer& serializer,
02338   const EReductionType reductType,
02339   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
02340   )
02341 {
02342   TEUCHOS_COMM_TIME_MONITOR(
02343     "Teuchos::CommHelpers: scan<"
02344     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02345     <<">( value type, "<<toString(reductType)<<" )"
02346     );
02347   std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
02348     reductOp(createOp<Ordinal,Packet>(reductType));
02349   scan(comm,serializer,*reductOp,count,sendBuffer,scanReducts);
02350 }
02351 
02352 template<typename Ordinal, typename Packet>
02353 void Teuchos::send(
02354   const Comm<Ordinal>& comm,
02355   const Ordinal count, const Packet sendBuffer[], const int destRank
02356   )
02357 {
02358   TEUCHOS_COMM_TIME_MONITOR(
02359     "Teuchos::CommHelpers: send<"
02360     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02361     <<">( value type )"
02362     );
02363   ConstValueTypeSerializationBuffer<Ordinal,Packet>
02364     charSendBuffer(count,sendBuffer);
02365   comm.send(
02366     charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
02367     ,destRank
02368     );
02369 }
02370 
02371 template<typename Ordinal, typename Packet>
02372 void
02373 Teuchos::send (const Packet sendBuffer[],
02374                const Ordinal count,
02375                const int destRank,
02376                const int tag,
02377                const Comm<Ordinal>& comm)
02378 {
02379   TEUCHOS_COMM_TIME_MONITOR(
02380     "Teuchos::CommHelpers: send<"
02381     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02382     <<">( value type )"
02383     );
02384   ConstValueTypeSerializationBuffer<Ordinal,Packet> charSendBuffer (count, sendBuffer);
02385   comm.send (charSendBuffer.getBytes (), charSendBuffer.getCharBuffer (), destRank, tag);
02386 }
02387 
02388 template<typename Ordinal, typename Packet>
02389 void Teuchos::ssend(
02390   const Comm<Ordinal>& comm,
02391   const Ordinal count, const Packet sendBuffer[], const int destRank
02392   )
02393 {
02394   TEUCHOS_COMM_TIME_MONITOR(
02395     "Teuchos::CommHelpers: ssend<"
02396     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02397     <<">( value type )"
02398     );
02399   ConstValueTypeSerializationBuffer<Ordinal,Packet>
02400     charSendBuffer(count,sendBuffer);
02401   comm.ssend(
02402     charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
02403     ,destRank
02404     );
02405 }
02406 
02407 template<typename Ordinal, typename Packet>
02408 void
02409 Teuchos::ssend (const Packet sendBuffer[],
02410                 const Ordinal count,
02411                 const int destRank,
02412                 const int tag,
02413                 const Comm<Ordinal>& comm)
02414 {
02415   TEUCHOS_COMM_TIME_MONITOR(
02416     "Teuchos::CommHelpers: ssend<"
02417     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02418     <<">( value type )"
02419     );
02420   typedef ConstValueTypeSerializationBuffer<Ordinal, Packet> buf_type;
02421   buf_type charSendBuffer (count, sendBuffer);
02422   comm.ssend (charSendBuffer.getBytes (),
02423               charSendBuffer.getCharBuffer (),
02424               destRank, tag);
02425 }
02426 
02427 template<typename Ordinal, typename Packet>
02428 void Teuchos::send(
02429   const Comm<Ordinal>& comm,
02430   const Packet &send, const int destRank
02431   )
02432 {
02433   Teuchos::send<Ordinal,Packet>(comm,1,&send,destRank);
02434 }
02435 
02436 template<typename Ordinal, typename Packet>
02437 void Teuchos::ssend(
02438   const Comm<Ordinal>& comm,
02439   const Packet &send, const int destRank
02440   )
02441 {
02442   Teuchos::ssend<Ordinal,Packet>(comm,1,&send,destRank);
02443 }
02444 
02445 template<typename Ordinal, typename Packet>
02446 void Teuchos::send(
02447   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
02448   const Ordinal count, const Packet*const sendBuffer[], const int destRank
02449   )
02450 {
02451   TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
02452 }
02453 
02454 template<typename Ordinal, typename Packet, typename Serializer>
02455 void Teuchos::send(
02456   const Comm<Ordinal>& comm,
02457   const Serializer& serializer,
02458   const Ordinal count, const Packet sendBuffer[], const int destRank
02459   )
02460 {
02461   TEUCHOS_COMM_TIME_MONITOR(
02462     "Teuchos::CommHelpers: send<"
02463     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02464     <<">( value type )"
02465     );
02466   ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
02467     charSendBuffer(count,sendBuffer,rcp(&serializer,false));
02468   comm.send(
02469     charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
02470     ,destRank
02471     );
02472 }
02473 
02474 template<typename Ordinal, typename Packet>
02475 int Teuchos::receive(
02476   const Comm<Ordinal>& comm,
02477   const int sourceRank, const Ordinal count, Packet recvBuffer[]
02478   )
02479 {
02480   TEUCHOS_COMM_TIME_MONITOR(
02481     "Teuchos::CommHelpers: receive<"
02482     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02483     <<">( value type )"
02484     );
02485   ValueTypeSerializationBuffer<Ordinal,Packet>
02486     charRecvBuffer(count,recvBuffer);
02487   return comm.receive(
02488     sourceRank
02489     ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
02490     );
02491 }
02492 
02493 
02494 template<typename Ordinal, typename Packet>
02495 int Teuchos::receive(
02496   const Comm<Ordinal>& comm,
02497   const int sourceRank, Packet *recv
02498   )
02499 {
02500   return Teuchos::receive<Ordinal,Packet>(comm,sourceRank,1,recv);
02501 }
02502 
02503 
02504 template<typename Ordinal, typename Packet>
02505 int Teuchos::receive(
02506   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
02507   const int sourceRank, const Ordinal count, Packet*const recvBuffer[]
02508   )
02509 {
02510   TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
02511 }
02512 
02513 template<typename Ordinal, typename Packet, typename Serializer>
02514 int Teuchos::receive(
02515   const Comm<Ordinal>& comm,
02516   const Serializer& serializer,
02517   const int sourceRank, const Ordinal count, Packet recvBuffer[]
02518   )
02519 {
02520   TEUCHOS_COMM_TIME_MONITOR(
02521     "Teuchos::CommHelpers: receive<"
02522     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02523     <<">( value type )"
02524     );
02525   ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
02526     charRecvBuffer(count,recvBuffer,rcp(&serializer,false));
02527   return comm.receive(
02528     sourceRank
02529     ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
02530     );
02531 }
02532 
02533 template<typename Ordinal, typename Packet>
02534 void Teuchos::readySend(
02535   const Comm<Ordinal>& comm,
02536   const ArrayView<const Packet> &sendBuffer,
02537   const int destRank
02538   )
02539 {
02540   TEUCHOS_COMM_TIME_MONITOR(
02541     "Teuchos::CommHelpers: readySend<"
02542     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02543     <<">( value type )"
02544     );
02545   ConstValueTypeSerializationBuffer<Ordinal,Packet>
02546     charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr());
02547   comm.readySend( charSendBuffer.getCharBufferView(), destRank );
02548 }
02549 
02550 template<typename Ordinal, typename Packet>
02551 void
02552 Teuchos::readySend (const Packet sendBuffer[],
02553                     const Ordinal count,
02554                     const int destRank,
02555                     const int tag,
02556                     const Comm<Ordinal>& comm)
02557 {
02558   TEUCHOS_COMM_TIME_MONITOR(
02559     "Teuchos::CommHelpers: readySend<"
02560     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02561     <<">( value type )"
02562     );
02563   typedef ConstValueTypeSerializationBuffer<Ordinal, Packet> buf_type;
02564   buf_type charSendBuffer (count, sendBuffer);
02565   comm.readySend (charSendBuffer.getBytes (),
02566                   charSendBuffer.getCharBuffer (),
02567                   destRank, tag);
02568 }
02569 
02570 template<typename Ordinal, typename Packet>
02571 void Teuchos::readySend(
02572   const Comm<Ordinal>& comm,
02573   const Packet &send,
02574   const int destRank
02575   )
02576 {
02577   readySend<Ordinal, Packet>( comm, arrayView(&send,1), destRank );
02578 }
02579 
02580 template<typename Ordinal, typename Packet, typename Serializer>
02581 void Teuchos::readySend(
02582   const Comm<Ordinal>& comm,
02583   const Serializer& serializer,
02584   const ArrayView<const Packet> &sendBuffer,
02585   const int destRank
02586   )
02587 {
02588   TEUCHOS_COMM_TIME_MONITOR(
02589     "Teuchos::CommHelpers: readySend<"
02590     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02591     <<">( value type )"
02592     );
02593   ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
02594     charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr(), serializer);
02595   comm.readySend( charSendBuffer.getCharBufferView(), destRank );
02596 }
02597 
02598 template<typename Ordinal, typename Packet>
02599 Teuchos::RCP<Teuchos::CommRequest<Ordinal> >
02600 Teuchos::isend(
02601   const Comm<Ordinal>& comm,
02602   const ArrayRCP<const Packet> &sendBuffer,
02603   const int destRank
02604   )
02605 {
02606   TEUCHOS_COMM_TIME_MONITOR(
02607     "Teuchos::CommHelpers: isend<"
02608     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02609     <<">( value type )"
02610     );
02611   ConstValueTypeSerializationBuffer<Ordinal,Packet>
02612     charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr());
02613   RCP<CommRequest<Ordinal> > commRequest = comm.isend(
02614     charSendBuffer.getCharBufferView(), destRank );
02615   set_extra_data( sendBuffer, "buffer", inOutArg(commRequest) );
02616   return commRequest;
02617 }
02618 
02619 template<typename Ordinal, typename Packet>
02620 Teuchos::RCP<Teuchos::CommRequest<Ordinal> >
02621 Teuchos::isend (const ArrayRCP<const Packet> &sendBuffer,
02622                 const int destRank,
02623                 const int tag,
02624                 const Comm<Ordinal>& comm)
02625 {
02626   TEUCHOS_COMM_TIME_MONITOR(
02627     "Teuchos::isend<" << OrdinalTraits<Ordinal>::name () << ","
02628     << TypeNameTraits<Packet>::name () << ">");
02629   ConstValueTypeSerializationBuffer<Ordinal,Packet>
02630     charSendBuffer (sendBuffer.size (), sendBuffer.getRawPtr ());
02631   RCP<CommRequest<Ordinal> > commRequest =
02632     comm.isend (charSendBuffer.getCharBufferView (), destRank, tag);
02633   set_extra_data (sendBuffer, "buffer", inOutArg (commRequest));
02634   return commRequest;
02635 }
02636 
02637 template<typename Ordinal, typename Packet>
02638 Teuchos::RCP<Teuchos::CommRequest<Ordinal> >
02639 Teuchos::isend(
02640   const Comm<Ordinal>& comm,
02641   const RCP<const Packet> &send,
02642   const int destRank
02643   )
02644 {
02645   const ArrayRCP<const Packet> sendBuffer =
02646     arcpWithEmbeddedObj( send.get(), 0, 1, send, false );
02647   // 2008/07/29: rabartl: Above: I need to write a helper function to create
02648   // new ArrayRCP object given a single object to copy.
02649   return isend<Ordinal, Packet>( comm, sendBuffer, destRank );
02650 }
02651 
02652 template<typename Ordinal, typename Packet, typename Serializer>
02653 Teuchos::RCP<Teuchos::CommRequest<Ordinal> >
02654 Teuchos::isend(
02655   const Comm<Ordinal>& comm,
02656   const Serializer& serializer,
02657   const ArrayRCP<const Packet> &sendBuffer,
02658   const int destRank
02659   )
02660 {
02661   TEUCHOS_COMM_TIME_MONITOR(
02662     "Teuchos::CommHelpers: isend<"
02663     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02664     <<">( value type )"
02665     );
02666   ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
02667     charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr(), serializer);
02668   RCP<CommRequest<Ordinal> > commRequest = comm.isend(
02669     charSendBuffer.getCharBufferView(), destRank );
02670   set_extra_data( sendBuffer, "buffer", inOutArg(commRequest) );
02671   return commRequest;
02672 }
02673 
02674 template<typename Ordinal, typename Packet>
02675 Teuchos::RCP<Teuchos::CommRequest<Ordinal> >
02676 Teuchos::ireceive(
02677   const Comm<Ordinal>& comm,
02678   const ArrayRCP<Packet> &recvBuffer,
02679   const int sourceRank
02680   )
02681 {
02682   TEUCHOS_COMM_TIME_MONITOR(
02683     "Teuchos::ireceive<int, " << "," << TypeNameTraits<Packet>::name () << ">");
02684   ValueTypeSerializationBuffer<Ordinal,Packet>
02685     charRecvBuffer(recvBuffer.size(), recvBuffer.getRawPtr());
02686   RCP<CommRequest<Ordinal> > commRequest = comm.ireceive(
02687     charRecvBuffer.getCharBufferView(), sourceRank );
02688   set_extra_data( recvBuffer, "buffer", inOutArg(commRequest) );
02689   return commRequest;
02690 }
02691 
02692 template<typename Ordinal, typename Packet>
02693 Teuchos::RCP<Teuchos::CommRequest<Ordinal> >
02694 Teuchos::ireceive (const Teuchos::ArrayRCP<Packet> &recvBuffer,
02695                    const int sourceRank,
02696                    const int tag,
02697                    const Teuchos::Comm<Ordinal>& comm)
02698 {
02699   TEUCHOS_COMM_TIME_MONITOR(
02700     "Teuchos::ireceive<int, " << "," << TypeNameTraits<Packet>::name () << ">");
02701   ValueTypeSerializationBuffer<int, Packet>
02702     charRecvBuffer (recvBuffer.size (), recvBuffer.getRawPtr ());
02703   RCP<CommRequest<int> > commRequest =
02704     comm.ireceive (charRecvBuffer.getCharBufferView (), sourceRank, tag);
02705   set_extra_data (recvBuffer, "buffer", inOutArg (commRequest));
02706   return commRequest;
02707 }
02708 
02709 template<typename Ordinal, typename Packet>
02710 Teuchos::RCP<Teuchos::CommRequest<Ordinal> >
02711 Teuchos::ireceive(
02712   const Comm<Ordinal>& comm,
02713   const RCP<Packet> &recv,
02714   const int sourceRank
02715   )
02716 {
02717   const ArrayRCP<Packet> recvBuffer =
02718     arcpWithEmbeddedObj( recv.get(), 0, 1, recv, false );
02719   // 2008/07/29: rabartl: Above: I need to write a helper function to create
02720   // new ArrayRCP object given a single object to copy.
02721   return ireceive<Ordinal, Packet>( comm, recvBuffer, sourceRank );
02722 }
02723 
02724 template<typename Ordinal, typename Packet, typename Serializer>
02725 Teuchos::RCP<Teuchos::CommRequest<Ordinal> >
02726 Teuchos::ireceive(
02727   const Comm<Ordinal>& comm,
02728   const Serializer& serializer,
02729   const ArrayRCP<Packet> &recvBuffer,
02730   const int sourceRank
02731   )
02732 {
02733   TEUCHOS_COMM_TIME_MONITOR(
02734     "Teuchos::CommHelpers: ireceive<"
02735     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02736     <<">( value type )"
02737     );
02738   ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
02739     charRecvBuffer(recvBuffer.size(), recvBuffer.getRawPtr(), serializer);
02740   RCP<CommRequest<Ordinal> > commRequest = comm.ireceive(
02741     charRecvBuffer.getCharBufferView(), sourceRank );
02742   set_extra_data( recvBuffer, "buffer", inOutArg(commRequest) );
02743   return commRequest;
02744 }
02745 
02746 template<typename Ordinal>
02747 void Teuchos::waitAll(
02748   const Comm<Ordinal>& comm,
02749   const ArrayView<RCP<CommRequest<Ordinal> > > &requests
02750   )
02751 {
02752   comm.waitAll(requests);
02753 }
02754 
02755 
02756 template<typename Ordinal>
02757 void
02758 Teuchos::waitAll (const Comm<Ordinal>& comm,
02759                   const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
02760                   const ArrayView<RCP<CommStatus<Ordinal> > >& statuses)
02761 {
02762   comm.waitAll (requests, statuses);
02763 }
02764 
02765 
02766 template<typename Ordinal>
02767 Teuchos::RCP<Teuchos::CommStatus<Ordinal> >
02768 Teuchos::wait (const Comm<Ordinal>& comm,
02769                const Ptr<RCP<CommRequest<Ordinal> > > &request)
02770 {
02771   return comm.wait (request);
02772 }
02773 
02774 
02775 #endif // TEUCHOS_COMM_HELPERS_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines