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_MPI
59 #endif // HAVE_MPI
60 #include "Teuchos_DefaultSerialComm.hpp"
61 
62 
63 namespace Teuchos {
64 
65 
66 //
67 // Teuchos::Comm Helper Functions
68 //
69 
80 };
81 
86 const char* toString (const EReductionType reductType);
87 
92 template<typename Ordinal>
93 int rank(const Comm<Ordinal>& comm);
94 
99 template<typename Ordinal>
100 int size(const Comm<Ordinal>& comm);
101 
106 template<typename Ordinal>
107 void barrier(const Comm<Ordinal>& comm);
108 
113 template<typename Ordinal, typename Packet>
114 void broadcast(
115  const Comm<Ordinal>& comm,
116  const int rootRank,
117  const Ordinal count, Packet buffer[]
118  );
119 
124 template<typename Ordinal, typename Packet>
125 void broadcast(
126  const Comm<Ordinal>& comm,
127  const int rootRank,
128  const ArrayView<Packet> &buffer
129  );
130 
135 template<typename Ordinal, typename Packet>
136 void broadcast(
137  const Comm<Ordinal>& comm,
138  const int rootRank, Packet *object
139  );
140 
145 template<typename Ordinal, typename Packet>
146 void broadcast(
147  const Comm<Ordinal>& comm,
148  const int rootRank, const Ptr<Packet> &object
149  );
150 
155 template<typename Ordinal, typename Packet>
156 void broadcast(
157  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
158  const int rootRank, const Ordinal count, Packet*const buffer[]
159  );
160 
165 template<typename Ordinal, typename Packet>
166 void broadcast(
167  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
168  const int rootRank, const ArrayView<const Ptr<Packet> > &buffer
169  );
170 
176 template<typename Ordinal, typename Packet, typename Serializer>
177 void broadcast(
178  const Comm<Ordinal>& comm,
179  const Serializer& serializer,
180  const int rootRank,
181  const Ordinal count, Packet buffer[]
182  );
183 
188 template<typename Ordinal, typename Packet>
189 void
190 gather (const Packet sendBuf[],
191  const Ordinal sendCount,
192  Packet recvBuf[],
193  const Ordinal recvCount,
194  const int root,
195  const Comm<Ordinal>& comm);
196 
201 template<typename Ordinal, typename Packet>
202 void
203 gatherv (const Packet sendBuf[],
204  const Ordinal sendCount,
205  Packet recvBuf[],
206  const Ordinal recvCounts[],
207  const Ordinal displs[],
208  const int root,
209  const Comm<Ordinal>& comm);
210 
216 template<typename Ordinal, typename Packet>
217 void gatherAll(
218  const Comm<Ordinal>& comm,
219  const Ordinal sendCount, const Packet sendBuffer[],
220  const Ordinal recvCount, Packet recvBuffer[]
221  );
222 
228 template<typename Ordinal, typename Packet>
229 void gatherAll(
230  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
231  const Ordinal sendCount, const Packet*const sendBuffer[],
232  const Ordinal recvCount, Packet*const recvBuffer[]
233  );
234 
240 template<typename Ordinal, typename Packet, typename Serializer>
241 void gatherAll(
242  const Comm<Ordinal>& comm,
243  const Serializer& serializer,
244  const Ordinal sendCount, const Packet sendBuffer[],
245  const Ordinal recvCount, Packet recvBuffer[]
246  );
247 
274 template<typename Ordinal, typename Packet>
275 void
276 scatter (const Packet sendBuf[],
277  const Ordinal sendCount,
278  Packet recvBuf[],
279  const Ordinal recvCount,
280  const Ordinal root,
281  const Comm<Ordinal>& comm)
282 {
283  // See Bug 6375; Tpetra does not actually need any specializations
284  // other than Ordinal = int and Packet = int. We may add them later
285  // if there is interest.
287  (true, std::logic_error, "Teuchos::scatter<" <<
289  << ">: Generic version is not yet implemented. This function currently "
290  "only has an implementtion for Ordinal = int and Packet = int. "
291  "See Bug 6375 and Bug 6336.");
292 }
293 
321 template<typename Ordinal, typename Packet>
322 void
323 reduce (const Packet sendBuf[],
324  Packet recvBuf[],
325  const Ordinal count,
326  const EReductionType reductType,
327  const Ordinal root,
328  const Comm<Ordinal>& comm);
329 
352 template<typename Ordinal, typename Packet>
353 void reduceAll(
354  const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
355  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
356  );
357 
363 template<typename Ordinal, typename Packet>
364 void reduceAll(
365  const Comm<Ordinal>& comm, const EReductionType reductType,
366  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
367  );
368 
374 template<typename Ordinal, typename Packet>
375 void reduceAll(
376  const Comm<Ordinal>& comm, const EReductionType reductType,
377  const Packet &send, const Ptr<Packet> &globalReduct
378  );
379 
381 template<typename Ordinal, typename Packet>
382 TEUCHOS_DEPRECATED void reduceAll(
383  const Comm<Ordinal>& comm, const EReductionType reductType,
384  const Packet &send, Packet *globalReduct
385  )
386 {
387  reduceAll<Ordinal,Packet>(comm, reductType, send, ptr(globalReduct));
388 }
389 
395 template<typename Ordinal, typename Packet>
396 void reduceAll(
397  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
399  const Ordinal count, const Packet*const sendBuffer[], Packet*const globalReducts[]
400  );
401 
407 template<typename Ordinal, typename Packet, typename Serializer>
408 void reduceAll(
409  const Comm<Ordinal>& comm,
410  const Serializer& serializer,
411  const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
412  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
413  );
414 
420 template<typename Ordinal, typename Packet, typename Serializer>
421 void reduceAll(
422  const Comm<Ordinal>& comm,
423  const Serializer& serializer,
424  const EReductionType reductType,
425  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
426  );
427 
436 template<typename Ordinal, typename Packet>
437 TEUCHOS_DEPRECATED void
438 reduceAllAndScatter (
439  const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
440  const Ordinal sendCount, const Packet sendBuffer[] ,
441  const Ordinal recvCounts[], Packet myGlobalReducts[]
442  );
443 
453 template<typename Ordinal, typename Packet>
454 TEUCHOS_DEPRECATED void
455 reduceAllAndScatter(
456  const Comm<Ordinal>& comm, const EReductionType reductType,
457  const Ordinal sendCount, const Packet sendBuffer[] ,
458  const Ordinal recvCounts[], Packet myGlobalReducts[]
459  );
460 
461 
471 template<typename Ordinal, typename Packet>
472 TEUCHOS_DEPRECATED void
473 reduceAllAndScatter(
474  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
476  const Ordinal sendCount, const Packet*const sendBuffer[] ,
477  const Ordinal recvCounts[], Packet*const myGlobalReducts[]
478  );
479 
489 template<typename Ordinal, typename Packet, typename Serializer>
490 TEUCHOS_DEPRECATED void
491 reduceAllAndScatter(
492  const Comm<Ordinal>& comm,
493  const Serializer& serializer,
494  const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
495  const Ordinal sendCount, const Packet sendBuffer[],
496  const Ordinal recvCounts[], Packet myGlobalReducts[]
497  );
498 
508 template<typename Ordinal, typename Packet, typename Serializer>
509 TEUCHOS_DEPRECATED void
510 reduceAllAndScatter(
511  const Comm<Ordinal>& comm,
512  const Serializer& serializer,
513  const EReductionType reductType,
514  const Ordinal sendCount, const Packet sendBuffer[] ,
515  const Ordinal recvCounts[], Packet myGlobalReducts[]
516  );
517 
523 template<typename Ordinal, typename Packet>
524 void scan(
525  const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
526  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
527  );
528 
534 template<typename Ordinal, typename Packet>
535 void scan(
536  const Comm<Ordinal>& comm, const EReductionType reductType,
537  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
538  );
539 
545 template<typename Ordinal, typename Packet>
546 void scan(
547  const Comm<Ordinal>& comm, const EReductionType reductType,
548  const Packet &send, const Ptr<Packet> &scanReduct
549  );
550 
552 template<typename Ordinal, typename Packet>
553 TEUCHOS_DEPRECATED void scan(
554  const Comm<Ordinal>& comm, const EReductionType reductType,
555  const Packet &send, Packet *scanReduct
556  )
557 {
558  scan(comm, reductType, send, ptr(scanReduct));
559 }
560 
566 template<typename Ordinal, typename Packet>
567 void scan(
568  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
570  const Ordinal count, const Packet*const sendBuffer[], Packet*const scanReducts[]
571  );
572 
578 template<typename Ordinal, typename Packet, typename Serializer>
579 void scan(
580  const Comm<Ordinal>& comm,
581  const Serializer& serializer,
582  const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
583  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
584  );
585 
591 template<typename Ordinal, typename Packet, typename Serializer>
592 void scan(
593  const Comm<Ordinal>& comm,
594  const Serializer& serializer,
595  const EReductionType reductType,
596  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
597  );
598 
603 template<typename Ordinal, typename Packet>
604 void send(
605  const Comm<Ordinal>& comm,
606  const Ordinal count, const Packet sendBuffer[], const int destRank
607  );
608 
610 template<typename Ordinal, typename Packet>
611 void
612 send (const Packet sendBuffer[],
613  const Ordinal count,
614  const int destRank,
615  const int tag,
616  const Comm<Ordinal>& comm);
617 
622 template<typename Ordinal, typename Packet>
623 void ssend(
624  const Comm<Ordinal>& comm,
625  const Ordinal count, const Packet sendBuffer[], const int destRank
626  );
627 
629 template<typename Ordinal, typename Packet>
630 void
631 ssend (const Packet sendBuffer[],
632  const Ordinal count,
633  const int destRank,
634  const int tag,
635  const Comm<Ordinal>& comm);
636 
641 template<typename Ordinal, typename Packet>
642 void send(
643  const Comm<Ordinal>& comm,
644  const Packet &send, const int destRank
645  );
646 
651 template<typename Ordinal, typename Packet>
652 void ssend(
653  const Comm<Ordinal>& comm,
654  const Packet &send, const int destRank
655  );
656 
663 template<typename Ordinal, typename Packet>
664 void send(
665  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
666  const Ordinal count, const Packet*const sendBuffer[], const int destRank
667  );
668 
674 template<typename Ordinal, typename Packet, typename Serializer>
675 void send(
676  const Comm<Ordinal>& comm,
677  const Serializer& serializer,
678  const Ordinal count, const Packet sendBuffer[], const int destRank
679  );
680 
685 template<typename Ordinal, typename Packet>
686 int receive(
687  const Comm<Ordinal>& comm,
688  const int sourceRank, const Ordinal count, Packet recvBuffer[]
689  );
690 
695 template<typename Ordinal, typename Packet>
696 int receive(
697  const Comm<Ordinal>& comm,
698  const int sourceRank, Packet *recv
699  );
700 
705 template<typename Ordinal, typename Packet>
706 int receive(
707  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
708  const int sourceRank, const Ordinal count, Packet*const recvBuffer[]
709  );
710 
716 template<typename Ordinal, typename Packet, typename Serializer>
717 int receive(
718  const Comm<Ordinal>& comm,
719  const Serializer& serializer,
720  const int sourceRank, const Ordinal count, Packet recvBuffer[]
721  );
722 
728 template<typename Ordinal, typename Packet>
729 void readySend(
730  const Comm<Ordinal>& comm,
731  const ArrayView<const Packet> &sendBuffer,
732  const int destRank
733  );
734 
736 template<typename Ordinal, typename Packet>
737 void
738 readySend (const Packet sendBuffer[],
739  const Ordinal count,
740  const int destRank,
741  const int tag,
742  const Comm<Ordinal>& comm);
743 
748 template<typename Ordinal, typename Packet>
749 void readySend(
750  const Comm<Ordinal>& comm,
751  const Packet &send,
752  const int destRank
753  );
754 
760 template<typename Ordinal, typename Packet, typename Serializer>
761 void readySend(
762  const Comm<Ordinal>& comm,
763  const Serializer& serializer,
764  const ArrayView<const Packet> &sendBuffer,
765  const int destRank
766  );
767 
772 template<typename Ordinal, typename Packet>
774  const Comm<Ordinal>& comm,
775  const ArrayRCP<const Packet> &sendBuffer,
776  const int destRank
777  );
778 
780 template<typename Ordinal, typename Packet>
782 isend (const ArrayRCP<const Packet>& sendBuffer,
783  const int destRank,
784  const int tag,
785  const Comm<Ordinal>& comm);
786 
791 template<typename Ordinal, typename Packet>
793  const Comm<Ordinal>& comm,
794  const RCP<const Packet> &send,
795  const int destRank
796  );
797 
803 template<typename Ordinal, typename Packet, typename Serializer>
805  const Comm<Ordinal>& comm,
806  const Serializer& serializer,
807  const ArrayRCP<const Packet> &sendBuffer,
808  const int destRank
809  );
810 
811 
812 // 2008/07/29: rabartl: ToDo: Add reference semantics version of isend!
813 
814 
824 template<typename Ordinal, typename Packet>
826  const Comm<Ordinal>& comm,
827  const ArrayRCP<Packet> &recvBuffer,
828  const int sourceRank
829  );
830 
832 template<typename Ordinal, typename Packet>
834 ireceive (const ArrayRCP<Packet> &recvBuffer,
835  const int sourceRank,
836  const int tag,
837  const Comm<Ordinal>& comm);
838 
850 template<typename Ordinal, typename Packet>
852  const Comm<Ordinal>& comm,
853  const RCP<Packet> &recv,
854  const int sourceRank
855  );
856 
862 template<typename Ordinal, typename Packet, typename Serializer>
864  const Comm<Ordinal>& comm,
865  const Serializer& serializer,
866  const ArrayRCP<Packet> &recvBuffer,
867  const int sourceRank
868  );
869 
870 
871 // 2008/07/29: rabartl: ToDo: Add reference semantics version of ireceive!
872 
873 
881 template<typename Ordinal>
882 void waitAll(
883  const Comm<Ordinal>& comm,
884  const ArrayView<RCP<CommRequest<Ordinal> > > &requests
885  );
886 
916 template<typename Ordinal>
917 void
918 waitAll (const Comm<Ordinal>& comm,
919  const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
920  const ArrayView<RCP<CommStatus<Ordinal> > >& statuses);
921 
945 template<typename Ordinal>
947 wait (const Comm<Ordinal>& comm, const Ptr<RCP<CommRequest<Ordinal> > >& request);
948 
949 //
950 // Standard reduction subclasses for objects that use value semantics
951 //
952 
953 
958 template<typename Ordinal, typename Packet>
959 class SumValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
960 {
961 public:
963  void reduce(
964  const Ordinal count,
965  const Packet inBuffer[],
966  Packet inoutBuffer[]
967  ) const;
968 };
969 
970 
979 template<typename Ordinal, typename Packet>
980 class MinValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
981 {
982 public:
984  void reduce(
985  const Ordinal count,
986  const Packet inBuffer[],
987  Packet inoutBuffer[]
988  ) const;
989 };
990 
991 
1000 template<typename Ordinal, typename Packet>
1001 class MaxValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
1002 {
1003 public:
1005  void reduce(
1006  const Ordinal count,
1007  const Packet inBuffer[],
1008  Packet inoutBuffer[]
1009  ) const;
1010 };
1011 
1012 
1017 template<typename Ordinal, typename Packet>
1018 class ANDValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
1019 {
1020 public:
1022  void reduce(
1023  const Ordinal count,
1024  const Packet inBuffer[],
1025  Packet inoutBuffer[]
1026  ) const;
1027 };
1028 
1029 
1030 // ////////////////////////////////////////////////////////////
1031 // Implementation details (not for geneal users to mess with)
1032 
1033 
1034 //
1035 // ReductionOp Utilities
1036 //
1037 
1038 
1039 namespace MixMaxUtilities {
1040 
1041 
1042 template<bool isComparable, typename Ordinal, typename Packet>
1043 class Min {};
1044 
1045 
1046 template<typename Ordinal, typename Packet>
1047 class Min<true,Ordinal,Packet> {
1048 public:
1049  static void min(
1050  const Ordinal count,
1051  const Packet inBuffer[],
1052  Packet inoutBuffer[]
1053  )
1054  {
1055  for( int i = 0; i < count; ++i )
1056  inoutBuffer[i] = TEUCHOS_MIN(inoutBuffer[i],inBuffer[i]);
1057  }
1058 };
1059 
1060 
1061 template<typename Ordinal, typename Packet>
1062 class Min<false,Ordinal,Packet> {
1063 public:
1064  static void min(
1065  const Ordinal,
1066  const Packet[],
1067  Packet[]
1068  )
1069  {
1071  true,std::logic_error,
1072  "Error, the type "<<TypeNameTraits<Packet>::name()
1073  <<" does not support comparison operations!"
1074  );
1075  }
1076 };
1077 
1078 
1079 template<bool isComparable, typename Ordinal, typename Packet>
1080 class Max {};
1081 
1082 
1083 template<typename Ordinal, typename Packet>
1084 class Max<true,Ordinal,Packet> {
1085 public:
1086  static void max(
1087  const Ordinal count,
1088  const Packet inBuffer[],
1089  Packet inoutBuffer[]
1090  )
1091  {
1092  for( int i = 0; i < count; ++i )
1093  inoutBuffer[i] = TEUCHOS_MAX(inoutBuffer[i],inBuffer[i]);
1094  }
1095 };
1096 
1097 
1098 template<typename Ordinal, typename Packet>
1099 class Max<false,Ordinal,Packet> {
1100 public:
1101  static void max(
1102  const Ordinal,
1103  const Packet[],
1104  Packet[]
1105  )
1106  {
1108  true,std::logic_error,
1109  "Error, the type "<<TypeNameTraits<Packet>::name()
1110  <<" does not support comparison operations!"
1111  );
1112  }
1113 };
1114 
1115 
1116 template<bool isComparable, typename Ordinal, typename Packet>
1117 class AND {};
1118 
1119 
1120 template<typename Ordinal, typename Packet>
1121 class AND<true,Ordinal,Packet> {
1122 public:
1123  static void andOp(
1124  const Ordinal count,
1125  const Packet inBuffer[],
1126  Packet inoutBuffer[]
1127  )
1128  {
1129  for( int i = 0; i < count; ++i )
1130  inoutBuffer[i] = inoutBuffer[i] && inBuffer[i];
1131  }
1132 };
1133 
1134 
1135 template<typename Ordinal, typename Packet>
1136 class AND<false,Ordinal,Packet> {
1137 public:
1138  static void andOp(
1139  const Ordinal,
1140  const Packet[],
1141  Packet[]
1142  )
1143  {
1145  true,std::logic_error,
1146  "Error, the type "<<TypeNameTraits<Packet>::name()
1147  <<" does not support logical AND operations!"
1148  );
1149  }
1150 };
1151 
1152 
1153 } // namespace MixMaxUtilities
1154 
1155 
1156 template<typename Ordinal, typename Packet>
1158  const Ordinal count,
1159  const Packet inBuffer[],
1160  Packet inoutBuffer[]
1161  ) const
1162 {
1163  for( int i = 0; i < count; ++i )
1164  inoutBuffer[i] += inBuffer[i];
1165 }
1166 
1167 
1168 template<typename Ordinal, typename Packet>
1170  const Ordinal count,
1171  const Packet inBuffer[],
1172  Packet inoutBuffer[]
1173  ) const
1174 {
1175  typedef MixMaxUtilities::Min<ScalarTraits<Packet>::isComparable, Ordinal, Packet> min_type;
1176  min_type::min (count, inBuffer, inoutBuffer);
1177 }
1178 
1179 
1180 template<typename Ordinal, typename Packet>
1182  const Ordinal count,
1183  const Packet inBuffer[],
1184  Packet inoutBuffer[]
1185  ) const
1186 {
1187  typedef MixMaxUtilities::Max<ScalarTraits<Packet>::isComparable, Ordinal, Packet> max_type;
1188  max_type::max (count,inBuffer,inoutBuffer);
1189 }
1190 
1191 
1192 template<typename Ordinal, typename Packet>
1194  const Ordinal count,
1195  const Packet inBuffer[],
1196  Packet inoutBuffer[]
1197  ) const
1198 {
1199  typedef MixMaxUtilities::AND<ScalarTraits<Packet>::isComparable, Ordinal, Packet> and_type;
1200  and_type::andOp (count, inBuffer, inoutBuffer);
1201 }
1202 
1203 
1204 } // namespace Teuchos
1205 
1206 
1207 // //////////////////////////
1208 // Template implemenations
1209 
1210 
1211 //
1212 // ReductionOp utilities
1213 //
1214 
1215 
1216 namespace Teuchos {
1217 
1218 
1219 // Not for the general user to use! I am returning a raw ReductionOp* pointer
1220 // to avoid the overhead of using RCP. However, given the use case
1221 // this is just fine since I can just use std::auto_ptr to make sure things
1222 // are deleted correctly.
1223 //
1224 // NOTE (mfh 08 Feb 2015) std::auto_ptr has been deprecated in C++11.
1225 // I could either replace it with std::unique_ptr, or just call 'new'
1226 // and 'delete' manually. The former is less error prone, but
1227 // requires checking a macro for whether C++11 is actually enabled.
1228 // Thus, I've chosen (for now) to rewrite all the code that uses
1229 // std::auto_ptr, so that it allocates and deletes manually.
1230 template<typename Ordinal, typename Packet>
1232 createOp (const EReductionType reductType)
1233 {
1234  typedef ScalarTraits<Packet> ST;
1235  switch (reductType) {
1236  case REDUCE_SUM: {
1238  }
1239  case REDUCE_MIN: {
1241  ! ST::isComparable, std::invalid_argument, "Teuchos::createOp"
1242  "(EReductionType): The Packet type " << TypeNameTraits<Packet>::name ()
1243  << " is not less-than comparable, so it does not make sense to do a "
1244  "MIN reduction with it.");
1246  }
1247  case REDUCE_MAX: {
1249  ! ST::isComparable, std::invalid_argument, "Teuchos::createOp"
1250  "(EReductionType): The Packet type " << TypeNameTraits<Packet>::name ()
1251  << " is not less-than comparable, so it does not make sense to do a "
1252  "MAX reduction with it.");
1254  }
1255  case REDUCE_AND: {
1257  }
1258  default:
1260  true, std::invalid_argument, "Teuchos::createOp(EReductionType): "
1261  "Invalid EReductionType value " << reductType << ". Valid values "
1262  "include REDUCE_SUM, REDUCE_MIN, REDUCE_MAX, and REDUCE_AND.");
1263  }
1264 }
1265 
1266 
1267 } // namespace Teuchos
1268 
1269 
1270 //
1271 // Teuchos::Comm wrapper functions
1272 //
1273 
1274 
1275 template<typename Ordinal>
1276 int Teuchos::rank(const Comm<Ordinal>& comm)
1277 {
1278  return comm.getRank();
1279 }
1280 
1281 
1282 template<typename Ordinal>
1283 int Teuchos::size(const Comm<Ordinal>& comm)
1284 {
1285  return comm.getSize();
1286 }
1287 
1288 
1289 template<typename Ordinal>
1290 void Teuchos::barrier(const Comm<Ordinal>& comm)
1291 {
1292  TEUCHOS_COMM_TIME_MONITOR(
1293  "Teuchos::CommHelpers: barrier<"
1295  <<">()"
1296  );
1297  comm.barrier();
1298 }
1299 
1300 
1301 template<typename Ordinal, typename Packet>
1302 void Teuchos::broadcast(
1303  const Comm<Ordinal>& comm,
1304  const int rootRank, const Ordinal count, Packet buffer[]
1305  )
1306 {
1307  TEUCHOS_COMM_TIME_MONITOR(
1308  "Teuchos::CommHelpers: broadcast<"
1310  <<">( value type )"
1311  );
1313  charBuffer(count,buffer);
1314  comm.broadcast(
1315  rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1316  );
1317 }
1318 
1319 
1320 template<typename Ordinal, typename Packet>
1321 void Teuchos::broadcast(
1322  const Comm<Ordinal>& comm,
1323  const int rootRank,
1324  const ArrayView<Packet> &buffer
1325  )
1326 {
1327  broadcast<Ordinal, Packet>(comm, rootRank, buffer.size(), buffer.getRawPtr() );
1328 }
1329 
1330 
1331 template<typename Ordinal, typename Packet>
1332 void Teuchos::broadcast(
1333  const Comm<Ordinal>& comm,
1334  const int rootRank, Packet *object
1335  )
1336 {
1337  broadcast<Ordinal,Packet>(comm,rootRank,1,object);
1338 }
1339 
1340 
1341 template<typename Ordinal, typename Packet>
1342 void Teuchos::broadcast(
1343  const Comm<Ordinal>& comm,
1344  const int rootRank, const Ptr<Packet> &object
1345  )
1346 {
1347  broadcast<Ordinal,Packet>(comm,rootRank,1,object.getRawPtr());
1348 }
1349 
1350 
1351 template<typename Ordinal, typename Packet>
1352 void Teuchos::broadcast(
1353  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
1354  const int rootRank, const Ordinal count, Packet*const buffer[]
1355  )
1356 {
1357  TEUCHOS_COMM_TIME_MONITOR(
1358  "Teuchos::CommHelpers: broadcast<"
1360  <<">( reference type )"
1361  );
1363  charBuffer(serializer, count, buffer);
1364  comm.broadcast(
1365  rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1366  );
1367 }
1368 
1369 
1370 template<typename Ordinal, typename Packet>
1371 void Teuchos::broadcast(
1372  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
1373  const int rootRank, const ArrayView<const Ptr<Packet> > &buffer
1374  )
1375 {
1376  Array<Packet*> bufferPtrArray;
1377  for (int i = 0; i < buffer.size(); ++i) {
1378  bufferPtrArray.push_back(buffer[i].getRawPtr());
1379  }
1380  broadcast<Ordinal,Packet>(comm, serializer, rootRank,
1381  buffer.size(), bufferPtrArray.getRawPtr());
1382 }
1383 
1384 template<typename Ordinal, typename Packet, typename Serializer>
1385 void Teuchos::broadcast(
1386  const Comm<Ordinal>& comm,
1387  const Serializer& serializer,
1388  const int rootRank, const Ordinal count, Packet buffer[]
1389  )
1390 {
1391  TEUCHOS_COMM_TIME_MONITOR(
1392  "Teuchos::CommHelpers: broadcast<"
1394  <<">( value type )"
1395  );
1397  charBuffer(count,buffer,rcp(&serializer,false));
1398  comm.broadcast(
1399  rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1400  );
1401 }
1402 
1403 
1404 template<typename Ordinal, typename Packet>
1405 void Teuchos::gatherAll(
1406  const Comm<Ordinal>& comm,
1407  const Ordinal sendCount, const Packet sendBuffer[],
1408  const Ordinal recvCount, Packet recvBuffer[]
1409  )
1410 {
1411  TEUCHOS_COMM_TIME_MONITOR(
1412  "Teuchos::CommHelpers: gatherAll<"
1414  <<">( value type )"
1415  );
1417  charSendBuffer(sendCount,sendBuffer);
1419  charRecvBuffer(recvCount,recvBuffer);
1420  comm.gatherAll(
1421  charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1422  ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
1423  );
1424 }
1425 
1426 template<typename Ordinal, typename Packet>
1427 void
1428 Teuchos::gather (const Packet sendBuf[],
1429  const Ordinal sendCount,
1430  Packet recvBuf[],
1431  const Ordinal recvCount,
1432  const int root,
1433  const Comm<Ordinal>& comm)
1434 {
1435  TEUCHOS_COMM_TIME_MONITOR(
1436  "Teuchos::CommHelpers: gather<"
1438  <<">( value type )"
1439  );
1441  charSendBuffer (sendCount, sendBuf);
1443  charRecvBuffer (recvCount, recvBuf);
1444  comm.gather (charSendBuffer.getBytes (),
1445  charSendBuffer.getCharBuffer (),
1446  charRecvBuffer.getBytes (),
1447  charRecvBuffer.getCharBuffer (),
1448  root);
1449 }
1450 
1451 template<typename Ordinal, typename Packet>
1452 void
1453 Teuchos::gatherv (const Packet sendBuf[],
1454  const Ordinal sendCount,
1455  Packet recvBuf[],
1456  const Ordinal recvCounts[],
1457  const Ordinal displs[],
1458  const int root,
1459  const Comm<Ordinal>& comm)
1460 {
1461  // Ordinal totalRecvCount = 0;
1462 
1463  // // In order to get the right output buffer length, we have to sum
1464  // // the receive counts from all the processes in the communicator.
1465  // const Ordinal numProcs = as<Ordinal> (comm->getSize ());
1466  // for (Ordinal k = 0; k < as<Ordinal> (numProcs); ++k) {
1467  // totalRecvCount += recvCounts[k];
1468  // }
1469 
1470  // // FIXME (mfh 16 Apr 2013) We also have to redo the displacements.
1471 
1472  // ConstValueTypeSerializationBuffer<Ordinal,Packet>
1473  // charSendBuffer (sendCount, sendBuf);
1474  // ValueTypeSerializationBuffer<Ordinal,Packet>
1475  // charRecvBuffer (totalRecvCount, recvBuf);
1476  // comm.gatherv (charSendBuffer.getBytes (),
1477  // charSendBuffer.getCharBuffer (),
1478  // charRecvBuffer.getBytes (),
1479  // charRecvBuffer.getCharBuffer (),
1480  // root);
1481  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
1482  "Teuchos::gatherv: The general case is not implemented.");
1483 }
1484 
1485 template<typename Ordinal, typename Packet>
1486 void Teuchos::gatherAll(
1487  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
1488  const Ordinal sendCount, const Packet*const sendBuffer[],
1489  const Ordinal recvCount, Packet*const recvBuffer[]
1490  )
1491 {
1492  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
1493 }
1494 
1495 template<typename Ordinal, typename Packet, typename Serializer>
1496 void Teuchos::gatherAll(
1497  const Comm<Ordinal>& comm,
1498  const Serializer& serializer,
1499  const Ordinal sendCount, const Packet sendBuffer[],
1500  const Ordinal recvCount, Packet recvBuffer[]
1501  )
1502 {
1503  TEUCHOS_COMM_TIME_MONITOR(
1504  "Teuchos::CommHelpers: gatherAll<"
1506  <<">( value type )"
1507  );
1509  charSendBuffer(sendCount,sendBuffer,rcp(&serializer,false));
1511  charRecvBuffer(recvCount,recvBuffer,rcp(&serializer,false));
1512  comm.gatherAll(
1513  charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1514  ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
1515  );
1516 }
1517 
1518 
1519 template<typename Ordinal, typename Packet>
1520 void
1521 Teuchos::reduce (const Packet sendBuf[],
1522  Packet recvBuf[],
1523  const Ordinal count,
1524  const EReductionType reductType,
1525  const Ordinal root,
1526  const Comm<Ordinal>& comm)
1527 {
1528  // See Bug 6375; Tpetra does not actually need any specializations
1529  // other than Ordinal = int and Packet = int. We may add them later
1530  // if there is interest.
1532  (true, std::logic_error, "Teuchos::reduce<" <<
1534  << ">: Generic version not implemented. We only implement this function "
1535  "for Ordinal = int and Packet = specific types.");
1536 }
1537 
1538 
1539 template<typename Ordinal, typename Packet>
1540 void Teuchos::reduceAll(
1541  const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp
1542  ,const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
1543  )
1544 {
1545  TEUCHOS_COMM_TIME_MONITOR(
1546  "Teuchos::CommHelpers: reduceAll<"
1548  <<">( value type, user-defined op )"
1549  );
1551  charSendBuffer(count,sendBuffer);
1553  charGlobalReducts(count,globalReducts);
1555  charReductOp(rcp(&reductOp,false));
1556  comm.reduceAll(
1557  charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1558  ,charGlobalReducts.getCharBuffer()
1559  );
1560 }
1561 
1562 
1563 template<typename Ordinal, typename Packet>
1564 void Teuchos::reduceAll(
1565  const Comm<Ordinal>& comm, const EReductionType reductType,
1566  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
1567  )
1568 {
1569  TEUCHOS_COMM_TIME_MONITOR(
1570  "Teuchos::CommHelpers: reduceAll<"
1572  <<">( value type, "<<toString(reductType)<<" )"
1573  );
1574 
1576  createOp<Ordinal, Packet> (reductType);
1577  try {
1578  reduceAll(comm,*reductOp,count,sendBuffer,globalReducts);
1579  }
1580  catch (std::exception& e) {
1581  delete reductOp;
1582  throw e;
1583  }
1584  delete reductOp;
1585 }
1586 
1587 
1588 namespace Teuchos {
1589 
1590 // amb 11 Nov 2014. I am disabling these specializations for
1591 // now. MPI_C_DOUBLE_COMPLEX is causing a problem in some builds. This code was
1592 // effectively turned on only yesterday (10 Nov 2014) when TEUCHOS_HAVE_COMPLEX
1593 // was corrected to be HAVE_TEUCHOS_COMPLEX, so evidently there are no users of
1594 // these specializations.
1595 #if 0
1596 #ifdef HAVE_TEUCHOS_COMPLEX
1597 // Specialization for Ordinal=int and Packet=std::complex<double>.
1598 template<>
1599 TEUCHOSCOMM_LIB_DLL_EXPORT void
1600 reduceAll<int, std::complex<double> > (const Comm<int>& comm,
1601  const EReductionType reductType,
1602  const int count,
1603  const std::complex<double> sendBuffer[],
1604  std::complex<double> globalReducts[]);
1605 template<>
1606 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1607 ireceive<int, std::complex<double> > (const Comm<int>& comm,
1608  const ArrayRCP<std::complex<double> >& recvBuffer,
1609  const int sourceRank);
1610 template<>
1611 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1612 ireceive<int, std::complex<double> > (const ArrayRCP<std::complex<double> > &recvBuffer,
1613  const int sourceRank,
1614  const int tag,
1615  const Comm<int>& comm);
1616 template<>
1617 TEUCHOSCOMM_LIB_DLL_EXPORT void
1618 send<int, std::complex<double> > (const Comm<int>& comm,
1619  const int count,
1620  const std::complex<double> sendBuffer[],
1621  const int destRank);
1622 template<>
1623 TEUCHOSCOMM_LIB_DLL_EXPORT void
1624 send<int, std::complex<double> > (const std::complex<double> sendBuffer[],
1625  const int count,
1626  const int destRank,
1627  const int tag,
1628  const Comm<int>& comm);
1629 template<>
1630 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1631 isend<int, std::complex<double> > (const ArrayRCP<const std::complex<double> >& sendBuffer,
1632  const int destRank,
1633  const int tag,
1634  const Comm<int>& comm);
1635 
1636 // Specialization for Ordinal=int and Packet=std::complex<float>.
1637 template<>
1638 TEUCHOSCOMM_LIB_DLL_EXPORT void
1639 reduceAll<int, std::complex<float> > (const Comm<int>& comm,
1640  const EReductionType reductType,
1641  const int count,
1642  const std::complex<float> sendBuffer[],
1643  std::complex<float> globalReducts[]);
1644 template<>
1645 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1646 ireceive<int, std::complex<float> > (const Comm<int>& comm,
1647  const ArrayRCP<std::complex<float> >& recvBuffer,
1648  const int sourceRank);
1649 template<>
1650 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1651 ireceive<int, std::complex<float> > (const ArrayRCP<std::complex<float> > &recvBuffer,
1652  const int sourceRank,
1653  const int tag,
1654  const Comm<int>& comm);
1655 template<>
1656 TEUCHOSCOMM_LIB_DLL_EXPORT void
1657 send<int, std::complex<float> > (const Comm<int>& comm,
1658  const int count,
1659  const std::complex<float> sendBuffer[],
1660  const int destRank);
1661 template<>
1662 TEUCHOSCOMM_LIB_DLL_EXPORT void
1663 send<int, std::complex<float> > (const std::complex<float> sendBuffer[],
1664  const int count,
1665  const int destRank,
1666  const int tag,
1667  const Comm<int>& comm);
1668 template<>
1669 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1670 isend<int, std::complex<float> > (const ArrayRCP<const std::complex<float> >& sendBuffer,
1671  const int destRank,
1672  const int tag,
1673  const Comm<int>& comm);
1674 #endif // HAVE_TEUCHOS_COMPLEX
1675 #endif // if 0
1676 
1677 // Specialization for Ordinal=int and Packet=double.
1678 template<>
1679 TEUCHOSCOMM_LIB_DLL_EXPORT void
1680 reduceAll<int, double> (const Comm<int>& comm,
1681  const EReductionType reductType,
1682  const int count,
1683  const double sendBuffer[],
1684  double globalReducts[]);
1685 template<>
1686 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1687 ireceive<int, double> (const Comm<int>& comm,
1688  const ArrayRCP<double>& recvBuffer,
1689  const int sourceRank);
1690 template<>
1691 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1692 ireceive<int, double> (const ArrayRCP<double> &recvBuffer,
1693  const int sourceRank,
1694  const int tag,
1695  const Comm<int>& comm);
1696 template<>
1697 TEUCHOSCOMM_LIB_DLL_EXPORT void
1698 send<int, double> (const Comm<int>& comm,
1699  const int count,
1700  const double sendBuffer[],
1701  const int destRank);
1702 template<>
1703 TEUCHOSCOMM_LIB_DLL_EXPORT void
1704 send<int, double> (const double sendBuffer[],
1705  const int count,
1706  const int destRank,
1707  const int tag,
1708  const Comm<int>& comm);
1709 template<>
1710 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1711 isend<int, double> (const ArrayRCP<const double>& sendBuffer,
1712  const int destRank,
1713  const int tag,
1714  const Comm<int>& comm);
1715 
1716 // Specialization for Ordinal=int and Packet=float.
1717 template<>
1718 TEUCHOSCOMM_LIB_DLL_EXPORT void
1719 reduceAll<int, float> (const Comm<int>& comm,
1720  const EReductionType reductType,
1721  const int count,
1722  const float sendBuffer[],
1723  float globalReducts[]);
1724 template<>
1725 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1726 ireceive<int, float> (const Comm<int>& comm,
1727  const ArrayRCP<float>& recvBuffer,
1728  const int sourceRank);
1729 template<>
1730 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1731 ireceive<int, float> (const ArrayRCP<float> &recvBuffer,
1732  const int sourceRank,
1733  const int tag,
1734  const Comm<int>& comm);
1735 template<>
1736 TEUCHOSCOMM_LIB_DLL_EXPORT void
1737 send<int, float> (const Comm<int>& comm,
1738  const int count,
1739  const float sendBuffer[],
1740  const int destRank);
1741 template<>
1742 TEUCHOSCOMM_LIB_DLL_EXPORT void
1743 send<int, float> (const float sendBuffer[],
1744  const int count,
1745  const int destRank,
1746  const int tag,
1747  const Comm<int>& comm);
1748 template<>
1749 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1750 isend<int, float> (const ArrayRCP<const float>& sendBuffer,
1751  const int destRank,
1752  const int tag,
1753  const Comm<int>& comm);
1754 
1755 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
1756 // Specialization for Ordinal=int and Packet=long long.
1757 template<>
1758 TEUCHOSCOMM_LIB_DLL_EXPORT void
1759 gather<int, long long> (const long long sendBuf[],
1760  const int sendCount,
1761  long long recvBuf[],
1762  const int recvCount,
1763  const int root,
1764  const Comm<int>& comm);
1765 template<>
1766 TEUCHOSCOMM_LIB_DLL_EXPORT void
1767 gatherv<int, long long> (const long long sendBuf[],
1768  const int sendCount,
1769  long long recvBuf[],
1770  const int recvCounts[],
1771  const int displs[],
1772  const int root,
1773  const Comm<int>& comm);
1774 template<>
1775 TEUCHOSCOMM_LIB_DLL_EXPORT void
1776 reduceAll<int, long long> (const Comm<int>& comm,
1777  const EReductionType reductType,
1778  const int count,
1779  const long long sendBuffer[],
1780  long long globalReducts[]);
1781 template<>
1782 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1783 ireceive<int, long long> (const Comm<int>& comm,
1784  const ArrayRCP<long long>& recvBuffer,
1785  const int sourceRank);
1786 template<>
1787 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1788 ireceive<int, long long> (const ArrayRCP<long long> &recvBuffer,
1789  const int sourceRank,
1790  const int tag,
1791  const Comm<int>& comm);
1792 template<>
1793 TEUCHOSCOMM_LIB_DLL_EXPORT void
1794 send<int, long long> (const Comm<int>& comm,
1795  const int count,
1796  const long long sendBuffer[],
1797  const int destRank);
1798 template<>
1799 TEUCHOSCOMM_LIB_DLL_EXPORT void
1800 send<int, long long> (const long long sendBuffer[],
1801  const int count,
1802  const int destRank,
1803  const int tag,
1804  const Comm<int>& comm);
1805 template<>
1806 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1807 isend<int, long long> (const ArrayRCP<const long long>& sendBuffer,
1808  const int destRank,
1809  const int tag,
1810  const Comm<int>& comm);
1811 
1812 // Specialization for Ordinal=int and Packet=unsigned long long.
1813 template<>
1814 TEUCHOSCOMM_LIB_DLL_EXPORT void
1815 gather<int, unsigned long long> (const unsigned long long sendBuf[],
1816  const int sendCount,
1817  unsigned long long recvBuf[],
1818  const int recvCount,
1819  const int root,
1820  const Comm<int>& comm);
1821 template<>
1822 TEUCHOSCOMM_LIB_DLL_EXPORT void
1823 gatherv<int, unsigned long long> (const unsigned long long sendBuf[],
1824  const int sendCount,
1825  unsigned long long recvBuf[],
1826  const int recvCounts[],
1827  const int displs[],
1828  const int root,
1829  const Comm<int>& comm);
1830 template<>
1831 TEUCHOSCOMM_LIB_DLL_EXPORT void
1832 reduceAll<int, unsigned long long> (const Comm<int>& comm,
1833  const EReductionType reductType,
1834  const int count,
1835  const unsigned long long sendBuffer[],
1836  unsigned long long globalReducts[]);
1837 template<>
1838 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1839 ireceive<int, unsigned long long> (const Comm<int>& comm,
1840  const ArrayRCP<unsigned long long>& recvBuffer,
1841  const int sourceRank);
1842 template<>
1843 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1844 ireceive<int, unsigned long long> (const ArrayRCP<unsigned long long> &recvBuffer,
1845  const int sourceRank,
1846  const int tag,
1847  const Comm<int>& comm);
1848 template<>
1849 TEUCHOSCOMM_LIB_DLL_EXPORT void
1850 send<int, unsigned long long> (const Comm<int>& comm,
1851  const int count,
1852  const unsigned long long sendBuffer[],
1853  const int destRank);
1854 template<>
1855 TEUCHOSCOMM_LIB_DLL_EXPORT void
1856 send<int, unsigned long long> (const unsigned long long sendBuffer[],
1857  const int count,
1858  const int destRank,
1859  const int tag,
1860  const Comm<int>& comm);
1861 template<>
1862 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1863 isend<int, unsigned long long> (const ArrayRCP<const unsigned long long>& sendBuffer,
1864  const int destRank,
1865  const int tag,
1866  const Comm<int>& comm);
1867 #endif // HAVE_TEUCHOS_LONG_LONG_INT
1868 
1869 // Specialization for Ordinal=int and Packet=long.
1870 template<>
1871 TEUCHOSCOMM_LIB_DLL_EXPORT void
1872 gather<int, long> (const long sendBuf[],
1873  const int sendCount,
1874  long recvBuf[],
1875  const int recvCount,
1876  const int root,
1877  const Comm<int>& comm);
1878 template<>
1879 TEUCHOSCOMM_LIB_DLL_EXPORT void
1880 gatherv<int, long> (const long sendBuf[],
1881  const int sendCount,
1882  long recvBuf[],
1883  const int recvCounts[],
1884  const int displs[],
1885  const int root,
1886  const Comm<int>& comm);
1887 template<>
1888 TEUCHOSCOMM_LIB_DLL_EXPORT void
1889 reduceAll<int, long> (const Comm<int>& comm,
1890  const EReductionType reductType,
1891  const int count,
1892  const long sendBuffer[],
1893  long globalReducts[]);
1894 template<>
1895 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1896 ireceive<int, long> (const Comm<int>& comm,
1897  const ArrayRCP<long>& recvBuffer,
1898  const int sourceRank);
1899 template<>
1900 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1901 ireceive<int, long> (const ArrayRCP<long> &recvBuffer,
1902  const int sourceRank,
1903  const int tag,
1904  const Comm<int>& comm);
1905 template<>
1906 TEUCHOSCOMM_LIB_DLL_EXPORT void
1907 send<int, long> (const Comm<int>& comm,
1908  const int count,
1909  const long sendBuffer[],
1910  const int destRank);
1911 template<>
1912 TEUCHOSCOMM_LIB_DLL_EXPORT void
1913 send<int, long> (const long sendBuffer[],
1914  const int count,
1915  const int destRank,
1916  const int tag,
1917  const Comm<int>& comm);
1918 template<>
1919 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1920 isend<int, long> (const ArrayRCP<const long>& sendBuffer,
1921  const int destRank,
1922  const int tag,
1923  const Comm<int>& comm);
1924 
1925 // Specialization for Ordinal=int and Packet=unsigned long.
1926 template<>
1927 TEUCHOSCOMM_LIB_DLL_EXPORT void
1928 gather<int, unsigned long> (const unsigned long sendBuf[],
1929  const int sendCount,
1930  unsigned long recvBuf[],
1931  const int recvCount,
1932  const int root,
1933  const Comm<int>& comm);
1934 template<>
1935 TEUCHOSCOMM_LIB_DLL_EXPORT void
1936 gatherv<int, unsigned long> (const unsigned long sendBuf[],
1937  const int sendCount,
1938  unsigned long recvBuf[],
1939  const int recvCounts[],
1940  const int displs[],
1941  const int root,
1942  const Comm<int>& comm);
1943 template<>
1944 TEUCHOSCOMM_LIB_DLL_EXPORT void
1945 reduceAll<int, unsigned long> (const Comm<int>& comm,
1946  const EReductionType reductType,
1947  const int count,
1948  const unsigned long sendBuffer[],
1949  unsigned long globalReducts[]);
1950 template<>
1951 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1952 ireceive<int, unsigned long> (const Comm<int>& comm,
1953  const ArrayRCP<unsigned long>& recvBuffer,
1954  const int sourceRank);
1955 template<>
1956 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1957 ireceive<int, unsigned long> (const ArrayRCP<unsigned long> &recvBuffer,
1958  const int sourceRank,
1959  const int tag,
1960  const Comm<int>& comm);
1961 template<>
1962 TEUCHOSCOMM_LIB_DLL_EXPORT void
1963 send<int, unsigned long> (const Comm<int>& comm,
1964  const int count,
1965  const unsigned long sendBuffer[],
1966  const int destRank);
1967 template<>
1968 TEUCHOSCOMM_LIB_DLL_EXPORT void
1969 send<int, unsigned long> (const unsigned long sendBuffer[],
1970  const int count,
1971  const int destRank,
1972  const int tag,
1973  const Comm<int>& comm);
1974 template<>
1975 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1976 isend<int, unsigned long> (const ArrayRCP<const unsigned long>& sendBuffer,
1977  const int destRank,
1978  const int tag,
1979  const Comm<int>& comm);
1980 
1981 // Specialization for Ordinal=int and Packet=int.
1982 template<>
1983 TEUCHOSCOMM_LIB_DLL_EXPORT void
1984 gather<int, int> (const int sendBuf[],
1985  const int sendCount,
1986  int recvBuf[],
1987  const int recvCount,
1988  const int root,
1989  const Comm<int>& comm);
1990 template<>
1991 TEUCHOSCOMM_LIB_DLL_EXPORT void
1992 gatherv<int, int> (const int sendBuf[],
1993  const int sendCount,
1994  int recvBuf[],
1995  const int recvCounts[],
1996  const int displs[],
1997  const int root,
1998  const Comm<int>& comm);
1999 template<>
2000 TEUCHOSCOMM_LIB_DLL_EXPORT void
2001 scatter (const int sendBuf[],
2002  const int sendCount,
2003  int recvBuf[],
2004  const int recvCount,
2005  const int root,
2006  const Comm<int>& comm);
2007 template<>
2008 TEUCHOSCOMM_LIB_DLL_EXPORT void
2009 reduce<int, int> (const int sendBuf[],
2010  int recvBuf[],
2011  const int count,
2012  const EReductionType reductType,
2013  const int root,
2014  const Comm<int>& comm);
2015 template<>
2016 TEUCHOSCOMM_LIB_DLL_EXPORT void
2017 reduceAll<int, int> (const Comm<int>& comm,
2018  const EReductionType reductType,
2019  const int count,
2020  const int sendBuffer[],
2021  int globalReducts[]);
2022 
2023 // mfh 09 Apr 2013: We provide a full specialization of
2024 // reduceAllAndScatter, because it is an important part of
2025 // Tpetra::Distributor initialization.
2026 template<>
2027 TEUCHOSCOMM_LIB_DLL_EXPORT TEUCHOS_DEPRECATED void
2028 reduceAllAndScatter<int, int> (const Comm<int>& comm,
2029  const EReductionType reductType,
2030  const int sendCount,
2031  const int sendBuffer[],
2032  const int recvCounts[],
2033  int myGlobalReducts[]);
2034 template<>
2035 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2036 ireceive<int, int> (const Comm<int>& comm,
2037  const ArrayRCP<int>& recvBuffer,
2038  const int sourceRank);
2039 template<>
2040 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2041 ireceive<int, int> (const ArrayRCP<int> &recvBuffer,
2042  const int sourceRank,
2043  const int tag,
2044  const Comm<int>& comm);
2045 template<>
2046 TEUCHOSCOMM_LIB_DLL_EXPORT void
2047 send<int, int> (const Comm<int>& comm,
2048  const int count,
2049  const int sendBuffer[],
2050  const int destRank);
2051 template<>
2052 TEUCHOSCOMM_LIB_DLL_EXPORT void
2053 send<int, int> (const int sendBuffer[],
2054  const int count,
2055  const int destRank,
2056  const int tag,
2057  const Comm<int>& comm);
2058 template<>
2059 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2060 isend<int, int> (const ArrayRCP<const int>& sendBuffer,
2061  const int destRank,
2062  const int tag,
2063  const Comm<int>& comm);
2064 
2065 // Specialization for Ordinal=int and Packet=unsigned int.
2066 template<>
2067 TEUCHOSCOMM_LIB_DLL_EXPORT void
2068 gather<int, unsigned int> (const unsigned int sendBuf[],
2069  const int sendCount,
2070  unsigned int recvBuf[],
2071  const int recvCount,
2072  const int root,
2073  const Comm<int>& comm);
2074 template<>
2075 TEUCHOSCOMM_LIB_DLL_EXPORT void
2076 gatherv<int, unsigned int> (const unsigned int sendBuf[],
2077  const int sendCount,
2078  unsigned int recvBuf[],
2079  const int recvCounts[],
2080  const int displs[],
2081  const int root,
2082  const Comm<int>& comm);
2083 template<>
2084 TEUCHOSCOMM_LIB_DLL_EXPORT void
2085 reduceAll<int, unsigned int> (const Comm<int>& comm,
2086  const EReductionType reductType,
2087  const int count,
2088  const unsigned int sendBuffer[],
2089  unsigned int globalReducts[]);
2090 template<>
2091 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2092 ireceive<int, unsigned int> (const Comm<int>& comm,
2093  const ArrayRCP<unsigned int>& recvBuffer,
2094  const int sourceRank);
2095 template<>
2096 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2097 ireceive<int, unsigned int> (const ArrayRCP<unsigned int> &recvBuffer,
2098  const int sourceRank,
2099  const int tag,
2100  const Comm<int>& comm);
2101 template<>
2102 TEUCHOSCOMM_LIB_DLL_EXPORT void
2103 send<int, unsigned int> (const Comm<int>& comm,
2104  const int count,
2105  const unsigned int sendBuffer[],
2106  const int destRank);
2107 template<>
2108 TEUCHOSCOMM_LIB_DLL_EXPORT void
2109 send<int, unsigned int> (const unsigned int sendBuffer[],
2110  const int count,
2111  const int destRank,
2112  const int tag,
2113  const Comm<int>& comm);
2114 template<>
2115 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2116 isend<int, unsigned int> (const ArrayRCP<const unsigned int>& sendBuffer,
2117  const int destRank,
2118  const int tag,
2119  const Comm<int>& comm);
2120 
2121 // Specialization for Ordinal=int and Packet=short.
2122 template<>
2123 TEUCHOSCOMM_LIB_DLL_EXPORT void
2124 gather<int, short> (const short sendBuf[],
2125  const int sendCount,
2126  short recvBuf[],
2127  const int recvCount,
2128  const int root,
2129  const Comm<int>& comm);
2130 template<>
2131 TEUCHOSCOMM_LIB_DLL_EXPORT void
2132 gatherv<int, short> (const short sendBuf[],
2133  const int sendCount,
2134  short recvBuf[],
2135  const int recvCounts[],
2136  const int displs[],
2137  const int root,
2138  const Comm<int>& comm);
2139 template<>
2140 TEUCHOSCOMM_LIB_DLL_EXPORT void
2141 reduceAll<int, short> (const Comm<int>& comm,
2142  const EReductionType reductType,
2143  const int count,
2144  const short sendBuffer[],
2145  short globalReducts[]);
2146 template<>
2147 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2148 ireceive<int, short> (const Comm<int>& comm,
2149  const ArrayRCP<short>& recvBuffer,
2150  const int sourceRank);
2151 template<>
2152 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2153 ireceive<int, short> (const ArrayRCP<short> &recvBuffer,
2154  const int sourceRank,
2155  const int tag,
2156  const Comm<int>& comm);
2157 template<>
2158 TEUCHOSCOMM_LIB_DLL_EXPORT void
2159 send<int, short> (const Comm<int>& comm,
2160  const int count,
2161  const short sendBuffer[],
2162  const int destRank);
2163 template<>
2164 TEUCHOSCOMM_LIB_DLL_EXPORT void
2165 send<int, short> (const short sendBuffer[],
2166  const int count,
2167  const int destRank,
2168  const int tag,
2169  const Comm<int>& comm);
2170 template<>
2171 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2172 isend<int, short> (const ArrayRCP<const short>& sendBuffer,
2173  const int destRank,
2174  const int tag,
2175  const Comm<int>& comm);
2176 
2177 // mfh 18 Oct 2012: The specialization for Packet=char seems to be
2178 // causing problems such as the following:
2179 //
2180 // http://testing.sandia.gov/cdash/testDetails.php?test=9909246&build=747699
2181 //
2182 // I am disabling it for now. This should revert back to the old
2183 // behavior for Packet=char. That should fix the Tpetra errors, since
2184 // many Tpetra objects inherit from DistObject<char, ...>.
2185 #if 0
2186 // Specialization for Ordinal=int and Packet=char.
2187 template<>
2188 TEUCHOSCOMM_LIB_DLL_EXPORT void
2189 reduceAll<int, char> (const Comm<int>& comm,
2190  const EReductionType reductType,
2191  const int count,
2192  const char sendBuffer[],
2193  char globalReducts[]);
2194 #endif // 0
2195 } // namespace Teuchos
2196 
2197 
2198 template<typename Ordinal, typename Packet>
2199 void Teuchos::reduceAll(
2200  const Comm<Ordinal>& comm, const EReductionType reductType
2201  ,const Packet &send, const Ptr<Packet> &globalReduct
2202  )
2203 {
2204  // mfh 17 Oct 2012: This will invoke the above specializations for
2205  // general count, so we don't need to specialize this function.
2206  reduceAll<Ordinal,Packet>(comm, reductType, 1, &send, &*globalReduct);
2207 }
2208 
2209 
2210 template<typename Ordinal, typename Packet>
2211 void Teuchos::reduceAll(
2212  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2214  const Ordinal count, const Packet*const sendBuffer[], Packet*const globalReducts[]
2215  )
2216 {
2217  TEUCHOS_COMM_TIME_MONITOR(
2218  "Teuchos::CommHelpers: reduceAll<"
2220  <<">( reference type )"
2221  );
2223  charSendBuffer(serializer,count,sendBuffer);
2225  charGlobalReducts(serializer,count,globalReducts);
2227  charReductOp(rcp(&serializer,false),rcp(&reductOp,false));
2228  comm.reduceAll(
2229  charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2230  ,charGlobalReducts.getCharBuffer()
2231  );
2232 }
2233 
2234 template<typename Ordinal, typename Packet, typename Serializer>
2235 void Teuchos::reduceAll(
2236  const Comm<Ordinal>& comm,
2237  const Serializer& serializer,
2238  const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
2239  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
2240  )
2241 {
2242  TEUCHOS_COMM_TIME_MONITOR(
2243  "Teuchos::CommHelpers: reduceAll<"
2245  <<">( value type, user-defined op )"
2246  );
2248  charSendBuffer(count,sendBuffer,rcp(&serializer,false));
2250  charGlobalReducts(count,globalReducts,rcp(&serializer,false));
2252  charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
2253  comm.reduceAll(
2254  charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2255  ,charGlobalReducts.getCharBuffer()
2256  );
2257 }
2258 
2259 
2260 template<typename Ordinal, typename Packet, typename Serializer>
2261 void Teuchos::reduceAll(
2262  const Comm<Ordinal>& comm,
2263  const Serializer& serializer,
2264  const EReductionType reductType,
2265  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
2266  )
2267 {
2268  TEUCHOS_COMM_TIME_MONITOR(
2269  "Teuchos::CommHelpers: reduceAll<"
2271  <<">( value type, "<<toString(reductType)<<" )"
2272  );
2273 
2275  createOp<Ordinal, Packet> (reductType);
2276  try {
2277  reduceAll(comm,serializer,*reductOp,count,sendBuffer,globalReducts);
2278  }
2279  catch (std::exception& e) {
2280  delete reductOp;
2281  throw e;
2282  }
2283  delete reductOp;
2284 }
2285 
2286 
2287 template<typename Ordinal, typename Packet>
2288 TEUCHOS_DEPRECATED void
2289 Teuchos::reduceAllAndScatter(
2290  const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
2291  const Ordinal sendCount, const Packet sendBuffer[] ,
2292  const Ordinal recvCounts[], Packet myGlobalReducts[]
2293  )
2294 {
2295 
2296  TEUCHOS_COMM_TIME_MONITOR(
2297  "Teuchos::CommHelpers: reduceAllAndScatter<"
2299  <<">( value type, user-defined op )"
2300  );
2301 
2302  const Ordinal size = Teuchos::size(comm);
2303  const Ordinal rank = Teuchos::rank(comm);
2304 
2305 #ifdef TEUCHOS_DEBUG
2306  Ordinal sumRecvCounts = 0;
2307  for( Ordinal i = 0; i < size; ++i )
2308  sumRecvCounts += recvCounts[static_cast<ptrdiff_t>(i)];
2309  TEUCHOS_TEST_FOR_EXCEPT(!(sumRecvCounts==sendCount));
2310 #endif
2311 
2313  charSendBuffer(sendCount,sendBuffer);
2315  charMyGlobalReducts(recvCounts[static_cast<ptrdiff_t>(rank)], myGlobalReducts);
2317  charReductOp(rcp(&reductOp,false));
2318 
2319  const Ordinal
2320  packetSize = charSendBuffer.getBytes()/sendCount;
2321 
2323  Workspace<Ordinal> charRecvCounts(wss, size);
2324  for (Ordinal k = 0; k < size; ++k) {
2325  charRecvCounts[k] = as<Ordinal>(recvCounts[static_cast<ptrdiff_t>(k)] * packetSize);
2326  }
2327 
2328  comm.reduceAllAndScatter(
2329  charReductOp, charSendBuffer.getBytes(), charSendBuffer.getCharBuffer(),
2330  &charRecvCounts[0], charMyGlobalReducts.getCharBuffer()
2331  );
2332 
2333 }
2334 
2335 
2336 template<typename Ordinal, typename Packet>
2337 TEUCHOS_DEPRECATED void
2338 Teuchos::reduceAllAndScatter(
2339  const Comm<Ordinal>& comm, const EReductionType reductType,
2340  const Ordinal sendCount, const Packet sendBuffer[] ,
2341  const Ordinal recvCounts[], Packet myGlobalReducts[]
2342  )
2343 {
2344  TEUCHOS_COMM_TIME_MONITOR(
2345  "Teuchos::CommHelpers: reduceAllAndScatter<"
2347  <<">( value type, "<<toString(reductType)<<" )"
2348  );
2350  createOp<Ordinal, Packet> (reductType);
2351  try {
2352  reduceAllAndScatter (comm, *reductOp, sendCount, sendBuffer,
2353  recvCounts, myGlobalReducts);
2354  }
2355  catch (std::exception& e) {
2356  delete reductOp;
2357  throw e;
2358  }
2359  delete reductOp;
2360 }
2361 
2362 
2363 template<typename Ordinal, typename Packet>
2364 TEUCHOS_DEPRECATED void
2365 Teuchos::reduceAllAndScatter(
2366  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2368  const Ordinal sendCount, const Packet*const sendBuffer[],
2369  const Ordinal recvCounts[], Packet*const myGlobalReducts[]
2370  )
2371 {
2372  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2373 }
2374 
2375 template<typename Ordinal, typename Packet, typename Serializer>
2376 TEUCHOS_DEPRECATED void
2377 Teuchos::reduceAllAndScatter(
2378  const Comm<Ordinal>& comm,
2379  const Serializer& serializer,
2380  const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
2381  const Ordinal sendCount, const Packet sendBuffer[] ,
2382  const Ordinal recvCounts[], Packet myGlobalReducts[]
2383  )
2384 {
2385 
2386  TEUCHOS_COMM_TIME_MONITOR(
2387  "Teuchos::CommHelpers: reduceAllAndScatter<"
2389  <<">( value type, user-defined op )"
2390  );
2391 
2392  const Ordinal size = Teuchos::size(comm);
2393  const Ordinal rank = Teuchos::rank(comm);
2394 
2395 #ifdef TEUCHOS_DEBUG
2396  Ordinal sumRecvCounts = 0;
2397  for( Ordinal i = 0; i < size; ++i )
2398  sumRecvCounts += recvCounts[static_cast<ptrdiff_t>(i)];
2399  TEUCHOS_TEST_FOR_EXCEPT(!(sumRecvCounts==sendCount));
2400 #endif
2401 
2403  charSendBuffer(sendCount,sendBuffer,rcp(&serializer,false));
2405  charMyGlobalReducts(recvCounts[static_cast<ptrdiff_t>(rank)], myGlobalReducts,rcp(&serializer,false));
2407  charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
2408 
2409  const Ordinal
2410  packetSize = charSendBuffer.getBytes()/sendCount;
2411 
2413  Workspace<Ordinal> charRecvCounts(wss, size);
2414  for (Ordinal k = 0; k < size; ++k) {
2415  charRecvCounts[k] = as<Ordinal>(recvCounts[static_cast<ptrdiff_t>(k)] * packetSize);
2416  }
2417 
2418  comm.reduceAllAndScatter(
2419  charReductOp, charSendBuffer.getBytes(), charSendBuffer.getCharBuffer(),
2420  &charRecvCounts[0], charMyGlobalReducts.getCharBuffer()
2421  );
2422 
2423 }
2424 
2425 template<typename Ordinal, typename Packet, typename Serializer>
2426 TEUCHOS_DEPRECATED void
2427 Teuchos::reduceAllAndScatter(
2428  const Comm<Ordinal>& comm,
2429  const Serializer& serializer,
2430  const EReductionType reductType,
2431  const Ordinal sendCount, const Packet sendBuffer[] ,
2432  const Ordinal recvCounts[], Packet myGlobalReducts[]
2433  )
2434 {
2435  TEUCHOS_COMM_TIME_MONITOR(
2436  "Teuchos::CommHelpers: reduceAllAndScatter<"
2438  <<">( value type, "<<toString(reductType)<<" )"
2439  );
2440 
2442  createOp<Ordinal, Packet> (reductType);
2443  try {
2444  reduceAllAndScatter (comm, serializer, *reductOp, sendCount,
2445  sendBuffer, recvCounts, myGlobalReducts);
2446  }
2447  catch (std::exception& e) {
2448  delete reductOp;
2449  throw e;
2450  }
2451  delete reductOp;
2452 }
2453 
2454 
2455 template<typename Ordinal, typename Packet>
2456 void Teuchos::scan(
2457  const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
2458  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2459  )
2460 {
2461  TEUCHOS_COMM_TIME_MONITOR(
2462  "Teuchos::CommHelpers: scan<"
2464  <<">( value type, user-defined op )"
2465  );
2467  charSendBuffer(count,sendBuffer);
2469  charScanReducts(count,scanReducts);
2471  charReductOp(rcp(&reductOp,false));
2472  comm.scan(
2473  charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2474  ,charScanReducts.getCharBuffer()
2475  );
2476 }
2477 
2478 
2479 template<typename Ordinal, typename Packet>
2480 void Teuchos::scan(
2481  const Comm<Ordinal>& comm, const EReductionType reductType,
2482  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2483  )
2484 {
2485  TEUCHOS_COMM_TIME_MONITOR(
2486  "Teuchos::CommHelpers: scan<"
2488  <<">( value type, "<<toString(reductType)<<" )"
2489  );
2490 
2492  createOp<Ordinal, Packet> (reductType);
2493  try {
2494  scan(comm,*reductOp,count,sendBuffer,scanReducts);
2495  }
2496  catch (std::exception& e) {
2497  delete reductOp;
2498  throw e;
2499  }
2500  delete reductOp;
2501 }
2502 
2503 
2504 template<typename Ordinal, typename Packet>
2505 void Teuchos::scan(
2506  const Comm<Ordinal>& comm, const EReductionType reductType,
2507  const Packet &send, const Ptr<Packet> &scanReduct
2508  )
2509 {
2510  scan<Ordinal,Packet>(comm, reductType, 1, &send, &*scanReduct);
2511 }
2512 
2513 
2514 template<typename Ordinal, typename Packet>
2515 void Teuchos::scan(
2516  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2518  const Ordinal count, const Packet*const sendBuffer[], Packet*const scanReducts[]
2519  )
2520 {
2521  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2522 }
2523 
2524 template<typename Ordinal, typename Packet, typename Serializer>
2525 void Teuchos::scan(
2526  const Comm<Ordinal>& comm,
2527  const Serializer& serializer,
2528  const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
2529  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2530  )
2531 {
2532  TEUCHOS_COMM_TIME_MONITOR(
2533  "Teuchos::CommHelpers: scan<"
2535  <<">( value type, user-defined op )"
2536  );
2538  charSendBuffer(count,sendBuffer,rcp(&serializer,false));
2540  charScanReducts(count,scanReducts,rcp(&serializer,false));
2542  charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
2543  comm.scan(
2544  charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2545  ,charScanReducts.getCharBuffer()
2546  );
2547 }
2548 
2549 
2550 template<typename Ordinal, typename Packet, typename Serializer>
2551 void Teuchos::scan(
2552  const Comm<Ordinal>& comm,
2553  const Serializer& serializer,
2554  const EReductionType reductType,
2555  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2556  )
2557 {
2558  TEUCHOS_COMM_TIME_MONITOR(
2559  "Teuchos::CommHelpers: scan<"
2561  <<">( value type, "<<toString(reductType)<<" )"
2562  );
2563 
2565  createOp<Ordinal, Packet> (reductType);
2566  try {
2567  scan(comm,serializer,*reductOp,count,sendBuffer,scanReducts);
2568  }
2569  catch (std::exception& e) {
2570  delete reductOp;
2571  throw e;
2572  }
2573  delete reductOp;
2574 }
2575 
2576 template<typename Ordinal, typename Packet>
2577 void Teuchos::send(
2578  const Comm<Ordinal>& comm,
2579  const Ordinal count, const Packet sendBuffer[], const int destRank
2580  )
2581 {
2582  TEUCHOS_COMM_TIME_MONITOR(
2583  "Teuchos::CommHelpers: send<"
2585  <<">( value type )"
2586  );
2588  charSendBuffer(count,sendBuffer);
2589  comm.send(
2590  charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2591  ,destRank
2592  );
2593 }
2594 
2595 template<typename Ordinal, typename Packet>
2596 void
2597 Teuchos::send (const Packet sendBuffer[],
2598  const Ordinal count,
2599  const int destRank,
2600  const int tag,
2601  const Comm<Ordinal>& comm)
2602 {
2603  TEUCHOS_COMM_TIME_MONITOR(
2604  "Teuchos::CommHelpers: send<"
2606  <<">( value type )"
2607  );
2608  ConstValueTypeSerializationBuffer<Ordinal,Packet> charSendBuffer (count, sendBuffer);
2609  comm.send (charSendBuffer.getBytes (), charSendBuffer.getCharBuffer (), destRank, tag);
2610 }
2611 
2612 template<typename Ordinal, typename Packet>
2613 void Teuchos::ssend(
2614  const Comm<Ordinal>& comm,
2615  const Ordinal count, const Packet sendBuffer[], const int destRank
2616  )
2617 {
2618  TEUCHOS_COMM_TIME_MONITOR(
2619  "Teuchos::CommHelpers: ssend<"
2621  <<">( value type )"
2622  );
2624  charSendBuffer(count,sendBuffer);
2625  comm.ssend(
2626  charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2627  ,destRank
2628  );
2629 }
2630 
2631 template<typename Ordinal, typename Packet>
2632 void
2633 Teuchos::ssend (const Packet sendBuffer[],
2634  const Ordinal count,
2635  const int destRank,
2636  const int tag,
2637  const Comm<Ordinal>& comm)
2638 {
2639  TEUCHOS_COMM_TIME_MONITOR(
2640  "Teuchos::CommHelpers: ssend<"
2642  <<">( value type )"
2643  );
2645  buf_type charSendBuffer (count, sendBuffer);
2646  comm.ssend (charSendBuffer.getBytes (),
2647  charSendBuffer.getCharBuffer (),
2648  destRank, tag);
2649 }
2650 
2651 template<typename Ordinal, typename Packet>
2652 void Teuchos::send(
2653  const Comm<Ordinal>& comm,
2654  const Packet &send, const int destRank
2655  )
2656 {
2657  Teuchos::send<Ordinal,Packet>(comm,1,&send,destRank);
2658 }
2659 
2660 template<typename Ordinal, typename Packet>
2661 void Teuchos::ssend(
2662  const Comm<Ordinal>& comm,
2663  const Packet &send, const int destRank
2664  )
2665 {
2666  Teuchos::ssend<Ordinal,Packet>(comm,1,&send,destRank);
2667 }
2668 
2669 template<typename Ordinal, typename Packet>
2670 void Teuchos::send(
2671  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2672  const Ordinal count, const Packet*const sendBuffer[], const int destRank
2673  )
2674 {
2675  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2676 }
2677 
2678 template<typename Ordinal, typename Packet, typename Serializer>
2679 void Teuchos::send(
2680  const Comm<Ordinal>& comm,
2681  const Serializer& serializer,
2682  const Ordinal count, const Packet sendBuffer[], const int destRank
2683  )
2684 {
2685  TEUCHOS_COMM_TIME_MONITOR(
2686  "Teuchos::CommHelpers: send<"
2688  <<">( value type )"
2689  );
2691  charSendBuffer(count,sendBuffer,rcp(&serializer,false));
2692  comm.send(
2693  charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2694  ,destRank
2695  );
2696 }
2697 
2698 template<typename Ordinal, typename Packet>
2699 int Teuchos::receive(
2700  const Comm<Ordinal>& comm,
2701  const int sourceRank, const Ordinal count, Packet recvBuffer[]
2702  )
2703 {
2704  TEUCHOS_COMM_TIME_MONITOR(
2705  "Teuchos::CommHelpers: receive<"
2707  <<">( value type )"
2708  );
2710  charRecvBuffer(count,recvBuffer);
2711  return comm.receive(
2712  sourceRank
2713  ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
2714  );
2715 }
2716 
2717 
2718 template<typename Ordinal, typename Packet>
2719 int Teuchos::receive(
2720  const Comm<Ordinal>& comm,
2721  const int sourceRank, Packet *recv
2722  )
2723 {
2724  return Teuchos::receive<Ordinal,Packet>(comm,sourceRank,1,recv);
2725 }
2726 
2727 
2728 template<typename Ordinal, typename Packet>
2729 int Teuchos::receive(
2730  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2731  const int sourceRank, const Ordinal count, Packet*const recvBuffer[]
2732  )
2733 {
2734  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2735 }
2736 
2737 template<typename Ordinal, typename Packet, typename Serializer>
2738 int Teuchos::receive(
2739  const Comm<Ordinal>& comm,
2740  const Serializer& serializer,
2741  const int sourceRank, const Ordinal count, Packet recvBuffer[]
2742  )
2743 {
2744  TEUCHOS_COMM_TIME_MONITOR(
2745  "Teuchos::CommHelpers: receive<"
2747  <<">( value type )"
2748  );
2750  charRecvBuffer(count,recvBuffer,rcp(&serializer,false));
2751  return comm.receive(
2752  sourceRank
2753  ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
2754  );
2755 }
2756 
2757 template<typename Ordinal, typename Packet>
2758 void Teuchos::readySend(
2759  const Comm<Ordinal>& comm,
2760  const ArrayView<const Packet> &sendBuffer,
2761  const int destRank
2762  )
2763 {
2764  TEUCHOS_COMM_TIME_MONITOR(
2765  "Teuchos::CommHelpers: readySend<"
2767  <<">( value type )"
2768  );
2770  charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr());
2771  comm.readySend( charSendBuffer.getCharBufferView(), destRank );
2772 }
2773 
2774 template<typename Ordinal, typename Packet>
2775 void
2776 Teuchos::readySend (const Packet sendBuffer[],
2777  const Ordinal count,
2778  const int destRank,
2779  const int tag,
2780  const Comm<Ordinal>& comm)
2781 {
2782  TEUCHOS_COMM_TIME_MONITOR(
2783  "Teuchos::CommHelpers: readySend<"
2785  <<">( value type )"
2786  );
2788  buf_type charSendBuffer (count, sendBuffer);
2789  comm.readySend (charSendBuffer.getBytes (),
2790  charSendBuffer.getCharBuffer (),
2791  destRank, tag);
2792 }
2793 
2794 template<typename Ordinal, typename Packet>
2795 void Teuchos::readySend(
2796  const Comm<Ordinal>& comm,
2797  const Packet &send,
2798  const int destRank
2799  )
2800 {
2801  readySend<Ordinal, Packet>( comm, arrayView(&send,1), destRank );
2802 }
2803 
2804 template<typename Ordinal, typename Packet, typename Serializer>
2805 void Teuchos::readySend(
2806  const Comm<Ordinal>& comm,
2807  const Serializer& serializer,
2808  const ArrayView<const Packet> &sendBuffer,
2809  const int destRank
2810  )
2811 {
2812  TEUCHOS_COMM_TIME_MONITOR(
2813  "Teuchos::CommHelpers: readySend<"
2815  <<">( value type )"
2816  );
2818  charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr(), serializer);
2819  comm.readySend( charSendBuffer.getCharBufferView(), destRank );
2820 }
2821 
2822 template<typename Ordinal, typename Packet>
2825  const Comm<Ordinal>& comm,
2826  const ArrayRCP<const Packet> &sendBuffer,
2827  const int destRank
2828  )
2829 {
2830  TEUCHOS_COMM_TIME_MONITOR(
2831  "Teuchos::CommHelpers: isend<"
2833  <<">( value type )"
2834  );
2836  charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr());
2837  RCP<CommRequest<Ordinal> > commRequest = comm.isend(
2838  charSendBuffer.getCharBufferView(), destRank );
2839  set_extra_data( sendBuffer, "buffer", inOutArg(commRequest) );
2840  return commRequest;
2841 }
2842 
2843 template<typename Ordinal, typename Packet>
2845 Teuchos::isend (const ArrayRCP<const Packet> &sendBuffer,
2846  const int destRank,
2847  const int tag,
2848  const Comm<Ordinal>& comm)
2849 {
2850  TEUCHOS_COMM_TIME_MONITOR(
2851  "Teuchos::isend<" << OrdinalTraits<Ordinal>::name () << ","
2852  << TypeNameTraits<Packet>::name () << ">");
2854  charSendBuffer (sendBuffer.size (), sendBuffer.getRawPtr ());
2855  RCP<CommRequest<Ordinal> > commRequest =
2856  comm.isend (charSendBuffer.getCharBufferView (), destRank, tag);
2857  set_extra_data (sendBuffer, "buffer", inOutArg (commRequest));
2858  return commRequest;
2859 }
2860 
2861 template<typename Ordinal, typename Packet>
2864  const Comm<Ordinal>& comm,
2865  const RCP<const Packet> &send,
2866  const int destRank
2867  )
2868 {
2869  const ArrayRCP<const Packet> sendBuffer =
2870  arcpWithEmbeddedObj( send.get(), 0, 1, send, false );
2871  // 2008/07/29: rabartl: Above: I need to write a helper function to create
2872  // new ArrayRCP object given a single object to copy.
2873  return isend<Ordinal, Packet>( comm, sendBuffer, destRank );
2874 }
2875 
2876 template<typename Ordinal, typename Packet, typename Serializer>
2879  const Comm<Ordinal>& comm,
2880  const Serializer& serializer,
2881  const ArrayRCP<const Packet> &sendBuffer,
2882  const int destRank
2883  )
2884 {
2885  TEUCHOS_COMM_TIME_MONITOR(
2886  "Teuchos::CommHelpers: isend<"
2888  <<">( value type )"
2889  );
2891  charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr(), serializer);
2892  RCP<CommRequest<Ordinal> > commRequest = comm.isend(
2893  charSendBuffer.getCharBufferView(), destRank );
2894  set_extra_data( sendBuffer, "buffer", inOutArg(commRequest) );
2895  return commRequest;
2896 }
2897 
2898 template<typename Ordinal, typename Packet>
2901  const Comm<Ordinal>& comm,
2902  const ArrayRCP<Packet> &recvBuffer,
2903  const int sourceRank
2904  )
2905 {
2906  TEUCHOS_COMM_TIME_MONITOR(
2907  "Teuchos::ireceive<int, " << "," << TypeNameTraits<Packet>::name () << ">");
2909  charRecvBuffer(recvBuffer.size(), recvBuffer.getRawPtr());
2910  RCP<CommRequest<Ordinal> > commRequest = comm.ireceive(
2911  charRecvBuffer.getCharBufferView(), sourceRank );
2912  set_extra_data( recvBuffer, "buffer", inOutArg(commRequest) );
2913  return commRequest;
2914 }
2915 
2916 template<typename Ordinal, typename Packet>
2918 Teuchos::ireceive (const Teuchos::ArrayRCP<Packet> &recvBuffer,
2919  const int sourceRank,
2920  const int tag,
2921  const Teuchos::Comm<Ordinal>& comm)
2922 {
2923  TEUCHOS_COMM_TIME_MONITOR(
2924  "Teuchos::ireceive<int, " << "," << TypeNameTraits<Packet>::name () << ">");
2926  charRecvBuffer (recvBuffer.size (), recvBuffer.getRawPtr ());
2927  RCP<CommRequest<int> > commRequest =
2928  comm.ireceive (charRecvBuffer.getCharBufferView (), sourceRank, tag);
2929  set_extra_data (recvBuffer, "buffer", inOutArg (commRequest));
2930  return commRequest;
2931 }
2932 
2933 template<typename Ordinal, typename Packet>
2936  const Comm<Ordinal>& comm,
2937  const RCP<Packet> &recv,
2938  const int sourceRank
2939  )
2940 {
2941  const ArrayRCP<Packet> recvBuffer =
2942  arcpWithEmbeddedObj( recv.get(), 0, 1, recv, false );
2943  // 2008/07/29: rabartl: Above: I need to write a helper function to create
2944  // new ArrayRCP object given a single object to copy.
2945  return ireceive<Ordinal, Packet>( comm, recvBuffer, sourceRank );
2946 }
2947 
2948 template<typename Ordinal, typename Packet, typename Serializer>
2951  const Comm<Ordinal>& comm,
2952  const Serializer& serializer,
2953  const ArrayRCP<Packet> &recvBuffer,
2954  const int sourceRank
2955  )
2956 {
2957  TEUCHOS_COMM_TIME_MONITOR(
2958  "Teuchos::CommHelpers: ireceive<"
2960  <<">( value type )"
2961  );
2963  charRecvBuffer(recvBuffer.size(), recvBuffer.getRawPtr(), serializer);
2964  RCP<CommRequest<Ordinal> > commRequest = comm.ireceive(
2965  charRecvBuffer.getCharBufferView(), sourceRank );
2966  set_extra_data( recvBuffer, "buffer", inOutArg(commRequest) );
2967  return commRequest;
2968 }
2969 
2970 template<typename Ordinal>
2971 void Teuchos::waitAll(
2972  const Comm<Ordinal>& comm,
2973  const ArrayView<RCP<CommRequest<Ordinal> > > &requests
2974  )
2975 {
2976  comm.waitAll(requests);
2977 }
2978 
2979 
2980 template<typename Ordinal>
2981 void
2982 Teuchos::waitAll (const Comm<Ordinal>& comm,
2983  const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
2984  const ArrayView<RCP<CommStatus<Ordinal> > >& statuses)
2985 {
2986  comm.waitAll (requests, statuses);
2987 }
2988 
2989 
2990 template<typename Ordinal>
2992 Teuchos::wait (const Comm<Ordinal>& comm,
2993  const Ptr<RCP<CommRequest<Ordinal> > > &request)
2994 {
2995  return comm.wait (request);
2996 }
2997 
2998 
2999 #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...
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
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
Enumeration for selecting from a set of pre-defined reduction operations.
virtual RCP< CommStatus< Ordinal > > wait(const Ptr< RCP< CommRequest< Ordinal > > > &request) const =0
Wait on a single communication request, and return its status.
Templated class for workspace creation.
virtual void scan(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char scanReducts[]) const =0
Scan reduction.
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.
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
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 * get() const
Get the raw C++ pointer to the underlying object.
T * getRawPtr()
Return a raw pointer to beginning of array or NULL if unsized.
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
size_type size() const
The total number of entries in the array.
Standard logical AND operator for booleans.
Standard min operator for types with value semantics.
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.
Standard summation operator for types with value semantics.
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
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 TEUCHOS_DEPRECATED void reduceAllAndScatter(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal sendBytes, const char sendBuffer[], const Ordinal recvCounts[], char myGlobalReducts[]) const =0
Global reduction combined with a scatter.
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.
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.
Workspace encapsulation class.
T * getRawPtr() const
Return a raw pointer to beginning of array or NULL if unsized.
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.
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.
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
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.
Encapsulation of a pending nonblocking communication operation.
Defines basic traits returning the name of a type in a portable and readable way. ...
Definition of Teuchos::as, for conversions between types.
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...
TEUCHOSCORE_LIB_DLL_EXPORT Teuchos::RCP< WorkspaceStore > get_default_workspace_store()
Get the global workspace object set by set_default_workspace_store().
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...