Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_CommHelpers.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TEUCHOS_COMM_HELPERS_HPP
11 #define TEUCHOS_COMM_HELPERS_HPP
12 
13 #include "Teuchos_Comm.hpp"
18 #include "Teuchos_ScalarTraits.hpp"
20 #include "Teuchos_Array.hpp"
22 #include "Teuchos_Workspace.hpp"
23 #include "Teuchos_as.hpp"
24 
25 #ifdef HAVE_TEUCHOS_MPI
27 #endif // HAVE_TEUCHOS_MPI
30 
31 namespace Teuchos {
32 
33 //
34 // Teuchos::Comm Helper Functions
35 //
36 
37 #ifdef HAVE_TEUCHOS_MPI
38 namespace Details {
39 
46 std::string getMpiErrorString (const int errCode);
47 
48 } // namespace Details
49 #endif // HAVE_TEUCHOS_MPI
50 
55 template<typename Ordinal>
56 int rank(const Comm<Ordinal>& comm);
57 
62 template<typename Ordinal>
63 int size(const Comm<Ordinal>& comm);
64 
69 template<typename Ordinal>
70 void barrier(const Comm<Ordinal>& comm);
71 
76 template<typename Ordinal, typename Packet>
77 void broadcast(
78  const Comm<Ordinal>& comm,
79  const int rootRank,
80  const Ordinal count, Packet buffer[]
81  );
82 
87 template<typename Ordinal, typename Packet>
88 void broadcast(
89  const Comm<Ordinal>& comm,
90  const int rootRank,
91  const ArrayView<Packet> &buffer
92  );
93 
98 template<typename Ordinal, typename Packet>
99 void broadcast(
100  const Comm<Ordinal>& comm,
101  const int rootRank, Packet *object
102  );
103 
108 template<typename Ordinal, typename Packet>
109 void broadcast(
110  const Comm<Ordinal>& comm,
111  const int rootRank, const Ptr<Packet> &object
112  );
113 
118 template<typename Ordinal, typename Packet>
119 void broadcast(
120  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
121  const int rootRank, const Ordinal count, Packet*const buffer[]
122  );
123 
128 template<typename Ordinal, typename Packet>
129 void broadcast(
130  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
131  const int rootRank, const ArrayView<const Ptr<Packet> > &buffer
132  );
133 
139 template<typename Ordinal, typename Packet, typename Serializer>
140 void broadcast(
141  const Comm<Ordinal>& comm,
142  const Serializer& serializer,
143  const int rootRank,
144  const Ordinal count, Packet buffer[]
145  );
146 
151 template<typename Ordinal, typename Packet>
152 void
153 gather (const Packet sendBuf[],
154  const Ordinal sendCount,
155  Packet recvBuf[],
156  const Ordinal recvCount,
157  const int root,
158  const Comm<Ordinal>& comm);
159 
164 template<typename Ordinal, typename Packet>
165 void
166 gatherv (const Packet sendBuf[],
167  const Ordinal sendCount,
168  Packet recvBuf[],
169  const Ordinal recvCounts[],
170  const Ordinal displs[],
171  const int root,
172  const Comm<Ordinal>& comm);
173 
179 template<typename Ordinal, typename Packet>
180 void gatherAll(
181  const Comm<Ordinal>& comm,
182  const Ordinal sendCount, const Packet sendBuffer[],
183  const Ordinal recvCount, Packet recvBuffer[]
184  );
185 
191 template<typename Ordinal, typename Packet>
192 void gatherAll(
193  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
194  const Ordinal sendCount, const Packet*const sendBuffer[],
195  const Ordinal recvCount, Packet*const recvBuffer[]
196  );
197 
203 template<typename Ordinal, typename Packet, typename Serializer>
204 void gatherAll(
205  const Comm<Ordinal>& comm,
206  const Serializer& serializer,
207  const Ordinal sendCount, const Packet sendBuffer[],
208  const Ordinal recvCount, Packet recvBuffer[]
209  );
210 
237 template<typename Ordinal, typename Packet>
238 void
239 scatter (const Packet sendBuf[],
240  const Ordinal sendCount,
241  Packet recvBuf[],
242  const Ordinal recvCount,
243  const Ordinal root,
244  const Comm<Ordinal>& comm)
245 {
246  // See Bug 6375; Tpetra does not actually need any specializations
247  // other than Ordinal = int and Packet = int. We may add them later
248  // if there is interest.
250  (true, std::logic_error, "Teuchos::scatter<" <<
252  << ">: Generic version is not yet implemented. This function currently "
253  "only has an implementtion for Ordinal = int and Packet = int. "
254  "See Bug 6375 and Bug 6336.");
255 }
256 
284 template<typename Ordinal, typename Packet>
285 void
286 reduce (const Packet sendBuf[],
287  Packet recvBuf[],
288  const Ordinal count,
289  const EReductionType reductType,
290  const Ordinal root,
291  const Comm<Ordinal>& comm);
292 
315 template<typename Ordinal, typename Packet>
316 void reduceAll(
317  const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
318  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
319  );
320 
326 template<typename Ordinal, typename Packet>
327 void reduceAll(
328  const Comm<Ordinal>& comm, const EReductionType reductType,
329  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
330  );
331 
337 template<typename Ordinal, typename Packet>
338 void reduceAll(
339  const Comm<Ordinal>& comm, const EReductionType reductType,
340  const Packet &send, const Ptr<Packet> &globalReduct
341  );
342 
348 template<typename Ordinal, typename Packet>
349 void reduceAll(
350  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
352  const Ordinal count, const Packet*const sendBuffer[], Packet*const globalReducts[]
353  );
354 
360 template<typename Ordinal, typename Packet, typename Serializer>
361 void reduceAll(
362  const Comm<Ordinal>& comm,
363  const Serializer& serializer,
364  const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
365  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
366  );
367 
373 template<typename Ordinal, typename Packet, typename Serializer>
374 void reduceAll(
375  const Comm<Ordinal>& comm,
376  const Serializer& serializer,
377  const EReductionType reductType,
378  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
379  );
380 
386 template<typename Ordinal, typename Packet>
387 void scan(
388  const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
389  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
390  );
391 
397 template<typename Ordinal, typename Packet>
398 void scan(
399  const Comm<Ordinal>& comm, const EReductionType reductType,
400  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
401  );
402 
408 template<typename Ordinal, typename Packet>
409 void scan(
410  const Comm<Ordinal>& comm, const EReductionType reductType,
411  const Packet &send, const Ptr<Packet> &scanReduct
412  );
413 
419 template<typename Ordinal, typename Packet>
420 void scan(
421  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
423  const Ordinal count, const Packet*const sendBuffer[], Packet*const scanReducts[]
424  );
425 
431 template<typename Ordinal, typename Packet, typename Serializer>
432 void scan(
433  const Comm<Ordinal>& comm,
434  const Serializer& serializer,
435  const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
436  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
437  );
438 
444 template<typename Ordinal, typename Packet, typename Serializer>
445 void scan(
446  const Comm<Ordinal>& comm,
447  const Serializer& serializer,
448  const EReductionType reductType,
449  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
450  );
451 
456 template<typename Ordinal, typename Packet>
457 void send(
458  const Comm<Ordinal>& comm,
459  const Ordinal count, const Packet sendBuffer[], const int destRank
460  );
461 
463 template<typename Ordinal, typename Packet>
464 void
465 send (const Packet sendBuffer[],
466  const Ordinal count,
467  const int destRank,
468  const int tag,
469  const Comm<Ordinal>& comm);
470 
475 template<typename Ordinal, typename Packet>
476 void ssend(
477  const Comm<Ordinal>& comm,
478  const Ordinal count, const Packet sendBuffer[], const int destRank
479  );
480 
482 template<typename Ordinal, typename Packet>
483 void
484 ssend (const Packet sendBuffer[],
485  const Ordinal count,
486  const int destRank,
487  const int tag,
488  const Comm<Ordinal>& comm);
489 
494 template<typename Ordinal, typename Packet>
495 void send(
496  const Comm<Ordinal>& comm,
497  const Packet &send, const int destRank
498  );
499 
504 template<typename Ordinal, typename Packet>
505 void ssend(
506  const Comm<Ordinal>& comm,
507  const Packet &send, const int destRank
508  );
509 
516 template<typename Ordinal, typename Packet>
517 void send(
518  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
519  const Ordinal count, const Packet*const sendBuffer[], const int destRank
520  );
521 
527 template<typename Ordinal, typename Packet, typename Serializer>
528 void send(
529  const Comm<Ordinal>& comm,
530  const Serializer& serializer,
531  const Ordinal count, const Packet sendBuffer[], const int destRank
532  );
533 
538 template<typename Ordinal, typename Packet>
539 int receive(
540  const Comm<Ordinal>& comm,
541  const int sourceRank, const Ordinal count, Packet recvBuffer[]
542  );
543 
548 template<typename Ordinal, typename Packet>
549 int receive(
550  const Comm<Ordinal>& comm,
551  const int sourceRank, Packet *recv
552  );
553 
558 template<typename Ordinal, typename Packet>
559 int receive(
560  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
561  const int sourceRank, const Ordinal count, Packet*const recvBuffer[]
562  );
563 
569 template<typename Ordinal, typename Packet, typename Serializer>
570 int receive(
571  const Comm<Ordinal>& comm,
572  const Serializer& serializer,
573  const int sourceRank, const Ordinal count, Packet recvBuffer[]
574  );
575 
581 template<typename Ordinal, typename Packet>
582 void readySend(
583  const Comm<Ordinal>& comm,
584  const ArrayView<const Packet> &sendBuffer,
585  const int destRank
586  );
587 
589 template<typename Ordinal, typename Packet>
590 void
591 readySend (const Packet sendBuffer[],
592  const Ordinal count,
593  const int destRank,
594  const int tag,
595  const Comm<Ordinal>& comm);
596 
601 template<typename Ordinal, typename Packet>
602 void readySend(
603  const Comm<Ordinal>& comm,
604  const Packet &send,
605  const int destRank
606  );
607 
613 template<typename Ordinal, typename Packet, typename Serializer>
614 void readySend(
615  const Comm<Ordinal>& comm,
616  const Serializer& serializer,
617  const ArrayView<const Packet> &sendBuffer,
618  const int destRank
619  );
620 
625 template<typename Ordinal, typename Packet>
627  const Comm<Ordinal>& comm,
628  const ArrayRCP<const Packet> &sendBuffer,
629  const int destRank
630  );
631 
633 template<typename Ordinal, typename Packet>
635 isend (const ArrayRCP<const Packet>& sendBuffer,
636  const int destRank,
637  const int tag,
638  const Comm<Ordinal>& comm);
639 
644 template<typename Ordinal, typename Packet>
646  const Comm<Ordinal>& comm,
647  const RCP<const Packet> &send,
648  const int destRank
649  );
650 
656 template<typename Ordinal, typename Packet, typename Serializer>
658  const Comm<Ordinal>& comm,
659  const Serializer& serializer,
660  const ArrayRCP<const Packet> &sendBuffer,
661  const int destRank
662  );
663 
664 
665 // 2008/07/29: rabartl: ToDo: Add reference semantics version of isend!
666 
667 
677 template<typename Ordinal, typename Packet>
679  const Comm<Ordinal>& comm,
680  const ArrayRCP<Packet> &recvBuffer,
681  const int sourceRank
682  );
683 
685 template<typename Ordinal, typename Packet>
687 ireceive (const ArrayRCP<Packet> &recvBuffer,
688  const int sourceRank,
689  const int tag,
690  const Comm<Ordinal>& comm);
691 
703 template<typename Ordinal, typename Packet>
705  const Comm<Ordinal>& comm,
706  const RCP<Packet> &recv,
707  const int sourceRank
708  );
709 
715 template<typename Ordinal, typename Packet, typename Serializer>
717  const Comm<Ordinal>& comm,
718  const Serializer& serializer,
719  const ArrayRCP<Packet> &recvBuffer,
720  const int sourceRank
721  );
722 
723 
724 // 2008/07/29: rabartl: ToDo: Add reference semantics version of ireceive!
725 
726 
734 template<typename Ordinal>
735 void waitAll(
736  const Comm<Ordinal>& comm,
737  const ArrayView<RCP<CommRequest<Ordinal> > > &requests
738  );
739 
769 template<typename Ordinal>
770 void
771 waitAll (const Comm<Ordinal>& comm,
772  const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
773  const ArrayView<RCP<CommStatus<Ordinal> > >& statuses);
774 
798 template<typename Ordinal>
800 wait (const Comm<Ordinal>& comm, const Ptr<RCP<CommRequest<Ordinal> > >& request);
801 
802 //
803 // Standard reduction subclasses for objects that use value semantics
804 //
805 
806 
811 template<typename Ordinal, typename Packet>
812 class SumValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
813 {
814 public:
816  void reduce(
817  const Ordinal count,
818  const Packet inBuffer[],
819  Packet inoutBuffer[]
820  ) const;
821 };
822 
823 
832 template<typename Ordinal, typename Packet>
833 class MinValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
834 {
835 public:
837  void reduce(
838  const Ordinal count,
839  const Packet inBuffer[],
840  Packet inoutBuffer[]
841  ) const;
842 };
843 
844 
853 template<typename Ordinal, typename Packet>
854 class MaxValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
855 {
856 public:
858  void reduce(
859  const Ordinal count,
860  const Packet inBuffer[],
861  Packet inoutBuffer[]
862  ) const;
863 };
864 
865 
870 template<typename Ordinal, typename Packet>
871 class ANDValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
872 {
873 public:
875  void reduce(
876  const Ordinal count,
877  const Packet inBuffer[],
878  Packet inoutBuffer[]
879  ) const;
880 };
881 
882 
883 // ////////////////////////////////////////////////////////////
884 // Implementation details (not for geneal users to mess with)
885 
886 
887 //
888 // ReductionOp Utilities
889 //
890 
891 
892 namespace MixMaxUtilities {
893 
894 
895 template<bool isComparable, typename Ordinal, typename Packet>
896 class Min {};
897 
898 
899 template<typename Ordinal, typename Packet>
900 class Min<true,Ordinal,Packet> {
901 public:
902  static void min(
903  const Ordinal count,
904  const Packet inBuffer[],
905  Packet inoutBuffer[]
906  )
907  {
908  for( int i = 0; i < count; ++i )
909  inoutBuffer[i] = TEUCHOS_MIN(inoutBuffer[i],inBuffer[i]);
910  }
911 };
912 
913 
914 template<typename Ordinal, typename Packet>
915 class Min<false,Ordinal,Packet> {
916 public:
917  static void min(
918  const Ordinal,
919  const Packet[],
920  Packet[]
921  )
922  {
924  true,std::logic_error,
925  "Error, the type "<<TypeNameTraits<Packet>::name()
926  <<" does not support comparison operations!"
927  );
928  }
929 };
930 
931 
932 template<bool isComparable, typename Ordinal, typename Packet>
933 class Max {};
934 
935 
936 template<typename Ordinal, typename Packet>
937 class Max<true,Ordinal,Packet> {
938 public:
939  static void max(
940  const Ordinal count,
941  const Packet inBuffer[],
942  Packet inoutBuffer[]
943  )
944  {
945  for( int i = 0; i < count; ++i )
946  inoutBuffer[i] = TEUCHOS_MAX(inoutBuffer[i],inBuffer[i]);
947  }
948 };
949 
950 
951 template<typename Ordinal, typename Packet>
952 class Max<false,Ordinal,Packet> {
953 public:
954  static void max(
955  const Ordinal,
956  const Packet[],
957  Packet[]
958  )
959  {
961  true,std::logic_error,
962  "Error, the type "<<TypeNameTraits<Packet>::name()
963  <<" does not support comparison operations!"
964  );
965  }
966 };
967 
968 
969 template<bool isComparable, typename Ordinal, typename Packet>
970 class AND {};
971 
972 
973 template<typename Ordinal, typename Packet>
974 class AND<true,Ordinal,Packet> {
975 public:
976  static void andOp(
977  const Ordinal count,
978  const Packet inBuffer[],
979  Packet inoutBuffer[]
980  )
981  {
982  for( int i = 0; i < count; ++i )
983  inoutBuffer[i] = inoutBuffer[i] && inBuffer[i];
984  }
985 };
986 
987 
988 template<typename Ordinal, typename Packet>
989 class AND<false,Ordinal,Packet> {
990 public:
991  static void andOp(
992  const Ordinal,
993  const Packet[],
994  Packet[]
995  )
996  {
998  true,std::logic_error,
999  "Error, the type "<<TypeNameTraits<Packet>::name()
1000  <<" does not support logical AND operations!"
1001  );
1002  }
1003 };
1004 
1005 
1006 } // namespace MixMaxUtilities
1007 
1008 
1009 template<typename Ordinal, typename Packet>
1011  const Ordinal count,
1012  const Packet inBuffer[],
1013  Packet inoutBuffer[]
1014  ) const
1015 {
1016  for( int i = 0; i < count; ++i )
1017  inoutBuffer[i] += inBuffer[i];
1018 }
1019 
1020 
1021 template<typename Ordinal, typename Packet>
1023  const Ordinal count,
1024  const Packet inBuffer[],
1025  Packet inoutBuffer[]
1026  ) const
1027 {
1028  typedef MixMaxUtilities::Min<ScalarTraits<Packet>::isComparable, Ordinal, Packet> min_type;
1029  min_type::min (count, inBuffer, inoutBuffer);
1030 }
1031 
1032 
1033 template<typename Ordinal, typename Packet>
1035  const Ordinal count,
1036  const Packet inBuffer[],
1037  Packet inoutBuffer[]
1038  ) const
1039 {
1040  typedef MixMaxUtilities::Max<ScalarTraits<Packet>::isComparable, Ordinal, Packet> max_type;
1041  max_type::max (count,inBuffer,inoutBuffer);
1042 }
1043 
1044 
1045 template<typename Ordinal, typename Packet>
1047  const Ordinal count,
1048  const Packet inBuffer[],
1049  Packet inoutBuffer[]
1050  ) const
1051 {
1052  typedef MixMaxUtilities::AND<ScalarTraits<Packet>::isComparable, Ordinal, Packet> and_type;
1053  and_type::andOp (count, inBuffer, inoutBuffer);
1054 }
1055 
1056 
1057 } // namespace Teuchos
1058 
1059 
1060 // //////////////////////////
1061 // Template implemenations
1062 
1063 
1064 //
1065 // ReductionOp utilities
1066 //
1067 
1068 
1069 namespace Teuchos {
1070 
1071 
1072 // Not for the general user to use! I am returning a raw ReductionOp* pointer
1073 // to avoid the overhead of using RCP. However, given the use case
1074 // this is just fine since I can just use std::auto_ptr to make sure things
1075 // are deleted correctly.
1076 //
1077 // NOTE (mfh 08 Feb 2015) std::auto_ptr has been deprecated in C++11.
1078 // I could either replace it with std::unique_ptr, or just call 'new'
1079 // and 'delete' manually. The former is less error prone, but
1080 // requires checking a macro for whether C++11 is actually enabled.
1081 // Thus, I've chosen (for now) to rewrite all the code that uses
1082 // std::auto_ptr, so that it allocates and deletes manually.
1083 template<typename Ordinal, typename Packet>
1084 ValueTypeReductionOp<Ordinal,Packet>*
1085 createOp (const EReductionType reductType)
1086 {
1087  typedef ScalarTraits<Packet> ST;
1088  switch (reductType) {
1089  case REDUCE_SUM: {
1091  }
1092  case REDUCE_MIN: {
1093  if (ST::isComparable) {
1095  }
1096  else {
1098  (! ST::isComparable, std::invalid_argument, "Teuchos::createOp"
1099  "(EReductionType): The Packet type " << TypeNameTraits<Packet>::name ()
1100  << " is not less-than comparable, so it does not make sense to do a "
1101  "MIN reduction with it.");
1102  }
1103  }
1104  case REDUCE_MAX: {
1105  if (ST::isComparable) {
1107  }
1108  else {
1110  (! ST::isComparable, std::invalid_argument, "Teuchos::createOp"
1111  "(EReductionType): The Packet type " << TypeNameTraits<Packet>::name ()
1112  << " is not less-than comparable, so it does not make sense to do a "
1113  "MAX reduction with it.");
1114  }
1115  }
1116  case REDUCE_AND: {
1118  }
1119  default:
1121  true, std::invalid_argument, "Teuchos::createOp(EReductionType): "
1122  "Invalid EReductionType value " << reductType << ". Valid values "
1123  "include REDUCE_SUM, REDUCE_MIN, REDUCE_MAX, and REDUCE_AND.");
1124  }
1125 }
1126 
1127 
1128 } // namespace Teuchos
1129 
1130 
1131 //
1132 // Teuchos::Comm wrapper functions
1133 //
1134 
1135 
1136 template<typename Ordinal>
1137 int Teuchos::rank(const Comm<Ordinal>& comm)
1138 {
1139  return comm.getRank();
1140 }
1141 
1142 
1143 template<typename Ordinal>
1144 int Teuchos::size(const Comm<Ordinal>& comm)
1145 {
1146  return comm.getSize();
1147 }
1148 
1149 
1150 template<typename Ordinal>
1151 void Teuchos::barrier(const Comm<Ordinal>& comm)
1152 {
1154  "Teuchos::CommHelpers: barrier<"
1155  <<OrdinalTraits<Ordinal>::name()
1156  <<">()"
1157  );
1158  comm.barrier();
1159 }
1160 
1161 
1162 template<typename Ordinal, typename Packet>
1163 void Teuchos::broadcast(
1164  const Comm<Ordinal>& comm,
1165  const int rootRank, const Ordinal count, Packet buffer[]
1166  )
1167 {
1169  "Teuchos::CommHelpers: broadcast<"
1170  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
1171  <<">( value type )"
1172  );
1173  ValueTypeSerializationBuffer<Ordinal,Packet>
1174  charBuffer(count,buffer);
1175  comm.broadcast(
1176  rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1177  );
1178 }
1179 
1180 
1181 template<typename Ordinal, typename Packet>
1182 void Teuchos::broadcast(
1183  const Comm<Ordinal>& comm,
1184  const int rootRank,
1185  const ArrayView<Packet> &buffer
1186  )
1187 {
1188  broadcast<Ordinal, Packet>(comm, rootRank, buffer.size(), buffer.getRawPtr() );
1189 }
1190 
1191 
1192 template<typename Ordinal, typename Packet>
1193 void Teuchos::broadcast(
1194  const Comm<Ordinal>& comm,
1195  const int rootRank, Packet *object
1196  )
1197 {
1198  broadcast<Ordinal,Packet>(comm,rootRank,1,object);
1199 }
1200 
1201 
1202 template<typename Ordinal, typename Packet>
1203 void Teuchos::broadcast(
1204  const Comm<Ordinal>& comm,
1205  const int rootRank, const Ptr<Packet> &object
1206  )
1207 {
1208  broadcast<Ordinal,Packet>(comm,rootRank,1,object.getRawPtr());
1209 }
1210 
1211 
1212 template<typename Ordinal, typename Packet>
1213 void Teuchos::broadcast(
1214  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
1215  const int rootRank, const Ordinal count, Packet*const buffer[]
1216  )
1217 {
1219  "Teuchos::CommHelpers: broadcast<"
1220  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
1221  <<">( reference type )"
1222  );
1223  ReferenceTypeSerializationBuffer<Ordinal,Packet>
1224  charBuffer(serializer, count, buffer);
1225  comm.broadcast(
1226  rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1227  );
1228 }
1229 
1230 
1231 template<typename Ordinal, typename Packet>
1232 void Teuchos::broadcast(
1233  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
1234  const int rootRank, const ArrayView<const Ptr<Packet> > &buffer
1235  )
1236 {
1237  Array<Packet*> bufferPtrArray;
1238  for (int i = 0; i < buffer.size(); ++i) {
1239  bufferPtrArray.push_back(buffer[i].getRawPtr());
1240  }
1241  broadcast<Ordinal,Packet>(comm, serializer, rootRank,
1242  buffer.size(), bufferPtrArray.getRawPtr());
1243 }
1244 
1245 template<typename Ordinal, typename Packet, typename Serializer>
1246 void Teuchos::broadcast(
1247  const Comm<Ordinal>& comm,
1248  const Serializer& serializer,
1249  const int rootRank, const Ordinal count, Packet buffer[]
1250  )
1251 {
1253  "Teuchos::CommHelpers: broadcast<"
1254  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
1255  <<">( value type )"
1256  );
1257  ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
1258  charBuffer(count,buffer,rcp(&serializer,false));
1259  comm.broadcast(
1260  rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1261  );
1262 }
1263 
1264 
1265 template<typename Ordinal, typename Packet>
1266 void Teuchos::gatherAll(
1267  const Comm<Ordinal>& comm,
1268  const Ordinal sendCount, const Packet sendBuffer[],
1269  const Ordinal recvCount, Packet recvBuffer[]
1270  )
1271 {
1273  "Teuchos::CommHelpers: gatherAll<"
1274  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
1275  <<">( value type )"
1276  );
1277  ConstValueTypeSerializationBuffer<Ordinal,Packet>
1278  charSendBuffer(sendCount,sendBuffer);
1279  ValueTypeSerializationBuffer<Ordinal,Packet>
1280  charRecvBuffer(recvCount,recvBuffer);
1281  comm.gatherAll(
1282  charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1283  ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
1284  );
1285 }
1286 
1287 template<typename Ordinal, typename Packet>
1288 void
1289 Teuchos::gather (const Packet sendBuf[],
1290  const Ordinal sendCount,
1291  Packet recvBuf[],
1292  const Ordinal recvCount,
1293  const int root,
1294  const Comm<Ordinal>& comm)
1295 {
1297  "Teuchos::CommHelpers: gather<"
1298  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
1299  <<">( value type )"
1300  );
1301  ConstValueTypeSerializationBuffer<Ordinal,Packet>
1302  charSendBuffer (sendCount, sendBuf);
1303  ValueTypeSerializationBuffer<Ordinal,Packet>
1304  charRecvBuffer (recvCount, recvBuf);
1305  comm.gather (charSendBuffer.getBytes (),
1306  charSendBuffer.getCharBuffer (),
1307  charRecvBuffer.getBytes (),
1308  charRecvBuffer.getCharBuffer (),
1309  root);
1310 }
1311 
1312 template<typename Ordinal, typename Packet>
1313 void
1314 Teuchos::gatherv (const Packet sendBuf[],
1315  const Ordinal sendCount,
1316  Packet recvBuf[],
1317  const Ordinal recvCounts[],
1318  const Ordinal displs[],
1319  const int root,
1320  const Comm<Ordinal>& comm)
1321 {
1322  // Ordinal totalRecvCount = 0;
1323 
1324  // // In order to get the right output buffer length, we have to sum
1325  // // the receive counts from all the processes in the communicator.
1326  // const Ordinal numProcs = as<Ordinal> (comm->getSize ());
1327  // for (Ordinal k = 0; k < as<Ordinal> (numProcs); ++k) {
1328  // totalRecvCount += recvCounts[k];
1329  // }
1330 
1331  // // FIXME (mfh 16 Apr 2013) We also have to redo the displacements.
1332 
1333  // ConstValueTypeSerializationBuffer<Ordinal,Packet>
1334  // charSendBuffer (sendCount, sendBuf);
1335  // ValueTypeSerializationBuffer<Ordinal,Packet>
1336  // charRecvBuffer (totalRecvCount, recvBuf);
1337  // comm.gatherv (charSendBuffer.getBytes (),
1338  // charSendBuffer.getCharBuffer (),
1339  // charRecvBuffer.getBytes (),
1340  // charRecvBuffer.getCharBuffer (),
1341  // root);
1342  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
1343  "Teuchos::gatherv: The general case is not implemented.");
1344 }
1345 
1346 template<typename Ordinal, typename Packet>
1347 void Teuchos::gatherAll(
1348  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
1349  const Ordinal sendCount, const Packet*const sendBuffer[],
1350  const Ordinal recvCount, Packet*const recvBuffer[]
1351  )
1352 {
1353  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
1354 }
1355 
1356 template<typename Ordinal, typename Packet, typename Serializer>
1357 void Teuchos::gatherAll(
1358  const Comm<Ordinal>& comm,
1359  const Serializer& serializer,
1360  const Ordinal sendCount, const Packet sendBuffer[],
1361  const Ordinal recvCount, Packet recvBuffer[]
1362  )
1363 {
1365  "Teuchos::CommHelpers: gatherAll<"
1366  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
1367  <<">( value type )"
1368  );
1369  ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
1370  charSendBuffer(sendCount,sendBuffer,rcp(&serializer,false));
1371  ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
1372  charRecvBuffer(recvCount,recvBuffer,rcp(&serializer,false));
1373  comm.gatherAll(
1374  charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1375  ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
1376  );
1377 }
1378 
1379 
1380 template<typename Ordinal, typename Packet>
1381 void
1382 Teuchos::reduce (const Packet sendBuf[],
1383  Packet recvBuf[],
1384  const Ordinal count,
1385  const EReductionType reductType,
1386  const Ordinal root,
1387  const Comm<Ordinal>& comm)
1388 {
1389  // See Bug 6375; Tpetra does not actually need any specializations
1390  // other than Ordinal = int and Packet = int. We may add them later
1391  // if there is interest.
1393  (true, std::logic_error, "Teuchos::reduce<" <<
1394  TypeNameTraits<Ordinal>::name () << "," << TypeNameTraits<Packet>::name ()
1395  << ">: Generic version not implemented. We only implement this function "
1396  "for Ordinal = int and Packet = specific types.");
1397 }
1398 
1399 
1400 template<typename Ordinal, typename Packet>
1401 void Teuchos::reduceAll(
1402  const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp
1403  ,const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
1404  )
1405 {
1407  "Teuchos::CommHelpers: reduceAll<"
1408  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
1409  <<">( value type, user-defined op )"
1410  );
1411  ConstValueTypeSerializationBuffer<Ordinal,Packet>
1412  charSendBuffer(count,sendBuffer);
1413  ValueTypeSerializationBuffer<Ordinal,Packet>
1414  charGlobalReducts(count,globalReducts);
1415  CharToValueTypeReductionOp<Ordinal,Packet>
1416  charReductOp(rcp(&reductOp,false));
1417  comm.reduceAll(
1418  charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1419  ,charGlobalReducts.getCharBuffer()
1420  );
1421 }
1422 
1423 
1424 template<typename Ordinal, typename Packet>
1425 void Teuchos::reduceAll(
1426  const Comm<Ordinal>& comm, const EReductionType reductType,
1427  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
1428  )
1429 {
1431  "Teuchos::CommHelpers: reduceAll<"
1432  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
1433  <<">( value type, "<<toString(reductType)<<" )"
1434  );
1435 
1436  ValueTypeReductionOp<Ordinal,Packet>* reductOp =
1437  createOp<Ordinal, Packet> (reductType);
1438  try {
1439  reduceAll(comm,*reductOp,count,sendBuffer,globalReducts);
1440  }
1441  catch (std::exception& e) {
1442  delete reductOp;
1443  throw e;
1444  }
1445  delete reductOp;
1446 }
1447 
1448 
1449 namespace Teuchos {
1450 
1451 // amb 11 Nov 2014. I am disabling these specializations for
1452 // now. MPI_C_DOUBLE_COMPLEX is causing a problem in some builds. This code was
1453 // effectively turned on only yesterday (10 Nov 2014) when TEUCHOS_HAVE_COMPLEX
1454 // was corrected to be HAVE_TEUCHOS_COMPLEX, so evidently there are no users of
1455 // these specializations.
1456 #if 0
1457 #ifdef HAVE_TEUCHOS_COMPLEX
1458 // Specialization for Ordinal=int and Packet=std::complex<double>.
1459 template<>
1461 reduceAll<int, std::complex<double> > (const Comm<int>& comm,
1462  const EReductionType reductType,
1463  const int count,
1464  const std::complex<double> sendBuffer[],
1465  std::complex<double> globalReducts[]);
1466 template<>
1467 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1468 ireceive<int, std::complex<double> > (const Comm<int>& comm,
1469  const ArrayRCP<std::complex<double> >& recvBuffer,
1470  const int sourceRank);
1471 template<>
1472 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1473 ireceive<int, std::complex<double> > (const ArrayRCP<std::complex<double> > &recvBuffer,
1474  const int sourceRank,
1475  const int tag,
1476  const Comm<int>& comm);
1477 template<>
1479 send<int, std::complex<double> > (const Comm<int>& comm,
1480  const int count,
1481  const std::complex<double> sendBuffer[],
1482  const int destRank);
1483 template<>
1485 send<int, std::complex<double> > (const std::complex<double> sendBuffer[],
1486  const int count,
1487  const int destRank,
1488  const int tag,
1489  const Comm<int>& comm);
1490 template<>
1491 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1492 isend<int, std::complex<double> > (const ArrayRCP<const std::complex<double> >& sendBuffer,
1493  const int destRank,
1494  const int tag,
1495  const Comm<int>& comm);
1496 
1497 // Specialization for Ordinal=int and Packet=std::complex<float>.
1498 template<>
1500 reduceAll<int, std::complex<float> > (const Comm<int>& comm,
1501  const EReductionType reductType,
1502  const int count,
1503  const std::complex<float> sendBuffer[],
1504  std::complex<float> globalReducts[]);
1505 template<>
1506 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1507 ireceive<int, std::complex<float> > (const Comm<int>& comm,
1508  const ArrayRCP<std::complex<float> >& recvBuffer,
1509  const int sourceRank);
1510 template<>
1511 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1512 ireceive<int, std::complex<float> > (const ArrayRCP<std::complex<float> > &recvBuffer,
1513  const int sourceRank,
1514  const int tag,
1515  const Comm<int>& comm);
1516 template<>
1518 send<int, std::complex<float> > (const Comm<int>& comm,
1519  const int count,
1520  const std::complex<float> sendBuffer[],
1521  const int destRank);
1522 template<>
1524 send<int, std::complex<float> > (const std::complex<float> sendBuffer[],
1525  const int count,
1526  const int destRank,
1527  const int tag,
1528  const Comm<int>& comm);
1529 template<>
1530 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1531 isend<int, std::complex<float> > (const ArrayRCP<const std::complex<float> >& sendBuffer,
1532  const int destRank,
1533  const int tag,
1534  const Comm<int>& comm);
1535 #endif // HAVE_TEUCHOS_COMPLEX
1536 #endif // if 0
1537 
1538 // Specialization for Ordinal=int and Packet=double.
1539 template<>
1541 reduceAll<int, double> (const Comm<int>& comm,
1542  const EReductionType reductType,
1543  const int count,
1544  const double sendBuffer[],
1545  double globalReducts[]);
1546 template<>
1547 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1548 ireceive<int, double> (const Comm<int>& comm,
1549  const ArrayRCP<double>& recvBuffer,
1550  const int sourceRank);
1551 template<>
1552 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1553 ireceive<int, double> (const ArrayRCP<double> &recvBuffer,
1554  const int sourceRank,
1555  const int tag,
1556  const Comm<int>& comm);
1557 template<>
1559 send<int, double> (const Comm<int>& comm,
1560  const int count,
1561  const double sendBuffer[],
1562  const int destRank);
1563 template<>
1565 send<int, double> (const double sendBuffer[],
1566  const int count,
1567  const int destRank,
1568  const int tag,
1569  const Comm<int>& comm);
1570 template<>
1571 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1572 isend<int, double> (const ArrayRCP<const double>& sendBuffer,
1573  const int destRank,
1574  const int tag,
1575  const Comm<int>& comm);
1576 
1577 // Specialization for Ordinal=int and Packet=float.
1578 template<>
1580 reduceAll<int, float> (const Comm<int>& comm,
1581  const EReductionType reductType,
1582  const int count,
1583  const float sendBuffer[],
1584  float globalReducts[]);
1585 template<>
1586 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1587 ireceive<int, float> (const Comm<int>& comm,
1588  const ArrayRCP<float>& recvBuffer,
1589  const int sourceRank);
1590 template<>
1591 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1592 ireceive<int, float> (const ArrayRCP<float> &recvBuffer,
1593  const int sourceRank,
1594  const int tag,
1595  const Comm<int>& comm);
1596 template<>
1598 send<int, float> (const Comm<int>& comm,
1599  const int count,
1600  const float sendBuffer[],
1601  const int destRank);
1602 template<>
1604 send<int, float> (const float sendBuffer[],
1605  const int count,
1606  const int destRank,
1607  const int tag,
1608  const Comm<int>& comm);
1609 template<>
1610 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1611 isend<int, float> (const ArrayRCP<const float>& sendBuffer,
1612  const int destRank,
1613  const int tag,
1614  const Comm<int>& comm);
1615 
1616 // Specialization for Ordinal=int and Packet=long long.
1617 template<>
1619 gather<int, long long> (const long long sendBuf[],
1620  const int sendCount,
1621  long long recvBuf[],
1622  const int recvCount,
1623  const int root,
1624  const Comm<int>& comm);
1625 template<>
1627 gatherv<int, long long> (const long long sendBuf[],
1628  const int sendCount,
1629  long long recvBuf[],
1630  const int recvCounts[],
1631  const int displs[],
1632  const int root,
1633  const Comm<int>& comm);
1634 template<>
1636 reduceAll<int, long long> (const Comm<int>& comm,
1637  const EReductionType reductType,
1638  const int count,
1639  const long long sendBuffer[],
1640  long long globalReducts[]);
1641 template<>
1642 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1643 ireceive<int, long long> (const Comm<int>& comm,
1644  const ArrayRCP<long long>& recvBuffer,
1645  const int sourceRank);
1646 template<>
1647 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1648 ireceive<int, long long> (const ArrayRCP<long long> &recvBuffer,
1649  const int sourceRank,
1650  const int tag,
1651  const Comm<int>& comm);
1652 template<>
1654 send<int, long long> (const Comm<int>& comm,
1655  const int count,
1656  const long long sendBuffer[],
1657  const int destRank);
1658 template<>
1660 send<int, long long> (const long long sendBuffer[],
1661  const int count,
1662  const int destRank,
1663  const int tag,
1664  const Comm<int>& comm);
1665 template<>
1666 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1667 isend<int, long long> (const ArrayRCP<const long long>& sendBuffer,
1668  const int destRank,
1669  const int tag,
1670  const Comm<int>& comm);
1671 
1672 // Specialization for Ordinal=int and Packet=unsigned long long.
1673 template<>
1675 gather<int, unsigned long long> (const unsigned long long sendBuf[],
1676  const int sendCount,
1677  unsigned long long recvBuf[],
1678  const int recvCount,
1679  const int root,
1680  const Comm<int>& comm);
1681 template<>
1683 gatherv<int, unsigned long long> (const unsigned long long sendBuf[],
1684  const int sendCount,
1685  unsigned long long recvBuf[],
1686  const int recvCounts[],
1687  const int displs[],
1688  const int root,
1689  const Comm<int>& comm);
1690 template<>
1692 reduceAll<int, unsigned long long> (const Comm<int>& comm,
1693  const EReductionType reductType,
1694  const int count,
1695  const unsigned long long sendBuffer[],
1696  unsigned long long globalReducts[]);
1697 template<>
1698 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1699 ireceive<int, unsigned long long> (const Comm<int>& comm,
1700  const ArrayRCP<unsigned long long>& recvBuffer,
1701  const int sourceRank);
1702 template<>
1703 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1704 ireceive<int, unsigned long long> (const ArrayRCP<unsigned long long> &recvBuffer,
1705  const int sourceRank,
1706  const int tag,
1707  const Comm<int>& comm);
1708 template<>
1710 send<int, unsigned long long> (const Comm<int>& comm,
1711  const int count,
1712  const unsigned long long sendBuffer[],
1713  const int destRank);
1714 template<>
1716 send<int, unsigned long long> (const unsigned long long sendBuffer[],
1717  const int count,
1718  const int destRank,
1719  const int tag,
1720  const Comm<int>& comm);
1721 template<>
1722 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1723 isend<int, unsigned long long> (const ArrayRCP<const unsigned long long>& sendBuffer,
1724  const int destRank,
1725  const int tag,
1726  const Comm<int>& comm);
1727 
1728 // Specialization for Ordinal=int and Packet=long.
1729 template<>
1731 gather<int, long> (const long sendBuf[],
1732  const int sendCount,
1733  long recvBuf[],
1734  const int recvCount,
1735  const int root,
1736  const Comm<int>& comm);
1737 template<>
1739 gatherv<int, long> (const long sendBuf[],
1740  const int sendCount,
1741  long recvBuf[],
1742  const int recvCounts[],
1743  const int displs[],
1744  const int root,
1745  const Comm<int>& comm);
1746 template<>
1748 reduceAll<int, long> (const Comm<int>& comm,
1749  const EReductionType reductType,
1750  const int count,
1751  const long sendBuffer[],
1752  long globalReducts[]);
1753 template<>
1754 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1755 ireceive<int, long> (const Comm<int>& comm,
1756  const ArrayRCP<long>& recvBuffer,
1757  const int sourceRank);
1758 template<>
1759 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1760 ireceive<int, long> (const ArrayRCP<long> &recvBuffer,
1761  const int sourceRank,
1762  const int tag,
1763  const Comm<int>& comm);
1764 template<>
1766 send<int, long> (const Comm<int>& comm,
1767  const int count,
1768  const long sendBuffer[],
1769  const int destRank);
1770 template<>
1772 send<int, long> (const long sendBuffer[],
1773  const int count,
1774  const int destRank,
1775  const int tag,
1776  const Comm<int>& comm);
1777 template<>
1778 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1779 isend<int, long> (const ArrayRCP<const long>& sendBuffer,
1780  const int destRank,
1781  const int tag,
1782  const Comm<int>& comm);
1783 
1784 // Specialization for Ordinal=int and Packet=unsigned long.
1785 template<>
1787 gather<int, unsigned long> (const unsigned long sendBuf[],
1788  const int sendCount,
1789  unsigned long recvBuf[],
1790  const int recvCount,
1791  const int root,
1792  const Comm<int>& comm);
1793 template<>
1795 gatherv<int, unsigned long> (const unsigned long sendBuf[],
1796  const int sendCount,
1797  unsigned long recvBuf[],
1798  const int recvCounts[],
1799  const int displs[],
1800  const int root,
1801  const Comm<int>& comm);
1802 template<>
1804 reduceAll<int, unsigned long> (const Comm<int>& comm,
1805  const EReductionType reductType,
1806  const int count,
1807  const unsigned long sendBuffer[],
1808  unsigned long globalReducts[]);
1809 template<>
1810 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1811 ireceive<int, unsigned long> (const Comm<int>& comm,
1812  const ArrayRCP<unsigned long>& recvBuffer,
1813  const int sourceRank);
1814 template<>
1815 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1816 ireceive<int, unsigned long> (const ArrayRCP<unsigned long> &recvBuffer,
1817  const int sourceRank,
1818  const int tag,
1819  const Comm<int>& comm);
1820 template<>
1822 send<int, unsigned long> (const Comm<int>& comm,
1823  const int count,
1824  const unsigned long sendBuffer[],
1825  const int destRank);
1826 template<>
1828 send<int, unsigned long> (const unsigned long sendBuffer[],
1829  const int count,
1830  const int destRank,
1831  const int tag,
1832  const Comm<int>& comm);
1833 template<>
1834 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1835 isend<int, unsigned long> (const ArrayRCP<const unsigned long>& sendBuffer,
1836  const int destRank,
1837  const int tag,
1838  const Comm<int>& comm);
1839 
1840 // Specialization for Ordinal=int and Packet=int.
1841 template<>
1843 gather<int, int> (const int sendBuf[],
1844  const int sendCount,
1845  int recvBuf[],
1846  const int recvCount,
1847  const int root,
1848  const Comm<int>& comm);
1849 template<>
1851 gatherv<int, int> (const int sendBuf[],
1852  const int sendCount,
1853  int recvBuf[],
1854  const int recvCounts[],
1855  const int displs[],
1856  const int root,
1857  const Comm<int>& comm);
1858 template<>
1860 scatter (const int sendBuf[],
1861  const int sendCount,
1862  int recvBuf[],
1863  const int recvCount,
1864  const int root,
1865  const Comm<int>& comm);
1866 template<>
1868 reduce<int, int> (const int sendBuf[],
1869  int recvBuf[],
1870  const int count,
1871  const EReductionType reductType,
1872  const int root,
1873  const Comm<int>& comm);
1874 template<>
1876 reduce<int, long> (const long sendBuf[],
1877  long recvBuf[],
1878  const int count,
1879  const EReductionType reductType,
1880  const int root,
1881  const Comm<int>& comm);
1882 template<>
1884 reduce<int, unsigned long> (const unsigned long sendBuf[],
1885  unsigned long recvBuf[],
1886  const int count,
1887  const EReductionType reductType,
1888  const int root,
1889  const Comm<int>& comm);
1890 template<>
1892 reduce<int, unsigned long long > (const unsigned long long sendBuf[],
1893  unsigned long long recvBuf[],
1894  const int count,
1895  const EReductionType reductType,
1896  const int root,
1897  const Comm<int>& comm);
1898 template<>
1900 reduce<int, double> (const double sendBuf[],
1901  double recvBuf[],
1902  const int count,
1903  const EReductionType reductType,
1904  const int root,
1905  const Comm<int>& comm);
1906 template<>
1908 reduceAll<int, int> (const Comm<int>& comm,
1909  const EReductionType reductType,
1910  const int count,
1911  const int sendBuffer[],
1912  int globalReducts[]);
1913 
1914 template<>
1915 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1916 ireceive<int, int> (const Comm<int>& comm,
1917  const ArrayRCP<int>& recvBuffer,
1918  const int sourceRank);
1919 template<>
1920 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1921 ireceive<int, int> (const ArrayRCP<int> &recvBuffer,
1922  const int sourceRank,
1923  const int tag,
1924  const Comm<int>& comm);
1925 template<>
1927 send<int, int> (const Comm<int>& comm,
1928  const int count,
1929  const int sendBuffer[],
1930  const int destRank);
1931 template<>
1933 send<int, int> (const int sendBuffer[],
1934  const int count,
1935  const int destRank,
1936  const int tag,
1937  const Comm<int>& comm);
1938 template<>
1939 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1940 isend<int, int> (const ArrayRCP<const int>& sendBuffer,
1941  const int destRank,
1942  const int tag,
1943  const Comm<int>& comm);
1944 
1945 // Specialization for Ordinal=int and Packet=unsigned int.
1946 template<>
1948 gather<int, unsigned int> (const unsigned int sendBuf[],
1949  const int sendCount,
1950  unsigned int recvBuf[],
1951  const int recvCount,
1952  const int root,
1953  const Comm<int>& comm);
1954 template<>
1956 gatherv<int, unsigned int> (const unsigned int sendBuf[],
1957  const int sendCount,
1958  unsigned int recvBuf[],
1959  const int recvCounts[],
1960  const int displs[],
1961  const int root,
1962  const Comm<int>& comm);
1963 template<>
1965 reduceAll<int, unsigned int> (const Comm<int>& comm,
1966  const EReductionType reductType,
1967  const int count,
1968  const unsigned int sendBuffer[],
1969  unsigned int globalReducts[]);
1970 template<>
1971 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1972 ireceive<int, unsigned int> (const Comm<int>& comm,
1973  const ArrayRCP<unsigned int>& recvBuffer,
1974  const int sourceRank);
1975 template<>
1976 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1977 ireceive<int, unsigned int> (const ArrayRCP<unsigned int> &recvBuffer,
1978  const int sourceRank,
1979  const int tag,
1980  const Comm<int>& comm);
1981 template<>
1983 send<int, unsigned int> (const Comm<int>& comm,
1984  const int count,
1985  const unsigned int sendBuffer[],
1986  const int destRank);
1987 template<>
1989 send<int, unsigned int> (const unsigned int sendBuffer[],
1990  const int count,
1991  const int destRank,
1992  const int tag,
1993  const Comm<int>& comm);
1994 template<>
1995 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1996 isend<int, unsigned int> (const ArrayRCP<const unsigned int>& sendBuffer,
1997  const int destRank,
1998  const int tag,
1999  const Comm<int>& comm);
2000 
2001 // Specialization for Ordinal=int and Packet=short.
2002 template<>
2004 gather<int, short> (const short sendBuf[],
2005  const int sendCount,
2006  short recvBuf[],
2007  const int recvCount,
2008  const int root,
2009  const Comm<int>& comm);
2010 template<>
2012 gatherv<int, short> (const short sendBuf[],
2013  const int sendCount,
2014  short recvBuf[],
2015  const int recvCounts[],
2016  const int displs[],
2017  const int root,
2018  const Comm<int>& comm);
2019 template<>
2021 reduceAll<int, short> (const Comm<int>& comm,
2022  const EReductionType reductType,
2023  const int count,
2024  const short sendBuffer[],
2025  short globalReducts[]);
2026 template<>
2027 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2028 ireceive<int, short> (const Comm<int>& comm,
2029  const ArrayRCP<short>& recvBuffer,
2030  const int sourceRank);
2031 template<>
2032 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2033 ireceive<int, short> (const ArrayRCP<short> &recvBuffer,
2034  const int sourceRank,
2035  const int tag,
2036  const Comm<int>& comm);
2037 template<>
2039 send<int, short> (const Comm<int>& comm,
2040  const int count,
2041  const short sendBuffer[],
2042  const int destRank);
2043 template<>
2045 send<int, short> (const short sendBuffer[],
2046  const int count,
2047  const int destRank,
2048  const int tag,
2049  const Comm<int>& comm);
2050 template<>
2051 TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2052 isend<int, short> (const ArrayRCP<const short>& sendBuffer,
2053  const int destRank,
2054  const int tag,
2055  const Comm<int>& comm);
2056 
2057 // mfh 18 Oct 2012: The specialization for Packet=char seems to be
2058 // causing problems such as the following:
2059 //
2060 // http://testing.sandia.gov/cdash/testDetails.php?test=9909246&build=747699
2061 //
2062 // I am disabling it for now. This should revert back to the old
2063 // behavior for Packet=char. That should fix the Tpetra errors, since
2064 // many Tpetra objects inherit from DistObject<char, ...>.
2065 #if 0
2066 // Specialization for Ordinal=int and Packet=char.
2067 template<>
2069 reduceAll<int, char> (const Comm<int>& comm,
2070  const EReductionType reductType,
2071  const int count,
2072  const char sendBuffer[],
2073  char globalReducts[]);
2074 #endif // 0
2075 } // namespace Teuchos
2076 
2077 
2078 template<typename Ordinal, typename Packet>
2079 void Teuchos::reduceAll(
2080  const Comm<Ordinal>& comm, const EReductionType reductType
2081  ,const Packet &send, const Ptr<Packet> &globalReduct
2082  )
2083 {
2084  // mfh 17 Oct 2012: This will invoke the above specializations for
2085  // general count, so we don't need to specialize this function.
2086  reduceAll<Ordinal,Packet>(comm, reductType, 1, &send, &*globalReduct);
2087 }
2088 
2089 
2090 template<typename Ordinal, typename Packet>
2091 void Teuchos::reduceAll(
2092  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2093  const ReferenceTypeReductionOp<Ordinal,Packet> &reductOp,
2094  const Ordinal count, const Packet*const sendBuffer[], Packet*const globalReducts[]
2095  )
2096 {
2098  "Teuchos::CommHelpers: reduceAll<"
2099  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2100  <<">( reference type )"
2101  );
2102  ConstReferenceTypeSerializationBuffer<Ordinal,Packet>
2103  charSendBuffer(serializer,count,sendBuffer);
2104  ReferenceTypeSerializationBuffer<Ordinal,Packet>
2105  charGlobalReducts(serializer,count,globalReducts);
2106  CharToReferenceTypeReductionOp<Ordinal,Packet>
2107  charReductOp(rcp(&serializer,false),rcp(&reductOp,false));
2108  comm.reduceAll(
2109  charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2110  ,charGlobalReducts.getCharBuffer()
2111  );
2112 }
2113 
2114 template<typename Ordinal, typename Packet, typename Serializer>
2115 void Teuchos::reduceAll(
2116  const Comm<Ordinal>& comm,
2117  const Serializer& serializer,
2118  const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
2119  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
2120  )
2121 {
2123  "Teuchos::CommHelpers: reduceAll<"
2124  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2125  <<">( value type, user-defined op )"
2126  );
2127  ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
2128  charSendBuffer(count,sendBuffer,rcp(&serializer,false));
2129  ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
2130  charGlobalReducts(count,globalReducts,rcp(&serializer,false));
2131  CharToValueTypeReductionOp<Ordinal,Packet,Serializer>
2132  charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
2133  comm.reduceAll(
2134  charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2135  ,charGlobalReducts.getCharBuffer()
2136  );
2137 }
2138 
2139 
2140 template<typename Ordinal, typename Packet, typename Serializer>
2141 void Teuchos::reduceAll(
2142  const Comm<Ordinal>& comm,
2143  const Serializer& serializer,
2144  const EReductionType reductType,
2145  const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
2146  )
2147 {
2149  "Teuchos::CommHelpers: reduceAll<"
2150  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2151  <<">( value type, "<<toString(reductType)<<" )"
2152  );
2153 
2154  ValueTypeReductionOp<Ordinal,Packet>* reductOp =
2155  createOp<Ordinal, Packet> (reductType);
2156  try {
2157  reduceAll(comm,serializer,*reductOp,count,sendBuffer,globalReducts);
2158  }
2159  catch (std::exception& e) {
2160  delete reductOp;
2161  throw e;
2162  }
2163  delete reductOp;
2164 }
2165 
2166 
2167 template<typename Ordinal, typename Packet>
2168 void Teuchos::scan(
2169  const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
2170  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2171  )
2172 {
2174  "Teuchos::CommHelpers: scan<"
2175  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2176  <<">( value type, user-defined op )"
2177  );
2178  ConstValueTypeSerializationBuffer<Ordinal,Packet>
2179  charSendBuffer(count,sendBuffer);
2180  ValueTypeSerializationBuffer<Ordinal,Packet>
2181  charScanReducts(count,scanReducts);
2182  CharToValueTypeReductionOp<Ordinal,Packet>
2183  charReductOp(rcp(&reductOp,false));
2184  comm.scan(
2185  charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2186  ,charScanReducts.getCharBuffer()
2187  );
2188 }
2189 
2190 
2191 template<typename Ordinal, typename Packet>
2192 void Teuchos::scan(
2193  const Comm<Ordinal>& comm, const EReductionType reductType,
2194  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2195  )
2196 {
2198  "Teuchos::CommHelpers: scan<"
2199  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2200  <<">( value type, "<<toString(reductType)<<" )"
2201  );
2202 
2203  ValueTypeReductionOp<Ordinal,Packet>* reductOp =
2204  createOp<Ordinal, Packet> (reductType);
2205  try {
2206  scan(comm,*reductOp,count,sendBuffer,scanReducts);
2207  }
2208  catch (std::exception& e) {
2209  delete reductOp;
2210  throw e;
2211  }
2212  delete reductOp;
2213 }
2214 
2215 
2216 template<typename Ordinal, typename Packet>
2217 void Teuchos::scan(
2218  const Comm<Ordinal>& comm, const EReductionType reductType,
2219  const Packet &send, const Ptr<Packet> &scanReduct
2220  )
2221 {
2222  scan<Ordinal,Packet>(comm, reductType, 1, &send, &*scanReduct);
2223 }
2224 
2225 
2226 template<typename Ordinal, typename Packet>
2227 void Teuchos::scan(
2228  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2229  const ReferenceTypeReductionOp<Ordinal,Packet> &reductOp,
2230  const Ordinal count, const Packet*const sendBuffer[], Packet*const scanReducts[]
2231  )
2232 {
2233  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2234 }
2235 
2236 template<typename Ordinal, typename Packet, typename Serializer>
2237 void Teuchos::scan(
2238  const Comm<Ordinal>& comm,
2239  const Serializer& serializer,
2240  const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
2241  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2242  )
2243 {
2245  "Teuchos::CommHelpers: scan<"
2246  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2247  <<">( value type, user-defined op )"
2248  );
2249  ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
2250  charSendBuffer(count,sendBuffer,rcp(&serializer,false));
2251  ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
2252  charScanReducts(count,scanReducts,rcp(&serializer,false));
2253  CharToValueTypeReductionOp<Ordinal,Packet,Serializer>
2254  charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
2255  comm.scan(
2256  charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2257  ,charScanReducts.getCharBuffer()
2258  );
2259 }
2260 
2261 
2262 template<typename Ordinal, typename Packet, typename Serializer>
2263 void Teuchos::scan(
2264  const Comm<Ordinal>& comm,
2265  const Serializer& serializer,
2266  const EReductionType reductType,
2267  const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2268  )
2269 {
2271  "Teuchos::CommHelpers: scan<"
2272  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2273  <<">( value type, "<<toString(reductType)<<" )"
2274  );
2275 
2276  ValueTypeReductionOp<Ordinal,Packet>* reductOp =
2277  createOp<Ordinal, Packet> (reductType);
2278  try {
2279  scan(comm,serializer,*reductOp,count,sendBuffer,scanReducts);
2280  }
2281  catch (std::exception& e) {
2282  delete reductOp;
2283  throw e;
2284  }
2285  delete reductOp;
2286 }
2287 
2288 template<typename Ordinal, typename Packet>
2289 void Teuchos::send(
2290  const Comm<Ordinal>& comm,
2291  const Ordinal count, const Packet sendBuffer[], const int destRank
2292  )
2293 {
2295  "Teuchos::CommHelpers: send<"
2296  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2297  <<">( value type )"
2298  );
2299  ConstValueTypeSerializationBuffer<Ordinal,Packet>
2300  charSendBuffer(count,sendBuffer);
2301  comm.send(
2302  charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2303  ,destRank
2304  );
2305 }
2306 
2307 template<typename Ordinal, typename Packet>
2308 void
2309 Teuchos::send (const Packet sendBuffer[],
2310  const Ordinal count,
2311  const int destRank,
2312  const int tag,
2313  const Comm<Ordinal>& comm)
2314 {
2316  "Teuchos::CommHelpers: send<"
2318  <<">( value type )"
2319  );
2320  ConstValueTypeSerializationBuffer<Ordinal,Packet> charSendBuffer (count, sendBuffer);
2321  comm.send (charSendBuffer.getBytes (), charSendBuffer.getCharBuffer (), destRank, tag);
2322 }
2323 
2324 template<typename Ordinal, typename Packet>
2325 void Teuchos::ssend(
2326  const Comm<Ordinal>& comm,
2327  const Ordinal count, const Packet sendBuffer[], const int destRank
2328  )
2329 {
2331  "Teuchos::CommHelpers: ssend<"
2332  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2333  <<">( value type )"
2334  );
2335  ConstValueTypeSerializationBuffer<Ordinal,Packet>
2336  charSendBuffer(count,sendBuffer);
2337  comm.ssend(
2338  charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2339  ,destRank
2340  );
2341 }
2342 
2343 template<typename Ordinal, typename Packet>
2344 void
2345 Teuchos::ssend (const Packet sendBuffer[],
2346  const Ordinal count,
2347  const int destRank,
2348  const int tag,
2349  const Comm<Ordinal>& comm)
2350 {
2352  "Teuchos::CommHelpers: ssend<"
2354  <<">( value type )"
2355  );
2357  buf_type charSendBuffer (count, sendBuffer);
2358  comm.ssend (charSendBuffer.getBytes (),
2359  charSendBuffer.getCharBuffer (),
2360  destRank, tag);
2361 }
2362 
2363 template<typename Ordinal, typename Packet>
2364 void Teuchos::send(
2365  const Comm<Ordinal>& comm,
2366  const Packet &send, const int destRank
2367  )
2368 {
2369  Teuchos::send<Ordinal,Packet>(comm,1,&send,destRank);
2370 }
2371 
2372 template<typename Ordinal, typename Packet>
2373 void Teuchos::ssend(
2374  const Comm<Ordinal>& comm,
2375  const Packet &send, const int destRank
2376  )
2377 {
2378  Teuchos::ssend<Ordinal,Packet>(comm,1,&send,destRank);
2379 }
2380 
2381 template<typename Ordinal, typename Packet>
2382 void Teuchos::send(
2383  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2384  const Ordinal count, const Packet*const sendBuffer[], const int destRank
2385  )
2386 {
2387  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2388 }
2389 
2390 template<typename Ordinal, typename Packet, typename Serializer>
2391 void Teuchos::send(
2392  const Comm<Ordinal>& comm,
2393  const Serializer& serializer,
2394  const Ordinal count, const Packet sendBuffer[], const int destRank
2395  )
2396 {
2398  "Teuchos::CommHelpers: send<"
2399  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2400  <<">( value type )"
2401  );
2402  ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
2403  charSendBuffer(count,sendBuffer,rcp(&serializer,false));
2404  comm.send(
2405  charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2406  ,destRank
2407  );
2408 }
2409 
2410 template<typename Ordinal, typename Packet>
2411 int Teuchos::receive(
2412  const Comm<Ordinal>& comm,
2413  const int sourceRank, const Ordinal count, Packet recvBuffer[]
2414  )
2415 {
2417  "Teuchos::CommHelpers: receive<"
2418  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2419  <<">( value type )"
2420  );
2421  ValueTypeSerializationBuffer<Ordinal,Packet>
2422  charRecvBuffer(count,recvBuffer);
2423  return comm.receive(
2424  sourceRank
2425  ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
2426  );
2427 }
2428 
2429 
2430 template<typename Ordinal, typename Packet>
2431 int Teuchos::receive(
2432  const Comm<Ordinal>& comm,
2433  const int sourceRank, Packet *recv
2434  )
2435 {
2436  return Teuchos::receive<Ordinal,Packet>(comm,sourceRank,1,recv);
2437 }
2438 
2439 
2440 template<typename Ordinal, typename Packet>
2441 int Teuchos::receive(
2442  const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2443  const int sourceRank, const Ordinal count, Packet*const recvBuffer[]
2444  )
2445 {
2446  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2447 }
2448 
2449 template<typename Ordinal, typename Packet, typename Serializer>
2450 int Teuchos::receive(
2451  const Comm<Ordinal>& comm,
2452  const Serializer& serializer,
2453  const int sourceRank, const Ordinal count, Packet recvBuffer[]
2454  )
2455 {
2457  "Teuchos::CommHelpers: receive<"
2458  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2459  <<">( value type )"
2460  );
2461  ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
2462  charRecvBuffer(count,recvBuffer,rcp(&serializer,false));
2463  return comm.receive(
2464  sourceRank
2465  ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
2466  );
2467 }
2468 
2469 template<typename Ordinal, typename Packet>
2470 void Teuchos::readySend(
2471  const Comm<Ordinal>& comm,
2472  const ArrayView<const Packet> &sendBuffer,
2473  const int destRank
2474  )
2475 {
2477  "Teuchos::CommHelpers: readySend<"
2478  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2479  <<">( value type )"
2480  );
2481  ConstValueTypeSerializationBuffer<Ordinal,Packet>
2482  charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr());
2483  comm.readySend( charSendBuffer.getCharBufferView(), destRank );
2484 }
2485 
2486 template<typename Ordinal, typename Packet>
2487 void
2488 Teuchos::readySend (const Packet sendBuffer[],
2489  const Ordinal count,
2490  const int destRank,
2491  const int tag,
2492  const Comm<Ordinal>& comm)
2493 {
2495  "Teuchos::CommHelpers: readySend<"
2497  <<">( value type )"
2498  );
2500  buf_type charSendBuffer (count, sendBuffer);
2501  comm.readySend (charSendBuffer.getBytes (),
2502  charSendBuffer.getCharBuffer (),
2503  destRank, tag);
2504 }
2505 
2506 template<typename Ordinal, typename Packet>
2507 void Teuchos::readySend(
2508  const Comm<Ordinal>& comm,
2509  const Packet &send,
2510  const int destRank
2511  )
2512 {
2513  readySend<Ordinal, Packet>( comm, arrayView(&send,1), destRank );
2514 }
2515 
2516 template<typename Ordinal, typename Packet, typename Serializer>
2517 void Teuchos::readySend(
2518  const Comm<Ordinal>& comm,
2519  const Serializer& serializer,
2520  const ArrayView<const Packet> &sendBuffer,
2521  const int destRank
2522  )
2523 {
2525  "Teuchos::CommHelpers: readySend<"
2526  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2527  <<">( value type )"
2528  );
2529  ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
2530  charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr(), serializer);
2531  comm.readySend( charSendBuffer.getCharBufferView(), destRank );
2532 }
2533 
2534 template<typename Ordinal, typename Packet>
2537  const Comm<Ordinal>& comm,
2538  const ArrayRCP<const Packet> &sendBuffer,
2539  const int destRank
2540  )
2541 {
2543  "Teuchos::CommHelpers: isend<"
2544  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2545  <<">( value type )"
2546  );
2547  ConstValueTypeSerializationBuffer<Ordinal,Packet>
2548  charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr());
2549  RCP<CommRequest<Ordinal> > commRequest = comm.isend(
2550  charSendBuffer.getCharBufferView(), destRank );
2551  set_extra_data( sendBuffer, "buffer", inOutArg(commRequest) );
2552  return commRequest;
2553 }
2554 
2555 template<typename Ordinal, typename Packet>
2557 Teuchos::isend (const ArrayRCP<const Packet> &sendBuffer,
2558  const int destRank,
2559  const int tag,
2560  const Comm<Ordinal>& comm)
2561 {
2563  "Teuchos::isend<" << OrdinalTraits<Ordinal>::name () << ","
2564  << TypeNameTraits<Packet>::name () << ">");
2565  ConstValueTypeSerializationBuffer<Ordinal,Packet>
2566  charSendBuffer (sendBuffer.size (), sendBuffer.getRawPtr ());
2567  RCP<CommRequest<Ordinal> > commRequest =
2568  comm.isend (charSendBuffer.getCharBufferView (), destRank, tag);
2569  set_extra_data (sendBuffer, "buffer", inOutArg (commRequest));
2570  return commRequest;
2571 }
2572 
2573 template<typename Ordinal, typename Packet>
2576  const Comm<Ordinal>& comm,
2577  const RCP<const Packet> &send,
2578  const int destRank
2579  )
2580 {
2581  const ArrayRCP<const Packet> sendBuffer =
2582  arcpWithEmbeddedObj( send.get(), 0, 1, send, false );
2583  // 2008/07/29: rabartl: Above: I need to write a helper function to create
2584  // new ArrayRCP object given a single object to copy.
2585  return isend<Ordinal, Packet>( comm, sendBuffer, destRank );
2586 }
2587 
2588 template<typename Ordinal, typename Packet, typename Serializer>
2591  const Comm<Ordinal>& comm,
2592  const Serializer& serializer,
2593  const ArrayRCP<const Packet> &sendBuffer,
2594  const int destRank
2595  )
2596 {
2598  "Teuchos::CommHelpers: isend<"
2599  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2600  <<">( value type )"
2601  );
2602  ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
2603  charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr(), serializer);
2604  RCP<CommRequest<Ordinal> > commRequest = comm.isend(
2605  charSendBuffer.getCharBufferView(), destRank );
2606  set_extra_data( sendBuffer, "buffer", inOutArg(commRequest) );
2607  return commRequest;
2608 }
2609 
2610 template<typename Ordinal, typename Packet>
2613  const Comm<Ordinal>& comm,
2614  const ArrayRCP<Packet> &recvBuffer,
2615  const int sourceRank
2616  )
2617 {
2619  "Teuchos::ireceive<int, " << "," << TypeNameTraits<Packet>::name () << ">");
2620  ValueTypeSerializationBuffer<Ordinal,Packet>
2621  charRecvBuffer(recvBuffer.size(), recvBuffer.getRawPtr());
2622  RCP<CommRequest<Ordinal> > commRequest = comm.ireceive(
2623  charRecvBuffer.getCharBufferView(), sourceRank );
2624  set_extra_data( recvBuffer, "buffer", inOutArg(commRequest) );
2625  return commRequest;
2626 }
2627 
2628 template<typename Ordinal, typename Packet>
2630 Teuchos::ireceive (const Teuchos::ArrayRCP<Packet> &recvBuffer,
2631  const int sourceRank,
2632  const int tag,
2633  const Teuchos::Comm<Ordinal>& comm)
2634 {
2636  "Teuchos::ireceive<int, " << "," << TypeNameTraits<Packet>::name () << ">");
2637  ValueTypeSerializationBuffer<int, Packet>
2638  charRecvBuffer (recvBuffer.size (), recvBuffer.getRawPtr ());
2639  RCP<CommRequest<int> > commRequest =
2640  comm.ireceive (charRecvBuffer.getCharBufferView (), sourceRank, tag);
2641  set_extra_data (recvBuffer, "buffer", inOutArg (commRequest));
2642  return commRequest;
2643 }
2644 
2645 template<typename Ordinal, typename Packet>
2648  const Comm<Ordinal>& comm,
2649  const RCP<Packet> &recv,
2650  const int sourceRank
2651  )
2652 {
2653  const ArrayRCP<Packet> recvBuffer =
2654  arcpWithEmbeddedObj( recv.get(), 0, 1, recv, false );
2655  // 2008/07/29: rabartl: Above: I need to write a helper function to create
2656  // new ArrayRCP object given a single object to copy.
2657  return ireceive<Ordinal, Packet>( comm, recvBuffer, sourceRank );
2658 }
2659 
2660 template<typename Ordinal, typename Packet, typename Serializer>
2663  const Comm<Ordinal>& comm,
2664  const Serializer& serializer,
2665  const ArrayRCP<Packet> &recvBuffer,
2666  const int sourceRank
2667  )
2668 {
2670  "Teuchos::CommHelpers: ireceive<"
2671  <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2672  <<">( value type )"
2673  );
2674  ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
2675  charRecvBuffer(recvBuffer.size(), recvBuffer.getRawPtr(), serializer);
2676  RCP<CommRequest<Ordinal> > commRequest = comm.ireceive(
2677  charRecvBuffer.getCharBufferView(), sourceRank );
2678  set_extra_data( recvBuffer, "buffer", inOutArg(commRequest) );
2679  return commRequest;
2680 }
2681 
2682 template<typename Ordinal>
2683 void Teuchos::waitAll(
2684  const Comm<Ordinal>& comm,
2685  const ArrayView<RCP<CommRequest<Ordinal> > > &requests
2686  )
2687 {
2688  comm.waitAll(requests);
2689 }
2690 
2691 
2692 template<typename Ordinal>
2693 void
2694 Teuchos::waitAll (const Comm<Ordinal>& comm,
2695  const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
2696  const ArrayView<RCP<CommStatus<Ordinal> > >& statuses)
2697 {
2698  comm.waitAll (requests, statuses);
2699 }
2700 
2701 
2702 template<typename Ordinal>
2704 Teuchos::wait (const Comm<Ordinal>& comm,
2705  const Ptr<RCP<CommRequest<Ordinal> > > &request)
2706 {
2707  return comm.wait (request);
2708 }
2709 
2710 
2711 #endif // TEUCHOS_COMM_HELPERS_HPP
void reduce< int, unsigned long >(const unsigned long sendBuf[], unsigned long recvBuf[], const int count, const EReductionType reductType, const int root, const Comm< int > &comm)
void reduce< int, long >(const long sendBuf[], long recvBuf[], const int count, const EReductionType reductType, const int root, const Comm< int > &comm)
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object...
Strategy interface for the indirect serializing and deserializing objects of a given type handled usi...
ArrayView< T > arrayView(T *p, typename ArrayView< T >::size_type size)
Construct a const or non-const view to const or non-const data.
RCP< Teuchos::CommRequest< int > > ireceive< int, unsigned long long >(const Comm< int > &comm, const ArrayRCP< unsigned long long > &recvBuffer, const int sourceRank)
void set_extra_data(const T1 &extra_data, const std::string &name, const Ptr< ArrayRCP< T2 > > &p, EPrePostDestruction destroy_when=POST_DESTROY, bool force_unique=true)
Set extra data associated with a ArrayRCP object.
Ptr< T > inOutArg(T &arg)
create a non-persisting (required or optional) input/output argument for a function call...
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
TEUCHOSCOMM_LIB_DLL_EXPORT RCP< CommRequest< int > > isend< int, unsigned long >(const ArrayRCP< const unsigned long > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
void send< int, float >(const Comm< int > &comm, const int count, const float sendBuffer[], const int destRank)
EReductionType
Predefined reduction operations that Teuchos::Comm understands.
TEUCHOSCOMM_LIB_DLL_EXPORT RCP< CommRequest< int > > isend< int, float >(const ArrayRCP< const float > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
RCP< Teuchos::CommRequest< int > > ireceive< int, float >(const Comm< int > &comm, const ArrayRCP< float > &recvBuffer, const int sourceRank)
static void max(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[])
TEUCHOSCOMM_LIB_DLL_EXPORT RCP< CommRequest< int > > isend< int, long long >(const ArrayRCP< const long long > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
void gatherv< int, short >(const short sendBuf[], const int sendCount, short recvBuf[], const int recvCounts[], const int displs[], const int root, const Comm< int > &comm)
void gather< int, unsigned long long >(const unsigned long long sendBuf[], const int sendCount, unsigned long long recvBuf[], const int recvCount, const int root, const Comm< int > &comm)
TEUCHOSCOMM_LIB_DLL_EXPORT RCP< CommRequest< int > > isend< int, short >(const ArrayRCP< const short > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
void reduceAll< int, long >(const Comm< int > &comm, const EReductionType reductType, const int count, const long sendBuffer[], long globalReducts[])
void send< int, unsigned long long >(const Comm< int > &comm, const int count, const unsigned long long sendBuffer[], const int destRank)
RCP< Teuchos::CommRequest< int > > ireceive< int, double >(const Comm< int > &comm, const ArrayRCP< double > &recvBuffer, const int sourceRank)
RCP< Teuchos::CommRequest< int > > ireceive< int, short >(const Comm< int > &comm, const ArrayRCP< short > &recvBuffer, const int sourceRank)
void send< int, long >(const Comm< int > &comm, const int count, const long sendBuffer[], const int destRank)
void gather< int, unsigned int >(const unsigned int sendBuf[], const int sendCount, unsigned int recvBuf[], const int recvCount, const int root, const Comm< int > &comm)
static void andOp(const Ordinal, const Packet[], Packet[])
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
void reduce< int, double >(const double sendBuf[], double recvBuf[], const int count, const EReductionType reductType, const int root, const Comm< int > &comm)
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
RawPointerConversionTraits< Container >::Ptr_t getRawPtr(const Container &c)
void gatherv< int, int >(const int sendBuf[], const int sendCount, int recvBuf[], const int recvCounts[], const int displs[], const int root, const Comm< int > &comm)
TEUCHOSCOMM_LIB_DLL_EXPORT RCP< CommRequest< int > > isend< int, double >(const ArrayRCP< const double > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
void gatherv< int, long long >(const long long sendBuf[], const int sendCount, long long recvBuf[], const int recvCounts[], const int displs[], const int root, const Comm< int > &comm)
void gather< int, long >(const long sendBuf[], const int sendCount, long recvBuf[], const int recvCount, const int root, const Comm< int > &comm)
RCP< Teuchos::CommRequest< int > > ireceive< int, long long >(const Comm< int > &comm, const ArrayRCP< long long > &recvBuffer, const int sourceRank)
void send< int, int >(const Comm< int > &comm, const int count, const int sendBuffer[], const int destRank)
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
TEUCHOSCOMM_LIB_DLL_EXPORT RCP< CommRequest< int > > isend< int, unsigned int >(const ArrayRCP< const unsigned int > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
void send< int, double >(const Comm< int > &comm, const int count, const double sendBuffer[], const int destRank)
void gather< int, int >(const int sendBuf[], const int sendCount, int recvBuf[], const int recvCount, const int root, const Comm< int > &comm)
size_type size() const
The total number of entries in the array.
void gather< int, long long >(const long long sendBuf[], const int sendCount, long long recvBuf[], const int recvCount, const int root, const Comm< int > &comm)
Standard logical AND operator for booleans.
#define TEUCHOS_COMM_TIME_MONITOR(FUNCNAME)
void reduceAll(const Comm< Ordinal > &comm, const ValueTypeReductionOp< Ordinal, Packet > &reductOp, const Ordinal count, const Packet sendBuffer[], Packet globalReducts[])
Wrapper for MPI_Allreduce that takes a custom reduction operator.
Standard min operator for types with value semantics.
This structure defines some basic traits for a scalar field type.
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.
std::string toString(const any &rhs)
Converts the value in any to a std::string.
Standard summation operator for types with value semantics.
void gatherv< int, unsigned long >(const unsigned long sendBuf[], const int sendCount, unsigned long recvBuf[], const int recvCounts[], const int displs[], const int root, const Comm< int > &comm)
static void andOp(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[])
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
void reduceAll< int, unsigned int >(const Comm< int > &comm, const EReductionType reductType, const int count, const unsigned int sendBuffer[], unsigned int globalReducts[])
void send< int, long long >(const Comm< int > &comm, const int count, const long long sendBuffer[], const int destRank)
void reduceAll< int, short >(const Comm< int > &comm, const EReductionType reductType, const int count, const short sendBuffer[], short globalReducts[])
void reduce< int, unsigned long long >(const unsigned long long sendBuf[], unsigned long long recvBuf[], const int count, const EReductionType reductType, const int root, const Comm< int > &comm)
static void min(const Ordinal, const Packet[], Packet[])
void reduce< int, int >(const int sendBuf[], int recvBuf[], const int count, const EReductionType reductType, const int root, const Comm< int > &comm)
virtual RCP< CommRequest< Ordinal > > ireceive(const ArrayView< char > &recvBuffer, const int sourceRank) const =0
Non-blocking receive.
void send(const Comm< Ordinal > &comm, const Ordinal count, const Packet sendBuffer[], const int destRank)
Send objects that use values semantics to another process.
TEUCHOSCOMM_LIB_DLL_EXPORT RCP< CommRequest< int > > isend< int, unsigned long long >(const ArrayRCP< const unsigned long long > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
void reduceAll< int, double >(const Comm< int > &comm, const EReductionType reductType, const int count, const double sendBuffer[], double globalReducts[])
TEUCHOSCOMM_LIB_DLL_EXPORT RCP< CommRequest< int > > isend< int, long >(const ArrayRCP< const long > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
void gatherv< int, unsigned long long >(const unsigned long long sendBuf[], const int sendCount, unsigned long long recvBuf[], const int recvCounts[], const int displs[], const int root, const Comm< int > &comm)
Standard Max operator for types with value semantics.
void gatherv< int, long >(const long sendBuf[], const int sendCount, long recvBuf[], const int recvCounts[], const int displs[], const int root, const Comm< int > &comm)
Implementation of Teuchos wrappers for MPI.
Declaration of Teuchos::EReductionType enum, and related functions.
This structure defines some basic traits for the ordinal field type.
Encapsulation of the result of a receive (blocking or nonblocking).
#define TEUCHOS_MAX(x, y)
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). ...
void reduceAll< int, int >(const Comm< int > &comm, const EReductionType reductType, const int count, const int sendBuffer[], int globalReducts[])
void reduceAll< int, unsigned long long >(const Comm< int > &comm, const EReductionType reductType, const int count, const unsigned long long sendBuffer[], unsigned long long globalReducts[])
void gatherv< int, unsigned int >(const unsigned int sendBuf[], const int sendCount, unsigned int recvBuf[], const int recvCounts[], const int displs[], const int root, const Comm< int > &comm)
virtual void readySend(const ArrayView< const char > &sendBuffer, const int destRank) const =0
Ready send of data from this process to another process.
RCP< Teuchos::CommRequest< int > > ireceive< int, unsigned int >(const Comm< int > &comm, const ArrayRCP< unsigned int > &recvBuffer, const int sourceRank)
TEUCHOSCOMM_LIB_DLL_EXPORT RCP< CommRequest< int > > isend< int, int >(const ArrayRCP< const int > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
void reduceAll< int, unsigned long >(const Comm< int > &comm, const EReductionType reductType, const int count, const unsigned long sendBuffer[], unsigned long globalReducts[])
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).
RCP< Teuchos::CommRequest< int > > ireceive< int, int >(const Comm< int > &comm, const ArrayRCP< int > &recvBuffer, const int sourceRank)
Templated array class derived from the STL std::vector.
RCP< Teuchos::CommRequest< int > > ireceive< int, unsigned long >(const Comm< int > &comm, const ArrayRCP< unsigned long > &recvBuffer, const int sourceRank)
Nonowning array view.
Defines basic traits for the ordinal field type.
Default traits class that just returns typeid(T).name().
RCP< Teuchos::CommRequest< int > > isend(const ArrayRCP< const double > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
void reduceAll< int, float >(const Comm< int > &comm, const EReductionType reductType, const int count, const float sendBuffer[], float globalReducts[])
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 send(const Ordinal bytes, const char sendBuffer[], const int destRank) const =0
Possibly blocking send of data from this process to another 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.
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.
#define TEUCHOSCOMM_LIB_DLL_EXPORT
TEUCHOSCOMM_LIB_DLL_EXPORT void scatter(const int sendBuf[], const int sendCount, int recvBuf[], const int recvCount, const int root, const Comm< int > &comm)
ArrayRCP< T > arcpWithEmbeddedObj(T *p, typename ArrayRCP< T >::size_type lowerOffset, typename ArrayRCP< T >::size_type size, const Embedded &embedded, bool owns_mem=true)
Create an ArrayRCP with and also put in an embedded object.
static void max(const Ordinal, const Packet[], Packet[])
Smart reference counting pointer class for automatic garbage collection.
RCP< Teuchos::CommRequest< int > > ireceive< int, long >(const Comm< int > &comm, const ArrayRCP< long > &recvBuffer, const int sourceRank)
Encapsulation of a pending nonblocking communication operation.
void gather< int, short >(const short sendBuf[], const int sendCount, short recvBuf[], const int recvCount, const int root, const Comm< int > &comm)
#define TEUCHOS_MIN(x, y)
void send< int, short >(const Comm< int > &comm, const int count, const short sendBuffer[], const int destRank)
Defines basic traits returning the name of a type in a portable and readable way. ...
Definition of Teuchos::as, for conversions between types.
ValueTypeReductionOp< Ordinal, Packet > * createOp(const EReductionType reductType)
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...
void scan(const Comm< Ordinal > &comm, const ValueTypeReductionOp< Ordinal, Packet > &reductOp, const Ordinal count, const Packet sendBuffer[], Packet scanReducts[])
Scan/Reduce array of objects that use value semantics using a user-defined reduction operator...
void gather< int, unsigned long >(const unsigned long sendBuf[], const int sendCount, unsigned long recvBuf[], const int recvCount, const int root, const Comm< int > &comm)
void reduceAll< int, long long >(const Comm< int > &comm, const EReductionType reductType, const int count, const long long sendBuffer[], long long globalReducts[])
Encapsulate how an array of const objects with value sematics is serialized into a const char[] array...
void send< int, unsigned long >(const Comm< int > &comm, const int count, const unsigned long sendBuffer[], const int destRank)
static void min(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[])
Reference-counted smart pointer for managing arrays.
void send< int, unsigned int >(const Comm< int > &comm, const int count, const unsigned int sendBuffer[], const int destRank)