Teuchos - Trilinos Tools Package  Version of the Day
Teuchos_CommHelpers.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef TEUCHOS_COMM_HELPERS_HPP
43 #define TEUCHOS_COMM_HELPERS_HPP
44 
45 #include "Teuchos_Comm.hpp"
46 #include "Teuchos_CommUtilities.hpp"
47 #include "Teuchos_SerializationTraitsHelpers.hpp"
48 #include "Teuchos_ReductionOpHelpers.hpp"
49 #include "Teuchos_SerializerHelpers.hpp"
50 #include "Teuchos_ScalarTraits.hpp"
52 #include "Teuchos_Array.hpp"
54 #include "Teuchos_Workspace.hpp"
55 #include "Teuchos_as.hpp"
56 
57 #ifdef HAVE_TEUCHOS_MPI
59 #endif // HAVE_TEUCHOS_MPI
60 #include "Teuchos_DefaultSerialComm.hpp"
62 
63 namespace Teuchos {
64 
65 //
66 // Teuchos::Comm Helper Functions
67 //
68 
69 #ifdef HAVE_TEUCHOS_MPI
70 namespace Details {
71 
78 std::string getMpiErrorString (const int errCode);
79 
80 } // namespace Details
81 #endif // HAVE_TEUCHOS_MPI
82 
87 template<typename Ordinal>
88 int rank(const Comm<Ordinal>& comm);
89 
94 template<typename Ordinal>
95 int size(const Comm<Ordinal>& comm);
96 
101 template<typename Ordinal>
102 void barrier(const Comm<Ordinal>& comm);
103 
108 template<typename Ordinal, typename Packet>
109 void broadcast(
110  const Comm<Ordinal>& comm,
111  const int rootRank,
112  const Ordinal count, Packet buffer[]
113  );
114 
119 template<typename Ordinal, typename Packet>
120 void broadcast(
121  const Comm<Ordinal>& comm,
122  const int rootRank,
123  const ArrayView<Packet> &buffer
124  );
125 
130 template<typename Ordinal, typename Packet>
131 void broadcast(
132  const Comm<Ordinal>& comm,
133  const int rootRank, Packet *object
134  );
135 
140 template<typename Ordinal, typename Packet>
141 void broadcast(
142  const Comm<Ordinal>& comm,
143  const int rootRank, const Ptr<Packet> &object
144  );
145 
150 template<typename Ordinal, typename Packet>
151 void broadcast(
152  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
153  const int rootRank, const Ordinal count, Packet*const buffer[]
154  );
155 
160 template<typename Ordinal, typename Packet>
161 void broadcast(
162  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
163  const int rootRank, const ArrayView<const Ptr<Packet> > &buffer
164  );
165 
171 template<typename Ordinal, typename Packet, typename Serializer>
172 void broadcast(
173  const Comm<Ordinal>& comm,
174  const Serializer& serializer,
175  const int rootRank,
176  const Ordinal count, Packet buffer[]
177  );
178 
183 template<typename Ordinal, typename Packet>
184 void
185 gather (const Packet sendBuf[],
186  const Ordinal sendCount,
187  Packet recvBuf[],
188  const Ordinal recvCount,
189  const int root,
190  const Comm<Ordinal>& comm);
191 
196 template<typename Ordinal, typename Packet>
197 void
198 gatherv (const Packet sendBuf[],
199  const Ordinal sendCount,
200  Packet recvBuf[],
201  const Ordinal recvCounts[],
202  const Ordinal displs[],
203  const int root,
204  const Comm<Ordinal>& comm);
205 
211 template<typename Ordinal, typename Packet>
212 void gatherAll(
213  const Comm<Ordinal>& comm,
214  const Ordinal sendCount, const Packet sendBuffer[],
215  const Ordinal recvCount, Packet recvBuffer[]
216  );
217 
223 template<typename Ordinal, typename Packet>
224 void gatherAll(
225  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
226  const Ordinal sendCount, const Packet*const sendBuffer[],
227  const Ordinal recvCount, Packet*const recvBuffer[]
228  );
229 
235 template<typename Ordinal, typename Packet, typename Serializer>
236 void gatherAll(
237  const Comm<Ordinal>& comm,
238  const Serializer& serializer,
239  const Ordinal sendCount, const Packet sendBuffer[],
240  const Ordinal recvCount, Packet recvBuffer[]
241  );
242 
269 template<typename Ordinal, typename Packet>
270 void
271 scatter (const Packet sendBuf[],
272  const Ordinal sendCount,
273  Packet recvBuf[],
274  const Ordinal recvCount,
275  const Ordinal root,
276  const Comm<Ordinal>& comm)
277 {
278  // See Bug 6375; Tpetra does not actually need any specializations
279  // other than Ordinal = int and Packet = int. We may add them later
280  // if there is interest.
282  (true, std::logic_error, "Teuchos::scatter<" <<
284  << ">: Generic version is not yet implemented. This function currently "
285  "only has an implementtion for Ordinal = int and Packet = int. "
286  "See Bug 6375 and Bug 6336.");
287 }
288 
316 template<typename Ordinal, typename Packet>
317 void
318 reduce (const Packet sendBuf[],
319  Packet recvBuf[],
320  const Ordinal count,
321  const EReductionType reductType,
322  const Ordinal root,
323  const Comm<Ordinal>& comm);
324 
347 template<typename Ordinal, typename Packet>
348 void reduceAll(
349  const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
350  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
351  );
352 
358 template<typename Ordinal, typename Packet>
359 void reduceAll(
360  const Comm<Ordinal>& comm, const EReductionType reductType,
361  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
362  );
363 
369 template<typename Ordinal, typename Packet>
370 void reduceAll(
371  const Comm<Ordinal>& comm, const EReductionType reductType,
372  const Packet &send, const Ptr<Packet> &globalReduct
373  );
374 
376 template<typename Ordinal, typename Packet>
377 TEUCHOS_DEPRECATED void reduceAll(
378  const Comm<Ordinal>& comm, const EReductionType reductType,
379  const Packet &send, Packet *globalReduct
380  )
381 {
382  reduceAll<Ordinal,Packet>(comm, reductType, send, ptr(globalReduct));
383 }
384 
390 template<typename Ordinal, typename Packet>
391 void reduceAll(
392  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
394  const Ordinal count, const Packet*const sendBuffer[], Packet*const globalReducts[]
395  );
396 
402 template<typename Ordinal, typename Packet, typename Serializer>
403 void reduceAll(
404  const Comm<Ordinal>& comm,
405  const Serializer& serializer,
406  const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
407  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
408  );
409 
415 template<typename Ordinal, typename Packet, typename Serializer>
416 void reduceAll(
417  const Comm<Ordinal>& comm,
418  const Serializer& serializer,
419  const EReductionType reductType,
420  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
421  );
422 
428 template<typename Ordinal, typename Packet>
429 void scan(
430  const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
431  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
432  );
433 
439 template<typename Ordinal, typename Packet>
440 void scan(
441  const Comm<Ordinal>& comm, const EReductionType reductType,
442  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
443  );
444 
450 template<typename Ordinal, typename Packet>
451 void scan(
452  const Comm<Ordinal>& comm, const EReductionType reductType,
453  const Packet &send, const Ptr<Packet> &scanReduct
454  );
455 
457 template<typename Ordinal, typename Packet>
458 TEUCHOS_DEPRECATED void scan(
459  const Comm<Ordinal>& comm, const EReductionType reductType,
460  const Packet &send, Packet *scanReduct
461  )
462 {
463  scan(comm, reductType, send, ptr(scanReduct));
464 }
465 
471 template<typename Ordinal, typename Packet>
472 void scan(
473  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
475  const Ordinal count, const Packet*const sendBuffer[], Packet*const scanReducts[]
476  );
477 
483 template<typename Ordinal, typename Packet, typename Serializer>
484 void scan(
485  const Comm<Ordinal>& comm,
486  const Serializer& serializer,
487  const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
488  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
489  );
490 
496 template<typename Ordinal, typename Packet, typename Serializer>
497 void scan(
498  const Comm<Ordinal>& comm,
499  const Serializer& serializer,
500  const EReductionType reductType,
501  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
502  );
503 
508 template<typename Ordinal, typename Packet>
509 void send(
510  const Comm<Ordinal>& comm,
511  const Ordinal count, const Packet sendBuffer[], const int destRank
512  );
513 
515 template<typename Ordinal, typename Packet>
516 void
517 send (const Packet sendBuffer[],
518  const Ordinal count,
519  const int destRank,
520  const int tag,
521  const Comm<Ordinal>& comm);
522 
527 template<typename Ordinal, typename Packet>
528 void ssend(
529  const Comm<Ordinal>& comm,
530  const Ordinal count, const Packet sendBuffer[], const int destRank
531  );
532 
534 template<typename Ordinal, typename Packet>
535 void
536 ssend (const Packet sendBuffer[],
537  const Ordinal count,
538  const int destRank,
539  const int tag,
540  const Comm<Ordinal>& comm);
541 
546 template<typename Ordinal, typename Packet>
547 void send(
548  const Comm<Ordinal>& comm,
549  const Packet &send, const int destRank
550  );
551 
556 template<typename Ordinal, typename Packet>
557 void ssend(
558  const Comm<Ordinal>& comm,
559  const Packet &send, const int destRank
560  );
561 
568 template<typename Ordinal, typename Packet>
569 void send(
570  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
571  const Ordinal count, const Packet*const sendBuffer[], const int destRank
572  );
573 
579 template<typename Ordinal, typename Packet, typename Serializer>
580 void send(
581  const Comm<Ordinal>& comm,
582  const Serializer& serializer,
583  const Ordinal count, const Packet sendBuffer[], const int destRank
584  );
585 
590 template<typename Ordinal, typename Packet>
591 int receive(
592  const Comm<Ordinal>& comm,
593  const int sourceRank, const Ordinal count, Packet recvBuffer[]
594  );
595 
600 template<typename Ordinal, typename Packet>
601 int receive(
602  const Comm<Ordinal>& comm,
603  const int sourceRank, Packet *recv
604  );
605 
610 template<typename Ordinal, typename Packet>
611 int receive(
612  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
613  const int sourceRank, const Ordinal count, Packet*const recvBuffer[]
614  );
615 
621 template<typename Ordinal, typename Packet, typename Serializer>
622 int receive(
623  const Comm<Ordinal>& comm,
624  const Serializer& serializer,
625  const int sourceRank, const Ordinal count, Packet recvBuffer[]
626  );
627 
633 template<typename Ordinal, typename Packet>
634 void readySend(
635  const Comm<Ordinal>& comm,
636  const ArrayView<const Packet> &sendBuffer,
637  const int destRank
638  );
639 
641 template<typename Ordinal, typename Packet>
642 void
643 readySend (const Packet sendBuffer[],
644  const Ordinal count,
645  const int destRank,
646  const int tag,
647  const Comm<Ordinal>& comm);
648 
653 template<typename Ordinal, typename Packet>
654 void readySend(
655  const Comm<Ordinal>& comm,
656  const Packet &send,
657  const int destRank
658  );
659 
665 template<typename Ordinal, typename Packet, typename Serializer>
666 void readySend(
667  const Comm<Ordinal>& comm,
668  const Serializer& serializer,
669  const ArrayView<const Packet> &sendBuffer,
670  const int destRank
671  );
672 
677 template<typename Ordinal, typename Packet>
679  const Comm<Ordinal>& comm,
680  const ArrayRCP<const Packet> &sendBuffer,
681  const int destRank
682  );
683 
685 template<typename Ordinal, typename Packet>
687 isend (const ArrayRCP<const Packet>& sendBuffer,
688  const int destRank,
689  const int tag,
690  const Comm<Ordinal>& comm);
691 
696 template<typename Ordinal, typename Packet>
698  const Comm<Ordinal>& comm,
699  const RCP<const Packet> &send,
700  const int destRank
701  );
702 
708 template<typename Ordinal, typename Packet, typename Serializer>
710  const Comm<Ordinal>& comm,
711  const Serializer& serializer,
712  const ArrayRCP<const Packet> &sendBuffer,
713  const int destRank
714  );
715 
716 
717 // 2008/07/29: rabartl: ToDo: Add reference semantics version of isend!
718 
719 
729 template<typename Ordinal, typename Packet>
731  const Comm<Ordinal>& comm,
732  const ArrayRCP<Packet> &recvBuffer,
733  const int sourceRank
734  );
735 
737 template<typename Ordinal, typename Packet>
739 ireceive (const ArrayRCP<Packet> &recvBuffer,
740  const int sourceRank,
741  const int tag,
742  const Comm<Ordinal>& comm);
743 
755 template<typename Ordinal, typename Packet>
757  const Comm<Ordinal>& comm,
758  const RCP<Packet> &recv,
759  const int sourceRank
760  );
761 
767 template<typename Ordinal, typename Packet, typename Serializer>
769  const Comm<Ordinal>& comm,
770  const Serializer& serializer,
771  const ArrayRCP<Packet> &recvBuffer,
772  const int sourceRank
773  );
774 
775 
776 // 2008/07/29: rabartl: ToDo: Add reference semantics version of ireceive!
777 
778 
786 template<typename Ordinal>
787 void waitAll(
788  const Comm<Ordinal>& comm,
789  const ArrayView<RCP<CommRequest<Ordinal> > > &requests
790  );
791 
821 template<typename Ordinal>
822 void
823 waitAll (const Comm<Ordinal>& comm,
824  const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
825  const ArrayView<RCP<CommStatus<Ordinal> > >& statuses);
826 
850 template<typename Ordinal>
852 wait (const Comm<Ordinal>& comm, const Ptr<RCP<CommRequest<Ordinal> > >& request);
853 
854 //
855 // Standard reduction subclasses for objects that use value semantics
856 //
857 
858 
863 template<typename Ordinal, typename Packet>
864 class SumValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
865 {
866 public:
868  void reduce(
869  const Ordinal count,
870  const Packet inBuffer[],
871  Packet inoutBuffer[]
872  ) const;
873 };
874 
875 
884 template<typename Ordinal, typename Packet>
885 class MinValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
886 {
887 public:
889  void reduce(
890  const Ordinal count,
891  const Packet inBuffer[],
892  Packet inoutBuffer[]
893  ) const;
894 };
895 
896 
905 template<typename Ordinal, typename Packet>
906 class MaxValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
907 {
908 public:
910  void reduce(
911  const Ordinal count,
912  const Packet inBuffer[],
913  Packet inoutBuffer[]
914  ) const;
915 };
916 
917 
922 template<typename Ordinal, typename Packet>
923 class ANDValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
924 {
925 public:
927  void reduce(
928  const Ordinal count,
929  const Packet inBuffer[],
930  Packet inoutBuffer[]
931  ) const;
932 };
933 
934 
935 // ////////////////////////////////////////////////////////////
936 // Implementation details (not for geneal users to mess with)
937 
938 
939 //
940 // ReductionOp Utilities
941 //
942 
943 
944 namespace MixMaxUtilities {
945 
946 
947 template<bool isComparable, typename Ordinal, typename Packet>
948 class Min {};
949 
950 
951 template<typename Ordinal, typename Packet>
952 class Min<true,Ordinal,Packet> {
953 public:
954  static void min(
955  const Ordinal count,
956  const Packet inBuffer[],
957  Packet inoutBuffer[]
958  )
959  {
960  for( int i = 0; i < count; ++i )
961  inoutBuffer[i] = TEUCHOS_MIN(inoutBuffer[i],inBuffer[i]);
962  }
963 };
964 
965 
966 template<typename Ordinal, typename Packet>
967 class Min<false,Ordinal,Packet> {
968 public:
969  static void min(
970  const Ordinal,
971  const Packet[],
972  Packet[]
973  )
974  {
976  true,std::logic_error,
977  "Error, the type "<<TypeNameTraits<Packet>::name()
978  <<" does not support comparison operations!"
979  );
980  }
981 };
982 
983 
984 template<bool isComparable, typename Ordinal, typename Packet>
985 class Max {};
986 
987 
988 template<typename Ordinal, typename Packet>
989 class Max<true,Ordinal,Packet> {
990 public:
991  static void max(
992  const Ordinal count,
993  const Packet inBuffer[],
994  Packet inoutBuffer[]
995  )
996  {
997  for( int i = 0; i < count; ++i )
998  inoutBuffer[i] = TEUCHOS_MAX(inoutBuffer[i],inBuffer[i]);
999  }
1000 };
1001 
1002 
1003 template<typename Ordinal, typename Packet>
1004 class Max<false,Ordinal,Packet> {
1005 public:
1006  static void max(
1007  const Ordinal,
1008  const Packet[],
1009  Packet[]
1010  )
1011  {
1013  true,std::logic_error,
1014  "Error, the type "<<TypeNameTraits<Packet>::name()
1015  <<" does not support comparison operations!"
1016  );
1017  }
1018 };
1019 
1020 
1021 template<bool isComparable, typename Ordinal, typename Packet>
1022 class AND {};
1023 
1024 
1025 template<typename Ordinal, typename Packet>
1026 class AND<true,Ordinal,Packet> {
1027 public:
1028  static void andOp(
1029  const Ordinal count,
1030  const Packet inBuffer[],
1031  Packet inoutBuffer[]
1032  )
1033  {
1034  for( int i = 0; i < count; ++i )
1035  inoutBuffer[i] = inoutBuffer[i] && inBuffer[i];
1036  }
1037 };
1038 
1039 
1040 template<typename Ordinal, typename Packet>
1041 class AND<false,Ordinal,Packet> {
1042 public:
1043  static void andOp(
1044  const Ordinal,
1045  const Packet[],
1046  Packet[]
1047  )
1048  {
1050  true,std::logic_error,
1051  "Error, the type "<<TypeNameTraits<Packet>::name()
1052  <<" does not support logical AND operations!"
1053  );
1054  }
1055 };
1056 
1057 
1058 } // namespace MixMaxUtilities
1059 
1060 
1061 template<typename Ordinal, typename Packet>
1063  const Ordinal count,
1064  const Packet inBuffer[],
1065  Packet inoutBuffer[]
1066  ) const
1067 {
1068  for( int i = 0; i < count; ++i )
1069  inoutBuffer[i] += inBuffer[i];
1070 }
1071 
1072 
1073 template<typename Ordinal, typename Packet>
1075  const Ordinal count,
1076  const Packet inBuffer[],
1077  Packet inoutBuffer[]
1078  ) const
1079 {
1080  typedef MixMaxUtilities::Min<ScalarTraits<Packet>::isComparable, Ordinal, Packet> min_type;
1081  min_type::min (count, inBuffer, inoutBuffer);
1082 }
1083 
1084 
1085 template<typename Ordinal, typename Packet>
1087  const Ordinal count,
1088  const Packet inBuffer[],
1089  Packet inoutBuffer[]
1090  ) const
1091 {
1092  typedef MixMaxUtilities::Max<ScalarTraits<Packet>::isComparable, Ordinal, Packet> max_type;
1093  max_type::max (count,inBuffer,inoutBuffer);
1094 }
1095 
1096 
1097 template<typename Ordinal, typename Packet>
1099  const Ordinal count,
1100  const Packet inBuffer[],
1101  Packet inoutBuffer[]
1102  ) const
1103 {
1104  typedef MixMaxUtilities::AND<ScalarTraits<Packet>::isComparable, Ordinal, Packet> and_type;
1105  and_type::andOp (count, inBuffer, inoutBuffer);
1106 }
1107 
1108 
1109 } // namespace Teuchos
1110 
1111 
1112 // //////////////////////////
1113 // Template implemenations
1114 
1115 
1116 //
1117 // ReductionOp utilities
1118 //
1119 
1120 
1121 namespace Teuchos {
1122 
1123 
1124 // Not for the general user to use! I am returning a raw ReductionOp* pointer
1125 // to avoid the overhead of using RCP. However, given the use case
1126 // this is just fine since I can just use std::auto_ptr to make sure things
1127 // are deleted correctly.
1128 //
1129 // NOTE (mfh 08 Feb 2015) std::auto_ptr has been deprecated in C++11.
1130 // I could either replace it with std::unique_ptr, or just call 'new'
1131 // and 'delete' manually. The former is less error prone, but
1132 // requires checking a macro for whether C++11 is actually enabled.
1133 // Thus, I've chosen (for now) to rewrite all the code that uses
1134 // std::auto_ptr, so that it allocates and deletes manually.
1135 template<typename Ordinal, typename Packet>
1137 createOp (const EReductionType reductType)
1138 {
1139  typedef ScalarTraits<Packet> ST;
1140  switch (reductType) {
1141  case REDUCE_SUM: {
1143  }
1144  case REDUCE_MIN: {
1145  if (ST::isComparable) {
1147  }
1148  else {
1150  (! ST::isComparable, std::invalid_argument, "Teuchos::createOp"
1151  "(EReductionType): The Packet type " << TypeNameTraits<Packet>::name ()
1152  << " is not less-than comparable, so it does not make sense to do a "
1153  "MIN reduction with it.");
1154  }
1155  }
1156  case REDUCE_MAX: {
1157  if (ST::isComparable) {
1159  }
1160  else {
1162  (! ST::isComparable, std::invalid_argument, "Teuchos::createOp"
1163  "(EReductionType): The Packet type " << TypeNameTraits<Packet>::name ()
1164  << " is not less-than comparable, so it does not make sense to do a "
1165  "MAX reduction with it.");
1166  }
1167  }
1168  case REDUCE_AND: {
1170  }
1171  default:
1173  true, std::invalid_argument, "Teuchos::createOp(EReductionType): "
1174  "Invalid EReductionType value " << reductType << ". Valid values "
1175  "include REDUCE_SUM, REDUCE_MIN, REDUCE_MAX, and REDUCE_AND.");
1176  }
1177 }
1178 
1179 
1180 } // namespace Teuchos
1181 
1182 
1183 //
1184 // Teuchos::Comm wrapper functions
1185 //
1186 
1187 
1188 template<typename Ordinal>
1189 int Teuchos::rank(const Comm<Ordinal>& comm)
1190 {
1191  return comm.getRank();
1192 }
1193 
1194 
1195 template<typename Ordinal>
1196 int Teuchos::size(const Comm<Ordinal>& comm)
1197 {
1198  return comm.getSize();
1199 }
1200 
1201 
1202 template<typename Ordinal>
1203 void Teuchos::barrier(const Comm<Ordinal>& comm)
1204 {
1205  TEUCHOS_COMM_TIME_MONITOR(
1206  "Teuchos::CommHelpers: barrier<"
1208  <<">()"
1209  );
1210  comm.barrier();
1211 }
1212 
1213 
1214 template<typename Ordinal, typename Packet>
1215 void Teuchos::broadcast(
1216  const Comm<Ordinal>& comm,
1217  const int rootRank, const Ordinal count, Packet buffer[]
1218  )
1219 {
1220  TEUCHOS_COMM_TIME_MONITOR(
1221  "Teuchos::CommHelpers: broadcast<"
1223  <<">( value type )"
1224  );
1226  charBuffer(count,buffer);
1227  comm.broadcast(
1228  rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1229  );
1230 }
1231 
1232 
1233 template<typename Ordinal, typename Packet>
1234 void Teuchos::broadcast(
1235  const Comm<Ordinal>& comm,
1236  const int rootRank,
1237  const ArrayView<Packet> &buffer
1238  )
1239 {
1240  broadcast<Ordinal, Packet>(comm, rootRank, buffer.size(), buffer.getRawPtr() );
1241 }
1242 
1243 
1244 template<typename Ordinal, typename Packet>
1245 void Teuchos::broadcast(
1246  const Comm<Ordinal>& comm,
1247  const int rootRank, Packet *object
1248  )
1249 {
1250  broadcast<Ordinal,Packet>(comm,rootRank,1,object);
1251 }
1252 
1253 
1254 template<typename Ordinal, typename Packet>
1255 void Teuchos::broadcast(
1256  const Comm<Ordinal>& comm,
1257  const int rootRank, const Ptr<Packet> &object
1258  )
1259 {
1260  broadcast<Ordinal,Packet>(comm,rootRank,1,object.getRawPtr());
1261 }
1262 
1263 
1264 template<typename Ordinal, typename Packet>
1265 void Teuchos::broadcast(
1266  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
1267  const int rootRank, const Ordinal count, Packet*const buffer[]
1268  )
1269 {
1270  TEUCHOS_COMM_TIME_MONITOR(
1271  "Teuchos::CommHelpers: broadcast<"
1273  <<">( reference type )"
1274  );
1276  charBuffer(serializer, count, buffer);
1277  comm.broadcast(
1278  rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1279  );
1280 }
1281 
1282 
1283 template<typename Ordinal, typename Packet>
1284 void Teuchos::broadcast(
1285  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
1286  const int rootRank, const ArrayView<const Ptr<Packet> > &buffer
1287  )
1288 {
1289  Array<Packet*> bufferPtrArray;
1290  for (int i = 0; i < buffer.size(); ++i) {
1291  bufferPtrArray.push_back(buffer[i].getRawPtr());
1292  }
1293  broadcast<Ordinal,Packet>(comm, serializer, rootRank,
1294  buffer.size(), bufferPtrArray.getRawPtr());
1295 }
1296 
1297 template<typename Ordinal, typename Packet, typename Serializer>
1298 void Teuchos::broadcast(
1299  const Comm<Ordinal>& comm,
1300  const Serializer& serializer,
1301  const int rootRank, const Ordinal count, Packet buffer[]
1302  )
1303 {
1304  TEUCHOS_COMM_TIME_MONITOR(
1305  "Teuchos::CommHelpers: broadcast<"
1307  <<">( value type )"
1308  );
1310  charBuffer(count,buffer,rcp(&serializer,false));
1311  comm.broadcast(
1312  rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1313  );
1314 }
1315 
1316 
1317 template<typename Ordinal, typename Packet>
1318 void Teuchos::gatherAll(
1319  const Comm<Ordinal>& comm,
1320  const Ordinal sendCount, const Packet sendBuffer[],
1321  const Ordinal recvCount, Packet recvBuffer[]
1322  )
1323 {
1324  TEUCHOS_COMM_TIME_MONITOR(
1325  "Teuchos::CommHelpers: gatherAll<"
1327  <<">( value type )"
1328  );
1330  charSendBuffer(sendCount,sendBuffer);
1332  charRecvBuffer(recvCount,recvBuffer);
1333  comm.gatherAll(
1334  charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1335  ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
1336  );
1337 }
1338 
1339 template<typename Ordinal, typename Packet>
1340 void
1341 Teuchos::gather (const Packet sendBuf[],
1342  const Ordinal sendCount,
1343  Packet recvBuf[],
1344  const Ordinal recvCount,
1345  const int root,
1346  const Comm<Ordinal>& comm)
1347 {
1348  TEUCHOS_COMM_TIME_MONITOR(
1349  "Teuchos::CommHelpers: gather<"
1351  <<">( value type )"
1352  );
1354  charSendBuffer (sendCount, sendBuf);
1356  charRecvBuffer (recvCount, recvBuf);
1357  comm.gather (charSendBuffer.getBytes (),
1358  charSendBuffer.getCharBuffer (),
1359  charRecvBuffer.getBytes (),
1360  charRecvBuffer.getCharBuffer (),
1361  root);
1362 }
1363 
1364 template<typename Ordinal, typename Packet>
1365 void
1366 Teuchos::gatherv (const Packet sendBuf[],
1367  const Ordinal sendCount,
1368  Packet recvBuf[],
1369  const Ordinal recvCounts[],
1370  const Ordinal displs[],
1371  const int root,
1372  const Comm<Ordinal>& comm)
1373 {
1374  // Ordinal totalRecvCount = 0;
1375 
1376  // // In order to get the right output buffer length, we have to sum
1377  // // the receive counts from all the processes in the communicator.
1378  // const Ordinal numProcs = as<Ordinal> (comm->getSize ());
1379  // for (Ordinal k = 0; k < as<Ordinal> (numProcs); ++k) {
1380  // totalRecvCount += recvCounts[k];
1381  // }
1382 
1383  // // FIXME (mfh 16 Apr 2013) We also have to redo the displacements.
1384 
1385  // ConstValueTypeSerializationBuffer<Ordinal,Packet>
1386  // charSendBuffer (sendCount, sendBuf);
1387  // ValueTypeSerializationBuffer<Ordinal,Packet>
1388  // charRecvBuffer (totalRecvCount, recvBuf);
1389  // comm.gatherv (charSendBuffer.getBytes (),
1390  // charSendBuffer.getCharBuffer (),
1391  // charRecvBuffer.getBytes (),
1392  // charRecvBuffer.getCharBuffer (),
1393  // root);
1394  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
1395  "Teuchos::gatherv: The general case is not implemented.");
1396 }
1397 
1398 template<typename Ordinal, typename Packet>
1399 void Teuchos::gatherAll(
1400  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
1401  const Ordinal sendCount, const Packet*const sendBuffer[],
1402  const Ordinal recvCount, Packet*const recvBuffer[]
1403  )
1404 {
1405  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
1406 }
1407 
1408 template<typename Ordinal, typename Packet, typename Serializer>
1409 void Teuchos::gatherAll(
1410  const Comm<Ordinal>& comm,
1411  const Serializer& serializer,
1412  const Ordinal sendCount, const Packet sendBuffer[],
1413  const Ordinal recvCount, Packet recvBuffer[]
1414  )
1415 {
1416  TEUCHOS_COMM_TIME_MONITOR(
1417  "Teuchos::CommHelpers: gatherAll<"
1419  <<">( value type )"
1420  );
1422  charSendBuffer(sendCount,sendBuffer,rcp(&serializer,false));
1424  charRecvBuffer(recvCount,recvBuffer,rcp(&serializer,false));
1425  comm.gatherAll(
1426  charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1427  ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
1428  );
1429 }
1430 
1431 
1432 template<typename Ordinal, typename Packet>
1433 void
1434 Teuchos::reduce (const Packet sendBuf[],
1435  Packet recvBuf[],
1436  const Ordinal count,
1437  const EReductionType reductType,
1438  const Ordinal root,
1439  const Comm<Ordinal>& comm)
1440 {
1441  // See Bug 6375; Tpetra does not actually need any specializations
1442  // other than Ordinal = int and Packet = int. We may add them later
1443  // if there is interest.
1445  (true, std::logic_error, "Teuchos::reduce<" <<
1447  << ">: Generic version not implemented. We only implement this function "
1448  "for Ordinal = int and Packet = specific types.");
1449 }
1450 
1451 
1452 template<typename Ordinal, typename Packet>
1453 void Teuchos::reduceAll(
1454  const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp
1455  ,const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
1456  )
1457 {
1458  TEUCHOS_COMM_TIME_MONITOR(
1459  "Teuchos::CommHelpers: reduceAll<"
1461  <<">( value type, user-defined op )"
1462  );
1464  charSendBuffer(count,sendBuffer);
1466  charGlobalReducts(count,globalReducts);
1468  charReductOp(rcp(&reductOp,false));
1469  comm.reduceAll(
1470  charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1471  ,charGlobalReducts.getCharBuffer()
1472  );
1473 }
1474 
1475 
1476 template<typename Ordinal, typename Packet>
1477 void Teuchos::reduceAll(
1478  const Comm<Ordinal>& comm, const EReductionType reductType,
1479  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
1480  )
1481 {
1482  TEUCHOS_COMM_TIME_MONITOR(
1483  "Teuchos::CommHelpers: reduceAll<"
1485  <<">( value type, "<<toString(reductType)<<" )"
1486  );
1487 
1489  createOp<Ordinal, Packet> (reductType);
1490  try {
1491  reduceAll(comm,*reductOp,count,sendBuffer,globalReducts);
1492  }
1493  catch (std::exception& e) {
1494  delete reductOp;
1495  throw e;
1496  }
1497  delete reductOp;
1498 }
1499 
1500 
1501 namespace Teuchos {
1502 
1503 // amb 11 Nov 2014. I am disabling these specializations for
1504 // now. MPI_C_DOUBLE_COMPLEX is causing a problem in some builds. This code was
1505 // effectively turned on only yesterday (10 Nov 2014) when TEUCHOS_HAVE_COMPLEX
1506 // was corrected to be HAVE_TEUCHOS_COMPLEX, so evidently there are no users of
1507 // these specializations.
1508 #if 0
1509 #ifdef HAVE_TEUCHOS_COMPLEX
1510 // Specialization for Ordinal=int and Packet=std::complex<double>.
1511 template<>
1512 TEUCHOSCOMM_LIB_DLL_EXPORT void
1513 reduceAll<int, std::complex<double> > (const Comm<int>& comm,
1514  const EReductionType reductType,
1515  const int count,
1516  const std::complex<double> sendBuffer[],
1517  std::complex<double> globalReducts[]);
1518 template<>
1519 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1520 ireceive<int, std::complex<double> > (const Comm<int>& comm,
1521  const ArrayRCP<std::complex<double> >& recvBuffer,
1522  const int sourceRank);
1523 template<>
1524 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1525 ireceive<int, std::complex<double> > (const ArrayRCP<std::complex<double> > &recvBuffer,
1526  const int sourceRank,
1527  const int tag,
1528  const Comm<int>& comm);
1529 template<>
1530 TEUCHOSCOMM_LIB_DLL_EXPORT void
1531 send<int, std::complex<double> > (const Comm<int>& comm,
1532  const int count,
1533  const std::complex<double> sendBuffer[],
1534  const int destRank);
1535 template<>
1536 TEUCHOSCOMM_LIB_DLL_EXPORT void
1537 send<int, std::complex<double> > (const std::complex<double> sendBuffer[],
1538  const int count,
1539  const int destRank,
1540  const int tag,
1541  const Comm<int>& comm);
1542 template<>
1543 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1544 isend<int, std::complex<double> > (const ArrayRCP<const std::complex<double> >& sendBuffer,
1545  const int destRank,
1546  const int tag,
1547  const Comm<int>& comm);
1548 
1549 // Specialization for Ordinal=int and Packet=std::complex<float>.
1550 template<>
1551 TEUCHOSCOMM_LIB_DLL_EXPORT void
1552 reduceAll<int, std::complex<float> > (const Comm<int>& comm,
1553  const EReductionType reductType,
1554  const int count,
1555  const std::complex<float> sendBuffer[],
1556  std::complex<float> globalReducts[]);
1557 template<>
1558 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1559 ireceive<int, std::complex<float> > (const Comm<int>& comm,
1560  const ArrayRCP<std::complex<float> >& recvBuffer,
1561  const int sourceRank);
1562 template<>
1563 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1564 ireceive<int, std::complex<float> > (const ArrayRCP<std::complex<float> > &recvBuffer,
1565  const int sourceRank,
1566  const int tag,
1567  const Comm<int>& comm);
1568 template<>
1569 TEUCHOSCOMM_LIB_DLL_EXPORT void
1570 send<int, std::complex<float> > (const Comm<int>& comm,
1571  const int count,
1572  const std::complex<float> sendBuffer[],
1573  const int destRank);
1574 template<>
1575 TEUCHOSCOMM_LIB_DLL_EXPORT void
1576 send<int, std::complex<float> > (const std::complex<float> sendBuffer[],
1577  const int count,
1578  const int destRank,
1579  const int tag,
1580  const Comm<int>& comm);
1581 template<>
1582 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1583 isend<int, std::complex<float> > (const ArrayRCP<const std::complex<float> >& sendBuffer,
1584  const int destRank,
1585  const int tag,
1586  const Comm<int>& comm);
1587 #endif // HAVE_TEUCHOS_COMPLEX
1588 #endif // if 0
1589 
1590 // Specialization for Ordinal=int and Packet=double.
1591 template<>
1592 TEUCHOSCOMM_LIB_DLL_EXPORT void
1593 reduceAll<int, double> (const Comm<int>& comm,
1594  const EReductionType reductType,
1595  const int count,
1596  const double sendBuffer[],
1597  double globalReducts[]);
1598 template<>
1599 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1600 ireceive<int, double> (const Comm<int>& comm,
1601  const ArrayRCP<double>& recvBuffer,
1602  const int sourceRank);
1603 template<>
1604 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1605 ireceive<int, double> (const ArrayRCP<double> &recvBuffer,
1606  const int sourceRank,
1607  const int tag,
1608  const Comm<int>& comm);
1609 template<>
1610 TEUCHOSCOMM_LIB_DLL_EXPORT void
1611 send<int, double> (const Comm<int>& comm,
1612  const int count,
1613  const double sendBuffer[],
1614  const int destRank);
1615 template<>
1616 TEUCHOSCOMM_LIB_DLL_EXPORT void
1617 send<int, double> (const double sendBuffer[],
1618  const int count,
1619  const int destRank,
1620  const int tag,
1621  const Comm<int>& comm);
1622 template<>
1623 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1624 isend<int, double> (const ArrayRCP<const double>& sendBuffer,
1625  const int destRank,
1626  const int tag,
1627  const Comm<int>& comm);
1628 
1629 // Specialization for Ordinal=int and Packet=float.
1630 template<>
1631 TEUCHOSCOMM_LIB_DLL_EXPORT void
1632 reduceAll<int, float> (const Comm<int>& comm,
1633  const EReductionType reductType,
1634  const int count,
1635  const float sendBuffer[],
1636  float globalReducts[]);
1637 template<>
1638 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1639 ireceive<int, float> (const Comm<int>& comm,
1640  const ArrayRCP<float>& recvBuffer,
1641  const int sourceRank);
1642 template<>
1643 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1644 ireceive<int, float> (const ArrayRCP<float> &recvBuffer,
1645  const int sourceRank,
1646  const int tag,
1647  const Comm<int>& comm);
1648 template<>
1649 TEUCHOSCOMM_LIB_DLL_EXPORT void
1650 send<int, float> (const Comm<int>& comm,
1651  const int count,
1652  const float sendBuffer[],
1653  const int destRank);
1654 template<>
1655 TEUCHOSCOMM_LIB_DLL_EXPORT void
1656 send<int, float> (const float sendBuffer[],
1657  const int count,
1658  const int destRank,
1659  const int tag,
1660  const Comm<int>& comm);
1661 template<>
1662 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1663 isend<int, float> (const ArrayRCP<const float>& sendBuffer,
1664  const int destRank,
1665  const int tag,
1666  const Comm<int>& comm);
1667 
1668 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
1669 // Specialization for Ordinal=int and Packet=long long.
1670 template<>
1671 TEUCHOSCOMM_LIB_DLL_EXPORT void
1672 gather<int, long long> (const long long sendBuf[],
1673  const int sendCount,
1674  long long recvBuf[],
1675  const int recvCount,
1676  const int root,
1677  const Comm<int>& comm);
1678 template<>
1679 TEUCHOSCOMM_LIB_DLL_EXPORT void
1680 gatherv<int, long long> (const long long sendBuf[],
1681  const int sendCount,
1682  long long recvBuf[],
1683  const int recvCounts[],
1684  const int displs[],
1685  const int root,
1686  const Comm<int>& comm);
1687 template<>
1688 TEUCHOSCOMM_LIB_DLL_EXPORT void
1689 reduceAll<int, long long> (const Comm<int>& comm,
1690  const EReductionType reductType,
1691  const int count,
1692  const long long sendBuffer[],
1693  long long globalReducts[]);
1694 template<>
1695 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1696 ireceive<int, long long> (const Comm<int>& comm,
1697  const ArrayRCP<long long>& recvBuffer,
1698  const int sourceRank);
1699 template<>
1700 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1701 ireceive<int, long long> (const ArrayRCP<long long> &recvBuffer,
1702  const int sourceRank,
1703  const int tag,
1704  const Comm<int>& comm);
1705 template<>
1706 TEUCHOSCOMM_LIB_DLL_EXPORT void
1707 send<int, long long> (const Comm<int>& comm,
1708  const int count,
1709  const long long sendBuffer[],
1710  const int destRank);
1711 template<>
1712 TEUCHOSCOMM_LIB_DLL_EXPORT void
1713 send<int, long long> (const long long sendBuffer[],
1714  const int count,
1715  const int destRank,
1716  const int tag,
1717  const Comm<int>& comm);
1718 template<>
1719 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1720 isend<int, long long> (const ArrayRCP<const long long>& sendBuffer,
1721  const int destRank,
1722  const int tag,
1723  const Comm<int>& comm);
1724 
1725 // Specialization for Ordinal=int and Packet=unsigned long long.
1726 template<>
1727 TEUCHOSCOMM_LIB_DLL_EXPORT void
1728 gather<int, unsigned long long> (const unsigned long long sendBuf[],
1729  const int sendCount,
1730  unsigned long long recvBuf[],
1731  const int recvCount,
1732  const int root,
1733  const Comm<int>& comm);
1734 template<>
1735 TEUCHOSCOMM_LIB_DLL_EXPORT void
1736 gatherv<int, unsigned long long> (const unsigned long long sendBuf[],
1737  const int sendCount,
1738  unsigned long long recvBuf[],
1739  const int recvCounts[],
1740  const int displs[],
1741  const int root,
1742  const Comm<int>& comm);
1743 template<>
1744 TEUCHOSCOMM_LIB_DLL_EXPORT void
1745 reduceAll<int, unsigned long long> (const Comm<int>& comm,
1746  const EReductionType reductType,
1747  const int count,
1748  const unsigned long long sendBuffer[],
1749  unsigned long long globalReducts[]);
1750 template<>
1751 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1752 ireceive<int, unsigned long long> (const Comm<int>& comm,
1753  const ArrayRCP<unsigned long long>& recvBuffer,
1754  const int sourceRank);
1755 template<>
1756 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1757 ireceive<int, unsigned long long> (const ArrayRCP<unsigned long long> &recvBuffer,
1758  const int sourceRank,
1759  const int tag,
1760  const Comm<int>& comm);
1761 template<>
1762 TEUCHOSCOMM_LIB_DLL_EXPORT void
1763 send<int, unsigned long long> (const Comm<int>& comm,
1764  const int count,
1765  const unsigned long long sendBuffer[],
1766  const int destRank);
1767 template<>
1768 TEUCHOSCOMM_LIB_DLL_EXPORT void
1769 send<int, unsigned long long> (const unsigned long long sendBuffer[],
1770  const int count,
1771  const int destRank,
1772  const int tag,
1773  const Comm<int>& comm);
1774 template<>
1775 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1776 isend<int, unsigned long long> (const ArrayRCP<const unsigned long long>& sendBuffer,
1777  const int destRank,
1778  const int tag,
1779  const Comm<int>& comm);
1780 #endif // HAVE_TEUCHOS_LONG_LONG_INT
1781 
1782 // Specialization for Ordinal=int and Packet=long.
1783 template<>
1784 TEUCHOSCOMM_LIB_DLL_EXPORT void
1785 gather<int, long> (const long sendBuf[],
1786  const int sendCount,
1787  long recvBuf[],
1788  const int recvCount,
1789  const int root,
1790  const Comm<int>& comm);
1791 template<>
1792 TEUCHOSCOMM_LIB_DLL_EXPORT void
1793 gatherv<int, long> (const long sendBuf[],
1794  const int sendCount,
1795  long recvBuf[],
1796  const int recvCounts[],
1797  const int displs[],
1798  const int root,
1799  const Comm<int>& comm);
1800 template<>
1801 TEUCHOSCOMM_LIB_DLL_EXPORT void
1802 reduceAll<int, long> (const Comm<int>& comm,
1803  const EReductionType reductType,
1804  const int count,
1805  const long sendBuffer[],
1806  long globalReducts[]);
1807 template<>
1808 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1809 ireceive<int, long> (const Comm<int>& comm,
1810  const ArrayRCP<long>& recvBuffer,
1811  const int sourceRank);
1812 template<>
1813 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1814 ireceive<int, long> (const ArrayRCP<long> &recvBuffer,
1815  const int sourceRank,
1816  const int tag,
1817  const Comm<int>& comm);
1818 template<>
1819 TEUCHOSCOMM_LIB_DLL_EXPORT void
1820 send<int, long> (const Comm<int>& comm,
1821  const int count,
1822  const long sendBuffer[],
1823  const int destRank);
1824 template<>
1825 TEUCHOSCOMM_LIB_DLL_EXPORT void
1826 send<int, long> (const long sendBuffer[],
1827  const int count,
1828  const int destRank,
1829  const int tag,
1830  const Comm<int>& comm);
1831 template<>
1832 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1833 isend<int, long> (const ArrayRCP<const long>& sendBuffer,
1834  const int destRank,
1835  const int tag,
1836  const Comm<int>& comm);
1837 
1838 // Specialization for Ordinal=int and Packet=unsigned long.
1839 template<>
1840 TEUCHOSCOMM_LIB_DLL_EXPORT void
1841 gather<int, unsigned long> (const unsigned long sendBuf[],
1842  const int sendCount,
1843  unsigned long recvBuf[],
1844  const int recvCount,
1845  const int root,
1846  const Comm<int>& comm);
1847 template<>
1848 TEUCHOSCOMM_LIB_DLL_EXPORT void
1849 gatherv<int, unsigned long> (const unsigned long sendBuf[],
1850  const int sendCount,
1851  unsigned long recvBuf[],
1852  const int recvCounts[],
1853  const int displs[],
1854  const int root,
1855  const Comm<int>& comm);
1856 template<>
1857 TEUCHOSCOMM_LIB_DLL_EXPORT void
1858 reduceAll<int, unsigned long> (const Comm<int>& comm,
1859  const EReductionType reductType,
1860  const int count,
1861  const unsigned long sendBuffer[],
1862  unsigned long globalReducts[]);
1863 template<>
1864 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1865 ireceive<int, unsigned long> (const Comm<int>& comm,
1866  const ArrayRCP<unsigned long>& recvBuffer,
1867  const int sourceRank);
1868 template<>
1869 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1870 ireceive<int, unsigned long> (const ArrayRCP<unsigned long> &recvBuffer,
1871  const int sourceRank,
1872  const int tag,
1873  const Comm<int>& comm);
1874 template<>
1875 TEUCHOSCOMM_LIB_DLL_EXPORT void
1876 send<int, unsigned long> (const Comm<int>& comm,
1877  const int count,
1878  const unsigned long sendBuffer[],
1879  const int destRank);
1880 template<>
1881 TEUCHOSCOMM_LIB_DLL_EXPORT void
1882 send<int, unsigned long> (const unsigned long sendBuffer[],
1883  const int count,
1884  const int destRank,
1885  const int tag,
1886  const Comm<int>& comm);
1887 template<>
1888 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1889 isend<int, unsigned long> (const ArrayRCP<const unsigned long>& sendBuffer,
1890  const int destRank,
1891  const int tag,
1892  const Comm<int>& comm);
1893 
1894 // Specialization for Ordinal=int and Packet=int.
1895 template<>
1896 TEUCHOSCOMM_LIB_DLL_EXPORT void
1897 gather<int, int> (const int sendBuf[],
1898  const int sendCount,
1899  int recvBuf[],
1900  const int recvCount,
1901  const int root,
1902  const Comm<int>& comm);
1903 template<>
1904 TEUCHOSCOMM_LIB_DLL_EXPORT void
1905 gatherv<int, int> (const int sendBuf[],
1906  const int sendCount,
1907  int recvBuf[],
1908  const int recvCounts[],
1909  const int displs[],
1910  const int root,
1911  const Comm<int>& comm);
1912 template<>
1913 TEUCHOSCOMM_LIB_DLL_EXPORT void
1914 scatter (const int sendBuf[],
1915  const int sendCount,
1916  int recvBuf[],
1917  const int recvCount,
1918  const int root,
1919  const Comm<int>& comm);
1920 template<>
1921 TEUCHOSCOMM_LIB_DLL_EXPORT void
1922 reduce<int, int> (const int sendBuf[],
1923  int recvBuf[],
1924  const int count,
1925  const EReductionType reductType,
1926  const int root,
1927  const Comm<int>& comm);
1928 template<>
1929 TEUCHOSCOMM_LIB_DLL_EXPORT void
1930 reduceAll<int, int> (const Comm<int>& comm,
1931  const EReductionType reductType,
1932  const int count,
1933  const int sendBuffer[],
1934  int globalReducts[]);
1935 
1936 template<>
1937 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1938 ireceive<int, int> (const Comm<int>& comm,
1939  const ArrayRCP<int>& recvBuffer,
1940  const int sourceRank);
1941 template<>
1942 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1943 ireceive<int, int> (const ArrayRCP<int> &recvBuffer,
1944  const int sourceRank,
1945  const int tag,
1946  const Comm<int>& comm);
1947 template<>
1948 TEUCHOSCOMM_LIB_DLL_EXPORT void
1949 send<int, int> (const Comm<int>& comm,
1950  const int count,
1951  const int sendBuffer[],
1952  const int destRank);
1953 template<>
1954 TEUCHOSCOMM_LIB_DLL_EXPORT void
1955 send<int, int> (const int sendBuffer[],
1956  const int count,
1957  const int destRank,
1958  const int tag,
1959  const Comm<int>& comm);
1960 template<>
1961 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1962 isend<int, int> (const ArrayRCP<const int>& sendBuffer,
1963  const int destRank,
1964  const int tag,
1965  const Comm<int>& comm);
1966 
1967 // Specialization for Ordinal=int and Packet=unsigned int.
1968 template<>
1969 TEUCHOSCOMM_LIB_DLL_EXPORT void
1970 gather<int, unsigned int> (const unsigned int sendBuf[],
1971  const int sendCount,
1972  unsigned int recvBuf[],
1973  const int recvCount,
1974  const int root,
1975  const Comm<int>& comm);
1976 template<>
1977 TEUCHOSCOMM_LIB_DLL_EXPORT void
1978 gatherv<int, unsigned int> (const unsigned int sendBuf[],
1979  const int sendCount,
1980  unsigned int recvBuf[],
1981  const int recvCounts[],
1982  const int displs[],
1983  const int root,
1984  const Comm<int>& comm);
1985 template<>
1986 TEUCHOSCOMM_LIB_DLL_EXPORT void
1987 reduceAll<int, unsigned int> (const Comm<int>& comm,
1988  const EReductionType reductType,
1989  const int count,
1990  const unsigned int sendBuffer[],
1991  unsigned int globalReducts[]);
1992 template<>
1993 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1994 ireceive<int, unsigned int> (const Comm<int>& comm,
1995  const ArrayRCP<unsigned int>& recvBuffer,
1996  const int sourceRank);
1997 template<>
1998 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1999 ireceive<int, unsigned int> (const ArrayRCP<unsigned int> &recvBuffer,
2000  const int sourceRank,
2001  const int tag,
2002  const Comm<int>& comm);
2003 template<>
2004 TEUCHOSCOMM_LIB_DLL_EXPORT void
2005 send<int, unsigned int> (const Comm<int>& comm,
2006  const int count,
2007  const unsigned int sendBuffer[],
2008  const int destRank);
2009 template<>
2010 TEUCHOSCOMM_LIB_DLL_EXPORT void
2011 send<int, unsigned int> (const unsigned int sendBuffer[],
2012  const int count,
2013  const int destRank,
2014  const int tag,
2015  const Comm<int>& comm);
2016 template<>
2017 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2018 isend<int, unsigned int> (const ArrayRCP<const unsigned int>& sendBuffer,
2019  const int destRank,
2020  const int tag,
2021  const Comm<int>& comm);
2022 
2023 // Specialization for Ordinal=int and Packet=short.
2024 template<>
2025 TEUCHOSCOMM_LIB_DLL_EXPORT void
2026 gather<int, short> (const short sendBuf[],
2027  const int sendCount,
2028  short recvBuf[],
2029  const int recvCount,
2030  const int root,
2031  const Comm<int>& comm);
2032 template<>
2033 TEUCHOSCOMM_LIB_DLL_EXPORT void
2034 gatherv<int, short> (const short sendBuf[],
2035  const int sendCount,
2036  short recvBuf[],
2037  const int recvCounts[],
2038  const int displs[],
2039  const int root,
2040  const Comm<int>& comm);
2041 template<>
2042 TEUCHOSCOMM_LIB_DLL_EXPORT void
2043 reduceAll<int, short> (const Comm<int>& comm,
2044  const EReductionType reductType,
2045  const int count,
2046  const short sendBuffer[],
2047  short globalReducts[]);
2048 template<>
2049 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2050 ireceive<int, short> (const Comm<int>& comm,
2051  const ArrayRCP<short>& recvBuffer,
2052  const int sourceRank);
2053 template<>
2054 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2055 ireceive<int, short> (const ArrayRCP<short> &recvBuffer,
2056  const int sourceRank,
2057  const int tag,
2058  const Comm<int>& comm);
2059 template<>
2060 TEUCHOSCOMM_LIB_DLL_EXPORT void
2061 send<int, short> (const Comm<int>& comm,
2062  const int count,
2063  const short sendBuffer[],
2064  const int destRank);
2065 template<>
2066 TEUCHOSCOMM_LIB_DLL_EXPORT void
2067 send<int, short> (const short sendBuffer[],
2068  const int count,
2069  const int destRank,
2070  const int tag,
2071  const Comm<int>& comm);
2072 template<>
2073 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2074 isend<int, short> (const ArrayRCP<const short>& sendBuffer,
2075  const int destRank,
2076  const int tag,
2077  const Comm<int>& comm);
2078 
2079 // mfh 18 Oct 2012: The specialization for Packet=char seems to be
2080 // causing problems such as the following:
2081 //
2082 // http://testing.sandia.gov/cdash/testDetails.php?test=9909246&build=747699
2083 //
2084 // I am disabling it for now. This should revert back to the old
2085 // behavior for Packet=char. That should fix the Tpetra errors, since
2086 // many Tpetra objects inherit from DistObject<char, ...>.
2087 #if 0
2088 // Specialization for Ordinal=int and Packet=char.
2089 template<>
2090 TEUCHOSCOMM_LIB_DLL_EXPORT void
2091 reduceAll<int, char> (const Comm<int>& comm,
2092  const EReductionType reductType,
2093  const int count,
2094  const char sendBuffer[],
2095  char globalReducts[]);
2096 #endif // 0
2097 } // namespace Teuchos
2098 
2099 
2100 template<typename Ordinal, typename Packet>
2101 void Teuchos::reduceAll(
2102  const Comm<Ordinal>& comm, const EReductionType reductType
2103  ,const Packet &send, const Ptr<Packet> &globalReduct
2104  )
2105 {
2106  // mfh 17 Oct 2012: This will invoke the above specializations for
2107  // general count, so we don't need to specialize this function.
2108  reduceAll<Ordinal,Packet>(comm, reductType, 1, &send, &*globalReduct);
2109 }
2110 
2111 
2112 template<typename Ordinal, typename Packet>
2113 void Teuchos::reduceAll(
2114  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2116  const Ordinal count, const Packet*const sendBuffer[], Packet*const globalReducts[]
2117  )
2118 {
2119  TEUCHOS_COMM_TIME_MONITOR(
2120  "Teuchos::CommHelpers: reduceAll<"
2122  <<">( reference type )"
2123  );
2125  charSendBuffer(serializer,count,sendBuffer);
2127  charGlobalReducts(serializer,count,globalReducts);
2129  charReductOp(rcp(&serializer,false),rcp(&reductOp,false));
2130  comm.reduceAll(
2131  charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2132  ,charGlobalReducts.getCharBuffer()
2133  );
2134 }
2135 
2136 template<typename Ordinal, typename Packet, typename Serializer>
2137 void Teuchos::reduceAll(
2138  const Comm<Ordinal>& comm,
2139  const Serializer& serializer,
2140  const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
2141  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
2142  )
2143 {
2144  TEUCHOS_COMM_TIME_MONITOR(
2145  "Teuchos::CommHelpers: reduceAll<"
2147  <<">( value type, user-defined op )"
2148  );
2150  charSendBuffer(count,sendBuffer,rcp(&serializer,false));
2152  charGlobalReducts(count,globalReducts,rcp(&serializer,false));
2154  charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
2155  comm.reduceAll(
2156  charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2157  ,charGlobalReducts.getCharBuffer()
2158  );
2159 }
2160 
2161 
2162 template<typename Ordinal, typename Packet, typename Serializer>
2163 void Teuchos::reduceAll(
2164  const Comm<Ordinal>& comm,
2165  const Serializer& serializer,
2166  const EReductionType reductType,
2167  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
2168  )
2169 {
2170  TEUCHOS_COMM_TIME_MONITOR(
2171  "Teuchos::CommHelpers: reduceAll<"
2173  <<">( value type, "<<toString(reductType)<<" )"
2174  );
2175 
2177  createOp<Ordinal, Packet> (reductType);
2178  try {
2179  reduceAll(comm,serializer,*reductOp,count,sendBuffer,globalReducts);
2180  }
2181  catch (std::exception& e) {
2182  delete reductOp;
2183  throw e;
2184  }
2185  delete reductOp;
2186 }
2187 
2188 
2189 template<typename Ordinal, typename Packet>
2190 void Teuchos::scan(
2191  const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
2192  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2193  )
2194 {
2195  TEUCHOS_COMM_TIME_MONITOR(
2196  "Teuchos::CommHelpers: scan<"
2198  <<">( value type, user-defined op )"
2199  );
2201  charSendBuffer(count,sendBuffer);
2203  charScanReducts(count,scanReducts);
2205  charReductOp(rcp(&reductOp,false));
2206  comm.scan(
2207  charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2208  ,charScanReducts.getCharBuffer()
2209  );
2210 }
2211 
2212 
2213 template<typename Ordinal, typename Packet>
2214 void Teuchos::scan(
2215  const Comm<Ordinal>& comm, const EReductionType reductType,
2216  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2217  )
2218 {
2219  TEUCHOS_COMM_TIME_MONITOR(
2220  "Teuchos::CommHelpers: scan<"
2222  <<">( value type, "<<toString(reductType)<<" )"
2223  );
2224 
2226  createOp<Ordinal, Packet> (reductType);
2227  try {
2228  scan(comm,*reductOp,count,sendBuffer,scanReducts);
2229  }
2230  catch (std::exception& e) {
2231  delete reductOp;
2232  throw e;
2233  }
2234  delete reductOp;
2235 }
2236 
2237 
2238 template<typename Ordinal, typename Packet>
2239 void Teuchos::scan(
2240  const Comm<Ordinal>& comm, const EReductionType reductType,
2241  const Packet &send, const Ptr<Packet> &scanReduct
2242  )
2243 {
2244  scan<Ordinal,Packet>(comm, reductType, 1, &send, &*scanReduct);
2245 }
2246 
2247 
2248 template<typename Ordinal, typename Packet>
2249 void Teuchos::scan(
2250  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2252  const Ordinal count, const Packet*const sendBuffer[], Packet*const scanReducts[]
2253  )
2254 {
2255  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2256 }
2257 
2258 template<typename Ordinal, typename Packet, typename Serializer>
2259 void Teuchos::scan(
2260  const Comm<Ordinal>& comm,
2261  const Serializer& serializer,
2262  const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
2263  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2264  )
2265 {
2266  TEUCHOS_COMM_TIME_MONITOR(
2267  "Teuchos::CommHelpers: scan<"
2269  <<">( value type, user-defined op )"
2270  );
2272  charSendBuffer(count,sendBuffer,rcp(&serializer,false));
2274  charScanReducts(count,scanReducts,rcp(&serializer,false));
2276  charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
2277  comm.scan(
2278  charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2279  ,charScanReducts.getCharBuffer()
2280  );
2281 }
2282 
2283 
2284 template<typename Ordinal, typename Packet, typename Serializer>
2285 void Teuchos::scan(
2286  const Comm<Ordinal>& comm,
2287  const Serializer& serializer,
2288  const EReductionType reductType,
2289  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2290  )
2291 {
2292  TEUCHOS_COMM_TIME_MONITOR(
2293  "Teuchos::CommHelpers: scan<"
2295  <<">( value type, "<<toString(reductType)<<" )"
2296  );
2297 
2299  createOp<Ordinal, Packet> (reductType);
2300  try {
2301  scan(comm,serializer,*reductOp,count,sendBuffer,scanReducts);
2302  }
2303  catch (std::exception& e) {
2304  delete reductOp;
2305  throw e;
2306  }
2307  delete reductOp;
2308 }
2309 
2310 template<typename Ordinal, typename Packet>
2311 void Teuchos::send(
2312  const Comm<Ordinal>& comm,
2313  const Ordinal count, const Packet sendBuffer[], const int destRank
2314  )
2315 {
2316  TEUCHOS_COMM_TIME_MONITOR(
2317  "Teuchos::CommHelpers: send<"
2319  <<">( value type )"
2320  );
2322  charSendBuffer(count,sendBuffer);
2323  comm.send(
2324  charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2325  ,destRank
2326  );
2327 }
2328 
2329 template<typename Ordinal, typename Packet>
2330 void
2331 Teuchos::send (const Packet sendBuffer[],
2332  const Ordinal count,
2333  const int destRank,
2334  const int tag,
2335  const Comm<Ordinal>& comm)
2336 {
2337  TEUCHOS_COMM_TIME_MONITOR(
2338  "Teuchos::CommHelpers: send<"
2340  <<">( value type )"
2341  );
2342  ConstValueTypeSerializationBuffer<Ordinal,Packet> charSendBuffer (count, sendBuffer);
2343  comm.send (charSendBuffer.getBytes (), charSendBuffer.getCharBuffer (), destRank, tag);
2344 }
2345 
2346 template<typename Ordinal, typename Packet>
2347 void Teuchos::ssend(
2348  const Comm<Ordinal>& comm,
2349  const Ordinal count, const Packet sendBuffer[], const int destRank
2350  )
2351 {
2352  TEUCHOS_COMM_TIME_MONITOR(
2353  "Teuchos::CommHelpers: ssend<"
2355  <<">( value type )"
2356  );
2358  charSendBuffer(count,sendBuffer);
2359  comm.ssend(
2360  charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2361  ,destRank
2362  );
2363 }
2364 
2365 template<typename Ordinal, typename Packet>
2366 void
2367 Teuchos::ssend (const Packet sendBuffer[],
2368  const Ordinal count,
2369  const int destRank,
2370  const int tag,
2371  const Comm<Ordinal>& comm)
2372 {
2373  TEUCHOS_COMM_TIME_MONITOR(
2374  "Teuchos::CommHelpers: ssend<"
2376  <<">( value type )"
2377  );
2379  buf_type charSendBuffer (count, sendBuffer);
2380  comm.ssend (charSendBuffer.getBytes (),
2381  charSendBuffer.getCharBuffer (),
2382  destRank, tag);
2383 }
2384 
2385 template<typename Ordinal, typename Packet>
2386 void Teuchos::send(
2387  const Comm<Ordinal>& comm,
2388  const Packet &send, const int destRank
2389  )
2390 {
2391  Teuchos::send<Ordinal,Packet>(comm,1,&send,destRank);
2392 }
2393 
2394 template<typename Ordinal, typename Packet>
2395 void Teuchos::ssend(
2396  const Comm<Ordinal>& comm,
2397  const Packet &send, const int destRank
2398  )
2399 {
2400  Teuchos::ssend<Ordinal,Packet>(comm,1,&send,destRank);
2401 }
2402 
2403 template<typename Ordinal, typename Packet>
2404 void Teuchos::send(
2405  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2406  const Ordinal count, const Packet*const sendBuffer[], const int destRank
2407  )
2408 {
2409  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2410 }
2411 
2412 template<typename Ordinal, typename Packet, typename Serializer>
2413 void Teuchos::send(
2414  const Comm<Ordinal>& comm,
2415  const Serializer& serializer,
2416  const Ordinal count, const Packet sendBuffer[], const int destRank
2417  )
2418 {
2419  TEUCHOS_COMM_TIME_MONITOR(
2420  "Teuchos::CommHelpers: send<"
2422  <<">( value type )"
2423  );
2425  charSendBuffer(count,sendBuffer,rcp(&serializer,false));
2426  comm.send(
2427  charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2428  ,destRank
2429  );
2430 }
2431 
2432 template<typename Ordinal, typename Packet>
2433 int Teuchos::receive(
2434  const Comm<Ordinal>& comm,
2435  const int sourceRank, const Ordinal count, Packet recvBuffer[]
2436  )
2437 {
2438  TEUCHOS_COMM_TIME_MONITOR(
2439  "Teuchos::CommHelpers: receive<"
2441  <<">( value type )"
2442  );
2444  charRecvBuffer(count,recvBuffer);
2445  return comm.receive(
2446  sourceRank
2447  ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
2448  );
2449 }
2450 
2451 
2452 template<typename Ordinal, typename Packet>
2453 int Teuchos::receive(
2454  const Comm<Ordinal>& comm,
2455  const int sourceRank, Packet *recv
2456  )
2457 {
2458  return Teuchos::receive<Ordinal,Packet>(comm,sourceRank,1,recv);
2459 }
2460 
2461 
2462 template<typename Ordinal, typename Packet>
2463 int Teuchos::receive(
2464  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2465  const int sourceRank, const Ordinal count, Packet*const recvBuffer[]
2466  )
2467 {
2468  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2469 }
2470 
2471 template<typename Ordinal, typename Packet, typename Serializer>
2472 int Teuchos::receive(
2473  const Comm<Ordinal>& comm,
2474  const Serializer& serializer,
2475  const int sourceRank, const Ordinal count, Packet recvBuffer[]
2476  )
2477 {
2478  TEUCHOS_COMM_TIME_MONITOR(
2479  "Teuchos::CommHelpers: receive<"
2481  <<">( value type )"
2482  );
2484  charRecvBuffer(count,recvBuffer,rcp(&serializer,false));
2485  return comm.receive(
2486  sourceRank
2487  ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
2488  );
2489 }
2490 
2491 template<typename Ordinal, typename Packet>
2492 void Teuchos::readySend(
2493  const Comm<Ordinal>& comm,
2494  const ArrayView<const Packet> &sendBuffer,
2495  const int destRank
2496  )
2497 {
2498  TEUCHOS_COMM_TIME_MONITOR(
2499  "Teuchos::CommHelpers: readySend<"
2501  <<">( value type )"
2502  );
2504  charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr());
2505  comm.readySend( charSendBuffer.getCharBufferView(), destRank );
2506 }
2507 
2508 template<typename Ordinal, typename Packet>
2509 void
2510 Teuchos::readySend (const Packet sendBuffer[],
2511  const Ordinal count,
2512  const int destRank,
2513  const int tag,
2514  const Comm<Ordinal>& comm)
2515 {
2516  TEUCHOS_COMM_TIME_MONITOR(
2517  "Teuchos::CommHelpers: readySend<"
2519  <<">( value type )"
2520  );
2522  buf_type charSendBuffer (count, sendBuffer);
2523  comm.readySend (charSendBuffer.getBytes (),
2524  charSendBuffer.getCharBuffer (),
2525  destRank, tag);
2526 }
2527 
2528 template<typename Ordinal, typename Packet>
2529 void Teuchos::readySend(
2530  const Comm<Ordinal>& comm,
2531  const Packet &send,
2532  const int destRank
2533  )
2534 {
2535  readySend<Ordinal, Packet>( comm, arrayView(&send,1), destRank );
2536 }
2537 
2538 template<typename Ordinal, typename Packet, typename Serializer>
2539 void Teuchos::readySend(
2540  const Comm<Ordinal>& comm,
2541  const Serializer& serializer,
2542  const ArrayView<const Packet> &sendBuffer,
2543  const int destRank
2544  )
2545 {
2546  TEUCHOS_COMM_TIME_MONITOR(
2547  "Teuchos::CommHelpers: readySend<"
2549  <<">( value type )"
2550  );
2552  charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr(), serializer);
2553  comm.readySend( charSendBuffer.getCharBufferView(), destRank );
2554 }
2555 
2556 template<typename Ordinal, typename Packet>
2559  const Comm<Ordinal>& comm,
2560  const ArrayRCP<const Packet> &sendBuffer,
2561  const int destRank
2562  )
2563 {
2564  TEUCHOS_COMM_TIME_MONITOR(
2565  "Teuchos::CommHelpers: isend<"
2567  <<">( value type )"
2568  );
2570  charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr());
2571  RCP<CommRequest<Ordinal> > commRequest = comm.isend(
2572  charSendBuffer.getCharBufferView(), destRank );
2573  set_extra_data( sendBuffer, "buffer", inOutArg(commRequest) );
2574  return commRequest;
2575 }
2576 
2577 template<typename Ordinal, typename Packet>
2579 Teuchos::isend (const ArrayRCP<const Packet> &sendBuffer,
2580  const int destRank,
2581  const int tag,
2582  const Comm<Ordinal>& comm)
2583 {
2584  TEUCHOS_COMM_TIME_MONITOR(
2585  "Teuchos::isend<" << OrdinalTraits<Ordinal>::name () << ","
2586  << TypeNameTraits<Packet>::name () << ">");
2588  charSendBuffer (sendBuffer.size (), sendBuffer.getRawPtr ());
2589  RCP<CommRequest<Ordinal> > commRequest =
2590  comm.isend (charSendBuffer.getCharBufferView (), destRank, tag);
2591  set_extra_data (sendBuffer, "buffer", inOutArg (commRequest));
2592  return commRequest;
2593 }
2594 
2595 template<typename Ordinal, typename Packet>
2598  const Comm<Ordinal>& comm,
2599  const RCP<const Packet> &send,
2600  const int destRank
2601  )
2602 {
2603  const ArrayRCP<const Packet> sendBuffer =
2604  arcpWithEmbeddedObj( send.get(), 0, 1, send, false );
2605  // 2008/07/29: rabartl: Above: I need to write a helper function to create
2606  // new ArrayRCP object given a single object to copy.
2607  return isend<Ordinal, Packet>( comm, sendBuffer, destRank );
2608 }
2609 
2610 template<typename Ordinal, typename Packet, typename Serializer>
2613  const Comm<Ordinal>& comm,
2614  const Serializer& serializer,
2615  const ArrayRCP<const Packet> &sendBuffer,
2616  const int destRank
2617  )
2618 {
2619  TEUCHOS_COMM_TIME_MONITOR(
2620  "Teuchos::CommHelpers: isend<"
2622  <<">( value type )"
2623  );
2625  charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr(), serializer);
2626  RCP<CommRequest<Ordinal> > commRequest = comm.isend(
2627  charSendBuffer.getCharBufferView(), destRank );
2628  set_extra_data( sendBuffer, "buffer", inOutArg(commRequest) );
2629  return commRequest;
2630 }
2631 
2632 template<typename Ordinal, typename Packet>
2635  const Comm<Ordinal>& comm,
2636  const ArrayRCP<Packet> &recvBuffer,
2637  const int sourceRank
2638  )
2639 {
2640  TEUCHOS_COMM_TIME_MONITOR(
2641  "Teuchos::ireceive<int, " << "," << TypeNameTraits<Packet>::name () << ">");
2643  charRecvBuffer(recvBuffer.size(), recvBuffer.getRawPtr());
2644  RCP<CommRequest<Ordinal> > commRequest = comm.ireceive(
2645  charRecvBuffer.getCharBufferView(), sourceRank );
2646  set_extra_data( recvBuffer, "buffer", inOutArg(commRequest) );
2647  return commRequest;
2648 }
2649 
2650 template<typename Ordinal, typename Packet>
2652 Teuchos::ireceive (const Teuchos::ArrayRCP<Packet> &recvBuffer,
2653  const int sourceRank,
2654  const int tag,
2655  const Teuchos::Comm<Ordinal>& comm)
2656 {
2657  TEUCHOS_COMM_TIME_MONITOR(
2658  "Teuchos::ireceive<int, " << "," << TypeNameTraits<Packet>::name () << ">");
2660  charRecvBuffer (recvBuffer.size (), recvBuffer.getRawPtr ());
2661  RCP<CommRequest<int> > commRequest =
2662  comm.ireceive (charRecvBuffer.getCharBufferView (), sourceRank, tag);
2663  set_extra_data (recvBuffer, "buffer", inOutArg (commRequest));
2664  return commRequest;
2665 }
2666 
2667 template<typename Ordinal, typename Packet>
2670  const Comm<Ordinal>& comm,
2671  const RCP<Packet> &recv,
2672  const int sourceRank
2673  )
2674 {
2675  const ArrayRCP<Packet> recvBuffer =
2676  arcpWithEmbeddedObj( recv.get(), 0, 1, recv, false );
2677  // 2008/07/29: rabartl: Above: I need to write a helper function to create
2678  // new ArrayRCP object given a single object to copy.
2679  return ireceive<Ordinal, Packet>( comm, recvBuffer, sourceRank );
2680 }
2681 
2682 template<typename Ordinal, typename Packet, typename Serializer>
2685  const Comm<Ordinal>& comm,
2686  const Serializer& serializer,
2687  const ArrayRCP<Packet> &recvBuffer,
2688  const int sourceRank
2689  )
2690 {
2691  TEUCHOS_COMM_TIME_MONITOR(
2692  "Teuchos::CommHelpers: ireceive<"
2694  <<">( value type )"
2695  );
2697  charRecvBuffer(recvBuffer.size(), recvBuffer.getRawPtr(), serializer);
2698  RCP<CommRequest<Ordinal> > commRequest = comm.ireceive(
2699  charRecvBuffer.getCharBufferView(), sourceRank );
2700  set_extra_data( recvBuffer, "buffer", inOutArg(commRequest) );
2701  return commRequest;
2702 }
2703 
2704 template<typename Ordinal>
2705 void Teuchos::waitAll(
2706  const Comm<Ordinal>& comm,
2707  const ArrayView<RCP<CommRequest<Ordinal> > > &requests
2708  )
2709 {
2710  comm.waitAll(requests);
2711 }
2712 
2713 
2714 template<typename Ordinal>
2715 void
2716 Teuchos::waitAll (const Comm<Ordinal>& comm,
2717  const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
2718  const ArrayView<RCP<CommStatus<Ordinal> > >& statuses)
2719 {
2720  comm.waitAll (requests, statuses);
2721 }
2722 
2723 
2724 template<typename Ordinal>
2726 Teuchos::wait (const Comm<Ordinal>& comm,
2727  const Ptr<RCP<CommRequest<Ordinal> > > &request)
2728 {
2729  return comm.wait (request);
2730 }
2731 
2732 
2733 #endif // TEUCHOS_COMM_HELPERS_HPP
virtual void reduceAll(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char globalReducts[]) const =0
Global reduction.
Strategy interface for the indirect serializing and deserializing objects of a given type handled usi...
Encapsulate how an array of non-const objects with reference sematics is serialized into a char[] arr...
virtual void readySend(const ArrayView< const char > &sendBuffer, const int destRank) const =0
Ready send of data from this process to another process.
EReductionType
Predefined reduction operations that Teuchos::Comm understands.
virtual RCP< CommStatus< Ordinal > > wait(const Ptr< RCP< CommRequest< Ordinal > > > &request) const =0
Wait on a single communication request, and return its status.
virtual void scan(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char scanReducts[]) const =0
Scan reduction.
size_type size() const
The total number of entries in the array.
virtual RCP< CommRequest< Ordinal > > ireceive(const ArrayView< char > &recvBuffer, const int sourceRank) const =0
Non-blocking receive.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
virtual void send(const Ordinal bytes, const char sendBuffer[], const int destRank) const =0
Possibly blocking send of data from this process to another process.
size_type size() const
The total number of items in the managed array.
T * getRawPtr()
Return a raw pointer to beginning of array or NULL if unsized.
Standard logical AND operator for booleans.
Standard min operator for types with value semantics.
T * get() const
Get the raw C++ pointer to the underlying object.
This structure defines some basic traits for a scalar field type.
Decorator class that uses traits to convert to and from char[] to typed buffers for objects that use ...
virtual void waitAll(const ArrayView< RCP< CommRequest< Ordinal > > > &requests) const =0
Wait on a set of communication requests.
void scatter(const Packet sendBuf[], const Ordinal sendCount, Packet recvBuf[], const Ordinal recvCount, const Ordinal root, const Comm< Ordinal > &comm)
Wrapper for MPI_Scatter; scatter collective.
Namespace of implementation details.
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
Standard summation operator for types with value semantics.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
virtual void gather(const Ordinal sendBytes, const char sendBuffer[], const Ordinal recvBytes, char recvBuffer[], const int root) const =0
Gather values from all processes to the root process.
virtual void ssend(const Ordinal bytes, const char sendBuffer[], const int destRank) const =0
Always blocking send of data from this process to another process.
TEUCHOS_DEPRECATED void scan(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *scanReduct)
Deprecated.
Encapsulate how an array of const objects with reference sematics is serialized into a char[] array...
virtual int getRank() const =0
Returns the rank of this process.
Standard Max operator for types with value semantics.
Decorator class that uses a strategy object to convert to and from char[] to typed buffers for object...
Implementation of Teuchos wrappers for MPI.
Declaration of Teuchos::EReductionType enum, and related functions.
virtual RCP< CommRequest< Ordinal > > isend(const ArrayView< const char > &sendBuffer, const int destRank) const =0
Non-blocking send.
This structure defines some basic traits for the ordinal field type.
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
Deprecated .
Encapsulation of the result of a receive (blocking or nonblocking).
void send(const Packet sendBuffer[], const Ordinal count, const int destRank, const int tag, const Comm< Ordinal > &comm)
Variant of send() that takes a tag (and restores the correct order of arguments). ...
virtual void barrier() const =0
Pause every process in *this communicator until all the processes reach this point.
Encapsulate how an array of non-const objects with value sematics is serialized into a char[] array...
RCP< CommRequest< Ordinal > > ireceive(const ArrayRCP< Packet > &recvBuffer, const int sourceRank, const int tag, const Comm< Ordinal > &comm)
Variant of ireceive that takes a tag argument (and restores the correct order of arguments).
Templated array class derived from the STL std::vector.
Abstract interface for distributed-memory communication.
void push_back(const value_type &x)
Nonowning array view.
T * getRawPtr() const
Return a raw pointer to beginning of array or NULL if unsized.
Defines basic traits for the ordinal field type.
Default traits class that just returns typeid(T).name().
virtual void broadcast(const int rootRank, const Ordinal bytes, char buffer[]) const =0
Broadcast values from the root process to the slave processes.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
Base interface class for user-defined reduction operations for objects that use reference semantics...
virtual void gatherAll(const Ordinal sendBytes, const char sendBuffer[], const Ordinal recvBytes, char recvBuffer[]) const =0
Gather values from each process to collect on all processes.
void ssend(const Packet sendBuffer[], const Ordinal count, const int destRank, const int tag, const Comm< Ordinal > &comm)
Variant of ssend() that takes a tag (and restores the correct order of arguments).
Defines basic traits for the scalar field type.
Smart reference counting pointer class for automatic garbage collection.
RCP< CommRequest< Ordinal > > isend(const ArrayRCP< const Packet > &sendBuffer, const int destRank, const int tag, const Comm< Ordinal > &comm)
Variant of isend() that takes a tag (and restores the correct order of arguments).
virtual int receive(const int sourceRank, const Ordinal bytes, char recvBuffer[]) const =0
Blocking receive of data from this process to another process.
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
Encapsulation of a pending nonblocking communication operation.
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
Defines basic traits returning the name of a type in a portable and readable way. ...
Definition of Teuchos::as, for conversions between types.
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
void readySend(const Packet sendBuffer[], const Ordinal count, const int destRank, const int tag, const Comm< Ordinal > &comm)
Variant of readySend() that accepts a message tag.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call...
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
virtual int getSize() const =0
Returns the number of processes that make up this communicator.
Encapsulate how an array of const objects with value sematics is serialized into a const char[] array...
Reference-counted smart pointer for managing arrays.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...