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_SerializationTraitsHelpers.hpp"
16#include "Teuchos_ReductionOpHelpers.hpp"
17#include "Teuchos_SerializerHelpers.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
28#include "Teuchos_DefaultSerialComm.hpp"
30
31namespace Teuchos {
32
33//
34// Teuchos::Comm Helper Functions
35//
36
37#ifdef HAVE_TEUCHOS_MPI
38namespace Details {
39
46std::string getMpiErrorString (const int errCode);
47
48} // namespace Details
49#endif // HAVE_TEUCHOS_MPI
50
55template<typename Ordinal>
56int rank(const Comm<Ordinal>& comm);
57
62template<typename Ordinal>
63int size(const Comm<Ordinal>& comm);
64
69template<typename Ordinal>
70void barrier(const Comm<Ordinal>& comm);
71
76template<typename Ordinal, typename Packet>
78 const Comm<Ordinal>& comm,
79 const int rootRank,
80 const Ordinal count, Packet buffer[]
81 );
82
87template<typename Ordinal, typename Packet>
89 const Comm<Ordinal>& comm,
90 const int rootRank,
91 const ArrayView<Packet> &buffer
92 );
93
98template<typename Ordinal, typename Packet>
100 const Comm<Ordinal>& comm,
101 const int rootRank, Packet *object
102 );
103
108template<typename Ordinal, typename Packet>
110 const Comm<Ordinal>& comm,
111 const int rootRank, const Ptr<Packet> &object
112 );
113
118template<typename Ordinal, typename Packet>
120 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
121 const int rootRank, const Ordinal count, Packet*const buffer[]
122 );
123
128template<typename Ordinal, typename Packet>
130 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
131 const int rootRank, const ArrayView<const Ptr<Packet> > &buffer
132 );
133
139template<typename Ordinal, typename Packet, typename Serializer>
141 const Comm<Ordinal>& comm,
142 const Serializer& serializer,
143 const int rootRank,
144 const Ordinal count, Packet buffer[]
145 );
146
151template<typename Ordinal, typename Packet>
152void
153gather (const Packet sendBuf[],
154 const Ordinal sendCount,
155 Packet recvBuf[],
156 const Ordinal recvCount,
157 const int root,
158 const Comm<Ordinal>& comm);
159
164template<typename Ordinal, typename Packet>
165void
166gatherv (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
179template<typename Ordinal, typename Packet>
181 const Comm<Ordinal>& comm,
182 const Ordinal sendCount, const Packet sendBuffer[],
183 const Ordinal recvCount, Packet recvBuffer[]
184 );
185
191template<typename Ordinal, typename Packet>
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
203template<typename Ordinal, typename Packet, typename Serializer>
205 const Comm<Ordinal>& comm,
206 const Serializer& serializer,
207 const Ordinal sendCount, const Packet sendBuffer[],
208 const Ordinal recvCount, Packet recvBuffer[]
209 );
210
237template<typename Ordinal, typename Packet>
238void
239scatter (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
257template<typename Ordinal, typename Packet>
258void
259scatterv (const Packet sendBuf[],
260 const Ordinal sendCounts[],
261 const Ordinal displs[],
262 Packet recvBuf[],
263 const Ordinal recvCount,
264 const Ordinal root,
265 const Comm<Ordinal>& comm)
266{
267 // See Bug 6375; Tpetra does not actually need any specializations
268 // other than Ordinal = int and Packet = int. We may add them later
269 // if there is interest.
271 (true, std::logic_error, "Teuchos::scatterv<" <<
273 << ">: Generic version is not yet implemented. This function currently "
274 "only has an implementtion for Ordinal = int and Packet = int. "
275 "See Bug 6375 and Bug 6336.");
276}
277
305template<typename Ordinal, typename Packet>
306void
307reduce (const Packet sendBuf[],
308 Packet recvBuf[],
309 const Ordinal count,
310 const EReductionType reductType,
311 const Ordinal root,
312 const Comm<Ordinal>& comm);
313
336template<typename Ordinal, typename Packet>
338 const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
339 const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
340 );
341
347template<typename Ordinal, typename Packet>
349 const Comm<Ordinal>& comm, const EReductionType reductType,
350 const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
351 );
352
358template<typename Ordinal, typename Packet>
360 const Comm<Ordinal>& comm, const EReductionType reductType,
361 const Packet &send, const Ptr<Packet> &globalReduct
362 );
363
369template<typename Ordinal, typename Packet>
371 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
373 const Ordinal count, const Packet*const sendBuffer[], Packet*const globalReducts[]
374 );
375
381template<typename Ordinal, typename Packet, typename Serializer>
383 const Comm<Ordinal>& comm,
384 const Serializer& serializer,
386 const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
387 );
388
394template<typename Ordinal, typename Packet, typename Serializer>
396 const Comm<Ordinal>& comm,
397 const Serializer& serializer,
398 const EReductionType reductType,
399 const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
400 );
401
407template<typename Ordinal, typename Packet>
408void scan(
409 const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
410 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
411 );
412
418template<typename Ordinal, typename Packet>
419void scan(
420 const Comm<Ordinal>& comm, const EReductionType reductType,
421 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
422 );
423
429template<typename Ordinal, typename Packet>
430void scan(
431 const Comm<Ordinal>& comm, const EReductionType reductType,
432 const Packet &send, const Ptr<Packet> &scanReduct
433 );
434
440template<typename Ordinal, typename Packet>
441void scan(
442 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
444 const Ordinal count, const Packet*const sendBuffer[], Packet*const scanReducts[]
445 );
446
452template<typename Ordinal, typename Packet, typename Serializer>
453void scan(
454 const Comm<Ordinal>& comm,
455 const Serializer& serializer,
457 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
458 );
459
465template<typename Ordinal, typename Packet, typename Serializer>
466void scan(
467 const Comm<Ordinal>& comm,
468 const Serializer& serializer,
469 const EReductionType reductType,
470 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
471 );
472
477template<typename Ordinal, typename Packet>
478void send(
479 const Comm<Ordinal>& comm,
480 const Ordinal count, const Packet sendBuffer[], const int destRank
481 );
482
484template<typename Ordinal, typename Packet>
485void
486send (const Packet sendBuffer[],
487 const Ordinal count,
488 const int destRank,
489 const int tag,
490 const Comm<Ordinal>& comm);
491
496template<typename Ordinal, typename Packet>
497void ssend(
498 const Comm<Ordinal>& comm,
499 const Ordinal count, const Packet sendBuffer[], const int destRank
500 );
501
503template<typename Ordinal, typename Packet>
504void
505ssend (const Packet sendBuffer[],
506 const Ordinal count,
507 const int destRank,
508 const int tag,
509 const Comm<Ordinal>& comm);
510
515template<typename Ordinal, typename Packet>
516void send(
517 const Comm<Ordinal>& comm,
518 const Packet &send, const int destRank
519 );
520
525template<typename Ordinal, typename Packet>
526void ssend(
527 const Comm<Ordinal>& comm,
528 const Packet &send, const int destRank
529 );
530
537template<typename Ordinal, typename Packet>
538void send(
539 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
540 const Ordinal count, const Packet*const sendBuffer[], const int destRank
541 );
542
548template<typename Ordinal, typename Packet, typename Serializer>
549void send(
550 const Comm<Ordinal>& comm,
551 const Serializer& serializer,
552 const Ordinal count, const Packet sendBuffer[], const int destRank
553 );
554
559template<typename Ordinal, typename Packet>
561 const Comm<Ordinal>& comm,
562 const int sourceRank, const Ordinal count, Packet recvBuffer[]
563 );
564
569template<typename Ordinal, typename Packet>
571 const Comm<Ordinal>& comm,
572 const int sourceRank, Packet *recv
573 );
574
579template<typename Ordinal, typename Packet>
581 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
582 const int sourceRank, const Ordinal count, Packet*const recvBuffer[]
583 );
584
590template<typename Ordinal, typename Packet, typename Serializer>
592 const Comm<Ordinal>& comm,
593 const Serializer& serializer,
594 const int sourceRank, const Ordinal count, Packet recvBuffer[]
595 );
596
602template<typename Ordinal, typename Packet>
604 const Comm<Ordinal>& comm,
605 const ArrayView<const Packet> &sendBuffer,
606 const int destRank
607 );
608
610template<typename Ordinal, typename Packet>
611void
612readySend (const Packet sendBuffer[],
613 const Ordinal count,
614 const int destRank,
615 const int tag,
616 const Comm<Ordinal>& comm);
617
622template<typename Ordinal, typename Packet>
624 const Comm<Ordinal>& comm,
625 const Packet &send,
626 const int destRank
627 );
628
634template<typename Ordinal, typename Packet, typename Serializer>
636 const Comm<Ordinal>& comm,
637 const Serializer& serializer,
638 const ArrayView<const Packet> &sendBuffer,
639 const int destRank
640 );
641
646template<typename Ordinal, typename Packet>
648 const Comm<Ordinal>& comm,
649 const ArrayRCP<const Packet> &sendBuffer,
650 const int destRank
651 );
652
654template<typename Ordinal, typename Packet>
656isend (const ArrayRCP<const Packet>& sendBuffer,
657 const int destRank,
658 const int tag,
659 const Comm<Ordinal>& comm);
660
665template<typename Ordinal, typename Packet>
667 const Comm<Ordinal>& comm,
668 const RCP<const Packet> &send,
669 const int destRank
670 );
671
677template<typename Ordinal, typename Packet, typename Serializer>
679 const Comm<Ordinal>& comm,
680 const Serializer& serializer,
681 const ArrayRCP<const Packet> &sendBuffer,
682 const int destRank
683 );
684
685
686// 2008/07/29: rabartl: ToDo: Add reference semantics version of isend!
687
688
698template<typename Ordinal, typename Packet>
700 const Comm<Ordinal>& comm,
701 const ArrayRCP<Packet> &recvBuffer,
702 const int sourceRank
703 );
704
706template<typename Ordinal, typename Packet>
708ireceive (const ArrayRCP<Packet> &recvBuffer,
709 const int sourceRank,
710 const int tag,
711 const Comm<Ordinal>& comm);
712
724template<typename Ordinal, typename Packet>
726 const Comm<Ordinal>& comm,
727 const RCP<Packet> &recv,
728 const int sourceRank
729 );
730
736template<typename Ordinal, typename Packet, typename Serializer>
738 const Comm<Ordinal>& comm,
739 const Serializer& serializer,
740 const ArrayRCP<Packet> &recvBuffer,
741 const int sourceRank
742 );
743
744
745// 2008/07/29: rabartl: ToDo: Add reference semantics version of ireceive!
746
747
755template<typename Ordinal>
757 const Comm<Ordinal>& comm,
758 const ArrayView<RCP<CommRequest<Ordinal> > > &requests
759 );
760
790template<typename Ordinal>
791void
793 const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
794 const ArrayView<RCP<CommStatus<Ordinal> > >& statuses);
795
819template<typename Ordinal>
821wait (const Comm<Ordinal>& comm, const Ptr<RCP<CommRequest<Ordinal> > >& request);
822
823//
824// Standard reduction subclasses for objects that use value semantics
825//
826
827
832template<typename Ordinal, typename Packet>
833class SumValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
834{
835public:
837 void reduce(
838 const Ordinal count,
839 const Packet inBuffer[],
840 Packet inoutBuffer[]
841 ) const;
842};
843
844
853template<typename Ordinal, typename Packet>
854class MinValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
855{
856public:
858 void reduce(
859 const Ordinal count,
860 const Packet inBuffer[],
861 Packet inoutBuffer[]
862 ) const;
863};
864
865
874template<typename Ordinal, typename Packet>
875class MaxValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
876{
877public:
879 void reduce(
880 const Ordinal count,
881 const Packet inBuffer[],
882 Packet inoutBuffer[]
883 ) const;
884};
885
886
891template<typename Ordinal, typename Packet>
892class ANDValueReductionOp : public ValueTypeReductionOp<Ordinal,Packet>
893{
894public:
896 void reduce(
897 const Ordinal count,
898 const Packet inBuffer[],
899 Packet inoutBuffer[]
900 ) const;
901};
902
903
904// ////////////////////////////////////////////////////////////
905// Implementation details (not for geneal users to mess with)
906
907
908//
909// ReductionOp Utilities
910//
911
912
913namespace MixMaxUtilities {
914
915
916template<bool isComparable, typename Ordinal, typename Packet>
917class Min {};
918
919
920template<typename Ordinal, typename Packet>
921class Min<true,Ordinal,Packet> {
922public:
923 static void min(
924 const Ordinal count,
925 const Packet inBuffer[],
926 Packet inoutBuffer[]
927 )
928 {
929 for( int i = 0; i < count; ++i )
930 inoutBuffer[i] = TEUCHOS_MIN(inoutBuffer[i],inBuffer[i]);
931 }
932};
933
934
935template<typename Ordinal, typename Packet>
936class Min<false,Ordinal,Packet> {
937public:
938 static void min(
939 const Ordinal,
940 const Packet[],
941 Packet[]
942 )
943 {
945 true,std::logic_error,
946 "Error, the type "<<TypeNameTraits<Packet>::name()
947 <<" does not support comparison operations!"
948 );
949 }
950};
951
952
953template<bool isComparable, typename Ordinal, typename Packet>
954class Max {};
955
956
957template<typename Ordinal, typename Packet>
958class Max<true,Ordinal,Packet> {
959public:
960 static void max(
961 const Ordinal count,
962 const Packet inBuffer[],
963 Packet inoutBuffer[]
964 )
965 {
966 for( int i = 0; i < count; ++i )
967 inoutBuffer[i] = TEUCHOS_MAX(inoutBuffer[i],inBuffer[i]);
968 }
969};
970
971
972template<typename Ordinal, typename Packet>
973class Max<false,Ordinal,Packet> {
974public:
975 static void max(
976 const Ordinal,
977 const Packet[],
978 Packet[]
979 )
980 {
982 true,std::logic_error,
983 "Error, the type "<<TypeNameTraits<Packet>::name()
984 <<" does not support comparison operations!"
985 );
986 }
987};
988
989
990template<bool isComparable, typename Ordinal, typename Packet>
991class AND {};
992
993
994template<typename Ordinal, typename Packet>
995class AND<true,Ordinal,Packet> {
996public:
997 static void andOp(
998 const Ordinal count,
999 const Packet inBuffer[],
1000 Packet inoutBuffer[]
1001 )
1002 {
1003 for( int i = 0; i < count; ++i )
1004 inoutBuffer[i] = inoutBuffer[i] && inBuffer[i];
1005 }
1006};
1007
1008
1009template<typename Ordinal, typename Packet>
1010class AND<false,Ordinal,Packet> {
1011public:
1012 static void andOp(
1013 const Ordinal,
1014 const Packet[],
1015 Packet[]
1016 )
1017 {
1019 true,std::logic_error,
1020 "Error, the type "<<TypeNameTraits<Packet>::name()
1021 <<" does not support logical AND operations!"
1022 );
1023 }
1024};
1025
1026
1027} // namespace MixMaxUtilities
1028
1029
1030template<typename Ordinal, typename Packet>
1032 const Ordinal count,
1033 const Packet inBuffer[],
1034 Packet inoutBuffer[]
1035 ) const
1036{
1037 for( int i = 0; i < count; ++i )
1038 inoutBuffer[i] += inBuffer[i];
1039}
1040
1041
1042template<typename Ordinal, typename Packet>
1044 const Ordinal count,
1045 const Packet inBuffer[],
1046 Packet inoutBuffer[]
1047 ) const
1048{
1049 typedef MixMaxUtilities::Min<ScalarTraits<Packet>::isComparable, Ordinal, Packet> min_type;
1050 min_type::min (count, inBuffer, inoutBuffer);
1051}
1052
1053
1054template<typename Ordinal, typename Packet>
1056 const Ordinal count,
1057 const Packet inBuffer[],
1058 Packet inoutBuffer[]
1059 ) const
1060{
1061 typedef MixMaxUtilities::Max<ScalarTraits<Packet>::isComparable, Ordinal, Packet> max_type;
1062 max_type::max (count,inBuffer,inoutBuffer);
1063}
1064
1065
1066template<typename Ordinal, typename Packet>
1068 const Ordinal count,
1069 const Packet inBuffer[],
1070 Packet inoutBuffer[]
1071 ) const
1072{
1073 typedef MixMaxUtilities::AND<ScalarTraits<Packet>::isComparable, Ordinal, Packet> and_type;
1074 and_type::andOp (count, inBuffer, inoutBuffer);
1075}
1076
1077
1078} // namespace Teuchos
1079
1080
1081// //////////////////////////
1082// Template implemenations
1083
1084
1085//
1086// ReductionOp utilities
1087//
1088
1089
1090namespace Teuchos {
1091
1092
1093// Not for the general user to use! I am returning a raw ReductionOp* pointer
1094// to avoid the overhead of using RCP. However, given the use case
1095// this is just fine since I can just use std::auto_ptr to make sure things
1096// are deleted correctly.
1097//
1098// NOTE (mfh 08 Feb 2015) std::auto_ptr has been deprecated in C++11.
1099// I could either replace it with std::unique_ptr, or just call 'new'
1100// and 'delete' manually. The former is less error prone, but
1101// requires checking a macro for whether C++11 is actually enabled.
1102// Thus, I've chosen (for now) to rewrite all the code that uses
1103// std::auto_ptr, so that it allocates and deletes manually.
1104template<typename Ordinal, typename Packet>
1105ValueTypeReductionOp<Ordinal,Packet>*
1106createOp (const EReductionType reductType)
1107{
1108 typedef ScalarTraits<Packet> ST;
1109 switch (reductType) {
1110 case REDUCE_SUM: {
1111 return new SumValueReductionOp<Ordinal,Packet> ();
1112 }
1113 case REDUCE_MIN: {
1114 if (ST::isComparable) {
1116 }
1117 else {
1119 (! ST::isComparable, std::invalid_argument, "Teuchos::createOp"
1120 "(EReductionType): The Packet type " << TypeNameTraits<Packet>::name ()
1121 << " is not less-than comparable, so it does not make sense to do a "
1122 "MIN reduction with it.");
1123 }
1124 }
1125 case REDUCE_MAX: {
1126 if (ST::isComparable) {
1128 }
1129 else {
1131 (! ST::isComparable, std::invalid_argument, "Teuchos::createOp"
1132 "(EReductionType): The Packet type " << TypeNameTraits<Packet>::name ()
1133 << " is not less-than comparable, so it does not make sense to do a "
1134 "MAX reduction with it.");
1135 }
1136 }
1137 case REDUCE_AND: {
1139 }
1140 default:
1142 true, std::invalid_argument, "Teuchos::createOp(EReductionType): "
1143 "Invalid EReductionType value " << reductType << ". Valid values "
1144 "include REDUCE_SUM, REDUCE_MIN, REDUCE_MAX, and REDUCE_AND.");
1145 }
1146}
1147
1148
1149} // namespace Teuchos
1150
1151
1152//
1153// Teuchos::Comm wrapper functions
1154//
1155
1156
1157template<typename Ordinal>
1159{
1160 return comm.getRank();
1161}
1162
1163
1164template<typename Ordinal>
1165int Teuchos::size(const Comm<Ordinal>& comm)
1166{
1167 return comm.getSize();
1168}
1169
1170
1171template<typename Ordinal>
1173{
1174 TEUCHOS_COMM_TIME_MONITOR(
1175 "Teuchos::CommHelpers: barrier<"
1177 <<">()"
1178 );
1179 comm.barrier();
1180}
1181
1182
1183template<typename Ordinal, typename Packet>
1185 const Comm<Ordinal>& comm,
1186 const int rootRank, const Ordinal count, Packet buffer[]
1187 )
1188{
1189 TEUCHOS_COMM_TIME_MONITOR(
1190 "Teuchos::CommHelpers: broadcast<"
1192 <<">( value type )"
1193 );
1195 charBuffer(count,buffer);
1196 comm.broadcast(
1197 rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1198 );
1199}
1200
1201
1202template<typename Ordinal, typename Packet>
1204 const Comm<Ordinal>& comm,
1205 const int rootRank,
1206 const ArrayView<Packet> &buffer
1207 )
1208{
1209 broadcast<Ordinal, Packet>(comm, rootRank, buffer.size(), buffer.getRawPtr() );
1210}
1211
1212
1213template<typename Ordinal, typename Packet>
1215 const Comm<Ordinal>& comm,
1216 const int rootRank, Packet *object
1217 )
1218{
1219 broadcast<Ordinal,Packet>(comm,rootRank,1,object);
1220}
1221
1222
1223template<typename Ordinal, typename Packet>
1225 const Comm<Ordinal>& comm,
1226 const int rootRank, const Ptr<Packet> &object
1227 )
1228{
1229 broadcast<Ordinal,Packet>(comm,rootRank,1,object.getRawPtr());
1230}
1231
1232
1233template<typename Ordinal, typename Packet>
1235 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
1236 const int rootRank, const Ordinal count, Packet*const buffer[]
1237 )
1238{
1239 TEUCHOS_COMM_TIME_MONITOR(
1240 "Teuchos::CommHelpers: broadcast<"
1242 <<">( reference type )"
1243 );
1245 charBuffer(serializer, count, buffer);
1246 comm.broadcast(
1247 rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1248 );
1249}
1250
1251
1252template<typename Ordinal, typename Packet>
1254 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
1255 const int rootRank, const ArrayView<const Ptr<Packet> > &buffer
1256 )
1257{
1258 Array<Packet*> bufferPtrArray;
1259 for (int i = 0; i < buffer.size(); ++i) {
1260 bufferPtrArray.push_back(buffer[i].getRawPtr());
1261 }
1262 broadcast<Ordinal,Packet>(comm, serializer, rootRank,
1263 buffer.size(), bufferPtrArray.getRawPtr());
1264}
1265
1266template<typename Ordinal, typename Packet, typename Serializer>
1268 const Comm<Ordinal>& comm,
1269 const Serializer& serializer,
1270 const int rootRank, const Ordinal count, Packet buffer[]
1271 )
1272{
1273 TEUCHOS_COMM_TIME_MONITOR(
1274 "Teuchos::CommHelpers: broadcast<"
1276 <<">( value type )"
1277 );
1279 charBuffer(count,buffer,rcp(&serializer,false));
1280 comm.broadcast(
1281 rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1282 );
1283}
1284
1285
1286template<typename Ordinal, typename Packet>
1288 const Comm<Ordinal>& comm,
1289 const Ordinal sendCount, const Packet sendBuffer[],
1290 const Ordinal recvCount, Packet recvBuffer[]
1291 )
1292{
1293 TEUCHOS_COMM_TIME_MONITOR(
1294 "Teuchos::CommHelpers: gatherAll<"
1296 <<">( value type )"
1297 );
1299 charSendBuffer(sendCount,sendBuffer);
1301 charRecvBuffer(recvCount,recvBuffer);
1302 comm.gatherAll(
1303 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1304 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
1305 );
1306}
1307
1308template<typename Ordinal, typename Packet>
1309void
1310Teuchos::gather (const Packet sendBuf[],
1311 const Ordinal sendCount,
1312 Packet recvBuf[],
1313 const Ordinal recvCount,
1314 const int root,
1315 const Comm<Ordinal>& comm)
1316{
1317 TEUCHOS_COMM_TIME_MONITOR(
1318 "Teuchos::CommHelpers: gather<"
1320 <<">( value type )"
1321 );
1323 charSendBuffer (sendCount, sendBuf);
1325 charRecvBuffer (recvCount, recvBuf);
1326 comm.gather (charSendBuffer.getBytes (),
1327 charSendBuffer.getCharBuffer (),
1328 charRecvBuffer.getBytes (),
1329 charRecvBuffer.getCharBuffer (),
1330 root);
1331}
1332
1333template<typename Ordinal, typename Packet>
1334void
1335Teuchos::gatherv (const Packet sendBuf[],
1336 const Ordinal sendCount,
1337 Packet recvBuf[],
1338 const Ordinal recvCounts[],
1339 const Ordinal displs[],
1340 const int root,
1341 const Comm<Ordinal>& comm)
1342{
1343 // Ordinal totalRecvCount = 0;
1344
1345 // // In order to get the right output buffer length, we have to sum
1346 // // the receive counts from all the processes in the communicator.
1347 // const Ordinal numProcs = as<Ordinal> (comm->getSize ());
1348 // for (Ordinal k = 0; k < as<Ordinal> (numProcs); ++k) {
1349 // totalRecvCount += recvCounts[k];
1350 // }
1351
1352 // // FIXME (mfh 16 Apr 2013) We also have to redo the displacements.
1353
1354 // ConstValueTypeSerializationBuffer<Ordinal,Packet>
1355 // charSendBuffer (sendCount, sendBuf);
1356 // ValueTypeSerializationBuffer<Ordinal,Packet>
1357 // charRecvBuffer (totalRecvCount, recvBuf);
1358 // comm.gatherv (charSendBuffer.getBytes (),
1359 // charSendBuffer.getCharBuffer (),
1360 // charRecvBuffer.getBytes (),
1361 // charRecvBuffer.getCharBuffer (),
1362 // root);
1363 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
1364 "Teuchos::gatherv: The general case is not implemented.");
1365}
1366
1367template<typename Ordinal, typename Packet>
1369 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
1370 const Ordinal sendCount, const Packet*const sendBuffer[],
1371 const Ordinal recvCount, Packet*const recvBuffer[]
1372 )
1373{
1374 TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
1375}
1376
1377template<typename Ordinal, typename Packet, typename Serializer>
1379 const Comm<Ordinal>& comm,
1380 const Serializer& serializer,
1381 const Ordinal sendCount, const Packet sendBuffer[],
1382 const Ordinal recvCount, Packet recvBuffer[]
1383 )
1384{
1385 TEUCHOS_COMM_TIME_MONITOR(
1386 "Teuchos::CommHelpers: gatherAll<"
1388 <<">( value type )"
1389 );
1391 charSendBuffer(sendCount,sendBuffer,rcp(&serializer,false));
1393 charRecvBuffer(recvCount,recvBuffer,rcp(&serializer,false));
1394 comm.gatherAll(
1395 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1396 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
1397 );
1398}
1399
1400
1401template<typename Ordinal, typename Packet>
1402void
1403Teuchos::reduce (const Packet sendBuf[],
1404 Packet recvBuf[],
1405 const Ordinal count,
1406 const EReductionType reductType,
1407 const Ordinal root,
1408 const Comm<Ordinal>& comm)
1409{
1410 // See Bug 6375; Tpetra does not actually need any specializations
1411 // other than Ordinal = int and Packet = int. We may add them later
1412 // if there is interest.
1414 (true, std::logic_error, "Teuchos::reduce<" <<
1416 << ">: Generic version not implemented. We only implement this function "
1417 "for Ordinal = int and Packet = specific types.");
1418}
1419
1420
1421template<typename Ordinal, typename Packet>
1423 const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp
1424 ,const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
1425 )
1426{
1427 TEUCHOS_COMM_TIME_MONITOR(
1428 "Teuchos::CommHelpers: reduceAll<"
1430 <<">( value type, user-defined op )"
1431 );
1433 charSendBuffer(count,sendBuffer);
1435 charGlobalReducts(count,globalReducts);
1437 charReductOp(rcp(&reductOp,false));
1438 comm.reduceAll(
1439 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1440 ,charGlobalReducts.getCharBuffer()
1441 );
1442}
1443
1444
1445template<typename Ordinal, typename Packet>
1447 const Comm<Ordinal>& comm, const EReductionType reductType,
1448 const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
1449 )
1450{
1451 TEUCHOS_COMM_TIME_MONITOR(
1452 "Teuchos::CommHelpers: reduceAll<"
1454 <<">( value type, "<<toString(reductType)<<" )"
1455 );
1456
1458 createOp<Ordinal, Packet> (reductType);
1459 try {
1460 reduceAll(comm,*reductOp,count,sendBuffer,globalReducts);
1461 }
1462 catch (std::exception& e) {
1463 delete reductOp;
1464 throw e;
1465 }
1466 delete reductOp;
1467}
1468
1469
1470namespace Teuchos {
1471
1472// amb 11 Nov 2014. I am disabling these specializations for
1473// now. MPI_C_DOUBLE_COMPLEX is causing a problem in some builds. This code was
1474// effectively turned on only yesterday (10 Nov 2014) when TEUCHOS_HAVE_COMPLEX
1475// was corrected to be HAVE_TEUCHOS_COMPLEX, so evidently there are no users of
1476// these specializations.
1477#if 0
1478#ifdef HAVE_TEUCHOS_COMPLEX
1479// Specialization for Ordinal=int and Packet=std::complex<double>.
1480template<>
1481TEUCHOSCOMM_LIB_DLL_EXPORT void
1483 const EReductionType reductType,
1484 const int count,
1485 const std::complex<double> sendBuffer[],
1486 std::complex<double> globalReducts[]);
1487template<>
1488TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1490 const ArrayRCP<std::complex<double> >& recvBuffer,
1491 const int sourceRank);
1492template<>
1493TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1495 const int sourceRank,
1496 const int tag,
1497 const Comm<int>& comm);
1498template<>
1499TEUCHOSCOMM_LIB_DLL_EXPORT void
1501 const int count,
1502 const std::complex<double> sendBuffer[],
1503 const int destRank);
1504template<>
1505TEUCHOSCOMM_LIB_DLL_EXPORT void
1506send<int, std::complex<double> > (const std::complex<double> sendBuffer[],
1507 const int count,
1508 const int destRank,
1509 const int tag,
1510 const Comm<int>& comm);
1511template<>
1512TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1513isend<int, std::complex<double> > (const ArrayRCP<const std::complex<double> >& sendBuffer,
1514 const int destRank,
1515 const int tag,
1516 const Comm<int>& comm);
1517
1518// Specialization for Ordinal=int and Packet=std::complex<float>.
1519template<>
1520TEUCHOSCOMM_LIB_DLL_EXPORT void
1522 const EReductionType reductType,
1523 const int count,
1524 const std::complex<float> sendBuffer[],
1525 std::complex<float> globalReducts[]);
1526template<>
1527TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1529 const ArrayRCP<std::complex<float> >& recvBuffer,
1530 const int sourceRank);
1531template<>
1532TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1534 const int sourceRank,
1535 const int tag,
1536 const Comm<int>& comm);
1537template<>
1538TEUCHOSCOMM_LIB_DLL_EXPORT void
1540 const int count,
1541 const std::complex<float> sendBuffer[],
1542 const int destRank);
1543template<>
1544TEUCHOSCOMM_LIB_DLL_EXPORT void
1545send<int, std::complex<float> > (const std::complex<float> sendBuffer[],
1546 const int count,
1547 const int destRank,
1548 const int tag,
1549 const Comm<int>& comm);
1550template<>
1551TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1552isend<int, std::complex<float> > (const ArrayRCP<const std::complex<float> >& sendBuffer,
1553 const int destRank,
1554 const int tag,
1555 const Comm<int>& comm);
1556#endif // HAVE_TEUCHOS_COMPLEX
1557#endif // if 0
1558
1559// Specialization for Ordinal=int and Packet=double.
1560template<>
1561TEUCHOSCOMM_LIB_DLL_EXPORT void
1563 const EReductionType reductType,
1564 const int count,
1565 const double sendBuffer[],
1566 double globalReducts[]);
1567template<>
1568TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1569ireceive<int, double> (const Comm<int>& comm,
1570 const ArrayRCP<double>& recvBuffer,
1571 const int sourceRank);
1572template<>
1573TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1574ireceive<int, double> (const ArrayRCP<double> &recvBuffer,
1575 const int sourceRank,
1576 const int tag,
1577 const Comm<int>& comm);
1578template<>
1579TEUCHOSCOMM_LIB_DLL_EXPORT void
1580send<int, double> (const Comm<int>& comm,
1581 const int count,
1582 const double sendBuffer[],
1583 const int destRank);
1584template<>
1585TEUCHOSCOMM_LIB_DLL_EXPORT void
1586send<int, double> (const double 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, double> (const ArrayRCP<const double>& sendBuffer,
1594 const int destRank,
1595 const int tag,
1596 const Comm<int>& comm);
1597
1598template<>
1599TEUCHOSCOMM_LIB_DLL_EXPORT void
1600gatherv<int, double> (const double sendBuf[],
1601 const int sendCount,
1602 double recvBuf[],
1603 const int recvCounts[],
1604 const int displs[],
1605 const int root,
1606 const Comm<int>& comm);
1607
1608// Specialization for Ordinal=int and Packet=float.
1609template<>
1610TEUCHOSCOMM_LIB_DLL_EXPORT void
1611reduceAll<int, float> (const Comm<int>& comm,
1612 const EReductionType reductType,
1613 const int count,
1614 const float sendBuffer[],
1615 float globalReducts[]);
1616template<>
1617TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1618ireceive<int, float> (const Comm<int>& comm,
1619 const ArrayRCP<float>& recvBuffer,
1620 const int sourceRank);
1621template<>
1622TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1623ireceive<int, float> (const ArrayRCP<float> &recvBuffer,
1624 const int sourceRank,
1625 const int tag,
1626 const Comm<int>& comm);
1627template<>
1628TEUCHOSCOMM_LIB_DLL_EXPORT void
1629send<int, float> (const Comm<int>& comm,
1630 const int count,
1631 const float sendBuffer[],
1632 const int destRank);
1633template<>
1634TEUCHOSCOMM_LIB_DLL_EXPORT void
1635send<int, float> (const float sendBuffer[],
1636 const int count,
1637 const int destRank,
1638 const int tag,
1639 const Comm<int>& comm);
1640template<>
1641TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1642isend<int, float> (const ArrayRCP<const float>& sendBuffer,
1643 const int destRank,
1644 const int tag,
1645 const Comm<int>& comm);
1646
1647template<>
1648TEUCHOSCOMM_LIB_DLL_EXPORT void
1649gatherv<int, float> (const float sendBuf[],
1650 const int sendCount,
1651 float recvBuf[],
1652 const int recvCounts[],
1653 const int displs[],
1654 const int root,
1655 const Comm<int>& comm);
1656
1657// Specialization for Ordinal=int and Packet=long long.
1658template<>
1659TEUCHOSCOMM_LIB_DLL_EXPORT void
1660gather<int, long long> (const long long sendBuf[],
1661 const int sendCount,
1662 long long recvBuf[],
1663 const int recvCount,
1664 const int root,
1665 const Comm<int>& comm);
1666template<>
1667TEUCHOSCOMM_LIB_DLL_EXPORT void
1668gatherv<int, long long> (const long long sendBuf[],
1669 const int sendCount,
1670 long long recvBuf[],
1671 const int recvCounts[],
1672 const int displs[],
1673 const int root,
1674 const Comm<int>& comm);
1675template<>
1676TEUCHOSCOMM_LIB_DLL_EXPORT void
1678 const EReductionType reductType,
1679 const int count,
1680 const long long sendBuffer[],
1681 long long globalReducts[]);
1682template<>
1683TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1685 const ArrayRCP<long long>& recvBuffer,
1686 const int sourceRank);
1687template<>
1688TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1690 const int sourceRank,
1691 const int tag,
1692 const Comm<int>& comm);
1693template<>
1694TEUCHOSCOMM_LIB_DLL_EXPORT void
1695send<int, long long> (const Comm<int>& comm,
1696 const int count,
1697 const long long sendBuffer[],
1698 const int destRank);
1699template<>
1700TEUCHOSCOMM_LIB_DLL_EXPORT void
1701send<int, long long> (const long long sendBuffer[],
1702 const int count,
1703 const int destRank,
1704 const int tag,
1705 const Comm<int>& comm);
1706template<>
1707TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1708isend<int, long long> (const ArrayRCP<const long long>& sendBuffer,
1709 const int destRank,
1710 const int tag,
1711 const Comm<int>& comm);
1712
1713// Specialization for Ordinal=int and Packet=unsigned long long.
1714template<>
1715TEUCHOSCOMM_LIB_DLL_EXPORT void
1716gather<int, unsigned long long> (const unsigned long long sendBuf[],
1717 const int sendCount,
1718 unsigned long long recvBuf[],
1719 const int recvCount,
1720 const int root,
1721 const Comm<int>& comm);
1722template<>
1723TEUCHOSCOMM_LIB_DLL_EXPORT void
1724gatherv<int, unsigned long long> (const unsigned long long sendBuf[],
1725 const int sendCount,
1726 unsigned long long recvBuf[],
1727 const int recvCounts[],
1728 const int displs[],
1729 const int root,
1730 const Comm<int>& comm);
1731template<>
1732TEUCHOSCOMM_LIB_DLL_EXPORT void
1734 const EReductionType reductType,
1735 const int count,
1736 const unsigned long long sendBuffer[],
1737 unsigned long long globalReducts[]);
1738template<>
1739TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1741 const ArrayRCP<unsigned long long>& recvBuffer,
1742 const int sourceRank);
1743template<>
1744TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1746 const int sourceRank,
1747 const int tag,
1748 const Comm<int>& comm);
1749template<>
1750TEUCHOSCOMM_LIB_DLL_EXPORT void
1752 const int count,
1753 const unsigned long long sendBuffer[],
1754 const int destRank);
1755template<>
1756TEUCHOSCOMM_LIB_DLL_EXPORT void
1757send<int, unsigned long long> (const unsigned long long sendBuffer[],
1758 const int count,
1759 const int destRank,
1760 const int tag,
1761 const Comm<int>& comm);
1762template<>
1763TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1764isend<int, unsigned long long> (const ArrayRCP<const unsigned long long>& sendBuffer,
1765 const int destRank,
1766 const int tag,
1767 const Comm<int>& comm);
1768
1769// Specialization for Ordinal=int and Packet=long.
1770template<>
1771TEUCHOSCOMM_LIB_DLL_EXPORT void
1772gather<int, long> (const long sendBuf[],
1773 const int sendCount,
1774 long recvBuf[],
1775 const int recvCount,
1776 const int root,
1777 const Comm<int>& comm);
1778template<>
1779TEUCHOSCOMM_LIB_DLL_EXPORT void
1780gatherv<int, long> (const long sendBuf[],
1781 const int sendCount,
1782 long recvBuf[],
1783 const int recvCounts[],
1784 const int displs[],
1785 const int root,
1786 const Comm<int>& comm);
1787template<>
1788TEUCHOSCOMM_LIB_DLL_EXPORT void
1789reduceAll<int, long> (const Comm<int>& comm,
1790 const EReductionType reductType,
1791 const int count,
1792 const long sendBuffer[],
1793 long globalReducts[]);
1794template<>
1795TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1796ireceive<int, long> (const Comm<int>& comm,
1797 const ArrayRCP<long>& recvBuffer,
1798 const int sourceRank);
1799template<>
1800TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1801ireceive<int, long> (const ArrayRCP<long> &recvBuffer,
1802 const int sourceRank,
1803 const int tag,
1804 const Comm<int>& comm);
1805template<>
1806TEUCHOSCOMM_LIB_DLL_EXPORT void
1807send<int, long> (const Comm<int>& comm,
1808 const int count,
1809 const long sendBuffer[],
1810 const int destRank);
1811template<>
1812TEUCHOSCOMM_LIB_DLL_EXPORT void
1813send<int, long> (const long sendBuffer[],
1814 const int count,
1815 const int destRank,
1816 const int tag,
1817 const Comm<int>& comm);
1818template<>
1819TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1820isend<int, long> (const ArrayRCP<const long>& sendBuffer,
1821 const int destRank,
1822 const int tag,
1823 const Comm<int>& comm);
1824
1825// Specialization for Ordinal=int and Packet=unsigned long.
1826template<>
1827TEUCHOSCOMM_LIB_DLL_EXPORT void
1828gather<int, unsigned long> (const unsigned long sendBuf[],
1829 const int sendCount,
1830 unsigned long recvBuf[],
1831 const int recvCount,
1832 const int root,
1833 const Comm<int>& comm);
1834template<>
1835TEUCHOSCOMM_LIB_DLL_EXPORT void
1836gatherv<int, unsigned long> (const unsigned long sendBuf[],
1837 const int sendCount,
1838 unsigned long recvBuf[],
1839 const int recvCounts[],
1840 const int displs[],
1841 const int root,
1842 const Comm<int>& comm);
1843template<>
1844TEUCHOSCOMM_LIB_DLL_EXPORT void
1846 const EReductionType reductType,
1847 const int count,
1848 const unsigned long sendBuffer[],
1849 unsigned long globalReducts[]);
1850template<>
1851TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1853 const ArrayRCP<unsigned long>& recvBuffer,
1854 const int sourceRank);
1855template<>
1856TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1858 const int sourceRank,
1859 const int tag,
1860 const Comm<int>& comm);
1861template<>
1862TEUCHOSCOMM_LIB_DLL_EXPORT void
1864 const int count,
1865 const unsigned long sendBuffer[],
1866 const int destRank);
1867template<>
1868TEUCHOSCOMM_LIB_DLL_EXPORT void
1869send<int, unsigned long> (const unsigned long sendBuffer[],
1870 const int count,
1871 const int destRank,
1872 const int tag,
1873 const Comm<int>& comm);
1874template<>
1875TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1876isend<int, unsigned long> (const ArrayRCP<const unsigned long>& sendBuffer,
1877 const int destRank,
1878 const int tag,
1879 const Comm<int>& comm);
1880
1881// Specialization for Ordinal=int and Packet=int.
1882template<>
1883TEUCHOSCOMM_LIB_DLL_EXPORT void
1884gather<int, int> (const int sendBuf[],
1885 const int sendCount,
1886 int recvBuf[],
1887 const int recvCount,
1888 const int root,
1889 const Comm<int>& comm);
1890template<>
1891TEUCHOSCOMM_LIB_DLL_EXPORT void
1892gatherv<int, int> (const int sendBuf[],
1893 const int sendCount,
1894 int recvBuf[],
1895 const int recvCounts[],
1896 const int displs[],
1897 const int root,
1898 const Comm<int>& comm);
1899template<>
1900TEUCHOSCOMM_LIB_DLL_EXPORT void
1901scatter (const int sendBuf[],
1902 const int sendCount,
1903 int recvBuf[],
1904 const int recvCount,
1905 const int root,
1906 const Comm<int>& comm);
1907template<>
1908TEUCHOSCOMM_LIB_DLL_EXPORT void
1909scatterv (const double sendBuf[],
1910 const int sendCounts[],
1911 const int displs[],
1912 double recvBuf[],
1913 const int recvCount,
1914 const int root,
1915 const Comm<int>& comm);
1916template<>
1917TEUCHOSCOMM_LIB_DLL_EXPORT void
1918scatterv (const float sendBuf[],
1919 const int sendCounts[],
1920 const int displs[],
1921 float recvBuf[],
1922 const int recvCount,
1923 const int root,
1924 const Comm<int>& comm);
1925template<>
1926TEUCHOSCOMM_LIB_DLL_EXPORT void
1927reduce<int, int> (const int sendBuf[],
1928 int recvBuf[],
1929 const int count,
1930 const EReductionType reductType,
1931 const int root,
1932 const Comm<int>& comm);
1933template<>
1934TEUCHOSCOMM_LIB_DLL_EXPORT void
1935reduce<int, long> (const long sendBuf[],
1936 long recvBuf[],
1937 const int count,
1938 const EReductionType reductType,
1939 const int root,
1940 const Comm<int>& comm);
1941template<>
1942TEUCHOSCOMM_LIB_DLL_EXPORT void
1943reduce<int, unsigned long> (const unsigned long sendBuf[],
1944 unsigned long recvBuf[],
1945 const int count,
1946 const EReductionType reductType,
1947 const int root,
1948 const Comm<int>& comm);
1949template<>
1950TEUCHOSCOMM_LIB_DLL_EXPORT void
1951reduce<int, unsigned long long > (const unsigned long long sendBuf[],
1952 unsigned long long recvBuf[],
1953 const int count,
1954 const EReductionType reductType,
1955 const int root,
1956 const Comm<int>& comm);
1957template<>
1958TEUCHOSCOMM_LIB_DLL_EXPORT void
1959reduce<int, double> (const double sendBuf[],
1960 double recvBuf[],
1961 const int count,
1962 const EReductionType reductType,
1963 const int root,
1964 const Comm<int>& comm);
1965template<>
1966TEUCHOSCOMM_LIB_DLL_EXPORT void
1967reduceAll<int, int> (const Comm<int>& comm,
1968 const EReductionType reductType,
1969 const int count,
1970 const int sendBuffer[],
1971 int globalReducts[]);
1972
1973template<>
1974TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1975ireceive<int, int> (const Comm<int>& comm,
1976 const ArrayRCP<int>& recvBuffer,
1977 const int sourceRank);
1978template<>
1979TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1980ireceive<int, int> (const ArrayRCP<int> &recvBuffer,
1981 const int sourceRank,
1982 const int tag,
1983 const Comm<int>& comm);
1984template<>
1985TEUCHOSCOMM_LIB_DLL_EXPORT void
1986send<int, int> (const Comm<int>& comm,
1987 const int count,
1988 const int sendBuffer[],
1989 const int destRank);
1990template<>
1991TEUCHOSCOMM_LIB_DLL_EXPORT void
1992send<int, int> (const int sendBuffer[],
1993 const int count,
1994 const int destRank,
1995 const int tag,
1996 const Comm<int>& comm);
1997template<>
1998TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
1999isend<int, int> (const ArrayRCP<const int>& sendBuffer,
2000 const int destRank,
2001 const int tag,
2002 const Comm<int>& comm);
2003
2004// Specialization for Ordinal=int and Packet=unsigned int.
2005template<>
2006TEUCHOSCOMM_LIB_DLL_EXPORT void
2007gather<int, unsigned int> (const unsigned int sendBuf[],
2008 const int sendCount,
2009 unsigned int recvBuf[],
2010 const int recvCount,
2011 const int root,
2012 const Comm<int>& comm);
2013template<>
2014TEUCHOSCOMM_LIB_DLL_EXPORT void
2015gatherv<int, unsigned int> (const unsigned int sendBuf[],
2016 const int sendCount,
2017 unsigned int recvBuf[],
2018 const int recvCounts[],
2019 const int displs[],
2020 const int root,
2021 const Comm<int>& comm);
2022template<>
2023TEUCHOSCOMM_LIB_DLL_EXPORT void
2025 const EReductionType reductType,
2026 const int count,
2027 const unsigned int sendBuffer[],
2028 unsigned int globalReducts[]);
2029template<>
2030TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2032 const ArrayRCP<unsigned int>& recvBuffer,
2033 const int sourceRank);
2034template<>
2035TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2037 const int sourceRank,
2038 const int tag,
2039 const Comm<int>& comm);
2040template<>
2041TEUCHOSCOMM_LIB_DLL_EXPORT void
2043 const int count,
2044 const unsigned int sendBuffer[],
2045 const int destRank);
2046template<>
2047TEUCHOSCOMM_LIB_DLL_EXPORT void
2048send<int, unsigned int> (const unsigned int sendBuffer[],
2049 const int count,
2050 const int destRank,
2051 const int tag,
2052 const Comm<int>& comm);
2053template<>
2054TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2055isend<int, unsigned int> (const ArrayRCP<const unsigned int>& sendBuffer,
2056 const int destRank,
2057 const int tag,
2058 const Comm<int>& comm);
2059
2060// Specialization for Ordinal=int and Packet=short.
2061template<>
2062TEUCHOSCOMM_LIB_DLL_EXPORT void
2063gather<int, short> (const short sendBuf[],
2064 const int sendCount,
2065 short recvBuf[],
2066 const int recvCount,
2067 const int root,
2068 const Comm<int>& comm);
2069template<>
2070TEUCHOSCOMM_LIB_DLL_EXPORT void
2071gatherv<int, short> (const short sendBuf[],
2072 const int sendCount,
2073 short recvBuf[],
2074 const int recvCounts[],
2075 const int displs[],
2076 const int root,
2077 const Comm<int>& comm);
2078template<>
2079TEUCHOSCOMM_LIB_DLL_EXPORT void
2080reduceAll<int, short> (const Comm<int>& comm,
2081 const EReductionType reductType,
2082 const int count,
2083 const short sendBuffer[],
2084 short globalReducts[]);
2085template<>
2086TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2087ireceive<int, short> (const Comm<int>& comm,
2088 const ArrayRCP<short>& recvBuffer,
2089 const int sourceRank);
2090template<>
2091TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2092ireceive<int, short> (const ArrayRCP<short> &recvBuffer,
2093 const int sourceRank,
2094 const int tag,
2095 const Comm<int>& comm);
2096template<>
2097TEUCHOSCOMM_LIB_DLL_EXPORT void
2098send<int, short> (const Comm<int>& comm,
2099 const int count,
2100 const short sendBuffer[],
2101 const int destRank);
2102template<>
2103TEUCHOSCOMM_LIB_DLL_EXPORT void
2104send<int, short> (const short sendBuffer[],
2105 const int count,
2106 const int destRank,
2107 const int tag,
2108 const Comm<int>& comm);
2109template<>
2110TEUCHOSCOMM_LIB_DLL_EXPORT RCP<CommRequest<int> >
2111isend<int, short> (const ArrayRCP<const short>& sendBuffer,
2112 const int destRank,
2113 const int tag,
2114 const Comm<int>& comm);
2115
2116// mfh 18 Oct 2012: The specialization for Packet=char seems to be
2117// causing problems such as the following:
2118//
2119// http://testing.sandia.gov/cdash/testDetails.php?test=9909246&build=747699
2120//
2121// I am disabling it for now. This should revert back to the old
2122// behavior for Packet=char. That should fix the Tpetra errors, since
2123// many Tpetra objects inherit from DistObject<char, ...>.
2124#if 0
2125// Specialization for Ordinal=int and Packet=char.
2126template<>
2127TEUCHOSCOMM_LIB_DLL_EXPORT void
2128reduceAll<int, char> (const Comm<int>& comm,
2129 const EReductionType reductType,
2130 const int count,
2131 const char sendBuffer[],
2132 char globalReducts[]);
2133#endif // 0
2134} // namespace Teuchos
2135
2136
2137template<typename Ordinal, typename Packet>
2139 const Comm<Ordinal>& comm, const EReductionType reductType
2140 ,const Packet &send, const Ptr<Packet> &globalReduct
2141 )
2142{
2143 // mfh 17 Oct 2012: This will invoke the above specializations for
2144 // general count, so we don't need to specialize this function.
2145 reduceAll<Ordinal,Packet>(comm, reductType, 1, &send, &*globalReduct);
2146}
2147
2148
2149template<typename Ordinal, typename Packet>
2151 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2153 const Ordinal count, const Packet*const sendBuffer[], Packet*const globalReducts[]
2154 )
2155{
2156 TEUCHOS_COMM_TIME_MONITOR(
2157 "Teuchos::CommHelpers: reduceAll<"
2159 <<">( reference type )"
2160 );
2162 charSendBuffer(serializer,count,sendBuffer);
2164 charGlobalReducts(serializer,count,globalReducts);
2166 charReductOp(rcp(&serializer,false),rcp(&reductOp,false));
2167 comm.reduceAll(
2168 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2169 ,charGlobalReducts.getCharBuffer()
2170 );
2171}
2172
2173template<typename Ordinal, typename Packet, typename Serializer>
2175 const Comm<Ordinal>& comm,
2176 const Serializer& serializer,
2178 const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
2179 )
2180{
2181 TEUCHOS_COMM_TIME_MONITOR(
2182 "Teuchos::CommHelpers: reduceAll<"
2184 <<">( value type, user-defined op )"
2185 );
2187 charSendBuffer(count,sendBuffer,rcp(&serializer,false));
2189 charGlobalReducts(count,globalReducts,rcp(&serializer,false));
2191 charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
2192 comm.reduceAll(
2193 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2194 ,charGlobalReducts.getCharBuffer()
2195 );
2196}
2197
2198
2199template<typename Ordinal, typename Packet, typename Serializer>
2201 const Comm<Ordinal>& comm,
2202 const Serializer& serializer,
2203 const EReductionType reductType,
2204 const Ordinal count, const Packet sendBuffer[], Packet globalReducts[]
2205 )
2206{
2207 TEUCHOS_COMM_TIME_MONITOR(
2208 "Teuchos::CommHelpers: reduceAll<"
2210 <<">( value type, "<<toString(reductType)<<" )"
2211 );
2212
2214 createOp<Ordinal, Packet> (reductType);
2215 try {
2216 reduceAll(comm,serializer,*reductOp,count,sendBuffer,globalReducts);
2217 }
2218 catch (std::exception& e) {
2219 delete reductOp;
2220 throw e;
2221 }
2222 delete reductOp;
2223}
2224
2225
2226template<typename Ordinal, typename Packet>
2228 const Comm<Ordinal>& comm, const ValueTypeReductionOp<Ordinal,Packet> &reductOp,
2229 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2230 )
2231{
2232 TEUCHOS_COMM_TIME_MONITOR(
2233 "Teuchos::CommHelpers: scan<"
2235 <<">( value type, user-defined op )"
2236 );
2238 charSendBuffer(count,sendBuffer);
2240 charScanReducts(count,scanReducts);
2242 charReductOp(rcp(&reductOp,false));
2243 comm.scan(
2244 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2245 ,charScanReducts.getCharBuffer()
2246 );
2247}
2248
2249
2250template<typename Ordinal, typename Packet>
2252 const Comm<Ordinal>& comm, const EReductionType reductType,
2253 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2254 )
2255{
2256 TEUCHOS_COMM_TIME_MONITOR(
2257 "Teuchos::CommHelpers: scan<"
2259 <<">( value type, "<<toString(reductType)<<" )"
2260 );
2261
2263 createOp<Ordinal, Packet> (reductType);
2264 try {
2265 scan(comm,*reductOp,count,sendBuffer,scanReducts);
2266 }
2267 catch (std::exception& e) {
2268 delete reductOp;
2269 throw e;
2270 }
2271 delete reductOp;
2272}
2273
2274
2275template<typename Ordinal, typename Packet>
2277 const Comm<Ordinal>& comm, const EReductionType reductType,
2278 const Packet &send, const Ptr<Packet> &scanReduct
2279 )
2280{
2281 scan<Ordinal,Packet>(comm, reductType, 1, &send, &*scanReduct);
2282}
2283
2284
2285template<typename Ordinal, typename Packet>
2287 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2289 const Ordinal count, const Packet*const sendBuffer[], Packet*const scanReducts[]
2290 )
2291{
2292 TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2293}
2294
2295template<typename Ordinal, typename Packet, typename Serializer>
2297 const Comm<Ordinal>& comm,
2298 const Serializer& serializer,
2300 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2301 )
2302{
2303 TEUCHOS_COMM_TIME_MONITOR(
2304 "Teuchos::CommHelpers: scan<"
2306 <<">( value type, user-defined op )"
2307 );
2309 charSendBuffer(count,sendBuffer,rcp(&serializer,false));
2311 charScanReducts(count,scanReducts,rcp(&serializer,false));
2313 charReductOp(rcp(&reductOp,false),rcp(&serializer,false));
2314 comm.scan(
2315 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2316 ,charScanReducts.getCharBuffer()
2317 );
2318}
2319
2320
2321template<typename Ordinal, typename Packet, typename Serializer>
2323 const Comm<Ordinal>& comm,
2324 const Serializer& serializer,
2325 const EReductionType reductType,
2326 const Ordinal count, const Packet sendBuffer[], Packet scanReducts[]
2327 )
2328{
2329 TEUCHOS_COMM_TIME_MONITOR(
2330 "Teuchos::CommHelpers: scan<"
2332 <<">( value type, "<<toString(reductType)<<" )"
2333 );
2334
2336 createOp<Ordinal, Packet> (reductType);
2337 try {
2338 scan(comm,serializer,*reductOp,count,sendBuffer,scanReducts);
2339 }
2340 catch (std::exception& e) {
2341 delete reductOp;
2342 throw e;
2343 }
2344 delete reductOp;
2345}
2346
2347template<typename Ordinal, typename Packet>
2349 const Comm<Ordinal>& comm,
2350 const Ordinal count, const Packet sendBuffer[], const int destRank
2351 )
2352{
2353 TEUCHOS_COMM_TIME_MONITOR(
2354 "Teuchos::CommHelpers: send<"
2356 <<">( value type )"
2357 );
2359 charSendBuffer(count,sendBuffer);
2360 comm.send(
2361 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2362 ,destRank
2363 );
2364}
2365
2366template<typename Ordinal, typename Packet>
2367void
2368Teuchos::send (const Packet sendBuffer[],
2369 const Ordinal count,
2370 const int destRank,
2371 const int tag,
2372 const Comm<Ordinal>& comm)
2373{
2374 TEUCHOS_COMM_TIME_MONITOR(
2375 "Teuchos::CommHelpers: send<"
2377 <<">( value type )"
2378 );
2379 ConstValueTypeSerializationBuffer<Ordinal,Packet> charSendBuffer (count, sendBuffer);
2380 comm.send (charSendBuffer.getBytes (), charSendBuffer.getCharBuffer (), destRank, tag);
2381}
2382
2383template<typename Ordinal, typename Packet>
2385 const Comm<Ordinal>& comm,
2386 const Ordinal count, const Packet sendBuffer[], const int destRank
2387 )
2388{
2389 TEUCHOS_COMM_TIME_MONITOR(
2390 "Teuchos::CommHelpers: ssend<"
2392 <<">( value type )"
2393 );
2395 charSendBuffer(count,sendBuffer);
2396 comm.ssend(
2397 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2398 ,destRank
2399 );
2400}
2401
2402template<typename Ordinal, typename Packet>
2403void
2404Teuchos::ssend (const Packet sendBuffer[],
2405 const Ordinal count,
2406 const int destRank,
2407 const int tag,
2408 const Comm<Ordinal>& comm)
2409{
2410 TEUCHOS_COMM_TIME_MONITOR(
2411 "Teuchos::CommHelpers: ssend<"
2413 <<">( value type )"
2414 );
2416 buf_type charSendBuffer (count, sendBuffer);
2417 comm.ssend (charSendBuffer.getBytes (),
2418 charSendBuffer.getCharBuffer (),
2419 destRank, tag);
2420}
2421
2422template<typename Ordinal, typename Packet>
2424 const Comm<Ordinal>& comm,
2425 const Packet &send, const int destRank
2426 )
2427{
2428 Teuchos::send<Ordinal,Packet>(comm,1,&send,destRank);
2429}
2430
2431template<typename Ordinal, typename Packet>
2433 const Comm<Ordinal>& comm,
2434 const Packet &send, const int destRank
2435 )
2436{
2437 Teuchos::ssend<Ordinal,Packet>(comm,1,&send,destRank);
2438}
2439
2440template<typename Ordinal, typename Packet>
2442 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2443 const Ordinal count, const Packet*const sendBuffer[], const int destRank
2444 )
2445{
2446 TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2447}
2448
2449template<typename Ordinal, typename Packet, typename Serializer>
2451 const Comm<Ordinal>& comm,
2452 const Serializer& serializer,
2453 const Ordinal count, const Packet sendBuffer[], const int destRank
2454 )
2455{
2456 TEUCHOS_COMM_TIME_MONITOR(
2457 "Teuchos::CommHelpers: send<"
2459 <<">( value type )"
2460 );
2462 charSendBuffer(count,sendBuffer,rcp(&serializer,false));
2463 comm.send(
2464 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2465 ,destRank
2466 );
2467}
2468
2469template<typename Ordinal, typename Packet>
2471 const Comm<Ordinal>& comm,
2472 const int sourceRank, const Ordinal count, Packet recvBuffer[]
2473 )
2474{
2475 TEUCHOS_COMM_TIME_MONITOR(
2476 "Teuchos::CommHelpers: receive<"
2478 <<">( value type )"
2479 );
2481 charRecvBuffer(count,recvBuffer);
2482 return comm.receive(
2483 sourceRank
2484 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
2485 );
2486}
2487
2488
2489template<typename Ordinal, typename Packet>
2491 const Comm<Ordinal>& comm,
2492 const int sourceRank, Packet *recv
2493 )
2494{
2495 return Teuchos::receive<Ordinal,Packet>(comm,sourceRank,1,recv);
2496}
2497
2498
2499template<typename Ordinal, typename Packet>
2501 const Comm<Ordinal>& comm, const Serializer<Ordinal,Packet> &serializer,
2502 const int sourceRank, const Ordinal count, Packet*const recvBuffer[]
2503 )
2504{
2505 TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement and test when needed!
2506}
2507
2508template<typename Ordinal, typename Packet, typename Serializer>
2510 const Comm<Ordinal>& comm,
2511 const Serializer& serializer,
2512 const int sourceRank, const Ordinal count, Packet recvBuffer[]
2513 )
2514{
2515 TEUCHOS_COMM_TIME_MONITOR(
2516 "Teuchos::CommHelpers: receive<"
2518 <<">( value type )"
2519 );
2521 charRecvBuffer(count,recvBuffer,rcp(&serializer,false));
2522 return comm.receive(
2523 sourceRank
2524 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
2525 );
2526}
2527
2528template<typename Ordinal, typename Packet>
2530 const Comm<Ordinal>& comm,
2531 const ArrayView<const Packet> &sendBuffer,
2532 const int destRank
2533 )
2534{
2535 TEUCHOS_COMM_TIME_MONITOR(
2536 "Teuchos::CommHelpers: readySend<"
2538 <<">( value type )"
2539 );
2541 charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr());
2542 comm.readySend( charSendBuffer.getCharBufferView(), destRank );
2543}
2544
2545template<typename Ordinal, typename Packet>
2546void
2547Teuchos::readySend (const Packet sendBuffer[],
2548 const Ordinal count,
2549 const int destRank,
2550 const int tag,
2551 const Comm<Ordinal>& comm)
2552{
2553 TEUCHOS_COMM_TIME_MONITOR(
2554 "Teuchos::CommHelpers: readySend<"
2556 <<">( value type )"
2557 );
2559 buf_type charSendBuffer (count, sendBuffer);
2560 comm.readySend (charSendBuffer.getBytes (),
2561 charSendBuffer.getCharBuffer (),
2562 destRank, tag);
2563}
2564
2565template<typename Ordinal, typename Packet>
2567 const Comm<Ordinal>& comm,
2568 const Packet &send,
2569 const int destRank
2570 )
2571{
2572 readySend<Ordinal, Packet>( comm, arrayView(&send,1), destRank );
2573}
2574
2575template<typename Ordinal, typename Packet, typename Serializer>
2577 const Comm<Ordinal>& comm,
2578 const Serializer& serializer,
2579 const ArrayView<const Packet> &sendBuffer,
2580 const int destRank
2581 )
2582{
2583 TEUCHOS_COMM_TIME_MONITOR(
2584 "Teuchos::CommHelpers: readySend<"
2586 <<">( value type )"
2587 );
2589 charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr(), serializer);
2590 comm.readySend( charSendBuffer.getCharBufferView(), destRank );
2591}
2592
2593template<typename Ordinal, typename Packet>
2595Teuchos::isend(
2596 const Comm<Ordinal>& comm,
2597 const ArrayRCP<const Packet> &sendBuffer,
2598 const int destRank
2599 )
2600{
2601 TEUCHOS_COMM_TIME_MONITOR(
2602 "Teuchos::CommHelpers: isend<"
2604 <<">( value type )"
2605 );
2607 charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr());
2608 RCP<CommRequest<Ordinal> > commRequest = comm.isend(
2609 charSendBuffer.getCharBufferView(), destRank );
2610 set_extra_data( sendBuffer, "buffer", inOutArg(commRequest) );
2611 return commRequest;
2612}
2613
2614template<typename Ordinal, typename Packet>
2616Teuchos::isend (const ArrayRCP<const Packet> &sendBuffer,
2617 const int destRank,
2618 const int tag,
2619 const Comm<Ordinal>& comm)
2620{
2621 TEUCHOS_COMM_TIME_MONITOR(
2622 "Teuchos::isend<" << OrdinalTraits<Ordinal>::name () << ","
2623 << TypeNameTraits<Packet>::name () << ">");
2624 ConstValueTypeSerializationBuffer<Ordinal,Packet>
2625 charSendBuffer (sendBuffer.size (), sendBuffer.getRawPtr ());
2626 RCP<CommRequest<Ordinal> > commRequest =
2627 comm.isend (charSendBuffer.getCharBufferView (), destRank, tag);
2628 set_extra_data (sendBuffer, "buffer", inOutArg (commRequest));
2629 return commRequest;
2630}
2631
2632template<typename Ordinal, typename Packet>
2634Teuchos::isend(
2635 const Comm<Ordinal>& comm,
2636 const RCP<const Packet> &send,
2637 const int destRank
2638 )
2639{
2640 const ArrayRCP<const Packet> sendBuffer =
2641 arcpWithEmbeddedObj( send.get(), 0, 1, send, false );
2642 // 2008/07/29: rabartl: Above: I need to write a helper function to create
2643 // new ArrayRCP object given a single object to copy.
2644 return isend<Ordinal, Packet>( comm, sendBuffer, destRank );
2645}
2646
2647template<typename Ordinal, typename Packet, typename Serializer>
2649Teuchos::isend(
2650 const Comm<Ordinal>& comm,
2651 const Serializer& serializer,
2652 const ArrayRCP<const Packet> &sendBuffer,
2653 const int destRank
2654 )
2655{
2656 TEUCHOS_COMM_TIME_MONITOR(
2657 "Teuchos::CommHelpers: isend<"
2658 <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2659 <<">( value type )"
2660 );
2661 ConstValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
2662 charSendBuffer(sendBuffer.size(), sendBuffer.getRawPtr(), serializer);
2663 RCP<CommRequest<Ordinal> > commRequest = comm.isend(
2664 charSendBuffer.getCharBufferView(), destRank );
2665 set_extra_data( sendBuffer, "buffer", inOutArg(commRequest) );
2666 return commRequest;
2667}
2668
2669template<typename Ordinal, typename Packet>
2672 const Comm<Ordinal>& comm,
2673 const ArrayRCP<Packet> &recvBuffer,
2674 const int sourceRank
2675 )
2676{
2677 TEUCHOS_COMM_TIME_MONITOR(
2678 "Teuchos::ireceive<int, " << "," << TypeNameTraits<Packet>::name () << ">");
2679 ValueTypeSerializationBuffer<Ordinal,Packet>
2680 charRecvBuffer(recvBuffer.size(), recvBuffer.getRawPtr());
2681 RCP<CommRequest<Ordinal> > commRequest = comm.ireceive(
2682 charRecvBuffer.getCharBufferView(), sourceRank );
2683 set_extra_data( recvBuffer, "buffer", inOutArg(commRequest) );
2684 return commRequest;
2685}
2686
2687template<typename Ordinal, typename Packet>
2690 const int sourceRank,
2691 const int tag,
2692 const Teuchos::Comm<Ordinal>& comm)
2693{
2694 TEUCHOS_COMM_TIME_MONITOR(
2695 "Teuchos::ireceive<int, " << "," << TypeNameTraits<Packet>::name () << ">");
2696 ValueTypeSerializationBuffer<int, Packet>
2697 charRecvBuffer (recvBuffer.size (), recvBuffer.getRawPtr ());
2698 RCP<CommRequest<int> > commRequest =
2699 comm.ireceive (charRecvBuffer.getCharBufferView (), sourceRank, tag);
2700 set_extra_data (recvBuffer, "buffer", inOutArg (commRequest));
2701 return commRequest;
2702}
2703
2704template<typename Ordinal, typename Packet>
2707 const Comm<Ordinal>& comm,
2708 const RCP<Packet> &recv,
2709 const int sourceRank
2710 )
2711{
2712 const ArrayRCP<Packet> recvBuffer =
2713 arcpWithEmbeddedObj( recv.get(), 0, 1, recv, false );
2714 // 2008/07/29: rabartl: Above: I need to write a helper function to create
2715 // new ArrayRCP object given a single object to copy.
2716 return ireceive<Ordinal, Packet>( comm, recvBuffer, sourceRank );
2717}
2718
2719template<typename Ordinal, typename Packet, typename Serializer>
2722 const Comm<Ordinal>& comm,
2723 const Serializer& serializer,
2724 const ArrayRCP<Packet> &recvBuffer,
2725 const int sourceRank
2726 )
2727{
2728 TEUCHOS_COMM_TIME_MONITOR(
2729 "Teuchos::CommHelpers: ireceive<"
2730 <<OrdinalTraits<Ordinal>::name()<<","<<TypeNameTraits<Packet>::name()
2731 <<">( value type )"
2732 );
2733 ValueTypeSerializationBuffer<Ordinal,Packet,Serializer>
2734 charRecvBuffer(recvBuffer.size(), recvBuffer.getRawPtr(), serializer);
2735 RCP<CommRequest<Ordinal> > commRequest = comm.ireceive(
2736 charRecvBuffer.getCharBufferView(), sourceRank );
2737 set_extra_data( recvBuffer, "buffer", inOutArg(commRequest) );
2738 return commRequest;
2739}
2740
2741template<typename Ordinal>
2743 const Comm<Ordinal>& comm,
2744 const ArrayView<RCP<CommRequest<Ordinal> > > &requests
2745 )
2746{
2747 comm.waitAll(requests);
2748}
2749
2750
2751template<typename Ordinal>
2752void
2754 const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
2755 const ArrayView<RCP<CommStatus<Ordinal> > >& statuses)
2756{
2757 comm.waitAll (requests, statuses);
2758}
2759
2760
2761template<typename Ordinal>
2763Teuchos::wait (const Comm<Ordinal>& comm,
2764 const Ptr<RCP<CommRequest<Ordinal> > > &request)
2765{
2766 return comm.wait (request);
2767}
2768
2769
2770#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
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.
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)
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 ...
Encapsulation of a pending nonblocking communication operation.
Encapsulation of the result of a receive (blocking or nonblocking).
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 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.
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.
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.
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.