42 #ifndef TEUCHOS_COMM_HELPERS_HPP 43 #define TEUCHOS_COMM_HELPERS_HPP 87 const char*
toString(
const EReductionType reductType )
103 template<
typename Ordinal>
110 template<
typename Ordinal>
117 template<
typename Ordinal>
124 template<
typename Ordinal,
typename Packet>
128 const Ordinal count, Packet buffer[]
135 template<
typename Ordinal,
typename Packet>
146 template<
typename Ordinal,
typename Packet>
149 const int rootRank, Packet *
object 156 template<
typename Ordinal,
typename Packet>
166 template<
typename Ordinal,
typename Packet>
169 const int rootRank,
const Ordinal count, Packet*
const buffer[]
176 template<
typename Ordinal,
typename Packet>
187 template<
typename Ordinal,
typename Packet,
typename Serializer>
192 const Ordinal count, Packet buffer[]
199 template<
typename Ordinal,
typename Packet>
201 gather (
const Packet sendBuf[],
202 const Ordinal sendCount,
204 const Ordinal recvCount,
212 template<
typename Ordinal,
typename Packet>
214 gatherv (
const Packet sendBuf[],
215 const Ordinal sendCount,
217 const Ordinal recvCounts[],
218 const Ordinal displs[],
227 template<
typename Ordinal,
typename Packet>
230 const Ordinal sendCount,
const Packet sendBuffer[],
231 const Ordinal recvCount, Packet recvBuffer[]
239 template<
typename Ordinal,
typename Packet>
242 const Ordinal sendCount,
const Packet*
const sendBuffer[],
243 const Ordinal recvCount, Packet*
const recvBuffer[]
251 template<
typename Ordinal,
typename Packet,
typename Serializer>
255 const Ordinal sendCount,
const Packet sendBuffer[],
256 const Ordinal recvCount, Packet recvBuffer[]
264 template<
typename Ordinal,
typename Packet>
267 const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
275 template<
typename Ordinal,
typename Packet>
278 const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
286 template<
typename Ordinal,
typename Packet>
293 template<
typename Ordinal,
typename Packet>
296 const Packet &send, Packet *globalReduct
299 reduceAll<Ordinal,Packet>(comm, reductType,
send, ptr(globalReduct));
307 template<
typename Ordinal,
typename Packet>
311 const Ordinal count,
const Packet*
const sendBuffer[], Packet*
const globalReducts[]
319 template<
typename Ordinal,
typename Packet,
typename Serializer>
324 const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
332 template<
typename Ordinal,
typename Packet,
typename Serializer>
336 const EReductionType reductType,
337 const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
345 template<
typename Ordinal,
typename Packet>
346 void reduceAllAndScatter(
348 const Ordinal sendCount,
const Packet sendBuffer[] ,
349 const Ordinal recvCounts[], Packet myGlobalReducts[]
357 template<
typename Ordinal,
typename Packet>
358 void reduceAllAndScatter(
360 const Ordinal sendCount,
const Packet sendBuffer[] ,
361 const Ordinal recvCounts[], Packet myGlobalReducts[]
369 template<
typename Ordinal,
typename Packet>
370 void reduceAllAndScatter(
373 const Ordinal sendCount,
const Packet*
const sendBuffer[] ,
374 const Ordinal recvCounts[], Packet*
const myGlobalReducts[]
382 template<
typename Ordinal,
typename Packet>
385 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
393 template<
typename Ordinal,
typename Packet,
typename Serializer>
394 void reduceAllAndScatter(
398 const Ordinal sendCount,
const Packet sendBuffer[],
399 const Ordinal recvCounts[], Packet myGlobalReducts[]
407 template<
typename Ordinal,
typename Packet,
typename Serializer>
408 void reduceAllAndScatter(
411 const EReductionType reductType,
412 const Ordinal sendCount,
const Packet sendBuffer[] ,
413 const Ordinal recvCounts[], Packet myGlobalReducts[]
421 template<
typename Ordinal,
typename Packet>
424 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
432 template<
typename Ordinal,
typename Packet>
439 template<
typename Ordinal,
typename Packet>
442 const Packet &send, Packet *scanReduct
445 scan(comm, reductType, send, ptr(scanReduct));
453 template<
typename Ordinal,
typename Packet>
457 const Ordinal count,
const Packet*
const sendBuffer[], Packet*
const scanReducts[]
465 template<
typename Ordinal,
typename Packet,
typename Serializer>
470 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
478 template<
typename Ordinal,
typename Packet,
typename Serializer>
482 const EReductionType reductType,
483 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
490 template<
typename Ordinal,
typename Packet>
493 const Ordinal count,
const Packet sendBuffer[],
const int destRank
497 template<
typename Ordinal,
typename Packet>
499 send (
const Packet sendBuffer[],
509 template<
typename Ordinal,
typename Packet>
512 const Ordinal count,
const Packet sendBuffer[],
const int destRank
516 template<
typename Ordinal,
typename Packet>
518 ssend (
const Packet sendBuffer[],
528 template<
typename Ordinal,
typename Packet>
531 const Packet &send,
const int destRank
538 template<
typename Ordinal,
typename Packet>
541 const Packet &send,
const int destRank
550 template<
typename Ordinal,
typename Packet>
553 const Ordinal count,
const Packet*
const sendBuffer[],
const int destRank
561 template<
typename Ordinal,
typename Packet,
typename Serializer>
565 const Ordinal count,
const Packet sendBuffer[],
const int destRank
572 template<
typename Ordinal,
typename Packet>
575 const int sourceRank,
const Ordinal count, Packet recvBuffer[]
582 template<
typename Ordinal,
typename Packet>
585 const int sourceRank, Packet *recv
592 template<
typename Ordinal,
typename Packet>
595 const int sourceRank,
const Ordinal count, Packet*
const recvBuffer[]
603 template<
typename Ordinal,
typename Packet,
typename Serializer>
607 const int sourceRank,
const Ordinal count, Packet recvBuffer[]
615 template<
typename Ordinal,
typename Packet>
623 template<
typename Ordinal,
typename Packet>
635 template<
typename Ordinal,
typename Packet>
647 template<
typename Ordinal,
typename Packet,
typename Serializer>
659 template<
typename Ordinal,
typename Packet>
667 template<
typename Ordinal,
typename Packet>
678 template<
typename Ordinal,
typename Packet>
690 template<
typename Ordinal,
typename Packet,
typename Serializer>
711 template<
typename Ordinal,
typename Packet>
719 template<
typename Ordinal,
typename Packet>
722 const int sourceRank,
737 template<
typename Ordinal,
typename Packet>
749 template<
typename Ordinal,
typename Packet,
typename Serializer>
768 template<
typename Ordinal>
803 template<
typename Ordinal>
832 template<
typename Ordinal>
845 template<
typename Ordinal,
typename Packet>
852 const Packet inBuffer[],
866 template<
typename Ordinal,
typename Packet>
873 const Packet inBuffer[],
887 template<
typename Ordinal,
typename Packet>
894 const Packet inBuffer[],
904 template<
typename Ordinal,
typename Packet>
911 const Packet inBuffer[],
926 namespace MixMaxUtilities {
929 template<
bool isComparable,
typename Ordinal,
typename Packet>
933 template<
typename Ordinal,
typename Packet>
934 class Min<true,Ordinal,Packet> {
938 const Packet inBuffer[],
942 for(
int i = 0; i < count; ++i )
943 inoutBuffer[i] =
TEUCHOS_MIN(inoutBuffer[i],inBuffer[i]);
948 template<
typename Ordinal,
typename Packet>
949 class Min<false,Ordinal,Packet> {
958 true,std::logic_error,
960 <<
" does not support comparison operations!" 966 template<
bool isComparable,
typename Ordinal,
typename Packet>
970 template<
typename Ordinal,
typename Packet>
971 class Max<true,Ordinal,Packet> {
975 const Packet inBuffer[],
979 for(
int i = 0; i < count; ++i )
980 inoutBuffer[i] =
TEUCHOS_MAX(inoutBuffer[i],inBuffer[i]);
985 template<
typename Ordinal,
typename Packet>
986 class Max<false,Ordinal,Packet> {
995 true,std::logic_error,
997 <<
" does not support comparison operations!" 1003 template<
bool isComparable,
typename Ordinal,
typename Packet>
1007 template<
typename Ordinal,
typename Packet>
1008 class AND<true,Ordinal,Packet> {
1011 const Ordinal count,
1012 const Packet inBuffer[],
1013 Packet inoutBuffer[]
1016 for(
int i = 0; i < count; ++i )
1017 inoutBuffer[i] = inoutBuffer[i] && inBuffer[i];
1022 template<
typename Ordinal,
typename Packet>
1023 class AND<false,Ordinal,Packet> {
1032 true,std::logic_error,
1034 <<
" does not support logical AND operations!" 1043 template<
typename Ordinal,
typename Packet>
1045 const Ordinal count,
1046 const Packet inBuffer[],
1047 Packet inoutBuffer[]
1050 for(
int i = 0; i < count; ++i )
1051 inoutBuffer[i] += inBuffer[i];
1055 template<
typename Ordinal,
typename Packet>
1057 const Ordinal count,
1058 const Packet inBuffer[],
1059 Packet inoutBuffer[]
1063 min_type::min (count, inBuffer, inoutBuffer);
1067 template<
typename Ordinal,
typename Packet>
1069 const Ordinal count,
1070 const Packet inBuffer[],
1071 Packet inoutBuffer[]
1075 max_type::max (count,inBuffer,inoutBuffer);
1079 template<
typename Ordinal,
typename Packet>
1081 const Ordinal count,
1082 const Packet inBuffer[],
1083 Packet inoutBuffer[]
1087 and_type::andOp (count, inBuffer, inoutBuffer);
1110 template<
typename Ordinal,
typename Packet>
1115 switch(reductType) {
1149 template<
typename Ordinal>
1156 template<
typename Ordinal>
1163 template<
typename Ordinal>
1167 "Teuchos::CommHelpers: barrier<" 1175 template<
typename Ordinal,
typename Packet>
1176 void Teuchos::broadcast(
1178 const int rootRank,
const Ordinal count, Packet buffer[]
1182 "Teuchos::CommHelpers: broadcast<" 1187 charBuffer(count,buffer);
1189 rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1194 template<
typename Ordinal,
typename Packet>
1195 void Teuchos::broadcast(
1201 broadcast<Ordinal, Packet>(comm, rootRank, buffer.
size(), buffer.
getRawPtr() );
1205 template<
typename Ordinal,
typename Packet>
1206 void Teuchos::broadcast(
1208 const int rootRank, Packet *
object 1211 broadcast<Ordinal,Packet>(comm,rootRank,1,object);
1215 template<
typename Ordinal,
typename Packet>
1216 void Teuchos::broadcast(
1221 broadcast<Ordinal,Packet>(comm,rootRank,1,
object.getRawPtr());
1225 template<
typename Ordinal,
typename Packet>
1226 void Teuchos::broadcast(
1228 const int rootRank,
const Ordinal count, Packet*
const buffer[]
1232 "Teuchos::CommHelpers: broadcast<" 1234 <<
">( reference type )" 1237 charBuffer(serializer, count, buffer);
1244 template<
typename Ordinal,
typename Packet>
1245 void Teuchos::broadcast(
1251 for (
int i = 0; i < buffer.
size(); ++i) {
1254 broadcast<Ordinal,Packet>(comm, serializer, rootRank,
1258 template<
typename Ordinal,
typename Packet,
typename Serializer>
1259 void Teuchos::broadcast(
1262 const int rootRank,
const Ordinal count, Packet buffer[]
1266 "Teuchos::CommHelpers: broadcast<" 1271 charBuffer(count,buffer,
rcp(&serializer,
false));
1273 rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1278 template<
typename Ordinal,
typename Packet>
1279 void Teuchos::gatherAll(
1281 const Ordinal sendCount,
const Packet sendBuffer[],
1282 const Ordinal recvCount, Packet recvBuffer[]
1286 "Teuchos::CommHelpers: gatherAll<" 1291 charSendBuffer(sendCount,sendBuffer);
1293 charRecvBuffer(recvCount,recvBuffer);
1295 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1296 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
1300 template<
typename Ordinal,
typename Packet>
1302 Teuchos::gather (
const Packet sendBuf[],
1303 const Ordinal sendCount,
1305 const Ordinal recvCount,
1310 "Teuchos::CommHelpers: gather<" 1315 charSendBuffer (sendCount, sendBuf);
1317 charRecvBuffer (recvCount, recvBuf);
1318 comm.
gather (charSendBuffer.getBytes (),
1319 charSendBuffer.getCharBuffer (),
1320 charRecvBuffer.getBytes (),
1321 charRecvBuffer.getCharBuffer (),
1325 template<
typename Ordinal,
typename Packet>
1327 Teuchos::gatherv (
const Packet sendBuf[],
1328 const Ordinal sendCount,
1330 const Ordinal recvCounts[],
1331 const Ordinal displs[],
1356 "Teuchos::gatherv: The general case is not implemented.");
1359 template<
typename Ordinal,
typename Packet>
1360 void Teuchos::gatherAll(
1362 const Ordinal sendCount,
const Packet*
const sendBuffer[],
1363 const Ordinal recvCount, Packet*
const recvBuffer[]
1369 template<
typename Ordinal,
typename Packet,
typename Serializer>
1370 void Teuchos::gatherAll(
1373 const Ordinal sendCount,
const Packet sendBuffer[],
1374 const Ordinal recvCount, Packet recvBuffer[]
1378 "Teuchos::CommHelpers: gatherAll<" 1383 charSendBuffer(sendCount,sendBuffer,
rcp(&serializer,
false));
1385 charRecvBuffer(recvCount,recvBuffer,
rcp(&serializer,
false));
1387 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1388 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
1393 template<
typename Ordinal,
typename Packet>
1396 ,
const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
1400 "Teuchos::CommHelpers: reduceAll<" 1402 <<
">( value type, user-defined op )" 1405 charSendBuffer(count,sendBuffer);
1407 charGlobalReducts(count,globalReducts);
1409 charReductOp(
rcp(&reductOp,
false));
1411 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1412 ,charGlobalReducts.getCharBuffer()
1417 template<
typename Ordinal,
typename Packet>
1420 const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
1424 "Teuchos::CommHelpers: reduceAll<" 1426 <<
">( value type, "<<
toString(reductType)<<
" )" 1428 std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
1429 reductOp(createOp<Ordinal,Packet>(reductType));
1430 reduceAll(comm,*reductOp,count,sendBuffer,globalReducts);
1436 #ifdef TEUCHOS_HAVE_COMPLEX 1440 reduceAll<int, std::complex<double> > (
const Comm<int>& comm,
1441 const EReductionType reductType,
1443 const std::complex<double> sendBuffer[],
1444 std::complex<double> globalReducts[]);
1447 ireceive<int, std::complex<double> > (
const Comm<int>& comm,
1449 const int sourceRank);
1453 const int sourceRank,
1458 send<int, std::complex<double> > (
const Comm<int>& comm,
1460 const std::complex<double> sendBuffer[],
1461 const int destRank);
1464 send<int, std::complex<double> > (
const std::complex<double> sendBuffer[],
1479 reduceAll<int, std::complex<float> > (
const Comm<int>& comm,
1480 const EReductionType reductType,
1482 const std::complex<float> sendBuffer[],
1483 std::complex<float> globalReducts[]);
1486 ireceive<int, std::complex<float> > (
const Comm<int>& comm,
1488 const int sourceRank);
1492 const int sourceRank,
1497 send<int, std::complex<float> > (
const Comm<int>& comm,
1499 const std::complex<float> sendBuffer[],
1500 const int destRank);
1503 send<int, std::complex<float> > (
const std::complex<float> sendBuffer[],
1514 #endif // TEUCHOS_HAVE_COMPLEX 1520 const EReductionType reductType,
1522 const double sendBuffer[],
1523 double globalReducts[]);
1528 const int sourceRank);
1532 const int sourceRank,
1539 const double sendBuffer[],
1540 const int destRank);
1559 const EReductionType reductType,
1561 const float sendBuffer[],
1562 float globalReducts[]);
1567 const int sourceRank);
1571 const int sourceRank,
1578 const float sendBuffer[],
1579 const int destRank);
1594 #ifdef TEUCHOS_HAVE_LONG_LONG_INT 1598 gather<int, long long> (
const long long sendBuf[],
1599 const int sendCount,
1600 long long recvBuf[],
1601 const int recvCount,
1606 gatherv<int, long long> (
const long long sendBuf[],
1607 const int sendCount,
1608 long long recvBuf[],
1609 const int recvCounts[],
1615 reduceAll<int, long long> (
const Comm<int>& comm,
1616 const EReductionType reductType,
1618 const long long sendBuffer[],
1619 long long globalReducts[]);
1622 ireceive<int, long long> (
const Comm<int>& comm,
1624 const int sourceRank);
1628 const int sourceRank,
1633 send<int, long long> (
const Comm<int>& comm,
1635 const long long sendBuffer[],
1636 const int destRank);
1639 send<int, long long> (
const long long sendBuffer[],
1650 #endif // TEUCHOS_HAVE_LONG_LONG_INT 1656 const int sendCount,
1658 const int recvCount,
1664 const int sendCount,
1666 const int recvCounts[],
1673 const EReductionType reductType,
1675 const long sendBuffer[],
1676 long globalReducts[]);
1681 const int sourceRank);
1685 const int sourceRank,
1692 const long sendBuffer[],
1693 const int destRank);
1712 const int sendCount,
1714 const int recvCount,
1720 const int sendCount,
1722 const int recvCounts[],
1729 const EReductionType reductType,
1731 const int sendBuffer[],
1732 int globalReducts[]);
1739 const EReductionType reductType,
1740 const int sendCount,
1741 const int sendBuffer[],
1742 const int recvCounts[],
1743 int myGlobalReducts[]);
1748 const int sourceRank);
1752 const int sourceRank,
1759 const int sendBuffer[],
1760 const int destRank);
1779 const int sendCount,
1781 const int recvCount,
1787 const int sendCount,
1789 const int recvCounts[],
1796 const EReductionType reductType,
1798 const short sendBuffer[],
1799 short globalReducts[]);
1804 const int sourceRank);
1808 const int sourceRank,
1815 const short sendBuffer[],
1816 const int destRank);
1843 reduceAll<int, char> (
const Comm<int>& comm,
1844 const EReductionType reductType,
1846 const char sendBuffer[],
1847 char globalReducts[]);
1852 template<
typename Ordinal,
typename Packet>
1860 reduceAll<Ordinal,Packet>(comm, reductType, 1, &
send, &*globalReduct);
1864 template<
typename Ordinal,
typename Packet>
1868 const Ordinal count,
const Packet*
const sendBuffer[], Packet*
const globalReducts[]
1872 "Teuchos::CommHelpers: reduceAll<" 1874 <<
">( reference type )" 1877 charSendBuffer(serializer,count,sendBuffer);
1879 charGlobalReducts(serializer,count,globalReducts);
1881 charReductOp(
rcp(&serializer,
false),
rcp(&reductOp,
false));
1888 template<
typename Ordinal,
typename Packet,
typename Serializer>
1893 const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
1897 "Teuchos::CommHelpers: reduceAll<" 1899 <<
">( value type, user-defined op )" 1902 charSendBuffer(count,sendBuffer,
rcp(&serializer,
false));
1904 charGlobalReducts(count,globalReducts,
rcp(&serializer,
false));
1906 charReductOp(
rcp(&reductOp,
false),
rcp(&serializer,
false));
1908 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1909 ,charGlobalReducts.getCharBuffer()
1914 template<
typename Ordinal,
typename Packet,
typename Serializer>
1918 const EReductionType reductType,
1919 const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
1923 "Teuchos::CommHelpers: reduceAll<" 1925 <<
">( value type, "<<
toString(reductType)<<
" )" 1927 std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
1928 reductOp(createOp<Ordinal,Packet>(reductType));
1929 reduceAll(comm,serializer,*reductOp,count,sendBuffer,globalReducts);
1933 template<
typename Ordinal,
typename Packet>
1934 void Teuchos::reduceAllAndScatter(
1936 const Ordinal sendCount,
const Packet sendBuffer[] ,
1937 const Ordinal recvCounts[], Packet myGlobalReducts[]
1942 "Teuchos::CommHelpers: reduceAllAndScatter<" 1944 <<
">( value type, user-defined op )" 1947 const Ordinal size = Teuchos::size(comm);
1948 const Ordinal rank = Teuchos::rank(comm);
1950 #ifdef TEUCHOS_DEBUG 1951 Ordinal sumRecvCounts = 0;
1952 for( Ordinal i = 0; i < size; ++i )
1953 sumRecvCounts += recvCounts[static_cast<ptrdiff_t>(i)];
1958 charSendBuffer(sendCount,sendBuffer);
1960 charMyGlobalReducts(recvCounts[static_cast<ptrdiff_t>(rank)], myGlobalReducts);
1962 charReductOp(
rcp(&reductOp,
false));
1965 packetSize = charSendBuffer.getBytes()/sendCount;
1969 for (Ordinal k = 0; k < size; ++k) {
1970 charRecvCounts[k] = as<Ordinal>(recvCounts[
static_cast<ptrdiff_t
>(k)] * packetSize);
1974 charReductOp, charSendBuffer.getBytes(), charSendBuffer.getCharBuffer(),
1975 &charRecvCounts[0], charMyGlobalReducts.getCharBuffer()
1981 template<
typename Ordinal,
typename Packet>
1982 void Teuchos::reduceAllAndScatter(
1984 const Ordinal sendCount,
const Packet sendBuffer[] ,
1985 const Ordinal recvCounts[], Packet myGlobalReducts[]
1989 "Teuchos::CommHelpers: reduceAllAndScatter<" 1991 <<
">( value type, "<<
toString(reductType)<<
" )" 1993 std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
1994 reductOp(createOp<Ordinal,Packet>(reductType));
1995 reduceAllAndScatter(
1996 comm, *reductOp, sendCount, sendBuffer, recvCounts, myGlobalReducts
2001 template<
typename Ordinal,
typename Packet>
2002 void Teuchos::reduceAllAndScatter(
2005 const Ordinal sendCount,
const Packet*
const sendBuffer[],
2006 const Ordinal recvCounts[], Packet*
const myGlobalReducts[]
2012 template<
typename Ordinal,
typename Packet,
typename Serializer>
2013 void Teuchos::reduceAllAndScatter(
2017 const Ordinal sendCount,
const Packet sendBuffer[] ,
2018 const Ordinal recvCounts[], Packet myGlobalReducts[]
2023 "Teuchos::CommHelpers: reduceAllAndScatter<" 2025 <<
">( value type, user-defined op )" 2028 const Ordinal size = Teuchos::size(comm);
2029 const Ordinal rank = Teuchos::rank(comm);
2031 #ifdef TEUCHOS_DEBUG 2032 Ordinal sumRecvCounts = 0;
2033 for( Ordinal i = 0; i < size; ++i )
2034 sumRecvCounts += recvCounts[static_cast<ptrdiff_t>(i)];
2039 charSendBuffer(sendCount,sendBuffer,
rcp(&serializer,
false));
2041 charMyGlobalReducts(recvCounts[static_cast<ptrdiff_t>(rank)], myGlobalReducts,
rcp(&serializer,
false));
2043 charReductOp(
rcp(&reductOp,
false),
rcp(&serializer,
false));
2046 packetSize = charSendBuffer.getBytes()/sendCount;
2050 for (Ordinal k = 0; k < size; ++k) {
2051 charRecvCounts[k] = as<Ordinal>(recvCounts[
static_cast<ptrdiff_t
>(k)] * packetSize);
2055 charReductOp, charSendBuffer.getBytes(), charSendBuffer.getCharBuffer(),
2056 &charRecvCounts[0], charMyGlobalReducts.getCharBuffer()
2061 template<
typename Ordinal,
typename Packet,
typename Serializer>
2062 void Teuchos::reduceAllAndScatter(
2065 const EReductionType reductType,
2066 const Ordinal sendCount,
const Packet sendBuffer[] ,
2067 const Ordinal recvCounts[], Packet myGlobalReducts[]
2071 "Teuchos::CommHelpers: reduceAllAndScatter<" 2073 <<
">( value type, "<<
toString(reductType)<<
" )" 2075 std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
2076 reductOp(createOp<Ordinal,Packet>(reductType));
2077 reduceAllAndScatter(
2078 comm, serializer, *reductOp, sendCount, sendBuffer, recvCounts,
2084 template<
typename Ordinal,
typename Packet>
2087 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
2091 "Teuchos::CommHelpers: scan<" 2093 <<
">( value type, user-defined op )" 2096 charSendBuffer(count,sendBuffer);
2098 charScanReducts(count,scanReducts);
2100 charReductOp(
rcp(&reductOp,
false));
2102 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2103 ,charScanReducts.getCharBuffer()
2108 template<
typename Ordinal,
typename Packet>
2111 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
2115 "Teuchos::CommHelpers: scan<" 2117 <<
">( value type, "<<
toString(reductType)<<
" )" 2119 std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
2120 reductOp(createOp<Ordinal,Packet>(reductType));
2121 scan(comm,*reductOp,count,sendBuffer,scanReducts);
2125 template<
typename Ordinal,
typename Packet>
2131 scan<Ordinal,Packet>(comm, reductType, 1, &
send, &*scanReduct);
2135 template<
typename Ordinal,
typename Packet>
2139 const Ordinal count,
const Packet*
const sendBuffer[], Packet*
const scanReducts[]
2145 template<
typename Ordinal,
typename Packet,
typename Serializer>
2150 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
2154 "Teuchos::CommHelpers: scan<" 2156 <<
">( value type, user-defined op )" 2159 charSendBuffer(count,sendBuffer,
rcp(&serializer,
false));
2161 charScanReducts(count,scanReducts,
rcp(&serializer,
false));
2163 charReductOp(
rcp(&reductOp,
false),
rcp(&serializer,
false));
2165 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2166 ,charScanReducts.getCharBuffer()
2171 template<
typename Ordinal,
typename Packet,
typename Serializer>
2175 const EReductionType reductType,
2176 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
2180 "Teuchos::CommHelpers: scan<" 2182 <<
">( value type, "<<
toString(reductType)<<
" )" 2184 std::auto_ptr<ValueTypeReductionOp<Ordinal,Packet> >
2185 reductOp(createOp<Ordinal,Packet>(reductType));
2186 scan(comm,serializer,*reductOp,count,sendBuffer,scanReducts);
2189 template<
typename Ordinal,
typename Packet>
2192 const Ordinal count,
const Packet sendBuffer[],
const int destRank
2196 "Teuchos::CommHelpers: send<" 2201 charSendBuffer(count,sendBuffer);
2203 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2208 template<
typename Ordinal,
typename Packet>
2211 const Ordinal count,
2217 "Teuchos::CommHelpers: send<" 2222 comm.
send (charSendBuffer.getBytes (), charSendBuffer.getCharBuffer (), destRank, tag);
2225 template<
typename Ordinal,
typename Packet>
2228 const Ordinal count,
const Packet sendBuffer[],
const int destRank
2232 "Teuchos::CommHelpers: ssend<" 2237 charSendBuffer(count,sendBuffer);
2239 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2244 template<
typename Ordinal,
typename Packet>
2247 const Ordinal count,
2253 "Teuchos::CommHelpers: ssend<" 2258 buf_type charSendBuffer (count, sendBuffer);
2259 comm.
ssend (charSendBuffer.getBytes (),
2260 charSendBuffer.getCharBuffer (),
2264 template<
typename Ordinal,
typename Packet>
2267 const Packet &
send,
const int destRank
2270 Teuchos::send<Ordinal,Packet>(comm,1,&
send,destRank);
2273 template<
typename Ordinal,
typename Packet>
2276 const Packet &
send,
const int destRank
2279 Teuchos::ssend<Ordinal,Packet>(comm,1,&
send,destRank);
2282 template<
typename Ordinal,
typename Packet>
2285 const Ordinal count,
const Packet*
const sendBuffer[],
const int destRank
2291 template<
typename Ordinal,
typename Packet,
typename Serializer>
2295 const Ordinal count,
const Packet sendBuffer[],
const int destRank
2299 "Teuchos::CommHelpers: send<" 2304 charSendBuffer(count,sendBuffer,
rcp(&serializer,
false));
2306 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2311 template<
typename Ordinal,
typename Packet>
2312 int Teuchos::receive(
2314 const int sourceRank,
const Ordinal count, Packet recvBuffer[]
2318 "Teuchos::CommHelpers: receive<" 2323 charRecvBuffer(count,recvBuffer);
2326 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
2331 template<
typename Ordinal,
typename Packet>
2332 int Teuchos::receive(
2334 const int sourceRank, Packet *recv
2337 return Teuchos::receive<Ordinal,Packet>(comm,sourceRank,1,recv);
2341 template<
typename Ordinal,
typename Packet>
2342 int Teuchos::receive(
2344 const int sourceRank,
const Ordinal count, Packet*
const recvBuffer[]
2350 template<
typename Ordinal,
typename Packet,
typename Serializer>
2351 int Teuchos::receive(
2354 const int sourceRank,
const Ordinal count, Packet recvBuffer[]
2358 "Teuchos::CommHelpers: receive<" 2363 charRecvBuffer(count,recvBuffer,
rcp(&serializer,
false));
2366 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
2370 template<
typename Ordinal,
typename Packet>
2378 "Teuchos::CommHelpers: readySend<" 2384 comm.
readySend( charSendBuffer.getCharBufferView(), destRank );
2387 template<
typename Ordinal,
typename Packet>
2390 const Ordinal count,
2396 "Teuchos::CommHelpers: readySend<" 2401 buf_type charSendBuffer (count, sendBuffer);
2402 comm.
readySend (charSendBuffer.getBytes (),
2403 charSendBuffer.getCharBuffer (),
2407 template<
typename Ordinal,
typename Packet>
2414 readySend<Ordinal, Packet>( comm, arrayView(&
send,1), destRank );
2417 template<
typename Ordinal,
typename Packet,
typename Serializer>
2426 "Teuchos::CommHelpers: readySend<" 2431 charSendBuffer(sendBuffer.
size(), sendBuffer.
getRawPtr(), serializer);
2432 comm.
readySend( charSendBuffer.getCharBufferView(), destRank );
2435 template<
typename Ordinal,
typename Packet>
2444 "Teuchos::CommHelpers: isend<" 2451 charSendBuffer.getCharBufferView(), destRank );
2452 set_extra_data( sendBuffer,
"buffer", inOutArg(commRequest) );
2456 template<
typename Ordinal,
typename Packet>
2467 charSendBuffer (sendBuffer.
size (), sendBuffer.
getRawPtr ());
2469 comm.
isend (charSendBuffer.getCharBufferView (), destRank, tag);
2470 set_extra_data (sendBuffer,
"buffer", inOutArg (commRequest));
2474 template<
typename Ordinal,
typename Packet>
2483 arcpWithEmbeddedObj( send.
get(), 0, 1,
send, false );
2486 return isend<Ordinal, Packet>( comm, sendBuffer, destRank );
2489 template<
typename Ordinal,
typename Packet,
typename Serializer>
2499 "Teuchos::CommHelpers: isend<" 2504 charSendBuffer(sendBuffer.
size(), sendBuffer.
getRawPtr(), serializer);
2506 charSendBuffer.getCharBufferView(), destRank );
2507 set_extra_data( sendBuffer,
"buffer", inOutArg(commRequest) );
2511 template<
typename Ordinal,
typename Packet>
2516 const int sourceRank
2524 charRecvBuffer.getCharBufferView(), sourceRank );
2525 set_extra_data( recvBuffer,
"buffer", inOutArg(commRequest) );
2529 template<
typename Ordinal,
typename Packet>
2532 const int sourceRank,
2539 charRecvBuffer (recvBuffer.
size (), recvBuffer.
getRawPtr ());
2541 comm.
ireceive (charRecvBuffer.getCharBufferView (), sourceRank, tag);
2542 set_extra_data (recvBuffer,
"buffer", inOutArg (commRequest));
2546 template<
typename Ordinal,
typename Packet>
2551 const int sourceRank
2555 arcpWithEmbeddedObj( recv.
get(), 0, 1, recv, false );
2558 return ireceive<Ordinal, Packet>( comm, recvBuffer, sourceRank );
2561 template<
typename Ordinal,
typename Packet,
typename Serializer>
2567 const int sourceRank
2571 "Teuchos::CommHelpers: ireceive<" 2576 charRecvBuffer(recvBuffer.
size(), recvBuffer.
getRawPtr(), serializer);
2578 charRecvBuffer.getCharBufferView(), sourceRank );
2579 set_extra_data( recvBuffer,
"buffer", inOutArg(commRequest) );
2583 template<
typename Ordinal>
2584 void Teuchos::waitAll(
2593 template<
typename Ordinal>
2599 comm.
waitAll (requests, statuses);
2603 template<
typename Ordinal>
2608 return comm.
wait (request);
2612 #endif // TEUCHOS_COMM_HELPERS_HPP
Strategy interface for the indirect serializing and deserializing objects of a given type handled usi...
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
Encapsulate how an array of non-const objects with reference sematics is serialized into a char[] arr...
TEUCHOSCOMM_LIB_DLL_EXPORT RCP< Teuchos::CommRequest< int > > isend(const ArrayRCP< const double > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
EReductionType
Enumeration for selecting from a set of pre-defined reduction operations.
TEUCHOSCOMM_LIB_DLL_EXPORT RCP< CommRequest< int > > isend< int, float >(const ArrayRCP< const float > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
RCP< Teuchos::CommRequest< int > > ireceive< int, float >(const Comm< int > &comm, const ArrayRCP< float > &recvBuffer, const int sourceRank)
static void max(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[])
Templated class for workspace creation.
void gatherv< int, short >(const short sendBuf[], const int sendCount, short recvBuf[], const int recvCounts[], const int displs[], const int root, const Comm< int > &comm)
TEUCHOSCOMM_LIB_DLL_EXPORT RCP< CommRequest< int > > isend< int, short >(const ArrayRCP< const short > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
virtual void reduceAllAndScatter(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal sendBytes, const char sendBuffer[], const Ordinal recvCounts[], char myGlobalReducts[]) const =0
Global reduction combined with a scatter.
void reduceAll< int, long >(const Comm< int > &comm, const EReductionType reductType, const int count, const long sendBuffer[], long globalReducts[])
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.
RCP< Teuchos::CommRequest< int > > ireceive< int, double >(const Comm< int > &comm, const ArrayRCP< double > &recvBuffer, const int sourceRank)
RCP< Teuchos::CommRequest< int > > ireceive< int, short >(const Comm< int > &comm, const ArrayRCP< short > &recvBuffer, const int sourceRank)
static void andOp(const Ordinal, const Packet[], Packet[])
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
virtual void broadcast(const int rootRank, const Ordinal bytes, char buffer[]) const =0
Broadcast values from the root process to the slave processes.
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
RawPointerConversionTraits< Container >::Ptr_t getRawPtr(const Container &c)
size_type size() const
The total number of items in the managed array.
void gatherv< int, int >(const int sendBuf[], const int sendCount, int recvBuf[], const int recvCounts[], const int displs[], const int root, const Comm< int > &comm)
TEUCHOSCOMM_LIB_DLL_EXPORT RCP< CommRequest< int > > isend< int, double >(const ArrayRCP< const double > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
TEUCHOSCOMM_LIB_DLL_EXPORT void send< int, short >(const Comm< int > &comm, const int count, const short sendBuffer[], const int destRank)
void gather< int, long >(const long sendBuf[], const int sendCount, long recvBuf[], const int recvCount, const int root, const Comm< int > &comm)
void reduceAllAndScatter< int, int >(const Comm< int > &comm, const EReductionType reductType, const int sendCount, const int sendBuffer[], const int recvCounts[], int myGlobalReducts[])
T * get() const
Get the raw C++ pointer to the underlying object.
virtual int getRank() const =0
Returns the rank of this process.
T * getRawPtr()
Return a raw pointer to beginning of array or NULL if unsized.
const char * getCharBuffer() const
virtual RCP< CommRequest< Ordinal > > ireceive(const ArrayView< char > &recvBuffer, const int sourceRank) const =0
Non-blocking receive.
TEUCHOSCOMM_LIB_DLL_EXPORT void send< int, long >(const Comm< int > &comm, const int count, const long sendBuffer[], const int destRank)
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.
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
void gather< int, int >(const int sendBuf[], const int sendCount, int recvBuf[], const int recvCount, const int root, const Comm< int > &comm)
size_type size() const
The total number of entries in the array.
Standard logical AND operator for booleans.
#define TEUCHOS_COMM_TIME_MONITOR(FUNCNAME)
Standard min operator for types with value semantics.
TEUCHOSCOMM_LIB_DLL_EXPORT void send< int, int >(const Comm< int > &comm, const int count, const int sendBuffer[], const int destRank)
This structure defines some basic traits for a scalar field type.
Decorator class that uses traits to convert to and from char[] to typed buffers for objects that use ...
Standard summation operator for types with value semantics.
static void andOp(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[])
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
virtual void ssend(const Ordinal bytes, const char sendBuffer[], const int destRank) const =0
Always blocking send of data from this process to another process.
void reduceAll< int, short >(const Comm< int > &comm, const EReductionType reductType, const int count, const short sendBuffer[], short globalReducts[])
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
virtual void readySend(const ArrayView< const char > &sendBuffer, const int destRank) const =0
Ready send of data from this process to another process.
static void min(const Ordinal, const Packet[], Packet[])
virtual void reduceAll(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char globalReducts[]) const =0
Global reduction.
void reduceAll< int, double >(const Comm< int > &comm, const EReductionType reductType, const int count, const double sendBuffer[], double globalReducts[])
TEUCHOS_DEPRECATED void scan(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *scanReduct)
Deprecated.
TEUCHOSCOMM_LIB_DLL_EXPORT RCP< CommRequest< int > > isend< int, long >(const ArrayRCP< const long > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
Encapsulate how an array of const objects with reference sematics is serialized into a char[] array...
std::string toString(const HashSet< Key > &h)
Standard Max operator for types with value semantics.
void gatherv< int, long >(const long sendBuf[], const int sendCount, long recvBuf[], const int recvCounts[], const int displs[], const int root, const Comm< int > &comm)
Decorator class that uses a strategy object to convert to and from char[] to typed buffers for object...
virtual void waitAll(const ArrayView< RCP< CommRequest< Ordinal > > > &requests) const =0
Wait on a set of communication requests.
This structure defines some basic traits for the ordinal field type.
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
Deprecated .
Encapsulation of the result of a receive (blocking or nonblocking).
#define TEUCHOS_MAX(x, y)
void send(const Packet sendBuffer[], const Ordinal count, const int destRank, const int tag, const Comm< Ordinal > &comm)
Variant of send() that takes a tag (and restores the correct order of arguments). ...
void reduceAll< int, int >(const Comm< int > &comm, const EReductionType reductType, const int count, const int sendBuffer[], int globalReducts[])
Workspace encapsulation class.
T * getRawPtr() const
Return a raw pointer to beginning of array or NULL if unsized.
TEUCHOSCOMM_LIB_DLL_EXPORT void send< int, double >(const Comm< int > &comm, const int count, const double sendBuffer[], const int destRank)
char * getCharBuffer() const
Encapsulate how an array of non-const objects with value sematics is serialized into a char[] array...
TEUCHOSCOMM_LIB_DLL_EXPORT RCP< CommRequest< int > > isend< int, int >(const ArrayRCP< const int > &sendBuffer, const int destRank, const int tag, const Comm< int > &comm)
RCP< CommRequest< Ordinal > > ireceive(const ArrayRCP< Packet > &recvBuffer, const int sourceRank, const int tag, const Comm< Ordinal > &comm)
Variant of ireceive that takes a tag argument (and restores the correct order of arguments).
RCP< Teuchos::CommRequest< int > > ireceive< int, int >(const Comm< int > &comm, const ArrayRCP< int > &recvBuffer, const int sourceRank)
Templated array class derived from the STL std::vector.
TEUCHOSCOMM_LIB_DLL_EXPORT void send< int, float >(const Comm< int > &comm, const int count, const float sendBuffer[], const int destRank)
Abstract interface for distributed-memory communication.
virtual RCP< CommRequest< Ordinal > > isend(const ArrayView< const char > &sendBuffer, const int destRank) const =0
Non-blocking send.
void push_back(const value_type &x)
Defines basic traits for the ordinal field type.
Default traits class that just returns typeid(T).name().
virtual void scan(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char scanReducts[]) const =0
Scan reduction.
virtual int getSize() const =0
Returns the number of processes that make up this communicator.
virtual int receive(const int sourceRank, const Ordinal bytes, char recvBuffer[]) const =0
Blocking receive of data from this process to another process.
void reduceAll< int, float >(const Comm< int > &comm, const EReductionType reductType, const int count, const float sendBuffer[], float globalReducts[])
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
Base interface class for user-defined reduction operations for objects that use reference semantics...
virtual void gatherAll(const Ordinal sendBytes, const char sendBuffer[], const Ordinal recvBytes, char recvBuffer[]) const =0
Gather values from each process to collect on all processes.
void ssend(const Packet sendBuffer[], const Ordinal count, const int destRank, const int tag, const Comm< Ordinal > &comm)
Variant of ssend() that takes a tag (and restores the correct order of arguments).
Defines basic traits for the scalar field type.
#define TEUCHOSCOMM_LIB_DLL_EXPORT
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 barrier() const =0
Pause every process in *this communicator until all the processes reach this point.
static void max(const Ordinal, const Packet[], Packet[])
Smart reference counting pointer class for automatic garbage collection.
RCP< Teuchos::CommRequest< int > > ireceive< int, long >(const Comm< int > &comm, const ArrayRCP< long > &recvBuffer, const int sourceRank)
Encapsulation of a pending nonblocking communication operation.
void gather< int, short >(const short sendBuf[], const int sendCount, short recvBuf[], const int recvCount, const int root, const Comm< int > &comm)
#define TEUCHOS_MIN(x, y)
Defines basic traits returning the name of a type in a portable and readable way. ...
Definition of Teuchos::as, for conversions between types.
ValueTypeReductionOp< Ordinal, Packet > * createOp(const EReductionType reductType)
void readySend(const Packet sendBuffer[], const Ordinal count, const int destRank, const int tag, const Comm< Ordinal > &comm)
Variant of readySend() that accepts a message tag.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call...
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
TEUCHOSCORE_LIB_DLL_EXPORT Teuchos::RCP< WorkspaceStore > get_default_workspace_store()
Get the global workspace object set by set_default_workspace_store().
Encapsulate how an array of const objects with value sematics is serialized into a const char[] array...
static void min(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[])
Reference-counted smart pointer for managing arrays.
Memory-safe templated array class that encapsulates std::vector.