Teuchos - Trilinos Tools Package Version of the Day
Teuchos_CommHelpers.hpp
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // 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 inline
00087 const char* toString( const EReductionType reductType )
00088 {
00089   switch(reductType) {
00090     case REDUCE_SUM: return "REDUCE_SUM";
00091     case REDUCE_MIN: return "REDUCE_MIN";
00092     case REDUCE_MAX: return "REDUCE_MAX";
00093     case REDUCE_AND: return "REDUCE_AND";
00094     default: TEUCHOS_TEST_FOR_EXCEPT(true);
00095   }
00096   return 0; // Will never be called
00097 }
00098 
00103 template<typename Ordinal>
00104 int rank(const Comm<Ordinal>& comm);
00105 
00110 template<typename Ordinal>
00111 int size(const Comm<Ordinal>& comm);
00112 
00117 template<typename Ordinal>
00118 void barrier(const Comm<Ordinal>& comm);
00119 
00124 template<typename Ordinal, typename Packet>
00125 void broadcast(
00126   const Comm<Ordinal>& comm,
00127   const int rootRank,
00128   const Ordinal count, Packet buffer[]
00129   );
00130 
00135 template<typename Ordinal, typename Packet>
00136 void broadcast(
00137   const Comm<Ordinal>& comm,
00138   const int rootRank,
00139   const ArrayView<Packet> &buffer
00140   );
00141 
00146 template<typename Ordinal, typename Packet>
00147 void broadcast(
00148   const Comm<Ordinal>& comm,
00149   const int rootRank, Packet *object
00150   );
00151 
00156 template<typename Ordinal, typename Packet>
00157 void broadcast(
00158   const Comm<Ordinal>& comm,
00159   const int rootRank, const Ptr<Packet> &object
00160   );
00161 
00166 template<typename Ordinal, typename Packet>
00167 void broadcast(
00168   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00169   const int rootRank, const Ordinal count, Packet*const buffer[]
00170   );
00171 
00176 template<typename Ordinal, typename Packet>
00177 void broadcast(
00178   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00179   const int rootRank, const ArrayView<const Ptr<Packet> > &buffer
00180   );
00181 
00187 template<typename Ordinal, typename Packet, typename Serializer>
00188 void broadcast(
00189   const Comm<Ordinal>& comm,
00190   const Serializer& serializer,
00191   const int rootRank,
00192   const Ordinal count, Packet buffer[]
00193   );
00194 
00200 template<typename Ordinal, typename Packet>
00201 void gatherAll(
00202   const Comm<Ordinal>& comm,
00203   const Ordinal sendCount, const Packet sendBuffer[],
00204   const Ordinal recvCount, Packet recvBuffer[]
00205   );
00206 
00212 template<typename Ordinal, typename Packet>
00213 void gatherAll(
00214   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00215   const Ordinal sendCount, const Packet*const sendBuffer[],
00216   const Ordinal recvCount, Packet*const recvBuffer[]
00217   );
00218 
00224 template<typename Ordinal, typename Packet, typename Serializer>
00225 void gatherAll(
00226   const Comm<Ordinal>& comm,
00227   const Serializer& serializer,
00228   const Ordinal sendCount, const Packet sendBuffer[],
00229   const Ordinal recvCount, Packet recvBuffer[]
00230   );
00231 
00237 template<typename Ordinal, typename Packet>
00238 void reduceAll(
00239   const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
00240   const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
00241   );
00242 
00248 template<typename Ordinal, typename Packet>
00249 void reduceAll(
00250   const Comm<Ordinal>& comm, const EReductionType reductType,
00251   const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
00252   );
00253 
00259 template<typename Ordinal, typename Packet>
00260 void reduceAll(
00261   const Comm<Ordinal>& comm, const EReductionType reductType,
00262   const Packet &send, const Ptr<Packet> &globalReduct
00263   );
00264 
00266 template<typename Ordinal, typename Packet>
00267 TEUCHOS_DEPRECATED void reduceAll(
00268   const Comm<Ordinal>& comm, const EReductionType reductType,
00269   const Packet &send, Packet *globalReduct
00270   )
00271 {
00272   reduceAll<Ordinal,Packet>(comm, reductType, send, ptr(globalReduct));
00273 }
00274 
00280 template<typename Ordinal, typename Packet>
00281 void reduceAll(
00282   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00283   const ReferenceTypeReductionOp<Ordinal,Packet> &reductOp,
00284   const Ordinal count, const Packet*const sendBuffer[], Packet*const globalReducts[]
00285   );
00286 
00292 template<typename Ordinal, typename Packet, typename Serializer>
00293 void reduceAll(
00294   const Comm<Ordinal>& comm, 
00295   const Serializer& serializer,
00296   const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
00297   const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
00298   );
00299 
00305 template<typename Ordinal, typename Packet, typename Serializer>
00306 void reduceAll(
00307   const Comm<Ordinal>& comm, 
00308   const Serializer& serializer,
00309   const EReductionType reductType,
00310   const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
00311   );
00312 
00318 template<typename Ordinal, typename Packet>
00319 void reduceAllAndScatter(
00320   const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
00321   const Ordinal sendCount, const Packet sendBuffer[] ,
00322   const Ordinal recvCounts[], Packet myGlobalReducts[]
00323   );
00324 
00330 template<typename Ordinal, typename Packet>
00331 void reduceAllAndScatter(
00332   const Comm<Ordinal>& comm, const EReductionType reductType,
00333   const Ordinal sendCount, const Packet sendBuffer[] ,
00334   const Ordinal recvCounts[], Packet myGlobalReducts[]
00335   );
00336 
00342 template<typename Ordinal, typename Packet>
00343 void reduceAllAndScatter(
00344   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00345   const ReferenceTypeReductionOp<Ordinal,Packet> &reductOp,
00346   const Ordinal sendCount, const Packet*const sendBuffer[] ,
00347   const Ordinal recvCounts[], Packet*const myGlobalReducts[]
00348   );
00349 
00355 template<typename Ordinal, typename Packet>
00356 void scan(
00357   const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
00358   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
00359   );
00360 
00366 template<typename Ordinal, typename Packet, typename Serializer>
00367 void reduceAllAndScatter(
00368   const Comm<Ordinal>& comm, 
00369   const Serializer& serializer,
00370   const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
00371   const Ordinal sendCount, const Packet sendBuffer[],
00372   const Ordinal recvCounts[], Packet myGlobalReducts[]
00373   );
00374 
00380 template<typename Ordinal, typename Packet, typename Serializer>
00381 void reduceAllAndScatter(
00382   const Comm<Ordinal>& comm, 
00383   const Serializer& serializer,
00384   const EReductionType reductType,
00385   const Ordinal sendCount, const Packet sendBuffer[] ,
00386   const Ordinal recvCounts[], Packet myGlobalReducts[]
00387   );
00388 
00394 template<typename Ordinal, typename Packet>
00395 void scan(
00396   const Comm<Ordinal>& comm, const EReductionType reductType,
00397   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
00398   );
00399 
00405 template<typename Ordinal, typename Packet>
00406 void scan(
00407   const Comm<Ordinal>& comm, const EReductionType reductType,
00408   const Packet &send, const Ptr<Packet> &scanReduct
00409   );
00410 
00412 template<typename Ordinal, typename Packet>
00413 TEUCHOS_DEPRECATED void scan(
00414   const Comm<Ordinal>& comm, const EReductionType reductType,
00415   const Packet &send, Packet *scanReduct
00416   )
00417 {
00418   scan(comm, reductType, send, ptr(scanReduct));
00419 }
00420 
00426 template<typename Ordinal, typename Packet>
00427 void scan(
00428   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00429   const ReferenceTypeReductionOp<Ordinal,Packet> &reductOp,
00430   const Ordinal count, const Packet*const sendBuffer[], Packet*const scanReducts[]
00431   );
00432 
00438 template<typename Ordinal, typename Packet, typename Serializer>
00439 void scan(
00440   const Comm<Ordinal>& comm, 
00441   const Serializer& serializer,
00442   const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
00443   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
00444   );
00445 
00451 template<typename Ordinal, typename Packet, typename Serializer>
00452 void scan(
00453   const Comm<Ordinal>& comm, 
00454   const Serializer& serializer,
00455   const EReductionType reductType,
00456   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
00457   );
00458 
00463 template<typename Ordinal, typename Packet>
00464 void send(
00465   const Comm<Ordinal>& comm,
00466   const Ordinal count, const Packet sendBuffer[], const int destRank
00467   );
00468 
00473 template<typename Ordinal, typename Packet>
00474 void ssend(
00475   const Comm<Ordinal>& comm,
00476   const Ordinal count, const Packet sendBuffer[], const int destRank
00477   );
00478 
00483 template<typename Ordinal, typename Packet>
00484 void send(
00485   const Comm<Ordinal>& comm,
00486   const Packet &send, const int destRank
00487   );
00488 
00493 template<typename Ordinal, typename Packet>
00494 void ssend(
00495   const Comm<Ordinal>& comm,
00496   const Packet &send, const int destRank
00497   );
00498 
00505 template<typename Ordinal, typename Packet>
00506 void send(
00507   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00508   const Ordinal count, const Packet*const sendBuffer[], const int destRank
00509   );
00510 
00516 template<typename Ordinal, typename Packet, typename Serializer>
00517 void send(
00518   const Comm<Ordinal>& comm,
00519   const Serializer& serializer,
00520   const Ordinal count, const Packet sendBuffer[], const int destRank
00521   );
00522 
00527 template<typename Ordinal, typename Packet>
00528 int receive(
00529   const Comm<Ordinal>& comm,
00530   const int sourceRank, const Ordinal count, Packet recvBuffer[] 
00531   );
00532 
00537 template<typename Ordinal, typename Packet>
00538 int receive(
00539   const Comm<Ordinal>& comm,
00540   const int sourceRank, Packet *recv 
00541   );
00542 
00547 template<typename Ordinal, typename Packet>
00548 int receive(
00549   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
00550   const int sourceRank, const Ordinal count, Packet*const recvBuffer[] 
00551   );
00552 
00558 template<typename Ordinal, typename Packet, typename Serializer>
00559 int receive(
00560   const Comm<Ordinal>& comm,
00561   const Serializer& serializer,
00562   const int sourceRank, const Ordinal count, Packet recvBuffer[] 
00563   );
00564 
00570 template<typename Ordinal, typename Packet>
00571 void readySend(
00572   const Comm<Ordinal>& comm,
00573   const ArrayView<const Packet> &sendBuffer,
00574   const int destRank
00575   );
00576 
00581 template<typename Ordinal, typename Packet>
00582 void readySend(
00583   const Comm<Ordinal>& comm,
00584   const Packet &send,
00585   const int destRank
00586   );
00587 
00593 template<typename Ordinal, typename Packet, typename Serializer>
00594 void readySend(
00595   const Comm<Ordinal>& comm,
00596   const Serializer& serializer,
00597   const ArrayView<const Packet> &sendBuffer,
00598   const int destRank
00599   );
00600 
00605 template<typename Ordinal, typename Packet>
00606 RCP<CommRequest<Ordinal> > isend(
00607   const Comm<Ordinal>& comm,
00608   const ArrayRCP<const Packet> &sendBuffer,
00609   const int destRank
00610   );
00611 
00612 
00617 template<typename Ordinal, typename Packet>
00618 RCP<CommRequest<Ordinal> > isend(
00619   const Comm<Ordinal>& comm,
00620   const RCP<const Packet> &send,
00621   const int destRank
00622   );
00623 
00629 template<typename Ordinal, typename Packet, typename Serializer>
00630 RCP<CommRequest<Ordinal> > isend(
00631   const Comm<Ordinal>& comm,
00632   const Serializer& serializer,
00633   const ArrayRCP<const Packet> &sendBuffer,
00634   const int destRank
00635   );
00636 
00637 
00638 // 2008/07/29: rabartl: ToDo: Add reference semantics version of isend!
00639 
00640 
00650 template<typename Ordinal, typename Packet>
00651 RCP<CommRequest<Ordinal> > ireceive(
00652   const Comm<Ordinal>& comm,
00653   const ArrayRCP<Packet> &recvBuffer,
00654   const int sourceRank
00655   );
00656 
00657 
00669 template<typename Ordinal, typename Packet>
00670 RCP<CommRequest<Ordinal> > ireceive(
00671   const Comm<Ordinal>& comm,
00672   const RCP<Packet> &recv,
00673   const int sourceRank
00674   );
00675 
00681 template<typename Ordinal, typename Packet, typename Serializer>
00682 RCP<CommRequest<Ordinal> > ireceive(
00683   const Comm<Ordinal>& comm,
00684   const Serializer& serializer,
00685   const ArrayRCP<Packet> &recvBuffer,
00686   const int sourceRank
00687   );
00688 
00689 
00690 // 2008/07/29: rabartl: ToDo: Add reference semantics version of ireceive!
00691 
00692 
00700 template<typename Ordinal>
00701 void waitAll(
00702   const Comm<Ordinal>& comm,
00703   const ArrayView<RCP<CommRequest<Ordinal> > > &requests
00704   );
00705 
00735 template<typename Ordinal>
00736 void 
00737 waitAll (const Comm<Ordinal>& comm,
00738    const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
00739    const ArrayView<RCP<CommStatus<Ordinal> > >& statuses);
00740 
00764 template<typename Ordinal>
00765 RCP<CommStatus<Ordinal> >
00766 wait (const Comm<Ordinal>& comm, const Ptr<RCP<CommRequest<Ordinal> > >& request);
00767 
00768 //
00769 // Standard reduction subclasses for objects that use value semantics
00770 //
00771 
00772 
00777 template<typename Ordinal, typename Packet>
00778 class SumValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
00779 {
00780 public:
00782   void reduce(
00783     const Ordinal count,
00784     const Packet inBuffer[],
00785     Packet inoutBuffer[]
00786     ) const;
00787 };
00788 
00789 
00798 template<typename Ordinal, typename Packet>
00799 class MinValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
00800 {
00801 public:
00803   void reduce(
00804     const Ordinal count,
00805     const Packet inBuffer[],
00806     Packet inoutBuffer[]
00807     ) const;
00808 };
00809 
00810 
00819 template<typename Ordinal, typename Packet>
00820 class MaxValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
00821 {
00822 public:
00824   void reduce(
00825     const Ordinal count,
00826     const Packet inBuffer[],
00827     Packet inoutBuffer[]
00828     ) const;
00829 };
00830 
00831 
00836 template<typename Ordinal, typename Packet>
00837 class ANDValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
00838 {
00839 public:
00841   void reduce(
00842     const Ordinal count,
00843     const Packet inBuffer[],
00844     Packet inoutBuffer[]
00845     ) const;
00846 };
00847 
00848 
00849 // ////////////////////////////////////////////////////////////
00850 // Implementation details (not for geneal users to mess with)
00851 
00852 
00853 //
00854 // ReductionOp Utilities
00855 //
00856 
00857 
00858 namespace MixMaxUtilities {
00859 
00860 
00861 template<bool isComparable, typename Ordinal, typename Packet>
00862 class Min {};
00863 
00864 
00865 template<typename Ordinal, typename Packet>
00866 class Min<true,Ordinal,Packet> {
00867 public:
00868   static void min(
00869     const Ordinal count,
00870     const Packet inBuffer[],
00871     Packet inoutBuffer[]
00872     )
00873     {
00874       for( int i = 0; i < count; ++i )
00875         inoutBuffer[i] = TEUCHOS_MIN(inoutBuffer[i],inBuffer[i]);
00876     }
00877 };
00878 
00879 
00880 template<typename Ordinal, typename Packet>
00881 class Min<false,Ordinal,Packet> {
00882 public:
00883   static void min(
00884     const Ordinal,
00885     const Packet[],
00886     Packet[]
00887     )
00888     {
00889       TEUCHOS_TEST_FOR_EXCEPTION(
00890         true,std::logic_error,
00891         "Error, the type "<<TypeNameTraits<Packet>::name()
00892         <<" does not support comparison operations!"
00893         );
00894     }
00895 };
00896 
00897 
00898 template<bool isComparable, typename Ordinal, typename Packet>
00899 class Max {};
00900 
00901 
00902 template<typename Ordinal, typename Packet>
00903 class Max<true,Ordinal,Packet> {
00904 public:
00905   static void max(
00906     const Ordinal count,
00907     const Packet inBuffer[],
00908     Packet inoutBuffer[]
00909     )
00910     {
00911       for( int i = 0; i < count; ++i )
00912         inoutBuffer[i] = TEUCHOS_MAX(inoutBuffer[i],inBuffer[i]);
00913     }
00914 };
00915 
00916 
00917 template<typename Ordinal, typename Packet>
00918 class Max<false,Ordinal,Packet> {
00919 public:
00920   static void max(
00921     const Ordinal,
00922     const Packet[],
00923     Packet[]
00924     )
00925     {
00926       TEUCHOS_TEST_FOR_EXCEPTION(
00927         true,std::logic_error,
00928         "Error, the type "<<TypeNameTraits<Packet>::name()
00929         <<" does not support comparison operations!"
00930         );
00931     }
00932 };
00933 
00934 
00935 template<bool isComparable, typename Ordinal, typename Packet>
00936 class AND {};
00937 
00938 
00939 template<typename Ordinal, typename Packet>
00940 class AND<true,Ordinal,Packet> {
00941 public:
00942   static void andOp(
00943     const Ordinal count,
00944     const Packet inBuffer[],
00945     Packet inoutBuffer[]
00946     )
00947     {
00948       for( int i = 0; i < count; ++i )
00949         inoutBuffer[i] = inoutBuffer[i] && inBuffer[i];
00950     }
00951 };
00952 
00953 
00954 template<typename Ordinal, typename Packet>
00955 class AND<false,Ordinal,Packet> {
00956 public:
00957   static void andOp(
00958     const Ordinal,
00959     const Packet[],
00960     Packet[]
00961     )
00962     {
00963       TEUCHOS_TEST_FOR_EXCEPTION(
00964         true,std::logic_error,
00965         "Error, the type "<<TypeNameTraits<Packet>::name()
00966         <<" does not support logical AND operations!"
00967         );
00968     }
00969 };
00970 
00971 
00972 } // namespace MixMaxUtilities
00973 
00974 
00975 template<typename Ordinal, typename Packet>
00976 void SumValueReductionOp<Ordinal,Packet>::reduce(
00977   const Ordinal count,
00978   const Packet inBuffer[],
00979   Packet inoutBuffer[]
00980   ) const
00981 {
00982   for( int i = 0; i < count; ++i )
00983     inoutBuffer[i] += inBuffer[i];
00984 }
00985 
00986 
00987 template<typename Ordinal, typename Packet>
00988 void MinValueReductionOp<Ordinal,Packet>::reduce(
00989   const Ordinal count,
00990   const Packet inBuffer[],
00991   Packet inoutBuffer[]
00992   ) const
00993 {
00994   typedef MixMaxUtilities::Min<ScalarTraits<Packet>::isComparable, Ordinal, Packet> min_type;
00995   min_type::min (count, inBuffer, inoutBuffer);
00996 }
00997 
00998 
00999 template<typename Ordinal, typename Packet>
01000 void MaxValueReductionOp<Ordinal,Packet>::reduce(
01001   const Ordinal count,
01002   const Packet inBuffer[],
01003   Packet inoutBuffer[]
01004   ) const
01005 {
01006   typedef MixMaxUtilities::Max<ScalarTraits<Packet>::isComparable, Ordinal, Packet> max_type;
01007   max_type::max (count,inBuffer,inoutBuffer);
01008 }
01009 
01010 
01011 template<typename Ordinal, typename Packet>
01012 void ANDValueReductionOp<Ordinal,Packet>::reduce(
01013   const Ordinal count,
01014   const Packet inBuffer[],
01015   Packet inoutBuffer[]
01016   ) const
01017 {
01018   typedef MixMaxUtilities::AND<ScalarTraits<Packet>::isComparable, Ordinal, Packet> and_type;
01019   and_type::andOp (count, inBuffer, inoutBuffer);
01020 }
01021 
01022 
01023 } // namespace Teuchos
01024 
01025 
01026 // //////////////////////////
01027 // Template implemenations
01028 
01029 
01030 //
01031 // ReductionOp utilities
01032 //
01033 
01034 
01035 namespace Teuchos {
01036 
01037 
01038 // Not for the general user to use! I am returning a raw ReducionOp* pointer
01039 // to avoid the overhead of using RCP. However, given the use case
01040 // this is just fine since I can just use std::auto_ptr to make sure things
01041 // are deleted correctly.
01042 template<typename Ordinal, typename Packet>
01043 ValueTypeReductionOp<Ordinal,Packet>*
01044 createOp( const EReductionType reductType )
01045 {
01046   typedef ScalarTraits<Packet> ST;
01047   switch(reductType) {
01048     case REDUCE_SUM: {
01049       return new SumValueReductionOp<Ordinal,Packet>();
01050       break;
01051     }
01052     case REDUCE_MIN: {
01053       TEUCHOS_TEST_FOR_EXCEPT(!ST::isComparable);
01054       return new MinValueReductionOp<Ordinal,Packet>();
01055       break;
01056     }
01057     case REDUCE_MAX: {
01058       TEUCHOS_TEST_FOR_EXCEPT(!ST::isComparable);
01059       return new MaxValueReductionOp<Ordinal,Packet>();
01060       break;
01061     }
01062     case REDUCE_AND: {
01063       return new ANDValueReductionOp<Ordinal, Packet>();
01064       break;
01065     }
01066     default:
01067       TEUCHOS_TEST_FOR_EXCEPT(true);
01068   }
01069   return 0; // Will never be called!
01070 }
01071 
01072 
01073 } // namespace Teuchos
01074 
01075 
01076 //
01077 // Teuchos::Comm wrapper functions
01078 //
01079 
01080 
01081 template<typename Ordinal>
01082 int Teuchos::rank(const Comm<Ordinal>& comm)
01083 {
01084   return comm.getRank();
01085 }
01086 
01087 
01088 template<typename Ordinal>
01089 int Teuchos::size(const Comm<Ordinal>& comm)
01090 {
01091   return comm.getSize();
01092 }
01093 
01094 
01095 template<typename Ordinal>
01096 void Teuchos::barrier(const Comm<Ordinal>& comm)
01097 {
01098   TEUCHOS_COMM_TIME_MONITOR(
01099     "Teuchos::CommHelpers: barrier<"
01100     <<OrdinalTraits<Ordinal>::name()
01101     <<">()"
01102     );
01103   comm.barrier();
01104 }
01105 
01106 
01107 template<typename Ordinal, typename Packet>
01108 void Teuchos::broadcast(
01109   const Comm<Ordinal>& comm,
01110   const int rootRank, const Ordinal count, Packet buffer[]
01111   )
01112 {
01113   TEUCHOS_COMM_TIME_MONITOR(
01114     "Teuchos::CommHelpers: broadcast<"
01115     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01116     <<">( value type )"
01117     );
01118   ValueTypeSerializationBuffer<Ordinal,Packet>
01119     charBuffer(count,buffer);
01120   comm.broadcast(
01121     rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
01122     );
01123 }
01124 
01125 
01126 template<typename Ordinal, typename Packet>
01127 void Teuchos::broadcast(
01128   const Comm<Ordinal>& comm,
01129   const int rootRank,
01130   const ArrayView<Packet> &buffer
01131   )
01132 {
01133   broadcast<Ordinal, Packet>(comm, rootRank, buffer.size(), buffer.getRawPtr() );
01134 }
01135 
01136 
01137 template<typename Ordinal, typename Packet>
01138 void Teuchos::broadcast(
01139   const Comm<Ordinal>& comm,
01140   const int rootRank, Packet *object
01141   )
01142 {
01143   broadcast<Ordinal,Packet>(comm,rootRank,1,object);
01144 }
01145 
01146 
01147 template<typename Ordinal, typename Packet>
01148 void Teuchos::broadcast(
01149   const Comm<Ordinal>& comm,
01150   const int rootRank, const Ptr<Packet> &object
01151   )
01152 {
01153   broadcast<Ordinal,Packet>(comm,rootRank,1,object.getRawPtr());
01154 }
01155 
01156 
01157 template<typename Ordinal, typename Packet>
01158 void Teuchos::broadcast(
01159   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
01160   const int rootRank, const Ordinal count, Packet*const buffer[]
01161   )
01162 {
01163   TEUCHOS_COMM_TIME_MONITOR(
01164     "Teuchos::CommHelpers: broadcast<"
01165     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01166     <<">( reference type )"
01167     );
01168   ReferenceTypeSerializationBuffer<Ordinal,Packet>
01169     charBuffer(serializer, count, buffer);
01170   comm.broadcast(
01171     rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
01172     );
01173 }
01174 
01175 
01176 template<typename Ordinal, typename Packet>
01177 void Teuchos::broadcast(
01178   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
01179   const int rootRank, const ArrayView<const Ptr<Packet> > &buffer
01180   )
01181 {
01182   Array<Packet*> bufferPtrArray;
01183   for (int i = 0; i < buffer.size(); ++i) {
01184     bufferPtrArray.push_back(buffer[i].getRawPtr());
01185   }
01186   broadcast<Ordinal,Packet>(comm, serializer, rootRank,
01187     buffer.size(), bufferPtrArray.getRawPtr());
01188 }
01189 
01190 template<typename Ordinal, typename Packet, typename Serializer>
01191 void Teuchos::broadcast(
01192   const Comm<Ordinal>& comm,
01193   const Serializer& serializer,
01194   const int rootRank, const Ordinal count, Packet buffer[]
01195   )
01196 {
01197   TEUCHOS_COMM_TIME_MONITOR(
01198     "Teuchos::CommHelpers: broadcast<"
01199     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01200     <<">( value type )"
01201     );
01202   ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
01203     charBuffer(count,buffer,rcp(&serializer,false));
01204   comm.broadcast(
01205     rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
01206     );
01207 }
01208 
01209 
01210 template<typename Ordinal, typename Packet>
01211 void Teuchos::gatherAll(
01212   const Comm<Ordinal>& comm,
01213   const Ordinal sendCount, const Packet sendBuffer[],
01214   const Ordinal recvCount, Packet recvBuffer[]
01215   )
01216 {
01217   TEUCHOS_COMM_TIME_MONITOR(
01218     "Teuchos::CommHelpers: gatherAll<"
01219     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01220     <<">( value type )"
01221     );
01222   ConstValueTypeSerializationBuffer<Ordinal,Packet>
01223     charSendBuffer(sendCount,sendBuffer);
01224   ValueTypeSerializationBuffer<Ordinal,Packet>
01225     charRecvBuffer(recvCount,recvBuffer);
01226   comm.gatherAll(
01227     charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
01228     ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
01229     );
01230 }
01231 
01232 
01233 template<typename Ordinal, typename Packet>
01234 void Teuchos::gatherAll(
01235   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
01236   const Ordinal sendCount, const Packet*const sendBuffer[],
01237   const Ordinal recvCount, Packet*const recvBuffer[]
01238   )
01239 {
01240   TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
01241 }
01242 
01243 template<typename Ordinal, typename Packet, typename Serializer>
01244 void Teuchos::gatherAll(
01245   const Comm<Ordinal>& comm,
01246   const Serializer& serializer,
01247   const Ordinal sendCount, const Packet sendBuffer[],
01248   const Ordinal recvCount, Packet recvBuffer[]
01249   )
01250 {
01251   TEUCHOS_COMM_TIME_MONITOR(
01252     "Teuchos::CommHelpers: gatherAll<"
01253     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01254     <<">( value type )"
01255     );
01256   ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
01257     charSendBuffer(sendCount,sendBuffer,rcp(&serializer,false));
01258   ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
01259     charRecvBuffer(recvCount,recvBuffer,rcp(&serializer,false));
01260   comm.gatherAll(
01261     charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
01262     ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
01263     );
01264 }
01265 
01266 
01267 template<typename Ordinal, typename Packet>
01268 void Teuchos::reduceAll(
01269   const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp
01270   ,const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
01271   )
01272 {
01273   TEUCHOS_COMM_TIME_MONITOR(
01274     "Teuchos::CommHelpers: reduceAll<"
01275     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01276     <<">( value type, user-defined op )"
01277     );
01278   ConstValueTypeSerializationBuffer<Ordinal,Packet>
01279     charSendBuffer(count,sendBuffer);
01280   ValueTypeSerializationBuffer<Ordinal,Packet>
01281     charGlobalReducts(count,globalReducts);
01282   CharToValueTypeReductionOp<Ordinal,Packet>
01283     charReductOp(rcp(&reductOp,false));
01284   comm.reduceAll(
01285     charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
01286     ,charGlobalReducts.getCharBuffer()
01287     );
01288 }
01289 
01290 
01291 template<typename Ordinal, typename Packet>
01292 void Teuchos::reduceAll(
01293   const Comm<Ordinal>& comm, const EReductionType reductType,
01294   const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
01295   )
01296 {
01297   TEUCHOS_COMM_TIME_MONITOR(
01298     "Teuchos::CommHelpers: reduceAll<"
01299     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01300     <<">( value type, "<<toString(reductType)<<" )"
01301     );
01302   std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
01303     reductOp(createOp<Ordinal,Packet>(reductType));
01304   reduceAll(comm,*reductOp,count,sendBuffer,globalReducts);
01305 }
01306 
01307 
01308 namespace Teuchos {
01309 
01310 #ifdef TEUCHOS_HAVE_COMPLEX
01311 // Specialization for Ordinal=int and Packet=std::complex<double>.
01312 template<>
01313 TEUCHOSCOMM_LIB_DLL_EXPORT void
01314 reduceAll<int, std::complex<double> > (const Comm<int>& comm, 
01315                const EReductionType reductType,
01316                const int count, 
01317                const std::complex<double> sendBuffer[], 
01318                std::complex<double> globalReducts[]);
01319 template<>
01320 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01321 ireceive<int, std::complex<double> > (const Comm<int>& comm, 
01322               const ArrayRCP<std::complex<double> >& recvBuffer,
01323               const int sourceRank);
01324 template<>
01325 TEUCHOSCOMM_LIB_DLL_EXPORT void
01326 send<int, std::complex<double> > (const Comm<int>& comm, 
01327           const int count,
01328           const std::complex<double> sendBuffer[],
01329           const int destRank);
01330 
01331 // Specialization for Ordinal=int and Packet=std::complex<float>.
01332 template<>
01333 TEUCHOSCOMM_LIB_DLL_EXPORT void
01334 reduceAll<int, std::complex<float> > (const Comm<int>& comm, 
01335               const EReductionType reductType,
01336               const int count, 
01337               const std::complex<float> sendBuffer[], 
01338               std::complex<float> globalReducts[]);
01339 template<>
01340 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01341 ireceive<int, std::complex<float> > (const Comm<int>& comm, 
01342              const ArrayRCP<std::complex<float> >& recvBuffer,
01343              const int sourceRank);
01344 template<>
01345 TEUCHOSCOMM_LIB_DLL_EXPORT void
01346 send<int, std::complex<float> > (const Comm<int>& comm, 
01347          const int count,
01348          const std::complex<float> sendBuffer[],
01349          const int destRank);
01350 #endif // TEUCHOS_HAVE_COMPLEX
01351 
01352 // Specialization for Ordinal=int and Packet=double.
01353 template<>
01354 TEUCHOSCOMM_LIB_DLL_EXPORT void
01355 reduceAll<int, double> (const Comm<int>& comm, 
01356       const EReductionType reductType,
01357       const int count, 
01358       const double sendBuffer[], 
01359       double globalReducts[]);
01360 template<>
01361 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01362 ireceive<int, double> (const Comm<int>& comm, 
01363            const ArrayRCP<double>& recvBuffer,
01364            const int sourceRank);
01365 template<>
01366 TEUCHOSCOMM_LIB_DLL_EXPORT void
01367 send<int, double> (const Comm<int>& comm, 
01368        const int count,
01369        const double sendBuffer[],
01370        const int destRank);
01371 
01372 // Specialization for Ordinal=int and Packet=float.
01373 template<>
01374 TEUCHOSCOMM_LIB_DLL_EXPORT void
01375 reduceAll<int, float> (const Comm<int>& comm, 
01376            const EReductionType reductType,
01377            const int count, 
01378            const float sendBuffer[], 
01379            float globalReducts[]);
01380 template<>
01381 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01382 ireceive<int, float> (const Comm<int>& comm, 
01383           const ArrayRCP<float>& recvBuffer,
01384           const int sourceRank);
01385 template<>
01386 TEUCHOSCOMM_LIB_DLL_EXPORT void
01387 send<int, float> (const Comm<int>& comm, 
01388       const int count,
01389       const float sendBuffer[],
01390       const int destRank);
01391 
01392 #ifdef TEUCHOS_HAVE_LONG_LONG_INT
01393 // Specialization for Ordinal=int and Packet=long long.
01394 template<>
01395 TEUCHOSCOMM_LIB_DLL_EXPORT void
01396 reduceAll<int, long long> (const Comm<int>& comm, 
01397          const EReductionType reductType,
01398          const int count, 
01399          const long long sendBuffer[], 
01400          long long globalReducts[]);
01401 template<>
01402 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01403 ireceive<int, long long> (const Comm<int>& comm, 
01404         const ArrayRCP<long long>& recvBuffer,
01405         const int sourceRank);
01406 template<>
01407 TEUCHOSCOMM_LIB_DLL_EXPORT void
01408 send<int, long long> (const Comm<int>& comm, 
01409           const int count,
01410           const long long sendBuffer[],
01411           const int destRank);
01412 #endif // TEUCHOS_HAVE_LONG_LONG_INT
01413 
01414 // Specialization for Ordinal=int and Packet=long.
01415 template<>
01416 TEUCHOSCOMM_LIB_DLL_EXPORT void
01417 reduceAll<int, long> (const Comm<int>& comm, 
01418           const EReductionType reductType,
01419           const int count, 
01420           const long sendBuffer[], 
01421           long globalReducts[]);
01422 template<>
01423 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01424 ireceive<int, long> (const Comm<int>& comm, 
01425          const ArrayRCP<long>& recvBuffer,
01426          const int sourceRank);
01427 template<>
01428 TEUCHOSCOMM_LIB_DLL_EXPORT void
01429 send<int, long> (const Comm<int>& comm, 
01430      const int count,
01431      const long sendBuffer[],
01432      const int destRank);
01433 
01434 // Specialization for Ordinal=int and Packet=int.
01435 template<>
01436 TEUCHOSCOMM_LIB_DLL_EXPORT void
01437 reduceAll<int, int> (const Comm<int>& comm, 
01438          const EReductionType reductType,
01439          const int count, 
01440          const int sendBuffer[], 
01441          int globalReducts[]);
01442 template<>
01443 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01444 ireceive<int, int> (const Comm<int>& comm, 
01445         const ArrayRCP<int>& recvBuffer,
01446         const int sourceRank);
01447 template<>
01448 TEUCHOSCOMM_LIB_DLL_EXPORT void
01449 send<int, int> (const Comm<int>& comm, 
01450     const int count,
01451     const int sendBuffer[],
01452     const int destRank);
01453 
01454 // Specialization for Ordinal=int and Packet=short.
01455 template<>
01456 TEUCHOSCOMM_LIB_DLL_EXPORT void
01457 reduceAll<int, short> (const Comm<int>& comm, 
01458            const EReductionType reductType,
01459            const int count, 
01460            const short sendBuffer[], 
01461            short globalReducts[]);
01462 template<>
01463 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
01464 ireceive<int, short> (const Comm<int>& comm, 
01465           const ArrayRCP<short>& recvBuffer,
01466           const int sourceRank);
01467 template<>
01468 TEUCHOSCOMM_LIB_DLL_EXPORT void
01469 send<int, short> (const Comm<int>& comm, 
01470       const int count,
01471       const short sendBuffer[],
01472       const int destRank);
01473 
01474 // mfh 18 Oct 2012: The specialization for Packet=char seems to be
01475 // causing problems such as the following:
01476 //
01477 // http://testing.sandia.gov/cdash/testDetails.php?test=9909246&build=747699
01478 // 
01479 // I am disabling it for now.  This should revert back to the old
01480 // behavior for Packet=char.  That should fix the Tpetra errors, since
01481 // many Tpetra objects inherit from DistObject<char, ...>.
01482 #if 0
01483 // Specialization for Ordinal=int and Packet=char.
01484 template<>
01485 TEUCHOSCOMM_LIB_DLL_EXPORT void
01486 reduceAll<int, char> (const Comm<int>& comm, 
01487           const EReductionType reductType,
01488           const int count, 
01489           const char sendBuffer[], 
01490           char globalReducts[]);
01491 #endif // 0
01492 } // namespace Teuchos
01493 
01494 
01495 template<typename Ordinal, typename Packet>
01496 void Teuchos::reduceAll(
01497   const Comm<Ordinal>& comm, const EReductionType reductType
01498   ,const Packet &send, const Ptr<Packet> &globalReduct
01499   )
01500 {
01501   // mfh 17 Oct 2012: This will invoke the above specializations for
01502   // general count, so we don't need to specialize this function.
01503   reduceAll<Ordinal,Packet>(comm, reductType, 1, &send, &*globalReduct);
01504 }
01505 
01506 
01507 template<typename Ordinal, typename Packet>
01508 void Teuchos::reduceAll(
01509   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
01510   const ReferenceTypeReductionOp<Ordinal,Packet> &reductOp,
01511   const Ordinal count, const Packet*const sendBuffer[], Packet*const globalReducts[]
01512   )
01513 {
01514   TEUCHOS_COMM_TIME_MONITOR(
01515     "Teuchos::CommHelpers: reduceAll<"
01516     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01517     <<">( reference type )"
01518     );
01519   ConstReferenceTypeSerializationBuffer<Ordinal,Packet>
01520     charSendBuffer(serializer,count,sendBuffer);
01521   ReferenceTypeSerializationBuffer<Ordinal,Packet>
01522     charGlobalReducts(serializer,count,globalReducts);
01523   CharToReferenceTypeReductionOp<Ordinal,Packet>
01524     charReductOp(rcp(&serializer,false),rcp(&reductOp,false));
01525   comm.reduceAll(
01526     charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
01527     ,charGlobalReducts.getCharBuffer()
01528     );
01529 }
01530 
01531 template<typename Ordinal, typename Packet, typename Serializer>
01532 void Teuchos::reduceAll(
01533   const Comm<Ordinal>& comm, 
01534   const Serializer& serializer,
01535   const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
01536   const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
01537   )
01538 {
01539   TEUCHOS_COMM_TIME_MONITOR(
01540     "Teuchos::CommHelpers: reduceAll<"
01541     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01542     <<">( value type, user-defined op )"
01543     );
01544   ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
01545     charSendBuffer(count,sendBuffer,rcp(&serializer,false));
01546   ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
01547     charGlobalReducts(count,globalReducts,rcp(&serializer,false));
01548   CharToValueTypeReductionOp<Ordinal,Packet,Serializer>
01549     charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
01550   comm.reduceAll(
01551     charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
01552     ,charGlobalReducts.getCharBuffer()
01553     );
01554 }
01555 
01556 
01557 template<typename Ordinal, typename Packet, typename Serializer>
01558 void Teuchos::reduceAll(
01559   const Comm<Ordinal>& comm, 
01560   const Serializer& serializer,
01561   const EReductionType reductType,
01562   const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
01563   )
01564 {
01565   TEUCHOS_COMM_TIME_MONITOR(
01566     "Teuchos::CommHelpers: reduceAll<"
01567     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01568     <<">( value type, "<<toString(reductType)<<" )"
01569     );
01570   std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
01571     reductOp(createOp<Ordinal,Packet>(reductType));
01572   reduceAll(comm,serializer,*reductOp,count,sendBuffer,globalReducts);
01573 }
01574 
01575 
01576 template<typename Ordinal, typename Packet>
01577 void Teuchos::reduceAllAndScatter(
01578   const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
01579   const Ordinal sendCount, const Packet sendBuffer[] ,
01580   const Ordinal recvCounts[], Packet myGlobalReducts[]
01581   )
01582 {
01583 
01584   TEUCHOS_COMM_TIME_MONITOR(
01585     "Teuchos::CommHelpers: reduceAllAndScatter<"
01586     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01587     <<">( value type, user-defined op )"
01588     );
01589 
01590   const Ordinal size = Teuchos::size(comm);
01591   const Ordinal rank = Teuchos::rank(comm);
01592 
01593 #ifdef TEUCHOS_DEBUG
01594   Ordinal sumRecvCounts = 0;
01595   for( Ordinal i = 0; i < size; ++i )
01596     sumRecvCounts += recvCounts[static_cast<ptrdiff_t>(i)];
01597   TEUCHOS_TEST_FOR_EXCEPT(!(sumRecvCounts==sendCount));
01598 #endif
01599 
01600   ConstValueTypeSerializationBuffer<Ordinal,Packet>
01601     charSendBuffer(sendCount,sendBuffer);
01602   ValueTypeSerializationBuffer<Ordinal,Packet>
01603     charMyGlobalReducts(recvCounts[static_cast<ptrdiff_t>(rank)], myGlobalReducts);
01604   CharToValueTypeReductionOp<Ordinal,Packet>
01605     charReductOp(rcp(&reductOp,false));
01606 
01607   const Ordinal
01608     packetSize = charSendBuffer.getBytes()/sendCount;
01609 
01610   WorkspaceStore* wss = get_default_workspace_store().get();
01611   Workspace<Ordinal> charRecvCounts(wss, size);
01612   for (Ordinal k = 0; k < size; ++k) {
01613     charRecvCounts[k] = as<Ordinal>(recvCounts[static_cast<ptrdiff_t>(k)] * packetSize);
01614   }
01615  
01616   comm.reduceAllAndScatter(
01617     charReductOp, charSendBuffer.getBytes(), charSendBuffer.getCharBuffer(),
01618     &charRecvCounts[0], charMyGlobalReducts.getCharBuffer()
01619     );
01620 
01621 }
01622 
01623 
01624 template<typename Ordinal, typename Packet>
01625 void Teuchos::reduceAllAndScatter(
01626   const Comm<Ordinal>& comm, const EReductionType reductType,
01627   const Ordinal sendCount, const Packet sendBuffer[] ,
01628   const Ordinal recvCounts[], Packet myGlobalReducts[]
01629   )
01630 {
01631   TEUCHOS_COMM_TIME_MONITOR(
01632     "Teuchos::CommHelpers: reduceAllAndScatter<"
01633     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01634     <<">( value type, "<<toString(reductType)<<" )"
01635     );
01636   std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
01637     reductOp(createOp<Ordinal,Packet>(reductType));
01638   reduceAllAndScatter(
01639     comm, *reductOp, sendCount, sendBuffer, recvCounts, myGlobalReducts
01640     );
01641 }
01642 
01643 
01644 template<typename Ordinal, typename Packet>
01645 void Teuchos::reduceAllAndScatter(
01646   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
01647   const ReferenceTypeReductionOp<Ordinal,Packet> &reductOp,
01648   const Ordinal sendCount, const Packet*const sendBuffer[],
01649   const Ordinal recvCounts[], Packet*const myGlobalReducts[]
01650   )
01651 {
01652   TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
01653 }
01654 
01655 template<typename Ordinal, typename Packet, typename Serializer>
01656 void Teuchos::reduceAllAndScatter(
01657   const Comm<Ordinal>& comm, 
01658   const Serializer& serializer,
01659   const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
01660   const Ordinal sendCount, const Packet sendBuffer[] ,
01661   const Ordinal recvCounts[], Packet myGlobalReducts[]
01662   )
01663 {
01664 
01665   TEUCHOS_COMM_TIME_MONITOR(
01666     "Teuchos::CommHelpers: reduceAllAndScatter<"
01667     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01668     <<">( value type, user-defined op )"
01669     );
01670 
01671   const Ordinal size = Teuchos::size(comm);
01672   const Ordinal rank = Teuchos::rank(comm);
01673 
01674 #ifdef TEUCHOS_DEBUG
01675   Ordinal sumRecvCounts = 0;
01676   for( Ordinal i = 0; i < size; ++i )
01677     sumRecvCounts += recvCounts[static_cast<ptrdiff_t>(i)];
01678   TEUCHOS_TEST_FOR_EXCEPT(!(sumRecvCounts==sendCount));
01679 #endif
01680 
01681   ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
01682     charSendBuffer(sendCount,sendBuffer,rcp(&serializer,false));
01683   ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
01684     charMyGlobalReducts(recvCounts[static_cast<ptrdiff_t>(rank)], myGlobalReducts,rcp(&serializer,false));
01685   CharToValueTypeReductionOp<Ordinal,Packet,Serializer>
01686     charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
01687 
01688   const Ordinal
01689     packetSize = charSendBuffer.getBytes()/sendCount;
01690 
01691   WorkspaceStore* wss = get_default_workspace_store().get();
01692   Workspace<Ordinal> charRecvCounts(wss, size);
01693   for (Ordinal k = 0; k < size; ++k) {
01694     charRecvCounts[k] = as<Ordinal>(recvCounts[static_cast<ptrdiff_t>(k)] * packetSize);
01695   }
01696  
01697   comm.reduceAllAndScatter(
01698     charReductOp, charSendBuffer.getBytes(), charSendBuffer.getCharBuffer(),
01699     &charRecvCounts[0], charMyGlobalReducts.getCharBuffer()
01700     );
01701 
01702 }
01703 
01704 template<typename Ordinal, typename Packet, typename Serializer>
01705 void Teuchos::reduceAllAndScatter(
01706   const Comm<Ordinal>& comm, 
01707   const Serializer& serializer,
01708   const EReductionType reductType,
01709   const Ordinal sendCount, const Packet sendBuffer[] ,
01710   const Ordinal recvCounts[], Packet myGlobalReducts[]
01711   )
01712 {
01713   TEUCHOS_COMM_TIME_MONITOR(
01714     "Teuchos::CommHelpers: reduceAllAndScatter<"
01715     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01716     <<">( value type, "<<toString(reductType)<<" )"
01717     );
01718   std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
01719     reductOp(createOp<Ordinal,Packet>(reductType));
01720   reduceAllAndScatter(
01721     comm, serializer, *reductOp, sendCount, sendBuffer, recvCounts, 
01722     myGlobalReducts
01723     );
01724 }
01725 
01726 
01727 template<typename Ordinal, typename Packet>
01728 void Teuchos::scan(
01729   const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
01730   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
01731   )
01732 {
01733   TEUCHOS_COMM_TIME_MONITOR(
01734     "Teuchos::CommHelpers: scan<"
01735     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01736     <<">( value type, user-defined op )"
01737     );
01738   ConstValueTypeSerializationBuffer<Ordinal,Packet>
01739     charSendBuffer(count,sendBuffer);
01740   ValueTypeSerializationBuffer<Ordinal,Packet>
01741     charScanReducts(count,scanReducts);
01742   CharToValueTypeReductionOp<Ordinal,Packet>
01743     charReductOp(rcp(&reductOp,false));
01744   comm.scan(
01745     charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
01746     ,charScanReducts.getCharBuffer()
01747     );
01748 }
01749 
01750 
01751 template<typename Ordinal, typename Packet>
01752 void Teuchos::scan(
01753   const Comm<Ordinal>& comm, const EReductionType reductType,
01754   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
01755   )
01756 {
01757   TEUCHOS_COMM_TIME_MONITOR(
01758     "Teuchos::CommHelpers: scan<"
01759     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01760     <<">( value type, "<<toString(reductType)<<" )"
01761     );
01762   std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
01763     reductOp(createOp<Ordinal,Packet>(reductType));
01764   scan(comm,*reductOp,count,sendBuffer,scanReducts);
01765 }
01766 
01767 
01768 template<typename Ordinal, typename Packet>
01769 void Teuchos::scan(
01770   const Comm<Ordinal>& comm, const EReductionType reductType,
01771   const Packet &send, const Ptr<Packet> &scanReduct
01772   )
01773 {
01774   scan<Ordinal,Packet>(comm, reductType, 1, &send, &*scanReduct);
01775 }
01776 
01777 
01778 template<typename Ordinal, typename Packet>
01779 void Teuchos::scan(
01780   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
01781   const ReferenceTypeReductionOp<Ordinal,Packet> &reductOp,
01782   const Ordinal count, const Packet*const sendBuffer[], Packet*const scanReducts[]
01783   )
01784 {
01785   TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
01786 }
01787 
01788 template<typename Ordinal, typename Packet, typename Serializer>
01789 void Teuchos::scan(
01790   const Comm<Ordinal>& comm, 
01791   const Serializer& serializer,
01792   const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
01793   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
01794   )
01795 {
01796   TEUCHOS_COMM_TIME_MONITOR(
01797     "Teuchos::CommHelpers: scan<"
01798     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01799     <<">( value type, user-defined op )"
01800     );
01801   ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
01802     charSendBuffer(count,sendBuffer,rcp(&serializer,false));
01803   ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
01804     charScanReducts(count,scanReducts,rcp(&serializer,false));
01805   CharToValueTypeReductionOp<Ordinal,Packet,Serializer>
01806     charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
01807   comm.scan(
01808     charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
01809     ,charScanReducts.getCharBuffer()
01810     );
01811 }
01812 
01813 
01814 template<typename Ordinal, typename Packet, typename Serializer>
01815 void Teuchos::scan(
01816   const Comm<Ordinal>& comm, 
01817   const Serializer& serializer,
01818   const EReductionType reductType,
01819   const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
01820   )
01821 {
01822   TEUCHOS_COMM_TIME_MONITOR(
01823     "Teuchos::CommHelpers: scan<"
01824     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01825     <<">( value type, "<<toString(reductType)<<" )"
01826     );
01827   std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
01828     reductOp(createOp<Ordinal,Packet>(reductType));
01829   scan(comm,serializer,*reductOp,count,sendBuffer,scanReducts);
01830 }
01831 
01832 template<typename Ordinal, typename Packet>
01833 void Teuchos::send(
01834   const Comm<Ordinal>& comm,
01835   const Ordinal count, const Packet sendBuffer[], const int destRank
01836   )
01837 {
01838   TEUCHOS_COMM_TIME_MONITOR(
01839     "Teuchos::CommHelpers: send<"
01840     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01841     <<">( value type )"
01842     );
01843   ConstValueTypeSerializationBuffer<Ordinal,Packet>
01844     charSendBuffer(count,sendBuffer);
01845   comm.send(
01846     charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
01847     ,destRank
01848     );
01849 }
01850 
01851 template<typename Ordinal, typename Packet>
01852 void Teuchos::ssend(
01853   const Comm<Ordinal>& comm,
01854   const Ordinal count, const Packet sendBuffer[], const int destRank
01855   )
01856 {
01857   TEUCHOS_COMM_TIME_MONITOR(
01858     "Teuchos::CommHelpers: ssend<"
01859     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01860     <<">( value type )"
01861     );
01862   ConstValueTypeSerializationBuffer<Ordinal,Packet>
01863     charSendBuffer(count,sendBuffer);
01864   comm.ssend(
01865     charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
01866     ,destRank
01867     );
01868 }
01869 
01870 template<typename Ordinal, typename Packet>
01871 void Teuchos::send(
01872   const Comm<Ordinal>& comm,
01873   const Packet &send, const int destRank
01874   )
01875 {
01876   Teuchos::send<Ordinal,Packet>(comm,1,&send,destRank);
01877 }
01878 
01879 template<typename Ordinal, typename Packet>
01880 void Teuchos::ssend(
01881   const Comm<Ordinal>& comm,
01882   const Packet &send, const int destRank
01883   )
01884 {
01885   Teuchos::ssend<Ordinal,Packet>(comm,1,&send,destRank);
01886 }
01887 
01888 template<typename Ordinal, typename Packet>
01889 void Teuchos::send(
01890   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
01891   const Ordinal count, const Packet*const sendBuffer[], const int destRank
01892   )
01893 {
01894   TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
01895 }
01896 
01897 template<typename Ordinal, typename Packet, typename Serializer>
01898 void Teuchos::send(
01899   const Comm<Ordinal>& comm,
01900   const Serializer& serializer,
01901   const Ordinal count, const Packet sendBuffer[], const int destRank
01902   )
01903 {
01904   TEUCHOS_COMM_TIME_MONITOR(
01905     "Teuchos::CommHelpers: send<"
01906     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01907     <<">( value type )"
01908     );
01909   ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
01910     charSendBuffer(count,sendBuffer,rcp(&serializer,false));
01911   comm.send(
01912     charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
01913     ,destRank
01914     );
01915 }
01916 
01917 template<typename Ordinal, typename Packet>
01918 int Teuchos::receive(
01919   const Comm<Ordinal>& comm,
01920   const int sourceRank, const Ordinal count, Packet recvBuffer[] 
01921   )
01922 {
01923   TEUCHOS_COMM_TIME_MONITOR(
01924     "Teuchos::CommHelpers: receive<"
01925     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01926     <<">( value type )"
01927     );
01928   ValueTypeSerializationBuffer<Ordinal,Packet>
01929     charRecvBuffer(count,recvBuffer);
01930   return comm.receive(
01931     sourceRank
01932     ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
01933     );
01934 }
01935 
01936 
01937 template<typename Ordinal, typename Packet>
01938 int Teuchos::receive(
01939   const Comm<Ordinal>& comm,
01940   const int sourceRank, Packet *recv 
01941   )
01942 {
01943   return Teuchos::receive<Ordinal,Packet>(comm,sourceRank,1,recv);
01944 }
01945 
01946 
01947 template<typename Ordinal, typename Packet>
01948 int Teuchos::receive(
01949   const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
01950   const int sourceRank, const Ordinal count, Packet*const recvBuffer[] 
01951   )
01952 {
01953   TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
01954 }
01955 
01956 template<typename Ordinal, typename Packet, typename Serializer>
01957 int Teuchos::receive(
01958   const Comm<Ordinal>& comm,
01959   const Serializer& serializer,
01960   const int sourceRank, const Ordinal count, Packet recvBuffer[] 
01961   )
01962 {
01963   TEUCHOS_COMM_TIME_MONITOR(
01964     "Teuchos::CommHelpers: receive<"
01965     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01966     <<">( value type )"
01967     );
01968   ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
01969     charRecvBuffer(count,recvBuffer,rcp(&serializer,false));
01970   return comm.receive(
01971     sourceRank
01972     ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
01973     );
01974 }
01975 
01976 template<typename Ordinal, typename Packet>
01977 void Teuchos::readySend(
01978   const Comm<Ordinal>& comm,
01979   const ArrayView<const Packet> &sendBuffer,
01980   const int destRank
01981   )
01982 {
01983   TEUCHOS_COMM_TIME_MONITOR(
01984     "Teuchos::CommHelpers: readySend<"
01985     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
01986     <<">( value type )"
01987     );
01988   ConstValueTypeSerializationBuffer<Ordinal,Packet>
01989     charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr());
01990   comm.readySend( charSendBuffer.getCharBufferView(), destRank );
01991 }
01992 
01993 
01994 template<typename Ordinal, typename Packet>
01995 void Teuchos::readySend(
01996   const Comm<Ordinal>& comm,
01997   const Packet &send,
01998   const int destRank
01999   )
02000 {
02001   readySend<Ordinal, Packet>( comm, arrayView(&send,1), destRank );
02002 }
02003 
02004 template<typename Ordinal, typename Packet, typename Serializer>
02005 void Teuchos::readySend(
02006   const Comm<Ordinal>& comm,
02007   const Serializer& serializer,
02008   const ArrayView<const Packet> &sendBuffer,
02009   const int destRank
02010   )
02011 {
02012   TEUCHOS_COMM_TIME_MONITOR(
02013     "Teuchos::CommHelpers: readySend<"
02014     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02015     <<">( value type )"
02016     );
02017   ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
02018     charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr(), serializer);
02019   comm.readySend( charSendBuffer.getCharBufferView(), destRank );
02020 }
02021 
02022 template<typename Ordinal, typename Packet>
02023 Teuchos::RCP<Teuchos::CommRequest<Ordinal> >
02024 Teuchos::isend(
02025   const Comm<Ordinal>& comm,
02026   const ArrayRCP<const Packet> &sendBuffer,
02027   const int destRank
02028   )
02029 {
02030   TEUCHOS_COMM_TIME_MONITOR(
02031     "Teuchos::CommHelpers: isend<"
02032     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02033     <<">( value type )"
02034     );
02035   ConstValueTypeSerializationBuffer<Ordinal,Packet>
02036     charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr());
02037   RCP<CommRequest<Ordinal> > commRequest = comm.isend(
02038     charSendBuffer.getCharBufferView(), destRank );
02039   set_extra_data( sendBuffer, "buffer", inOutArg(commRequest) );
02040   return commRequest;
02041 }
02042 
02043 
02044 template<typename Ordinal, typename Packet>
02045 Teuchos::RCP<Teuchos::CommRequest<Ordinal> >
02046 Teuchos::isend(
02047   const Comm<Ordinal>& comm,
02048   const RCP<const Packet> &send,
02049   const int destRank
02050   )
02051 {
02052   const ArrayRCP<const Packet> sendBuffer =
02053     arcpWithEmbeddedObj( send.get(), 0, 1, send, false );
02054   // 2008/07/29: rabartl: Above: I need to write a helper function to create
02055   // new ArrayRCP object given a single object to copy.
02056   return isend<Ordinal, Packet>( comm, sendBuffer, destRank );
02057 }
02058 
02059 template<typename Ordinal, typename Packet, typename Serializer>
02060 Teuchos::RCP<Teuchos::CommRequest<Ordinal> >
02061 Teuchos::isend(
02062   const Comm<Ordinal>& comm,
02063   const Serializer& serializer,
02064   const ArrayRCP<const Packet> &sendBuffer,
02065   const int destRank
02066   )
02067 {
02068   TEUCHOS_COMM_TIME_MONITOR(
02069     "Teuchos::CommHelpers: isend<"
02070     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02071     <<">( value type )"
02072     );
02073   ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
02074     charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr(), serializer);
02075   RCP<CommRequest<Ordinal> > commRequest = comm.isend(
02076     charSendBuffer.getCharBufferView(), destRank );
02077   set_extra_data( sendBuffer, "buffer", inOutArg(commRequest) );
02078   return commRequest;
02079 }
02080 
02081 template<typename Ordinal, typename Packet>
02082 Teuchos::RCP<Teuchos::CommRequest<Ordinal> >
02083 Teuchos::ireceive(
02084   const Comm<Ordinal>& comm,
02085   const ArrayRCP<Packet> &recvBuffer,
02086   const int sourceRank
02087   )
02088 {
02089   typedef std::pair<RCP<CommRequest<Ordinal> >, ArrayRCP<const Packet> > comm_buffer_pair_t;
02090   TEUCHOS_COMM_TIME_MONITOR(
02091     "Teuchos::CommHelpers: ireceive<"
02092     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02093     <<">( value type )"
02094     );
02095   ValueTypeSerializationBuffer<Ordinal,Packet>
02096     charRecvBuffer(recvBuffer.size(), recvBuffer.getRawPtr());
02097   RCP<CommRequest<Ordinal> > commRequest = comm.ireceive(
02098     charRecvBuffer.getCharBufferView(), sourceRank );
02099   set_extra_data( recvBuffer, "buffer", inOutArg(commRequest) );
02100   return commRequest;
02101 }
02102 
02103 
02104 template<typename Ordinal, typename Packet>
02105 Teuchos::RCP<Teuchos::CommRequest<Ordinal> >
02106 Teuchos::ireceive(
02107   const Comm<Ordinal>& comm,
02108   const RCP<Packet> &recv,
02109   const int sourceRank
02110   )
02111 {
02112   const ArrayRCP<Packet> recvBuffer =
02113     arcpWithEmbeddedObj( recv.get(), 0, 1, recv, false );
02114   // 2008/07/29: rabartl: Above: I need to write a helper function to create
02115   // new ArrayRCP object given a single object to copy.
02116   return ireceive<Ordinal, Packet>( comm, recvBuffer, sourceRank );
02117 }
02118 
02119 template<typename Ordinal, typename Packet, typename Serializer>
02120 Teuchos::RCP<Teuchos::CommRequest<Ordinal> >
02121 Teuchos::ireceive(
02122   const Comm<Ordinal>& comm,
02123   const Serializer& serializer,
02124   const ArrayRCP<Packet> &recvBuffer,
02125   const int sourceRank
02126   )
02127 {
02128   typedef std::pair<RCP<CommRequest<Ordinal> >, ArrayRCP<const Packet> > comm_buffer_pair_t;
02129   TEUCHOS_COMM_TIME_MONITOR(
02130     "Teuchos::CommHelpers: ireceive<"
02131     <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
02132     <<">( value type )"
02133     );
02134   ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
02135     charRecvBuffer(recvBuffer.size(), recvBuffer.getRawPtr(), serializer);
02136   RCP<CommRequest<Ordinal> > commRequest = comm.ireceive(
02137     charRecvBuffer.getCharBufferView(), sourceRank );
02138   set_extra_data( recvBuffer, "buffer", inOutArg(commRequest) );
02139   return commRequest;
02140 }
02141 
02142 template<typename Ordinal>
02143 void Teuchos::waitAll(
02144   const Comm<Ordinal>& comm,
02145   const ArrayView<RCP<CommRequest<Ordinal> > > &requests
02146   )
02147 {
02148   comm.waitAll(requests);
02149 }
02150 
02151 
02152 template<typename Ordinal>
02153 void 
02154 Teuchos::waitAll (const Comm<Ordinal>& comm,
02155       const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
02156       const ArrayView<RCP<CommStatus<Ordinal> > >& statuses)
02157 {
02158   comm.waitAll (requests, statuses);
02159 }
02160 
02161 
02162 template<typename Ordinal>
02163 Teuchos::RCP<Teuchos::CommStatus<Ordinal> >
02164 Teuchos::wait (const Comm<Ordinal>& comm,
02165          const Ptr<RCP<CommRequest<Ordinal> > > &request)
02166 {
02167   return comm.wait (request);
02168 }
02169 
02170 
02171 #endif // TEUCHOS_COMM_HELPERS_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines