Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_CommHelpers.hpp
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"
14#include "Teuchos_CommUtilities.hpp"
15#include "Teuchos_CompilerCodeTweakMacros.hpp"
16#include "Teuchos_SerializationTraitsHelpers.hpp"
17#include "Teuchos_ReductionOpHelpers.hpp"
18#include "Teuchos_SerializerHelpers.hpp"
21#include "Teuchos_Array.hpp"
23#include "Teuchos_Workspace.hpp"
24#include "Teuchos_as.hpp"
25
26#ifdef HAVE_TEUCHOS_MPI
28#endif // HAVE_TEUCHOS_MPI
29#include "Teuchos_DefaultSerialComm.hpp"
31
32namespace Teuchos {
33
34//
35// Teuchos::Comm Helper Functions
36//
37
38#ifdef HAVE_TEUCHOS_MPI
39namespace Details {
40
47std::string getMpiErrorString (const int errCode);
48
49} // namespace Details
50#endif // HAVE_TEUCHOS_MPI
51
56template<typename Ordinal>
57int rank(const Comm<Ordinal>& comm);
58
63template<typename Ordinal>
64int size(const Comm<Ordinal>& comm);
65
70template<typename Ordinal>
71void barrier(const Comm<Ordinal>& comm);
72
77template<typename Ordinal, typename Packet>
79 const Comm<Ordinal>& comm,
80 const int rootRank,
81 const Ordinal count, Packet buffer[]
82 );
83
88template<typename Ordinal, typename Packet>
90 const Comm<Ordinal>& comm,
91 const int rootRank,
92 const ArrayView<Packet> &buffer
93 );
94
99template<typename Ordinal, typename Packet>
101 const Comm<Ordinal>& comm,
102 const int rootRank, Packet *object
103 );
104
109template<typename Ordinal, typename Packet>
111 const Comm<Ordinal>& comm,
112 const int rootRank, const Ptr<Packet> &object
113 );
114
119template<typename Ordinal, typename Packet>
121 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
122 const int rootRank, const Ordinal count, Packet*const buffer[]
123 );
124
129template<typename Ordinal, typename Packet>
131 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
132 const int rootRank, const ArrayView<const Ptr<Packet> > &buffer
133 );
134
139template<typename Ordinal, typename Packet>
140void
141alltoAll (const Packet sendBuf[],
142 const Ordinal sendCount,
143 Packet recvBuf[],
144 const Ordinal recvCount,
145 const Comm<Ordinal>& comm)
146{
148 (true, std::logic_error, "Teuchos::alltoAll<" <<
150 << ">: Generic version is not yet implemented.");
151}
152
157template<typename Ordinal, typename Packet>
158void
159alltoAllv (const Packet sendBuf[],
160 const Ordinal sendCounts[],
161 const Ordinal sendDispls[],
162 Packet recvBuf[],
163 const Ordinal recvCounts[],
164 const Ordinal recvDispls[],
165 const Comm<Ordinal>& comm)
166{
168 (true, std::logic_error, "Teuchos::alltoAllv<" <<
170 << ">: Generic version is not yet implemented.");
171}
172
178template<typename Ordinal, typename Packet, typename Serializer>
180 const Comm<Ordinal>& comm,
181 const Serializer& serializer,
182 const int rootRank,
183 const Ordinal count, Packet buffer[]
184 );
185
190template<typename Ordinal, typename Packet>
191void
192gather (const Packet sendBuf[],
193 const Ordinal sendCount,
194 Packet recvBuf[],
195 const Ordinal recvCount,
196 const int root,
197 const Comm<Ordinal>& comm);
198
203template<typename Ordinal, typename Packet>
204void
205gatherv (const Packet sendBuf[],
206 const Ordinal sendCount,
207 Packet recvBuf[],
208 const Ordinal recvCounts[],
209 const Ordinal displs[],
210 const int root,
211 const Comm<Ordinal>& comm);
212
218template<typename Ordinal, typename Packet>
220 const Comm<Ordinal>& comm,
221 const Ordinal sendCount, const Packet sendBuffer[],
222 const Ordinal recvCount, Packet recvBuffer[]
223 );
224
230template<typename Ordinal, typename Packet>
232 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
233 const Ordinal sendCount, const Packet*const sendBuffer[],
234 const Ordinal recvCount, Packet*const recvBuffer[]
235 );
236
242template<typename Ordinal, typename Packet, typename Serializer>
244 const Comm<Ordinal>& comm,
245 const Serializer& serializer,
246 const Ordinal sendCount, const Packet sendBuffer[],
247 const Ordinal recvCount, Packet recvBuffer[]
248 );
249
276template<typename Ordinal, typename Packet>
277void
278scatter (const Packet sendBuf[],
279 const Ordinal sendCount,
280 Packet recvBuf[],
281 const Ordinal recvCount,
282 const Ordinal root,
283 const Comm<Ordinal>& comm)
284{
285 // See Bug 6375; Tpetra does not actually need any specializations
286 // other than Ordinal = int and Packet = int. We may add them later
287 // if there is interest.
289 (true, std::logic_error, "Teuchos::scatter<" <<
291 << ">: Generic version is not yet implemented. This function currently "
292 "only has an implementtion for Ordinal = int and Packet = int. "
293 "See Bug 6375 and Bug 6336.");
294}
295
296template<typename Ordinal, typename Packet>
297void
298scatterv (const Packet sendBuf[],
299 const Ordinal sendCounts[],
300 const Ordinal displs[],
301 Packet recvBuf[],
302 const Ordinal recvCount,
303 const Ordinal root,
304 const Comm<Ordinal>& comm)
305{
306 // See Bug 6375; Tpetra does not actually need any specializations
307 // other than Ordinal = int and Packet = int. We may add them later
308 // if there is interest.
310 (true, std::logic_error, "Teuchos::scatterv<" <<
312 << ">: Generic version is not yet implemented. This function currently "
313 "only has an implementtion for Ordinal = int and Packet = int. "
314 "See Bug 6375 and Bug 6336.");
315}
316
344template<typename Ordinal, typename Packet>
345void
346reduce (const Packet sendBuf[],
347 Packet recvBuf[],
348 const Ordinal count,
349 const EReductionType reductType,
350 const Ordinal root,
351 const Comm<Ordinal>& comm);
352
375template<typename Ordinal, typename Packet>
377 const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
378 const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
379 );
380
386template<typename Ordinal, typename Packet>
388 const Comm<Ordinal>& comm, const EReductionType reductType,
389 const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
390 );
391
397template<typename Ordinal, typename Packet>
399 const Comm<Ordinal>& comm, const EReductionType reductType,
400 const Packet &send, const Ptr<Packet> &globalReduct
401 );
402
408template<typename Ordinal, typename Packet>
410 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
412 const Ordinal count, const Packet*const sendBuffer[], Packet*const globalReducts[]
413 );
414
420template<typename Ordinal, typename Packet, typename Serializer>
422 const Comm<Ordinal>& comm,
423 const Serializer& serializer,
425 const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
426 );
427
433template<typename Ordinal, typename Packet, typename Serializer>
435 const Comm<Ordinal>& comm,
436 const Serializer& serializer,
437 const EReductionType reductType,
438 const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
439 );
440
446template<typename Ordinal, typename Packet>
447void scan(
448 const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
449 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
450 );
451
457template<typename Ordinal, typename Packet>
458void scan(
459 const Comm<Ordinal>& comm, const EReductionType reductType,
460 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
461 );
462
468template<typename Ordinal, typename Packet>
469void scan(
470 const Comm<Ordinal>& comm, const EReductionType reductType,
471 const Packet &send, const Ptr<Packet> &scanReduct
472 );
473
479template<typename Ordinal, typename Packet>
480void scan(
481 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
483 const Ordinal count, const Packet*const sendBuffer[], Packet*const scanReducts[]
484 );
485
491template<typename Ordinal, typename Packet, typename Serializer>
492void scan(
493 const Comm<Ordinal>& comm,
494 const Serializer& serializer,
496 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
497 );
498
504template<typename Ordinal, typename Packet, typename Serializer>
505void scan(
506 const Comm<Ordinal>& comm,
507 const Serializer& serializer,
508 const EReductionType reductType,
509 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
510 );
511
516template<typename Ordinal, typename Packet>
517void send(
518 const Comm<Ordinal>& comm,
519 const Ordinal count, const Packet sendBuffer[], const int destRank
520 );
521
523template<typename Ordinal, typename Packet>
524void
525send (const Packet sendBuffer[],
526 const Ordinal count,
527 const int destRank,
528 const int tag,
529 const Comm<Ordinal>& comm);
530
535template<typename Ordinal, typename Packet>
536void ssend(
537 const Comm<Ordinal>& comm,
538 const Ordinal count, const Packet sendBuffer[], const int destRank
539 );
540
542template<typename Ordinal, typename Packet>
543void
544ssend (const Packet sendBuffer[],
545 const Ordinal count,
546 const int destRank,
547 const int tag,
548 const Comm<Ordinal>& comm);
549
554template<typename Ordinal, typename Packet>
555void send(
556 const Comm<Ordinal>& comm,
557 const Packet &send, const int destRank
558 );
559
564template<typename Ordinal, typename Packet>
565void ssend(
566 const Comm<Ordinal>& comm,
567 const Packet &send, const int destRank
568 );
569
576template<typename Ordinal, typename Packet>
577void send(
578 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
579 const Ordinal count, const Packet*const sendBuffer[], const int destRank
580 );
581
587template<typename Ordinal, typename Packet, typename Serializer>
588void send(
589 const Comm<Ordinal>& comm,
590 const Serializer& serializer,
591 const Ordinal count, const Packet sendBuffer[], const int destRank
592 );
593
598template<typename Ordinal, typename Packet>
600 const Comm<Ordinal>& comm,
601 const int sourceRank, const Ordinal count, Packet recvBuffer[]
602 );
603
608template<typename Ordinal, typename Packet>
610 const Comm<Ordinal>& comm,
611 const int sourceRank, Packet *recv
612 );
613
618template<typename Ordinal, typename Packet>
620 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
621 const int sourceRank, const Ordinal count, Packet*const recvBuffer[]
622 );
623
629template<typename Ordinal, typename Packet, typename Serializer>
631 const Comm<Ordinal>& comm,
632 const Serializer& serializer,
633 const int sourceRank, const Ordinal count, Packet recvBuffer[]
634 );
635
641template<typename Ordinal, typename Packet>
643 const Comm<Ordinal>& comm,
644 const ArrayView<const Packet> &sendBuffer,
645 const int destRank
646 );
647
649template<typename Ordinal, typename Packet>
650void
651readySend (const Packet sendBuffer[],
652 const Ordinal count,
653 const int destRank,
654 const int tag,
655 const Comm<Ordinal>& comm);
656
661template<typename Ordinal, typename Packet>
663 const Comm<Ordinal>& comm,
664 const Packet &send,
665 const int destRank
666 );
667
673template<typename Ordinal, typename Packet, typename Serializer>
675 const Comm<Ordinal>& comm,
676 const Serializer& serializer,
677 const ArrayView<const Packet> &sendBuffer,
678 const int destRank
679 );
680
685template<typename Ordinal, typename Packet>
687 const Comm<Ordinal>& comm,
688 const ArrayRCP<const Packet> &sendBuffer,
689 const int destRank
690 );
691
693template<typename Ordinal, typename Packet>
695isend (const ArrayRCP<const Packet>& sendBuffer,
696 const int destRank,
697 const int tag,
698 const Comm<Ordinal>& comm);
699
704template<typename Ordinal, typename Packet>
706 const Comm<Ordinal>& comm,
707 const RCP<const Packet> &send,
708 const int destRank
709 );
710
716template<typename Ordinal, typename Packet, typename Serializer>
718 const Comm<Ordinal>& comm,
719 const Serializer& serializer,
720 const ArrayRCP<const Packet> &sendBuffer,
721 const int destRank
722 );
723
724
725// 2008/07/29: rabartl: ToDo: Add reference semantics version of isend!
726
727
737template<typename Ordinal, typename Packet>
739 const Comm<Ordinal>& comm,
740 const ArrayRCP<Packet> &recvBuffer,
741 const int sourceRank
742 );
743
745template<typename Ordinal, typename Packet>
747ireceive (const ArrayRCP<Packet> &recvBuffer,
748 const int sourceRank,
749 const int tag,
750 const Comm<Ordinal>& comm);
751
763template<typename Ordinal, typename Packet>
765 const Comm<Ordinal>& comm,
766 const RCP<Packet> &recv,
767 const int sourceRank
768 );
769
775template<typename Ordinal, typename Packet, typename Serializer>
777 const Comm<Ordinal>& comm,
778 const Serializer& serializer,
779 const ArrayRCP<Packet> &recvBuffer,
780 const int sourceRank
781 );
782
783
784// 2008/07/29: rabartl: ToDo: Add reference semantics version of ireceive!
785
786
794template<typename Ordinal>
796 const Comm<Ordinal>& comm,
797 const ArrayView<RCP<CommRequest<Ordinal> > > &requests
798 );
799
829template<typename Ordinal>
830void
832 const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
833 const ArrayView<RCP<CommStatus<Ordinal> > >& statuses);
834
858template<typename Ordinal>
860wait (const Comm<Ordinal>& comm, const Ptr<RCP<CommRequest<Ordinal> > >& request);
861
862//
863// Standard reduction subclasses for objects that use value semantics
864//
865
866
871template<typename Ordinal, typename Packet>
872class SumValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
873{
874public:
876 void reduce(
877 const Ordinal count,
878 const Packet inBuffer[],
879 Packet inoutBuffer[]
880 ) const;
881};
882
883
892template<typename Ordinal, typename Packet>
893class MinValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
894{
895public:
897 void reduce(
898 const Ordinal count,
899 const Packet inBuffer[],
900 Packet inoutBuffer[]
901 ) const;
902};
903
904
913template<typename Ordinal, typename Packet>
914class MaxValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
915{
916public:
918 void reduce(
919 const Ordinal count,
920 const Packet inBuffer[],
921 Packet inoutBuffer[]
922 ) const;
923};
924
925
930template<typename Ordinal, typename Packet>
931class ANDValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
932{
933public:
935 void reduce(
936 const Ordinal count,
937 const Packet inBuffer[],
938 Packet inoutBuffer[]
939 ) const;
940};
941
942
943// ////////////////////////////////////////////////////////////
944// Implementation details (not for geneal users to mess with)
945
946
947//
948// ReductionOp Utilities
949//
950
951
952namespace MixMaxUtilities {
953
954
955template<bool isComparable, typename Ordinal, typename Packet>
956class Min {};
957
958
959template<typename Ordinal, typename Packet>
960class Min<true,Ordinal,Packet> {
961public:
962 static void min(
963 const Ordinal count,
964 const Packet inBuffer[],
965 Packet inoutBuffer[]
966 )
967 {
968 for( int i = 0; i < count; ++i )
969 inoutBuffer[i] = TEUCHOS_MIN(inoutBuffer[i],inBuffer[i]);
970 }
971};
972
973
974template<typename Ordinal, typename Packet>
975class Min<false,Ordinal,Packet> {
976public:
977 static void min(
978 const Ordinal,
979 const Packet[],
980 Packet[]
981 )
982 {
984 true,std::logic_error,
985 "Error, the type "<<TypeNameTraits<Packet>::name()
986 <<" does not support comparison operations!"
987 );
988 }
989};
990
991
992template<bool isComparable, typename Ordinal, typename Packet>
993class Max {};
994
995
996template<typename Ordinal, typename Packet>
997class Max<true,Ordinal,Packet> {
998public:
999 static void max(
1000 const Ordinal count,
1001 const Packet inBuffer[],
1002 Packet inoutBuffer[]
1003 )
1004 {
1005 for( int i = 0; i < count; ++i )
1006 inoutBuffer[i] = TEUCHOS_MAX(inoutBuffer[i],inBuffer[i]);
1007 }
1008};
1009
1010
1011template<typename Ordinal, typename Packet>
1012class Max<false,Ordinal,Packet> {
1013public:
1014 static void max(
1015 const Ordinal,
1016 const Packet[],
1017 Packet[]
1018 )
1019 {
1021 true,std::logic_error,
1022 "Error, the type "<<TypeNameTraits<Packet>::name()
1023 <<" does not support comparison operations!"
1024 );
1025 }
1026};
1027
1028
1029template<bool isComparable, typename Ordinal, typename Packet>
1030class AND {};
1031
1032
1033template<typename Ordinal, typename Packet>
1034class AND<true,Ordinal,Packet> {
1035public:
1036 static void andOp(
1037 const Ordinal count,
1038 const Packet inBuffer[],
1039 Packet inoutBuffer[]
1040 )
1041 {
1042 for( int i = 0; i < count; ++i )
1043 inoutBuffer[i] = inoutBuffer[i] && inBuffer[i];
1044 }
1045};
1046
1047
1048template<typename Ordinal, typename Packet>
1049class AND<false,Ordinal,Packet> {
1050public:
1051 static void andOp(
1052 const Ordinal,
1053 const Packet[],
1054 Packet[]
1055 )
1056 {
1058 true,std::logic_error,
1059 "Error, the type "<<TypeNameTraits<Packet>::name()
1060 <<" does not support logical AND operations!"
1061 );
1062 }
1063};
1064
1065
1066} // namespace MixMaxUtilities
1067
1068
1069template<typename Ordinal, typename Packet>
1071 const Ordinal count,
1072 const Packet inBuffer[],
1073 Packet inoutBuffer[]
1074 ) const
1075{
1076 for( int i = 0; i < count; ++i )
1077 inoutBuffer[i] += inBuffer[i];
1078}
1079
1080
1081template<typename Ordinal, typename Packet>
1083 const Ordinal count,
1084 const Packet inBuffer[],
1085 Packet inoutBuffer[]
1086 ) const
1087{
1088 typedef MixMaxUtilities::Min<ScalarTraits<Packet>::isComparable, Ordinal, Packet> min_type;
1089 min_type::min (count, inBuffer, inoutBuffer);
1090}
1091
1092
1093template<typename Ordinal, typename Packet>
1095 const Ordinal count,
1096 const Packet inBuffer[],
1097 Packet inoutBuffer[]
1098 ) const
1099{
1100 typedef MixMaxUtilities::Max<ScalarTraits<Packet>::isComparable, Ordinal, Packet> max_type;
1101 max_type::max (count,inBuffer,inoutBuffer);
1102}
1103
1104
1105template<typename Ordinal, typename Packet>
1107 const Ordinal count,
1108 const Packet inBuffer[],
1109 Packet inoutBuffer[]
1110 ) const
1111{
1112 typedef MixMaxUtilities::AND<ScalarTraits<Packet>::isComparable, Ordinal, Packet> and_type;
1113 and_type::andOp (count, inBuffer, inoutBuffer);
1114}
1115
1116
1117} // namespace Teuchos
1118
1119
1120// //////////////////////////
1121// Template implemenations
1122
1123
1124//
1125// ReductionOp utilities
1126//
1127
1128
1129namespace Teuchos {
1130
1131
1132// Not for the general user to use! I am returning a raw ReductionOp* pointer
1133// to avoid the overhead of using RCP. However, given the use case
1134// this is just fine since I can just use std::auto_ptr to make sure things
1135// are deleted correctly.
1136//
1137// NOTE (mfh 08 Feb 2015) std::auto_ptr has been deprecated in C++11.
1138// I could either replace it with std::unique_ptr, or just call 'new'
1139// and 'delete' manually. The former is less error prone, but
1140// requires checking a macro for whether C++11 is actually enabled.
1141// Thus, I've chosen (for now) to rewrite all the code that uses
1142// std::auto_ptr, so that it allocates and deletes manually.
1143template<typename Ordinal, typename Packet>
1144ValueTypeReductionOp<Ordinal,Packet>*
1145createOp (const EReductionType reductType)
1146{
1147 typedef ScalarTraits<Packet> ST;
1148 switch (reductType) {
1149 case REDUCE_SUM: {
1150 return new SumValueReductionOp<Ordinal,Packet> ();
1151 }
1152 case REDUCE_MIN: {
1153 if (ST::isComparable) {
1155 }
1156 else {
1158 (! ST::isComparable, std::invalid_argument, "Teuchos::createOp"
1159 "(EReductionType): The Packet type " << TypeNameTraits<Packet>::name ()
1160 << " is not less-than comparable, so it does not make sense to do a "
1161 "MIN reduction with it.");
1163 }
1164 }
1165 case REDUCE_MAX: {
1166 if (ST::isComparable) {
1168 }
1169 else {
1171 (! ST::isComparable, std::invalid_argument, "Teuchos::createOp"
1172 "(EReductionType): The Packet type " << TypeNameTraits<Packet>::name ()
1173 << " is not less-than comparable, so it does not make sense to do a "
1174 "MAX reduction with it.");
1176 }
1177 }
1178 case REDUCE_AND: {
1180 }
1181 default:
1183 true, std::invalid_argument, "Teuchos::createOp(EReductionType): "
1184 "Invalid EReductionType value " << reductType << ". Valid values "
1185 "include REDUCE_SUM, REDUCE_MIN, REDUCE_MAX, and REDUCE_AND.");
1186 }
1187}
1188
1189
1190} // namespace Teuchos
1191
1192
1193//
1194// Teuchos::Comm wrapper functions
1195//
1196
1197
1198template<typename Ordinal>
1200{
1201 return comm.getRank();
1202}
1203
1204
1205template<typename Ordinal>
1206int Teuchos::size(const Comm<Ordinal>& comm)
1207{
1208 return comm.getSize();
1209}
1210
1211
1212template<typename Ordinal>
1214{
1215 TEUCHOS_COMM_TIME_MONITOR(
1216 "Teuchos::CommHelpers: barrier<"
1218 <<">()"
1219 );
1220 comm.barrier();
1221}
1222
1223
1224template<typename Ordinal, typename Packet>
1226 const Comm<Ordinal>& comm,
1227 const int rootRank, const Ordinal count, Packet buffer[]
1228 )
1229{
1230 TEUCHOS_COMM_TIME_MONITOR(
1231 "Teuchos::CommHelpers: broadcast<"
1233 <<">( value type )"
1234 );
1236 charBuffer(count,buffer);
1237 comm.broadcast(
1238 rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1239 );
1240}
1241
1242
1243template<typename Ordinal, typename Packet>
1245 const Comm<Ordinal>& comm,
1246 const int rootRank,
1247 const ArrayView<Packet> &buffer
1248 )
1249{
1250 broadcast<Ordinal, Packet>(comm, rootRank, buffer.size(), buffer.getRawPtr() );
1251}
1252
1253
1254template<typename Ordinal, typename Packet>
1256 const Comm<Ordinal>& comm,
1257 const int rootRank, Packet *object
1258 )
1259{
1260 broadcast<Ordinal,Packet>(comm,rootRank,1,object);
1261}
1262
1263
1264template<typename Ordinal, typename Packet>
1266 const Comm<Ordinal>& comm,
1267 const int rootRank, const Ptr<Packet> &object
1268 )
1269{
1270 broadcast<Ordinal,Packet>(comm,rootRank,1,object.getRawPtr());
1271}
1272
1273
1274template<typename Ordinal, typename Packet>
1276 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
1277 const int rootRank, const Ordinal count, Packet*const buffer[]
1278 )
1279{
1280 TEUCHOS_COMM_TIME_MONITOR(
1281 "Teuchos::CommHelpers: broadcast<"
1283 <<">( reference type )"
1284 );
1286 charBuffer(serializer, count, buffer);
1287 comm.broadcast(
1288 rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1289 );
1290}
1291
1292
1293template<typename Ordinal, typename Packet>
1295 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
1296 const int rootRank, const ArrayView<const Ptr<Packet> > &buffer
1297 )
1298{
1299 Array<Packet*> bufferPtrArray;
1300 for (int i = 0; i < buffer.size(); ++i) {
1301 bufferPtrArray.push_back(buffer[i].getRawPtr());
1302 }
1303 broadcast<Ordinal,Packet>(comm, serializer, rootRank,
1304 buffer.size(), bufferPtrArray.getRawPtr());
1305}
1306
1307template<typename Ordinal, typename Packet, typename Serializer>
1309 const Comm<Ordinal>& comm,
1310 const Serializer& serializer,
1311 const int rootRank, const Ordinal count, Packet buffer[]
1312 )
1313{
1314 TEUCHOS_COMM_TIME_MONITOR(
1315 "Teuchos::CommHelpers: broadcast<"
1317 <<">( value type )"
1318 );
1320 charBuffer(count,buffer,rcp(&serializer,false));
1321 comm.broadcast(
1322 rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1323 );
1324}
1325
1326
1327template<typename Ordinal, typename Packet>
1329 const Comm<Ordinal>& comm,
1330 const Ordinal sendCount, const Packet sendBuffer[],
1331 const Ordinal recvCount, Packet recvBuffer[]
1332 )
1333{
1334 TEUCHOS_COMM_TIME_MONITOR(
1335 "Teuchos::CommHelpers: gatherAll<"
1337 <<">( value type )"
1338 );
1340 charSendBuffer(sendCount,sendBuffer);
1342 charRecvBuffer(recvCount,recvBuffer);
1343 comm.gatherAll(
1344 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1345 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
1346 );
1347}
1348
1349template<typename Ordinal, typename Packet>
1350void
1351Teuchos::gather (const Packet sendBuf[],
1352 const Ordinal sendCount,
1353 Packet recvBuf[],
1354 const Ordinal recvCount,
1355 const int root,
1356 const Comm<Ordinal>& comm)
1357{
1358 TEUCHOS_COMM_TIME_MONITOR(
1359 "Teuchos::CommHelpers: gather<"
1361 <<">( value type )"
1362 );
1364 charSendBuffer (sendCount, sendBuf);
1366 charRecvBuffer (recvCount, recvBuf);
1367 comm.gather (charSendBuffer.getBytes (),
1368 charSendBuffer.getCharBuffer (),
1369 charRecvBuffer.getBytes (),
1370 charRecvBuffer.getCharBuffer (),
1371 root);
1372}
1373
1374template<typename Ordinal, typename Packet>
1375void
1376Teuchos::gatherv (const Packet sendBuf[],
1377 const Ordinal sendCount,
1378 Packet recvBuf[],
1379 const Ordinal recvCounts[],
1380 const Ordinal displs[],
1381 const int root,
1382 const Comm<Ordinal>& comm)
1383{
1384 // Ordinal totalRecvCount = 0;
1385
1386 // // In order to get the right output buffer length, we have to sum
1387 // // the receive counts from all the processes in the communicator.
1388 // const Ordinal numProcs = as<Ordinal> (comm->getSize ());
1389 // for (Ordinal k = 0; k < as<Ordinal> (numProcs); ++k) {
1390 // totalRecvCount += recvCounts[k];
1391 // }
1392
1393 // // FIXME (mfh 16 Apr 2013) We also have to redo the displacements.
1394
1395 // ConstValueTypeSerializationBuffer<Ordinal,Packet>
1396 // charSendBuffer (sendCount, sendBuf);
1397 // ValueTypeSerializationBuffer<Ordinal,Packet>
1398 // charRecvBuffer (totalRecvCount, recvBuf);
1399 // comm.gatherv (charSendBuffer.getBytes (),
1400 // charSendBuffer.getCharBuffer (),
1401 // charRecvBuffer.getBytes (),
1402 // charRecvBuffer.getCharBuffer (),
1403 // root);
1404 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
1405 "Teuchos::gatherv: The general case is not implemented.");
1406}
1407
1408template<typename Ordinal, typename Packet>
1410 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
1411 const Ordinal sendCount, const Packet*const sendBuffer[],
1412 const Ordinal recvCount, Packet*const recvBuffer[]
1413 )
1414{
1415 TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
1416}
1417
1418template<typename Ordinal, typename Packet, typename Serializer>
1420 const Comm<Ordinal>& comm,
1421 const Serializer& serializer,
1422 const Ordinal sendCount, const Packet sendBuffer[],
1423 const Ordinal recvCount, Packet recvBuffer[]
1424 )
1425{
1426 TEUCHOS_COMM_TIME_MONITOR(
1427 "Teuchos::CommHelpers: gatherAll<"
1429 <<">( value type )"
1430 );
1432 charSendBuffer(sendCount,sendBuffer,rcp(&serializer,false));
1434 charRecvBuffer(recvCount,recvBuffer,rcp(&serializer,false));
1435 comm.gatherAll(
1436 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1437 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
1438 );
1439}
1440
1441
1442template<typename Ordinal, typename Packet>
1443void
1444Teuchos::reduce (const Packet sendBuf[],
1445 Packet recvBuf[],
1446 const Ordinal count,
1447 const EReductionType reductType,
1448 const Ordinal root,
1449 const Comm<Ordinal>& comm)
1450{
1451 // See Bug 6375; Tpetra does not actually need any specializations
1452 // other than Ordinal = int and Packet = int. We may add them later
1453 // if there is interest.
1455 (true, std::logic_error, "Teuchos::reduce<" <<
1457 << ">: Generic version not implemented. We only implement this function "
1458 "for Ordinal = int and Packet = specific types.");
1459}
1460
1461
1462template<typename Ordinal, typename Packet>
1464 const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp
1465 ,const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
1466 )
1467{
1468 TEUCHOS_COMM_TIME_MONITOR(
1469 "Teuchos::CommHelpers: reduceAll<"
1471 <<">( value type, user-defined op )"
1472 );
1474 charSendBuffer(count,sendBuffer);
1476 charGlobalReducts(count,globalReducts);
1478 charReductOp(rcp(&reductOp,false));
1479 comm.reduceAll(
1480 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1481 ,charGlobalReducts.getCharBuffer()
1482 );
1483}
1484
1485
1486template<typename Ordinal, typename Packet>
1488 const Comm<Ordinal>& comm, const EReductionType reductType,
1489 const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
1490 )
1491{
1492 TEUCHOS_COMM_TIME_MONITOR(
1493 "Teuchos::CommHelpers: reduceAll<"
1495 <<">( value type, "<<toString(reductType)<<" )"
1496 );
1497
1499 createOp<Ordinal, Packet> (reductType);
1500 try {
1501 reduceAll(comm,*reductOp,count,sendBuffer,globalReducts);
1502 }
1503 catch (std::exception& e) {
1504 delete reductOp;
1505 throw e;
1506 }
1507 delete reductOp;
1508}
1509
1510
1511namespace Teuchos {
1512
1513// amb 11 Nov 2014. I am disabling these specializations for
1514// now. MPI_C_DOUBLE_COMPLEX is causing a problem in some builds. This code was
1515// effectively turned on only yesterday (10 Nov 2014) when TEUCHOS_HAVE_COMPLEX
1516// was corrected to be HAVE_TEUCHOS_COMPLEX, so evidently there are no users of
1517// these specializations.
1518#if 0
1519#ifdef HAVE_TEUCHOS_COMPLEX
1520// Specialization for Ordinal=int and Packet=std::complex<double>.
1521template<>
1522TEUCHOSCOMM_LIB_DLL_EXPORT void
1524 const EReductionType reductType,
1525 const int count,
1526 const std::complex<double> sendBuffer[],
1527 std::complex<double> globalReducts[]);
1528template<>
1529TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1531 const ArrayRCP<std::complex<double> >& recvBuffer,
1532 const int sourceRank);
1533template<>
1534TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1536 const int sourceRank,
1537 const int tag,
1538 const Comm<int>& comm);
1539template<>
1540TEUCHOSCOMM_LIB_DLL_EXPORT void
1542 const int count,
1543 const std::complex<double> sendBuffer[],
1544 const int destRank);
1545template<>
1546TEUCHOSCOMM_LIB_DLL_EXPORT void
1547send<int, std::complex<double> > (const std::complex<double> sendBuffer[],
1548 const int count,
1549 const int destRank,
1550 const int tag,
1551 const Comm<int>& comm);
1552template<>
1553TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1554isend<int, std::complex<double> > (const ArrayRCP<const std::complex<double> >& sendBuffer,
1555 const int destRank,
1556 const int tag,
1557 const Comm<int>& comm);
1558
1559// Specialization for Ordinal=int and Packet=std::complex<float>.
1560template<>
1561TEUCHOSCOMM_LIB_DLL_EXPORT void
1563 const EReductionType reductType,
1564 const int count,
1565 const std::complex<float> sendBuffer[],
1566 std::complex<float> globalReducts[]);
1567template<>
1568TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1570 const ArrayRCP<std::complex<float> >& recvBuffer,
1571 const int sourceRank);
1572template<>
1573TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1575 const int sourceRank,
1576 const int tag,
1577 const Comm<int>& comm);
1578template<>
1579TEUCHOSCOMM_LIB_DLL_EXPORT void
1581 const int count,
1582 const std::complex<float> sendBuffer[],
1583 const int destRank);
1584template<>
1585TEUCHOSCOMM_LIB_DLL_EXPORT void
1586send<int, std::complex<float> > (const std::complex<float> sendBuffer[],
1587 const int count,
1588 const int destRank,
1589 const int tag,
1590 const Comm<int>& comm);
1591template<>
1592TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1593isend<int, std::complex<float> > (const ArrayRCP<const std::complex<float> >& sendBuffer,
1594 const int destRank,
1595 const int tag,
1596 const Comm<int>& comm);
1597#endif // HAVE_TEUCHOS_COMPLEX
1598#endif // if 0
1599
1600// Specialization for Ordinal=int and Packet=double.
1601template<>
1602TEUCHOSCOMM_LIB_DLL_EXPORT void
1603alltoAllv<int, double> (const double sendBuf[],
1604 const int sendCounts[],
1605 const int sendDispls[],
1606 double recvBuf[],
1607 const int recvCounts[],
1608 const int recvDispls[],
1609 const Comm<int>& comm);
1610
1611template<>
1612TEUCHOSCOMM_LIB_DLL_EXPORT void
1614 const EReductionType reductType,
1615 const int count,
1616 const double sendBuffer[],
1617 double globalReducts[]);
1618template<>
1619TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1620ireceive<int, double> (const Comm<int>& comm,
1621 const ArrayRCP<double>& recvBuffer,
1622 const int sourceRank);
1623template<>
1624TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1625ireceive<int, double> (const ArrayRCP<double> &recvBuffer,
1626 const int sourceRank,
1627 const int tag,
1628 const Comm<int>& comm);
1629template<>
1630TEUCHOSCOMM_LIB_DLL_EXPORT void
1631send<int, double> (const Comm<int>& comm,
1632 const int count,
1633 const double sendBuffer[],
1634 const int destRank);
1635template<>
1636TEUCHOSCOMM_LIB_DLL_EXPORT void
1637send<int, double> (const double sendBuffer[],
1638 const int count,
1639 const int destRank,
1640 const int tag,
1641 const Comm<int>& comm);
1642template<>
1643TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1644isend<int, double> (const ArrayRCP<const double>& sendBuffer,
1645 const int destRank,
1646 const int tag,
1647 const Comm<int>& comm);
1648
1649template<>
1650TEUCHOSCOMM_LIB_DLL_EXPORT void
1651gatherv<int, double> (const double sendBuf[],
1652 const int sendCount,
1653 double recvBuf[],
1654 const int recvCounts[],
1655 const int displs[],
1656 const int root,
1657 const Comm<int>& comm);
1658
1659// Specialization for Ordinal=int and Packet=float.
1660template<>
1661TEUCHOSCOMM_LIB_DLL_EXPORT void
1662reduceAll<int, float> (const Comm<int>& comm,
1663 const EReductionType reductType,
1664 const int count,
1665 const float sendBuffer[],
1666 float globalReducts[]);
1667template<>
1668TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1669ireceive<int, float> (const Comm<int>& comm,
1670 const ArrayRCP<float>& recvBuffer,
1671 const int sourceRank);
1672template<>
1673TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1674ireceive<int, float> (const ArrayRCP<float> &recvBuffer,
1675 const int sourceRank,
1676 const int tag,
1677 const Comm<int>& comm);
1678template<>
1679TEUCHOSCOMM_LIB_DLL_EXPORT void
1680send<int, float> (const Comm<int>& comm,
1681 const int count,
1682 const float sendBuffer[],
1683 const int destRank);
1684template<>
1685TEUCHOSCOMM_LIB_DLL_EXPORT void
1686send<int, float> (const float sendBuffer[],
1687 const int count,
1688 const int destRank,
1689 const int tag,
1690 const Comm<int>& comm);
1691template<>
1692TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1693isend<int, float> (const ArrayRCP<const float>& sendBuffer,
1694 const int destRank,
1695 const int tag,
1696 const Comm<int>& comm);
1697
1698template<>
1699TEUCHOSCOMM_LIB_DLL_EXPORT void
1700gatherv<int, float> (const float sendBuf[],
1701 const int sendCount,
1702 float recvBuf[],
1703 const int recvCounts[],
1704 const int displs[],
1705 const int root,
1706 const Comm<int>& comm);
1707
1708// Specialization for Ordinal=int and Packet=long long.
1709template<>
1710TEUCHOSCOMM_LIB_DLL_EXPORT void
1711gather<int, long long> (const long long sendBuf[],
1712 const int sendCount,
1713 long long recvBuf[],
1714 const int recvCount,
1715 const int root,
1716 const Comm<int>& comm);
1717template<>
1718TEUCHOSCOMM_LIB_DLL_EXPORT void
1719gatherv<int, long long> (const long long sendBuf[],
1720 const int sendCount,
1721 long long recvBuf[],
1722 const int recvCounts[],
1723 const int displs[],
1724 const int root,
1725 const Comm<int>& comm);
1726template<>
1727TEUCHOSCOMM_LIB_DLL_EXPORT void
1729 const EReductionType reductType,
1730 const int count,
1731 const long long sendBuffer[],
1732 long long globalReducts[]);
1733template<>
1734TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1736 const ArrayRCP<long long>& recvBuffer,
1737 const int sourceRank);
1738template<>
1739TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1741 const int sourceRank,
1742 const int tag,
1743 const Comm<int>& comm);
1744template<>
1745TEUCHOSCOMM_LIB_DLL_EXPORT void
1746send<int, long long> (const Comm<int>& comm,
1747 const int count,
1748 const long long sendBuffer[],
1749 const int destRank);
1750template<>
1751TEUCHOSCOMM_LIB_DLL_EXPORT void
1752send<int, long long> (const long long sendBuffer[],
1753 const int count,
1754 const int destRank,
1755 const int tag,
1756 const Comm<int>& comm);
1757template<>
1758TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1759isend<int, long long> (const ArrayRCP<const long long>& sendBuffer,
1760 const int destRank,
1761 const int tag,
1762 const Comm<int>& comm);
1763
1764// Specialization for Ordinal=int and Packet=unsigned long long.
1765template<>
1766TEUCHOSCOMM_LIB_DLL_EXPORT void
1767gather<int, unsigned long long> (const unsigned long long sendBuf[],
1768 const int sendCount,
1769 unsigned long long recvBuf[],
1770 const int recvCount,
1771 const int root,
1772 const Comm<int>& comm);
1773template<>
1774TEUCHOSCOMM_LIB_DLL_EXPORT void
1775gatherv<int, unsigned long long> (const unsigned long long sendBuf[],
1776 const int sendCount,
1777 unsigned long long recvBuf[],
1778 const int recvCounts[],
1779 const int displs[],
1780 const int root,
1781 const Comm<int>& comm);
1782template<>
1783TEUCHOSCOMM_LIB_DLL_EXPORT void
1785 const EReductionType reductType,
1786 const int count,
1787 const unsigned long long sendBuffer[],
1788 unsigned long long globalReducts[]);
1789template<>
1790TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1792 const ArrayRCP<unsigned long long>& recvBuffer,
1793 const int sourceRank);
1794template<>
1795TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1797 const int sourceRank,
1798 const int tag,
1799 const Comm<int>& comm);
1800template<>
1801TEUCHOSCOMM_LIB_DLL_EXPORT void
1803 const int count,
1804 const unsigned long long sendBuffer[],
1805 const int destRank);
1806template<>
1807TEUCHOSCOMM_LIB_DLL_EXPORT void
1808send<int, unsigned long long> (const unsigned long long sendBuffer[],
1809 const int count,
1810 const int destRank,
1811 const int tag,
1812 const Comm<int>& comm);
1813template<>
1814TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1815isend<int, unsigned long long> (const ArrayRCP<const unsigned long long>& sendBuffer,
1816 const int destRank,
1817 const int tag,
1818 const Comm<int>& comm);
1819
1820// Specialization for Ordinal=int and Packet=long.
1821template<>
1822TEUCHOSCOMM_LIB_DLL_EXPORT void
1823gather<int, long> (const long sendBuf[],
1824 const int sendCount,
1825 long recvBuf[],
1826 const int recvCount,
1827 const int root,
1828 const Comm<int>& comm);
1829template<>
1830TEUCHOSCOMM_LIB_DLL_EXPORT void
1831gatherv<int, long> (const long sendBuf[],
1832 const int sendCount,
1833 long recvBuf[],
1834 const int recvCounts[],
1835 const int displs[],
1836 const int root,
1837 const Comm<int>& comm);
1838template<>
1839TEUCHOSCOMM_LIB_DLL_EXPORT void
1840reduceAll<int, long> (const Comm<int>& comm,
1841 const EReductionType reductType,
1842 const int count,
1843 const long sendBuffer[],
1844 long globalReducts[]);
1845template<>
1846TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1847ireceive<int, long> (const Comm<int>& comm,
1848 const ArrayRCP<long>& recvBuffer,
1849 const int sourceRank);
1850template<>
1851TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1852ireceive<int, long> (const ArrayRCP<long> &recvBuffer,
1853 const int sourceRank,
1854 const int tag,
1855 const Comm<int>& comm);
1856template<>
1857TEUCHOSCOMM_LIB_DLL_EXPORT void
1858send<int, long> (const Comm<int>& comm,
1859 const int count,
1860 const long sendBuffer[],
1861 const int destRank);
1862template<>
1863TEUCHOSCOMM_LIB_DLL_EXPORT void
1864send<int, long> (const long sendBuffer[],
1865 const int count,
1866 const int destRank,
1867 const int tag,
1868 const Comm<int>& comm);
1869template<>
1870TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1871isend<int, long> (const ArrayRCP<const long>& sendBuffer,
1872 const int destRank,
1873 const int tag,
1874 const Comm<int>& comm);
1875
1876// Specialization for Ordinal=int and Packet=unsigned long.
1877template<>
1878TEUCHOSCOMM_LIB_DLL_EXPORT void
1879gather<int, unsigned long> (const unsigned long sendBuf[],
1880 const int sendCount,
1881 unsigned long recvBuf[],
1882 const int recvCount,
1883 const int root,
1884 const Comm<int>& comm);
1885template<>
1886TEUCHOSCOMM_LIB_DLL_EXPORT void
1887gatherv<int, unsigned long> (const unsigned long sendBuf[],
1888 const int sendCount,
1889 unsigned long recvBuf[],
1890 const int recvCounts[],
1891 const int displs[],
1892 const int root,
1893 const Comm<int>& comm);
1894template<>
1895TEUCHOSCOMM_LIB_DLL_EXPORT void
1897 const EReductionType reductType,
1898 const int count,
1899 const unsigned long sendBuffer[],
1900 unsigned long globalReducts[]);
1901template<>
1902TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1904 const ArrayRCP<unsigned long>& recvBuffer,
1905 const int sourceRank);
1906template<>
1907TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1909 const int sourceRank,
1910 const int tag,
1911 const Comm<int>& comm);
1912template<>
1913TEUCHOSCOMM_LIB_DLL_EXPORT void
1915 const int count,
1916 const unsigned long sendBuffer[],
1917 const int destRank);
1918template<>
1919TEUCHOSCOMM_LIB_DLL_EXPORT void
1920send<int, unsigned long> (const unsigned long sendBuffer[],
1921 const int count,
1922 const int destRank,
1923 const int tag,
1924 const Comm<int>& comm);
1925template<>
1926TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1927isend<int, unsigned long> (const ArrayRCP<const unsigned long>& sendBuffer,
1928 const int destRank,
1929 const int tag,
1930 const Comm<int>& comm);
1931
1932// Specialization for Ordinal=int and Packet=int.
1933template<>
1934TEUCHOSCOMM_LIB_DLL_EXPORT void
1935alltoAll<int, int> (const int sendBuf[],
1936 const int sendCount,
1937 int recvBuf[],
1938 const int recvCount,
1939 const Comm<int>& comm);
1940
1941template<>
1942TEUCHOSCOMM_LIB_DLL_EXPORT void
1943alltoAllv<int, int> (const int sendBuf[],
1944 const int sendCounts[],
1945 const int sendDispls[],
1946 int recvBuf[],
1947 const int recvCounts[],
1948 const int recvDispls[],
1949 const Comm<int>& comm);
1950
1951template<>
1952TEUCHOSCOMM_LIB_DLL_EXPORT void
1953gather<int, int> (const int sendBuf[],
1954 const int sendCount,
1955 int recvBuf[],
1956 const int recvCount,
1957 const int root,
1958 const Comm<int>& comm);
1959template<>
1960TEUCHOSCOMM_LIB_DLL_EXPORT void
1961gatherv<int, int> (const int sendBuf[],
1962 const int sendCount,
1963 int recvBuf[],
1964 const int recvCounts[],
1965 const int displs[],
1966 const int root,
1967 const Comm<int>& comm);
1968template<>
1969TEUCHOSCOMM_LIB_DLL_EXPORT void
1970scatter (const int sendBuf[],
1971 const int sendCount,
1972 int recvBuf[],
1973 const int recvCount,
1974 const int root,
1975 const Comm<int>& comm);
1976template<>
1977TEUCHOSCOMM_LIB_DLL_EXPORT void
1978scatterv (const int sendBuf[],
1979 const int sendCounts[],
1980 const int displs[],
1981 int recvBuf[],
1982 const int recvCount,
1983 const int root,
1984 const Comm<int>& comm);
1985template<>
1986TEUCHOSCOMM_LIB_DLL_EXPORT void
1987scatterv (const double sendBuf[],
1988 const int sendCounts[],
1989 const int displs[],
1990 double recvBuf[],
1991 const int recvCount,
1992 const int root,
1993 const Comm<int>& comm);
1994template<>
1995TEUCHOSCOMM_LIB_DLL_EXPORT void
1996scatterv (const float sendBuf[],
1997 const int sendCounts[],
1998 const int displs[],
1999 float recvBuf[],
2000 const int recvCount,
2001 const int root,
2002 const Comm<int>& comm);
2003template<>
2004TEUCHOSCOMM_LIB_DLL_EXPORT void
2005reduce<int, int> (const int sendBuf[],
2006 int recvBuf[],
2007 const int count,
2008 const EReductionType reductType,
2009 const int root,
2010 const Comm<int>& comm);
2011template<>
2012TEUCHOSCOMM_LIB_DLL_EXPORT void
2013reduce<int, long> (const long sendBuf[],
2014 long recvBuf[],
2015 const int count,
2016 const EReductionType reductType,
2017 const int root,
2018 const Comm<int>& comm);
2019template<>
2020TEUCHOSCOMM_LIB_DLL_EXPORT void
2021reduce<int, unsigned long> (const unsigned long sendBuf[],
2022 unsigned long recvBuf[],
2023 const int count,
2024 const EReductionType reductType,
2025 const int root,
2026 const Comm<int>& comm);
2027template<>
2028TEUCHOSCOMM_LIB_DLL_EXPORT void
2029reduce<int, unsigned long long > (const unsigned long long sendBuf[],
2030 unsigned long long recvBuf[],
2031 const int count,
2032 const EReductionType reductType,
2033 const int root,
2034 const Comm<int>& comm);
2035template<>
2036TEUCHOSCOMM_LIB_DLL_EXPORT void
2037reduce<int, double> (const double sendBuf[],
2038 double recvBuf[],
2039 const int count,
2040 const EReductionType reductType,
2041 const int root,
2042 const Comm<int>& comm);
2043template<>
2044TEUCHOSCOMM_LIB_DLL_EXPORT void
2045reduceAll<int, int> (const Comm<int>& comm,
2046 const EReductionType reductType,
2047 const int count,
2048 const int sendBuffer[],
2049 int globalReducts[]);
2050
2051template<>
2052TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2053ireceive<int, int> (const Comm<int>& comm,
2054 const ArrayRCP<int>& recvBuffer,
2055 const int sourceRank);
2056template<>
2057TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2058ireceive<int, int> (const ArrayRCP<int> &recvBuffer,
2059 const int sourceRank,
2060 const int tag,
2061 const Comm<int>& comm);
2062template<>
2063TEUCHOSCOMM_LIB_DLL_EXPORT void
2064send<int, int> (const Comm<int>& comm,
2065 const int count,
2066 const int sendBuffer[],
2067 const int destRank);
2068template<>
2069TEUCHOSCOMM_LIB_DLL_EXPORT void
2070send<int, int> (const int sendBuffer[],
2071 const int count,
2072 const int destRank,
2073 const int tag,
2074 const Comm<int>& comm);
2075template<>
2076TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2077isend<int, int> (const ArrayRCP<const int>& sendBuffer,
2078 const int destRank,
2079 const int tag,
2080 const Comm<int>& comm);
2081
2082// Specialization for Ordinal=int and Packet=unsigned int.
2083template<>
2084TEUCHOSCOMM_LIB_DLL_EXPORT void
2085gather<int, unsigned int> (const unsigned int sendBuf[],
2086 const int sendCount,
2087 unsigned int recvBuf[],
2088 const int recvCount,
2089 const int root,
2090 const Comm<int>& comm);
2091template<>
2092TEUCHOSCOMM_LIB_DLL_EXPORT void
2093gatherv<int, unsigned int> (const unsigned int sendBuf[],
2094 const int sendCount,
2095 unsigned int recvBuf[],
2096 const int recvCounts[],
2097 const int displs[],
2098 const int root,
2099 const Comm<int>& comm);
2100template<>
2101TEUCHOSCOMM_LIB_DLL_EXPORT void
2103 const EReductionType reductType,
2104 const int count,
2105 const unsigned int sendBuffer[],
2106 unsigned int globalReducts[]);
2107template<>
2108TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2110 const ArrayRCP<unsigned int>& recvBuffer,
2111 const int sourceRank);
2112template<>
2113TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2115 const int sourceRank,
2116 const int tag,
2117 const Comm<int>& comm);
2118template<>
2119TEUCHOSCOMM_LIB_DLL_EXPORT void
2121 const int count,
2122 const unsigned int sendBuffer[],
2123 const int destRank);
2124template<>
2125TEUCHOSCOMM_LIB_DLL_EXPORT void
2126send<int, unsigned int> (const unsigned int sendBuffer[],
2127 const int count,
2128 const int destRank,
2129 const int tag,
2130 const Comm<int>& comm);
2131template<>
2132TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2133isend<int, unsigned int> (const ArrayRCP<const unsigned int>& sendBuffer,
2134 const int destRank,
2135 const int tag,
2136 const Comm<int>& comm);
2137
2138// Specialization for Ordinal=int and Packet=short.
2139template<>
2140TEUCHOSCOMM_LIB_DLL_EXPORT void
2141gather<int, short> (const short sendBuf[],
2142 const int sendCount,
2143 short recvBuf[],
2144 const int recvCount,
2145 const int root,
2146 const Comm<int>& comm);
2147template<>
2148TEUCHOSCOMM_LIB_DLL_EXPORT void
2149gatherv<int, short> (const short sendBuf[],
2150 const int sendCount,
2151 short recvBuf[],
2152 const int recvCounts[],
2153 const int displs[],
2154 const int root,
2155 const Comm<int>& comm);
2156template<>
2157TEUCHOSCOMM_LIB_DLL_EXPORT void
2158reduceAll<int, short> (const Comm<int>& comm,
2159 const EReductionType reductType,
2160 const int count,
2161 const short sendBuffer[],
2162 short globalReducts[]);
2163template<>
2164TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2165ireceive<int, short> (const Comm<int>& comm,
2166 const ArrayRCP<short>& recvBuffer,
2167 const int sourceRank);
2168template<>
2169TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2170ireceive<int, short> (const ArrayRCP<short> &recvBuffer,
2171 const int sourceRank,
2172 const int tag,
2173 const Comm<int>& comm);
2174template<>
2175TEUCHOSCOMM_LIB_DLL_EXPORT void
2176send<int, short> (const Comm<int>& comm,
2177 const int count,
2178 const short sendBuffer[],
2179 const int destRank);
2180template<>
2181TEUCHOSCOMM_LIB_DLL_EXPORT void
2182send<int, short> (const short sendBuffer[],
2183 const int count,
2184 const int destRank,
2185 const int tag,
2186 const Comm<int>& comm);
2187template<>
2188TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2189isend<int, short> (const ArrayRCP<const short>& sendBuffer,
2190 const int destRank,
2191 const int tag,
2192 const Comm<int>& comm);
2193
2194// mfh 18 Oct 2012: The specialization for Packet=char seems to be
2195// causing problems such as the following:
2196//
2197// http://testing.sandia.gov/cdash/testDetails.php?test=9909246&build=747699
2198//
2199// I am disabling it for now. This should revert back to the old
2200// behavior for Packet=char. That should fix the Tpetra errors, since
2201// many Tpetra objects inherit from DistObject<char, ...>.
2202#if 0
2203// Specialization for Ordinal=int and Packet=char.
2204template<>
2205TEUCHOSCOMM_LIB_DLL_EXPORT void
2206reduceAll<int, char> (const Comm<int>& comm,
2207 const EReductionType reductType,
2208 const int count,
2209 const char sendBuffer[],
2210 char globalReducts[]);
2211#endif // 0
2212} // namespace Teuchos
2213
2214
2215template<typename Ordinal, typename Packet>
2217 const Comm<Ordinal>& comm, const EReductionType reductType
2218 ,const Packet &send, const Ptr<Packet> &globalReduct
2219 )
2220{
2221 // mfh 17 Oct 2012: This will invoke the above specializations for
2222 // general count, so we don't need to specialize this function.
2223 reduceAll<Ordinal,Packet>(comm, reductType, 1, &send, &*globalReduct);
2224}
2225
2226
2227template<typename Ordinal, typename Packet>
2229 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2231 const Ordinal count, const Packet*const sendBuffer[], Packet*const globalReducts[]
2232 )
2233{
2234 TEUCHOS_COMM_TIME_MONITOR(
2235 "Teuchos::CommHelpers: reduceAll<"
2237 <<">( reference type )"
2238 );
2240 charSendBuffer(serializer,count,sendBuffer);
2242 charGlobalReducts(serializer,count,globalReducts);
2244 charReductOp(rcp(&serializer,false),rcp(&reductOp,false));
2245 comm.reduceAll(
2246 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2247 ,charGlobalReducts.getCharBuffer()
2248 );
2249}
2250
2251template<typename Ordinal, typename Packet, typename Serializer>
2253 const Comm<Ordinal>& comm,
2254 const Serializer& serializer,
2256 const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
2257 )
2258{
2259 TEUCHOS_COMM_TIME_MONITOR(
2260 "Teuchos::CommHelpers: reduceAll<"
2262 <<">( value type, user-defined op )"
2263 );
2265 charSendBuffer(count,sendBuffer,rcp(&serializer,false));
2267 charGlobalReducts(count,globalReducts,rcp(&serializer,false));
2269 charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
2270 comm.reduceAll(
2271 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2272 ,charGlobalReducts.getCharBuffer()
2273 );
2274}
2275
2276
2277template<typename Ordinal, typename Packet, typename Serializer>
2279 const Comm<Ordinal>& comm,
2280 const Serializer& serializer,
2281 const EReductionType reductType,
2282 const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
2283 )
2284{
2285 TEUCHOS_COMM_TIME_MONITOR(
2286 "Teuchos::CommHelpers: reduceAll<"
2288 <<">( value type, "<<toString(reductType)<<" )"
2289 );
2290
2292 createOp<Ordinal, Packet> (reductType);
2293 try {
2294 reduceAll(comm,serializer,*reductOp,count,sendBuffer,globalReducts);
2295 }
2296 catch (std::exception& e) {
2297 delete reductOp;
2298 throw e;
2299 }
2300 delete reductOp;
2301}
2302
2303
2304template<typename Ordinal, typename Packet>
2306 const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
2307 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2308 )
2309{
2310 TEUCHOS_COMM_TIME_MONITOR(
2311 "Teuchos::CommHelpers: scan<"
2313 <<">( value type, user-defined op )"
2314 );
2316 charSendBuffer(count,sendBuffer);
2318 charScanReducts(count,scanReducts);
2320 charReductOp(rcp(&reductOp,false));
2321 comm.scan(
2322 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2323 ,charScanReducts.getCharBuffer()
2324 );
2325}
2326
2327
2328template<typename Ordinal, typename Packet>
2330 const Comm<Ordinal>& comm, const EReductionType reductType,
2331 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2332 )
2333{
2334 TEUCHOS_COMM_TIME_MONITOR(
2335 "Teuchos::CommHelpers: scan<"
2337 <<">( value type, "<<toString(reductType)<<" )"
2338 );
2339
2341 createOp<Ordinal, Packet> (reductType);
2342 try {
2343 scan(comm,*reductOp,count,sendBuffer,scanReducts);
2344 }
2345 catch (std::exception& e) {
2346 delete reductOp;
2347 throw e;
2348 }
2349 delete reductOp;
2350}
2351
2352
2353template<typename Ordinal, typename Packet>
2355 const Comm<Ordinal>& comm, const EReductionType reductType,
2356 const Packet &send, const Ptr<Packet> &scanReduct
2357 )
2358{
2359 scan<Ordinal,Packet>(comm, reductType, 1, &send, &*scanReduct);
2360}
2361
2362
2363template<typename Ordinal, typename Packet>
2365 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2367 const Ordinal count, const Packet*const sendBuffer[], Packet*const scanReducts[]
2368 )
2369{
2370 TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2371}
2372
2373template<typename Ordinal, typename Packet, typename Serializer>
2375 const Comm<Ordinal>& comm,
2376 const Serializer& serializer,
2378 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2379 )
2380{
2381 TEUCHOS_COMM_TIME_MONITOR(
2382 "Teuchos::CommHelpers: scan<"
2384 <<">( value type, user-defined op )"
2385 );
2387 charSendBuffer(count,sendBuffer,rcp(&serializer,false));
2389 charScanReducts(count,scanReducts,rcp(&serializer,false));
2391 charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
2392 comm.scan(
2393 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2394 ,charScanReducts.getCharBuffer()
2395 );
2396}
2397
2398
2399template<typename Ordinal, typename Packet, typename Serializer>
2401 const Comm<Ordinal>& comm,
2402 const Serializer& serializer,
2403 const EReductionType reductType,
2404 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2405 )
2406{
2407 TEUCHOS_COMM_TIME_MONITOR(
2408 "Teuchos::CommHelpers: scan<"
2410 <<">( value type, "<<toString(reductType)<<" )"
2411 );
2412
2414 createOp<Ordinal, Packet> (reductType);
2415 try {
2416 scan(comm,serializer,*reductOp,count,sendBuffer,scanReducts);
2417 }
2418 catch (std::exception& e) {
2419 delete reductOp;
2420 throw e;
2421 }
2422 delete reductOp;
2423}
2424
2425template<typename Ordinal, typename Packet>
2427 const Comm<Ordinal>& comm,
2428 const Ordinal count, const Packet sendBuffer[], const int destRank
2429 )
2430{
2431 TEUCHOS_COMM_TIME_MONITOR(
2432 "Teuchos::CommHelpers: send<"
2434 <<">( value type )"
2435 );
2437 charSendBuffer(count,sendBuffer);
2438 comm.send(
2439 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2440 ,destRank
2441 );
2442}
2443
2444template<typename Ordinal, typename Packet>
2445void
2446Teuchos::send (const Packet sendBuffer[],
2447 const Ordinal count,
2448 const int destRank,
2449 const int tag,
2450 const Comm<Ordinal>& comm)
2451{
2452 TEUCHOS_COMM_TIME_MONITOR(
2453 "Teuchos::CommHelpers: send<"
2455 <<">( value type )"
2456 );
2457 ConstValueTypeSerializationBuffer<Ordinal,Packet> charSendBuffer (count, sendBuffer);
2458 comm.send (charSendBuffer.getBytes (), charSendBuffer.getCharBuffer (), destRank, tag);
2459}
2460
2461template<typename Ordinal, typename Packet>
2463 const Comm<Ordinal>& comm,
2464 const Ordinal count, const Packet sendBuffer[], const int destRank
2465 )
2466{
2467 TEUCHOS_COMM_TIME_MONITOR(
2468 "Teuchos::CommHelpers: ssend<"
2470 <<">( value type )"
2471 );
2473 charSendBuffer(count,sendBuffer);
2474 comm.ssend(
2475 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2476 ,destRank
2477 );
2478}
2479
2480template<typename Ordinal, typename Packet>
2481void
2482Teuchos::ssend (const Packet sendBuffer[],
2483 const Ordinal count,
2484 const int destRank,
2485 const int tag,
2486 const Comm<Ordinal>& comm)
2487{
2488 TEUCHOS_COMM_TIME_MONITOR(
2489 "Teuchos::CommHelpers: ssend<"
2491 <<">( value type )"
2492 );
2494 buf_type charSendBuffer (count, sendBuffer);
2495 comm.ssend (charSendBuffer.getBytes (),
2496 charSendBuffer.getCharBuffer (),
2497 destRank, tag);
2498}
2499
2500template<typename Ordinal, typename Packet>
2502 const Comm<Ordinal>& comm,
2503 const Packet &send, const int destRank
2504 )
2505{
2506 Teuchos::send<Ordinal,Packet>(comm,1,&send,destRank);
2507}
2508
2509template<typename Ordinal, typename Packet>
2511 const Comm<Ordinal>& comm,
2512 const Packet &send, const int destRank
2513 )
2514{
2515 Teuchos::ssend<Ordinal,Packet>(comm,1,&send,destRank);
2516}
2517
2518template<typename Ordinal, typename Packet>
2520 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2521 const Ordinal count, const Packet*const sendBuffer[], const int destRank
2522 )
2523{
2524 TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2525}
2526
2527template<typename Ordinal, typename Packet, typename Serializer>
2529 const Comm<Ordinal>& comm,
2530 const Serializer& serializer,
2531 const Ordinal count, const Packet sendBuffer[], const int destRank
2532 )
2533{
2534 TEUCHOS_COMM_TIME_MONITOR(
2535 "Teuchos::CommHelpers: send<"
2537 <<">( value type )"
2538 );
2540 charSendBuffer(count,sendBuffer,rcp(&serializer,false));
2541 comm.send(
2542 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2543 ,destRank
2544 );
2545}
2546
2547template<typename Ordinal, typename Packet>
2549 const Comm<Ordinal>& comm,
2550 const int sourceRank, const Ordinal count, Packet recvBuffer[]
2551 )
2552{
2553 TEUCHOS_COMM_TIME_MONITOR(
2554 "Teuchos::CommHelpers: receive<"
2556 <<">( value type )"
2557 );
2559 charRecvBuffer(count,recvBuffer);
2560 return comm.receive(
2561 sourceRank
2562 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
2563 );
2564}
2565
2566
2567template<typename Ordinal, typename Packet>
2569 const Comm<Ordinal>& comm,
2570 const int sourceRank, Packet *recv
2571 )
2572{
2573 return Teuchos::receive<Ordinal,Packet>(comm,sourceRank,1,recv);
2574}
2575
2576
2577template<typename Ordinal, typename Packet>
2579 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2580 const int sourceRank, const Ordinal count, Packet*const recvBuffer[]
2581 )
2582{
2583 TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2584}
2585
2586template<typename Ordinal, typename Packet, typename Serializer>
2588 const Comm<Ordinal>& comm,
2589 const Serializer& serializer,
2590 const int sourceRank, const Ordinal count, Packet recvBuffer[]
2591 )
2592{
2593 TEUCHOS_COMM_TIME_MONITOR(
2594 "Teuchos::CommHelpers: receive<"
2596 <<">( value type )"
2597 );
2599 charRecvBuffer(count,recvBuffer,rcp(&serializer,false));
2600 return comm.receive(
2601 sourceRank
2602 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
2603 );
2604}
2605
2606template<typename Ordinal, typename Packet>
2608 const Comm<Ordinal>& comm,
2609 const ArrayView<const Packet> &sendBuffer,
2610 const int destRank
2611 )
2612{
2613 TEUCHOS_COMM_TIME_MONITOR(
2614 "Teuchos::CommHelpers: readySend<"
2616 <<">( value type )"
2617 );
2619 charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr());
2620 comm.readySend( charSendBuffer.getCharBufferView(), destRank );
2621}
2622
2623template<typename Ordinal, typename Packet>
2624void
2625Teuchos::readySend (const Packet sendBuffer[],
2626 const Ordinal count,
2627 const int destRank,
2628 const int tag,
2629 const Comm<Ordinal>& comm)
2630{
2631 TEUCHOS_COMM_TIME_MONITOR(
2632 "Teuchos::CommHelpers: readySend<"
2634 <<">( value type )"
2635 );
2637 buf_type charSendBuffer (count, sendBuffer);
2638 comm.readySend (charSendBuffer.getBytes (),
2639 charSendBuffer.getCharBuffer (),
2640 destRank, tag);
2641}
2642
2643template<typename Ordinal, typename Packet>
2645 const Comm<Ordinal>& comm,
2646 const Packet &send,
2647 const int destRank
2648 )
2649{
2650 readySend<Ordinal, Packet>( comm, arrayView(&send,1), destRank );
2651}
2652
2653template<typename Ordinal, typename Packet, typename Serializer>
2655 const Comm<Ordinal>& comm,
2656 const Serializer& serializer,
2657 const ArrayView<const Packet> &sendBuffer,
2658 const int destRank
2659 )
2660{
2661 TEUCHOS_COMM_TIME_MONITOR(
2662 "Teuchos::CommHelpers: readySend<"
2664 <<">( value type )"
2665 );
2667 charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr(), serializer);
2668 comm.readySend( charSendBuffer.getCharBufferView(), destRank );
2669}
2670
2671template<typename Ordinal, typename Packet>
2673Teuchos::isend(
2674 const Comm<Ordinal>& comm,
2675 const ArrayRCP<const Packet> &sendBuffer,
2676 const int destRank
2677 )
2678{
2679 TEUCHOS_COMM_TIME_MONITOR(
2680 "Teuchos::CommHelpers: isend<"
2682 <<">( value type )"
2683 );
2685 charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr());
2686 RCP<CommRequest<Ordinal> > commRequest = comm.isend(
2687 charSendBuffer.getCharBufferView(), destRank );
2688 set_extra_data( sendBuffer, "buffer", inOutArg(commRequest) );
2689 return commRequest;
2690}
2691
2692template<typename Ordinal, typename Packet>
2694Teuchos::isend (const ArrayRCP<const Packet> &sendBuffer,
2695 const int destRank,
2696 const int tag,
2697 const Comm<Ordinal>& comm)
2698{
2699 TEUCHOS_COMM_TIME_MONITOR(
2700 "Teuchos::isend<" << OrdinalTraits<Ordinal>::name () << ","
2701 << TypeNameTraits<Packet>::name () << ">");
2702 ConstValueTypeSerializationBuffer<Ordinal,Packet>
2703 charSendBuffer (sendBuffer.size (), sendBuffer.getRawPtr ());
2704 RCP<CommRequest<Ordinal> > commRequest =
2705 comm.isend (charSendBuffer.getCharBufferView (), destRank, tag);
2706 set_extra_data (sendBuffer, "buffer", inOutArg (commRequest));
2707 return commRequest;
2708}
2709
2710template<typename Ordinal, typename Packet>
2712Teuchos::isend(
2713 const Comm<Ordinal>& comm,
2714 const RCP<const Packet> &send,
2715 const int destRank
2716 )
2717{
2718 const ArrayRCP<const Packet> sendBuffer =
2719 arcpWithEmbeddedObj( send.get(), 0, 1, send, false );
2720 // 2008/07/29: rabartl: Above: I need to write a helper function to create
2721 // new ArrayRCP object given a single object to copy.
2722 return isend<Ordinal, Packet>( comm, sendBuffer, destRank );
2723}
2724
2725template<typename Ordinal, typename Packet, typename Serializer>
2727Teuchos::isend(
2728 const Comm<Ordinal>& comm,
2729 const Serializer& serializer,
2730 const ArrayRCP<const Packet> &sendBuffer,
2731 const int destRank
2732 )
2733{
2734 TEUCHOS_COMM_TIME_MONITOR(
2735 "Teuchos::CommHelpers: isend<"
2736 <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2737 <<">( value type )"
2738 );
2739 ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
2740 charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr(), serializer);
2741 RCP<CommRequest<Ordinal> > commRequest = comm.isend(
2742 charSendBuffer.getCharBufferView(), destRank );
2743 set_extra_data( sendBuffer, "buffer", inOutArg(commRequest) );
2744 return commRequest;
2745}
2746
2747template<typename Ordinal, typename Packet>
2750 const Comm<Ordinal>& comm,
2751 const ArrayRCP<Packet> &recvBuffer,
2752 const int sourceRank
2753 )
2754{
2755 TEUCHOS_COMM_TIME_MONITOR(
2756 "Teuchos::ireceive<int, " << "," << TypeNameTraits<Packet>::name () << ">");
2757 ValueTypeSerializationBuffer<Ordinal,Packet>
2758 charRecvBuffer(recvBuffer.size(), recvBuffer.getRawPtr());
2759 RCP<CommRequest<Ordinal> > commRequest = comm.ireceive(
2760 charRecvBuffer.getCharBufferView(), sourceRank );
2761 set_extra_data( recvBuffer, "buffer", inOutArg(commRequest) );
2762 return commRequest;
2763}
2764
2765template<typename Ordinal, typename Packet>
2768 const int sourceRank,
2769 const int tag,
2770 const Teuchos::Comm<Ordinal>& comm)
2771{
2772 TEUCHOS_COMM_TIME_MONITOR(
2773 "Teuchos::ireceive<int, " << "," << TypeNameTraits<Packet>::name () << ">");
2774 ValueTypeSerializationBuffer<int, Packet>
2775 charRecvBuffer (recvBuffer.size (), recvBuffer.getRawPtr ());
2776 RCP<CommRequest<int> > commRequest =
2777 comm.ireceive (charRecvBuffer.getCharBufferView (), sourceRank, tag);
2778 set_extra_data (recvBuffer, "buffer", inOutArg (commRequest));
2779 return commRequest;
2780}
2781
2782template<typename Ordinal, typename Packet>
2785 const Comm<Ordinal>& comm,
2786 const RCP<Packet> &recv,
2787 const int sourceRank
2788 )
2789{
2790 const ArrayRCP<Packet> recvBuffer =
2791 arcpWithEmbeddedObj( recv.get(), 0, 1, recv, false );
2792 // 2008/07/29: rabartl: Above: I need to write a helper function to create
2793 // new ArrayRCP object given a single object to copy.
2794 return ireceive<Ordinal, Packet>( comm, recvBuffer, sourceRank );
2795}
2796
2797template<typename Ordinal, typename Packet, typename Serializer>
2800 const Comm<Ordinal>& comm,
2801 const Serializer& serializer,
2802 const ArrayRCP<Packet> &recvBuffer,
2803 const int sourceRank
2804 )
2805{
2806 TEUCHOS_COMM_TIME_MONITOR(
2807 "Teuchos::CommHelpers: ireceive<"
2808 <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2809 <<">( value type )"
2810 );
2811 ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
2812 charRecvBuffer(recvBuffer.size(), recvBuffer.getRawPtr(), serializer);
2813 RCP<CommRequest<Ordinal> > commRequest = comm.ireceive(
2814 charRecvBuffer.getCharBufferView(), sourceRank );
2815 set_extra_data( recvBuffer, "buffer", inOutArg(commRequest) );
2816 return commRequest;
2817}
2818
2819template<typename Ordinal>
2821 const Comm<Ordinal>& comm,
2822 const ArrayView<RCP<CommRequest<Ordinal> > > &requests
2823 )
2824{
2825 comm.waitAll(requests);
2826}
2827
2828
2829template<typename Ordinal>
2830void
2832 const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
2833 const ArrayView<RCP<CommStatus<Ordinal> > >& statuses)
2834{
2835 comm.waitAll (requests, statuses);
2836}
2837
2838
2839template<typename Ordinal>
2841Teuchos::wait (const Comm<Ordinal>& comm,
2842 const Ptr<RCP<CommRequest<Ordinal> > > &request)
2843{
2844 return comm.wait (request);
2845}
2846
2847
2848#endif // TEUCHOS_COMM_HELPERS_HPP
Templated array class derived from the STL std::vector.
Implementation of Teuchos wrappers for MPI.
Declaration of Teuchos::EReductionType enum, and related functions.
Defines basic traits for the ordinal field type.
Defines basic traits for the scalar field type.
Defines basic traits returning the name of a type in a portable and readable way.
Definition of Teuchos::as, for conversions between types.
Standard logical AND operator for booleans.
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
T * getRawPtr()
Return a raw pointer to beginning of array or NULL if unsized.
void push_back(const value_type &x)
Reference-counted smart pointer for managing arrays.
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.
size_type size() const
The total number of entries in the array.
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.
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
Nonowning array view.
size_type size() const
The total number of items in the managed array.
T * getRawPtr() const
Return a raw pointer to beginning of array or NULL if unsized.
ArrayView< T > arrayView(T *p, typename ArrayView< T >::size_type size)
Construct a const or non-const view to const or non-const data.
Decorator class that uses a strategy object to convert to and from char[] to typed buffers for object...
Decorator class that uses traits to convert to and from char[] to typed buffers for objects that use ...
Abstract interface for distributed-memory communication.
virtual void broadcast(const int rootRank, const Ordinal bytes, char buffer[]) const =0
Broadcast values from the root process to the slave processes.
void ssend(const Comm< Ordinal > &comm, const Packet &send, const int destRank)
Synchronously send a single object that use values semantics to another process.
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.
RCP< CommRequest< Ordinal > > ireceive(const Comm< Ordinal > &comm, const ArrayRCP< Packet > &recvBuffer, const int sourceRank)
Receive one or more objects (that use values semantics) from another process.
void scan(const Comm< Ordinal > &comm, const Serializer &serializer, 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 and cus...
virtual void waitAll(const ArrayView< RCP< CommRequest< Ordinal > > > &requests) const =0
Wait on a set of communication requests.
void broadcast(const Comm< Ordinal > &comm, const Serializer< Ordinal, Packet > &serializer, const int rootRank, const Ordinal count, Packet *const buffer[])
Broadcast array of objects that use reference semantics.
int receive(const Comm< Ordinal > &comm, const int sourceRank, const Ordinal count, Packet recvBuffer[])
Receive objects that use values semantics from another process.
virtual void readySend(const ArrayView< const char > &sendBuffer, const int destRank) const =0
Ready send of data from this process to another process.
void scan(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, const Ptr< Packet > &scanReduct)
Scan/Reduce single object using value semantics using a predefined reduction type.
virtual RCP< CommRequest< Ordinal > > ireceive(const ArrayView< char > &recvBuffer, const int sourceRank) const =0
Non-blocking receive.
virtual void reduceAll(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char globalReducts[]) const =0
Global reduction.
void send(const Comm< Ordinal > &comm, const Serializer &serializer, const Ordinal count, const Packet sendBuffer[], const int destRank)
Send objects that use values semantics to another process using customized serializer.
void send(const Comm< Ordinal > &comm, const Packet &send, const int destRank)
Send a single object that use values semantics to another process.
virtual int getSize() const =0
Returns the number of processes that make up this communicator.
void alltoAll(const Packet sendBuf[], const Ordinal sendCount, Packet recvBuf[], const Ordinal recvCount, const Comm< Ordinal > &comm)
Scatter values from all processes to all processes.
void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Ordinal count, const Packet sendBuffer[], Packet globalReducts[])
Collective reduce all of array of objects using value semantics using a pre-defined reduction type.
void alltoAllv(const Packet sendBuf[], const Ordinal sendCounts[], const Ordinal sendDispls[], Packet recvBuf[], const Ordinal recvCounts[], const Ordinal recvDispls[], const Comm< Ordinal > &comm)
Scatter values from all processes to all processes.
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 readySend(const Comm< Ordinal > &comm, const ArrayView< const Packet > &sendBuffer, const int destRank)
Ready-Send an array of objects that use values semantics to another process.
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.
void reduce(const Packet sendBuf[], Packet recvBuf[], const Ordinal count, const EReductionType reductType, const Ordinal root, const Comm< Ordinal > &comm)
Wrapper for MPI_Reduce; reduction to one process, using a built-in reduction operator selected by enu...
virtual RCP< CommStatus< Ordinal > > wait(const Ptr< RCP< CommRequest< Ordinal > > > &request) const =0
Wait on a single communication request, and return its status.
virtual void scan(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char scanReducts[]) const =0
Scan reduction.
int rank(const Comm< Ordinal > &comm)
Get the process rank.
void readySend(const Comm< Ordinal > &comm, const Serializer &serializer, const ArrayView< const Packet > &sendBuffer, const int destRank)
Ready-Send an array of objects that use values semantics to another process using customized serializ...
int receive(const Comm< Ordinal > &comm, const int sourceRank, Packet *recv)
Receive a single object that use values semantics from another process.
RCP< CommStatus< Ordinal > > wait(const Comm< Ordinal > &comm, const Ptr< RCP< CommRequest< Ordinal > > > &request)
Wait on a single communication request, and return its status.
void broadcast(const Comm< Ordinal > &comm, const int rootRank, const ArrayView< Packet > &buffer)
Broadcast array of objects that use value semantics.
void gather(const Packet sendBuf[], const Ordinal sendCount, Packet recvBuf[], const Ordinal recvCount, const int root, const Comm< Ordinal > &comm)
Gather values from each process to the root process.
virtual int receive(const int sourceRank, const Ordinal bytes, char recvBuffer[]) const =0
Blocking receive of data from this process to another process.
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.
void broadcast(const Comm< Ordinal > &comm, const Serializer< Ordinal, Packet > &serializer, const int rootRank, const ArrayView< const Ptr< Packet > > &buffer)
Broadcast array of objects that use reference semantics.
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.
RCP< CommRequest< Ordinal > > ireceive(const Comm< Ordinal > &comm, const RCP< Packet > &recv, const int sourceRank)
Receive one object (that uses values semantics) from another process.
void reduceAll(const Comm< Ordinal > &comm, const Serializer< Ordinal, Packet > &serializer, const ReferenceTypeReductionOp< Ordinal, Packet > &reductOp, const Ordinal count, const Packet *const sendBuffer[], Packet *const globalReducts[])
Collective reduce all for array of objects using reference semantics.
void waitAll(const Comm< Ordinal > &comm, const ArrayView< RCP< CommRequest< Ordinal > > > &requests, const ArrayView< RCP< CommStatus< Ordinal > > > &statuses)
Wait on one or more communication requests, and return their statuses.
void scan(const Comm< Ordinal > &comm, const Serializer &serializer, const EReductionType reductType, const Ordinal count, const Packet sendBuffer[], Packet scanReducts[])
Scan/Reduce array of objects using value semantics using a predefined reduction type and customized s...
virtual int getRank() const =0
Returns the rank of this process.
void scan(const Comm< Ordinal > &comm, const Serializer< Ordinal, Packet > &serializer, const ReferenceTypeReductionOp< Ordinal, Packet > &reductOp, const Ordinal count, const Packet *const sendBuffer[], Packet *const scanReducts[])
Scan/Reduce array of objects that use reference semantics using a user-defined reduction operator.
void gatherv(const Packet sendBuf[], const Ordinal sendCount, Packet recvBuf[], const Ordinal recvCounts[], const Ordinal displs[], const int root, const Comm< Ordinal > &comm)
Gather arrays of possibly different lengths from each process to the root process.
RCP< CommRequest< Ordinal > > isend(const Comm< Ordinal > &comm, const Serializer &serializer, const ArrayRCP< const Packet > &sendBuffer, const int destRank)
Send objects that use values semantics to another process using customized serializer.
void broadcast(const Comm< Ordinal > &comm, const int rootRank, const Ptr< Packet > &object)
Broadcast single object that use value semantics.
RCP< CommRequest< Ordinal > > isend(const Comm< Ordinal > &comm, const RCP< const Packet > &send, const int destRank)
Send a single object that use values semantics to another process.
RCP< CommRequest< Ordinal > > isend(const Comm< Ordinal > &comm, const ArrayRCP< const Packet > &sendBuffer, const int destRank)
Send objects that use values semantics to another process.
void gatherAll(const Comm< Ordinal > &comm, const Serializer< Ordinal, Packet > &serializer, const Ordinal sendCount, const Packet *const sendBuffer[], const Ordinal recvCount, Packet *const recvBuffer[])
Gather array of objects that use reference semantics from every process to every process.
void gatherAll(const Comm< Ordinal > &comm, const Ordinal sendCount, const Packet sendBuffer[], const Ordinal recvCount, Packet recvBuffer[])
Gather array of objects that use value semantics from every process to every process.
void readySend(const Comm< Ordinal > &comm, const Packet &send, const int destRank)
Ready-Send a single object that use values semantics to another process.
void gatherAll(const Comm< Ordinal > &comm, const Serializer &serializer, const Ordinal sendCount, const Packet sendBuffer[], const Ordinal recvCount, Packet recvBuffer[])
Gather array of objects that use value semantics from every process to every process using customized...
void ssend(const Comm< Ordinal > &comm, const Ordinal count, const Packet sendBuffer[], const int destRank)
Synchronously send objects that use values semantics to another process.
RCP< CommRequest< Ordinal > > ireceive(const Comm< Ordinal > &comm, const Serializer &serializer, const ArrayRCP< Packet > &recvBuffer, const int sourceRank)
Send objects that use values semantics to another process using customized serializer.
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 reduceAll(const Comm< Ordinal > &comm, const Serializer &serializer, const ValueTypeReductionOp< Ordinal, Packet > &reductOp, const Ordinal count, const Packet sendBuffer[], Packet globalReducts[])
Collective reduce all of array of objects using value semantics using a user-defined reduction operat...
virtual void barrier() const =0
Pause every process in *this communicator until all the processes reach this point.
void broadcast(const Comm< Ordinal > &comm, const int rootRank, Packet *object)
Broadcast single object that use value semantics.
int receive(const Comm< Ordinal > &comm, const Serializer< Ordinal, Packet > &serializer, const int sourceRank, const Ordinal count, Packet *const recvBuffer[])
Receive objects that use reference semantics from another process.
void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, const Ptr< Packet > &globalReduct)
Collective reduce all for single object using value semantics using a pre-defined reduction type.
void send(const Comm< Ordinal > &comm, const Serializer< Ordinal, Packet > &serializer, const Ordinal count, const Packet *const sendBuffer[], const int destRank)
Send objects that use reference semantics to another process.
void scan(const Comm< Ordinal > &comm, const EReductionType reductType, const Ordinal count, const Packet sendBuffer[], Packet scanReducts[])
Scan/Reduce array of objects using value semantics using a predefined reduction type.
void broadcast(const Comm< Ordinal > &comm, const Serializer &serializer, const int rootRank, const Ordinal count, Packet buffer[])
Broadcast array of objects that use value semantics using customized serializer.
void send(const Comm< OrdinalType > &comm, const OrdinalType count, const Packet sendBuffer[], const int destRank)
void broadcast(const Comm< Ordinal > &comm, const int rootRank, const Ordinal count, Packet buffer[])
Broadcast array of objects that use value semantics.
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
virtual RCP< CommRequest< Ordinal > > isend(const ArrayView< const char > &sendBuffer, const int destRank) const =0
Non-blocking send.
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.
int receive(const Comm< Ordinal > &comm, const Serializer &serializer, const int sourceRank, const Ordinal count, Packet recvBuffer[])
Receive objects that use values semantics from another process using customized serializer.
void reduceAll(const Comm< Ordinal > &comm, const Serializer &serializer, const EReductionType reductType, const Ordinal count, const Packet sendBuffer[], Packet globalReducts[])
Collective reduce all of array of objects using value semantics using a pre-defined reduction type an...
void waitAll(const Comm< Ordinal > &comm, const ArrayView< RCP< CommRequest< Ordinal > > > &requests)
Wait for an array of Teuchos::CommRequest objects.
void barrier(const Comm< Ordinal > &comm)
Barrier.
Encapsulation of a pending nonblocking communication operation.
Encapsulation of the result of a receive (blocking or nonblocking).
Encapsulate how an array of const objects with reference sematics is serialized into a char[] array.
Encapsulate how an array of const objects with value sematics is serialized into a const char[] array...
Standard Max operator for types with value semantics.
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
Standard min operator for types with value semantics.
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
Simple wrapper class for raw pointers to single objects where no persisting relationship exists.
Ptr< T > inOutArg(T &arg)
create a non-persisting (required or optional) input/output argument for a function call.
Smart reference counting pointer class for automatic garbage collection.
Base interface class for user-defined reduction operations for objects that use reference semantics.
Encapsulate how an array of non-const objects with reference sematics is serialized into a char[] arr...
Strategy interface for the indirect serializing and deserializing objects of a given type handled usi...
Standard summation operator for types with value semantics.
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
Base interface class for user-defined reduction operations for objects that use value semantics.
Encapsulate how an array of non-const objects with value sematics is serialized into a char[] array.
#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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
Avoid warning about unreachable or missing return from function.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
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).
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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
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).
@ REDUCE_AND
Logical AND.
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).
static std::string name()
Returns name of this ordinal type.