42 #ifndef TEUCHOS_COMM_HELPERS_HPP 43 #define TEUCHOS_COMM_HELPERS_HPP 45 #include "Teuchos_Comm.hpp" 46 #include "Teuchos_CommUtilities.hpp" 47 #include "Teuchos_SerializationTraitsHelpers.hpp" 48 #include "Teuchos_ReductionOpHelpers.hpp" 49 #include "Teuchos_SerializerHelpers.hpp" 54 #include "Teuchos_Workspace.hpp" 60 #include "Teuchos_DefaultSerialComm.hpp" 86 const char* toString (
const EReductionType reductType);
92 template<
typename Ordinal>
99 template<
typename Ordinal>
106 template<
typename Ordinal>
113 template<
typename Ordinal,
typename Packet>
117 const Ordinal count, Packet buffer[]
124 template<
typename Ordinal,
typename Packet>
135 template<
typename Ordinal,
typename Packet>
138 const int rootRank, Packet *
object 145 template<
typename Ordinal,
typename Packet>
155 template<
typename Ordinal,
typename Packet>
158 const int rootRank,
const Ordinal count, Packet*
const buffer[]
165 template<
typename Ordinal,
typename Packet>
176 template<
typename Ordinal,
typename Packet,
typename Serializer>
181 const Ordinal count, Packet buffer[]
188 template<
typename Ordinal,
typename Packet>
190 gather (
const Packet sendBuf[],
191 const Ordinal sendCount,
193 const Ordinal recvCount,
201 template<
typename Ordinal,
typename Packet>
203 gatherv (
const Packet sendBuf[],
204 const Ordinal sendCount,
206 const Ordinal recvCounts[],
207 const Ordinal displs[],
216 template<
typename Ordinal,
typename Packet>
219 const Ordinal sendCount,
const Packet sendBuffer[],
220 const Ordinal recvCount, Packet recvBuffer[]
228 template<
typename Ordinal,
typename Packet>
231 const Ordinal sendCount,
const Packet*
const sendBuffer[],
232 const Ordinal recvCount, Packet*
const recvBuffer[]
240 template<
typename Ordinal,
typename Packet,
typename Serializer>
244 const Ordinal sendCount,
const Packet sendBuffer[],
245 const Ordinal recvCount, Packet recvBuffer[]
274 template<
typename Ordinal,
typename Packet>
277 const Ordinal sendCount,
279 const Ordinal recvCount,
287 (
true, std::logic_error,
"Teuchos::scatter<" <<
289 <<
">: Generic version is not yet implemented. This function currently " 290 "only has an implementtion for Ordinal = int and Packet = int. " 291 "See Bug 6375 and Bug 6336.");
321 template<
typename Ordinal,
typename Packet>
323 reduce (
const Packet sendBuf[],
352 template<
typename Ordinal,
typename Packet>
355 const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
363 template<
typename Ordinal,
typename Packet>
366 const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
374 template<
typename Ordinal,
typename Packet>
381 template<
typename Ordinal,
typename Packet>
384 const Packet &send, Packet *globalReduct
387 reduceAll<Ordinal,Packet>(comm, reductType,
send, ptr(globalReduct));
395 template<
typename Ordinal,
typename Packet>
399 const Ordinal count,
const Packet*
const sendBuffer[], Packet*
const globalReducts[]
407 template<
typename Ordinal,
typename Packet,
typename Serializer>
412 const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
420 template<
typename Ordinal,
typename Packet,
typename Serializer>
424 const EReductionType reductType,
425 const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
433 template<
typename Ordinal,
typename Packet>
436 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
444 template<
typename Ordinal,
typename Packet>
447 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
455 template<
typename Ordinal,
typename Packet>
462 template<
typename Ordinal,
typename Packet>
465 const Packet &send, Packet *scanReduct
468 scan(comm, reductType, send, ptr(scanReduct));
476 template<
typename Ordinal,
typename Packet>
480 const Ordinal count,
const Packet*
const sendBuffer[], Packet*
const scanReducts[]
488 template<
typename Ordinal,
typename Packet,
typename Serializer>
493 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
501 template<
typename Ordinal,
typename Packet,
typename Serializer>
505 const EReductionType reductType,
506 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
513 template<
typename Ordinal,
typename Packet>
516 const Ordinal count,
const Packet sendBuffer[],
const int destRank
520 template<
typename Ordinal,
typename Packet>
522 send (
const Packet sendBuffer[],
532 template<
typename Ordinal,
typename Packet>
535 const Ordinal count,
const Packet sendBuffer[],
const int destRank
539 template<
typename Ordinal,
typename Packet>
541 ssend (
const Packet sendBuffer[],
551 template<
typename Ordinal,
typename Packet>
554 const Packet &send,
const int destRank
561 template<
typename Ordinal,
typename Packet>
564 const Packet &send,
const int destRank
573 template<
typename Ordinal,
typename Packet>
576 const Ordinal count,
const Packet*
const sendBuffer[],
const int destRank
584 template<
typename Ordinal,
typename Packet,
typename Serializer>
588 const Ordinal count,
const Packet sendBuffer[],
const int destRank
595 template<
typename Ordinal,
typename Packet>
598 const int sourceRank,
const Ordinal count, Packet recvBuffer[]
605 template<
typename Ordinal,
typename Packet>
608 const int sourceRank, Packet *recv
615 template<
typename Ordinal,
typename Packet>
618 const int sourceRank,
const Ordinal count, Packet*
const recvBuffer[]
626 template<
typename Ordinal,
typename Packet,
typename Serializer>
630 const int sourceRank,
const Ordinal count, Packet recvBuffer[]
638 template<
typename Ordinal,
typename Packet>
646 template<
typename Ordinal,
typename Packet>
658 template<
typename Ordinal,
typename Packet>
670 template<
typename Ordinal,
typename Packet,
typename Serializer>
682 template<
typename Ordinal,
typename Packet>
690 template<
typename Ordinal,
typename Packet>
701 template<
typename Ordinal,
typename Packet>
713 template<
typename Ordinal,
typename Packet,
typename Serializer>
734 template<
typename Ordinal,
typename Packet>
742 template<
typename Ordinal,
typename Packet>
745 const int sourceRank,
760 template<
typename Ordinal,
typename Packet>
772 template<
typename Ordinal,
typename Packet,
typename Serializer>
791 template<
typename Ordinal>
826 template<
typename Ordinal>
855 template<
typename Ordinal>
868 template<
typename Ordinal,
typename Packet>
875 const Packet inBuffer[],
889 template<
typename Ordinal,
typename Packet>
896 const Packet inBuffer[],
910 template<
typename Ordinal,
typename Packet>
917 const Packet inBuffer[],
927 template<
typename Ordinal,
typename Packet>
934 const Packet inBuffer[],
949 namespace MixMaxUtilities {
952 template<
bool isComparable,
typename Ordinal,
typename Packet>
956 template<
typename Ordinal,
typename Packet>
957 class Min<true,Ordinal,Packet> {
961 const Packet inBuffer[],
965 for(
int i = 0; i < count; ++i )
966 inoutBuffer[i] = TEUCHOS_MIN(inoutBuffer[i],inBuffer[i]);
971 template<
typename Ordinal,
typename Packet>
972 class Min<false,Ordinal,Packet> {
981 true,std::logic_error,
983 <<
" does not support comparison operations!" 989 template<
bool isComparable,
typename Ordinal,
typename Packet>
993 template<
typename Ordinal,
typename Packet>
994 class Max<true,Ordinal,Packet> {
998 const Packet inBuffer[],
1002 for(
int i = 0; i < count; ++i )
1003 inoutBuffer[i] = TEUCHOS_MAX(inoutBuffer[i],inBuffer[i]);
1008 template<
typename Ordinal,
typename Packet>
1009 class Max<false,Ordinal,Packet> {
1018 true,std::logic_error,
1020 <<
" does not support comparison operations!" 1026 template<
bool isComparable,
typename Ordinal,
typename Packet>
1030 template<
typename Ordinal,
typename Packet>
1031 class AND<true,Ordinal,Packet> {
1034 const Ordinal count,
1035 const Packet inBuffer[],
1036 Packet inoutBuffer[]
1039 for(
int i = 0; i < count; ++i )
1040 inoutBuffer[i] = inoutBuffer[i] && inBuffer[i];
1045 template<
typename Ordinal,
typename Packet>
1046 class AND<false,Ordinal,Packet> {
1055 true,std::logic_error,
1057 <<
" does not support logical AND operations!" 1066 template<
typename Ordinal,
typename Packet>
1068 const Ordinal count,
1069 const Packet inBuffer[],
1070 Packet inoutBuffer[]
1073 for(
int i = 0; i < count; ++i )
1074 inoutBuffer[i] += inBuffer[i];
1078 template<
typename Ordinal,
typename Packet>
1080 const Ordinal count,
1081 const Packet inBuffer[],
1082 Packet inoutBuffer[]
1085 typedef MixMaxUtilities::Min<ScalarTraits<Packet>::isComparable, Ordinal, Packet> min_type;
1086 min_type::min (count, inBuffer, inoutBuffer);
1090 template<
typename Ordinal,
typename Packet>
1092 const Ordinal count,
1093 const Packet inBuffer[],
1094 Packet inoutBuffer[]
1097 typedef MixMaxUtilities::Max<ScalarTraits<Packet>::isComparable, Ordinal, Packet> max_type;
1098 max_type::max (count,inBuffer,inoutBuffer);
1102 template<
typename Ordinal,
typename Packet>
1104 const Ordinal count,
1105 const Packet inBuffer[],
1106 Packet inoutBuffer[]
1109 typedef MixMaxUtilities::AND<ScalarTraits<Packet>::isComparable, Ordinal, Packet> and_type;
1110 and_type::andOp (count, inBuffer, inoutBuffer);
1140 template<
typename Ordinal,
typename Packet>
1142 createOp (
const EReductionType reductType)
1145 switch (reductType) {
1151 ! ST::isComparable, std::invalid_argument,
"Teuchos::createOp" 1153 <<
" is not less-than comparable, so it does not make sense to do a " 1154 "MIN reduction with it.");
1159 ! ST::isComparable, std::invalid_argument,
"Teuchos::createOp" 1161 <<
" is not less-than comparable, so it does not make sense to do a " 1162 "MAX reduction with it.");
1170 true, std::invalid_argument,
"Teuchos::createOp(EReductionType): " 1171 "Invalid EReductionType value " << reductType <<
". Valid values " 1172 "include REDUCE_SUM, REDUCE_MIN, REDUCE_MAX, and REDUCE_AND.");
1185 template<
typename Ordinal>
1192 template<
typename Ordinal>
1199 template<
typename Ordinal>
1202 TEUCHOS_COMM_TIME_MONITOR(
1203 "Teuchos::CommHelpers: barrier<" 1211 template<
typename Ordinal,
typename Packet>
1212 void Teuchos::broadcast(
1214 const int rootRank,
const Ordinal count, Packet buffer[]
1217 TEUCHOS_COMM_TIME_MONITOR(
1218 "Teuchos::CommHelpers: broadcast<" 1223 charBuffer(count,buffer);
1225 rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1230 template<
typename Ordinal,
typename Packet>
1231 void Teuchos::broadcast(
1237 broadcast<Ordinal, Packet>(comm, rootRank, buffer.
size(), buffer.
getRawPtr() );
1241 template<
typename Ordinal,
typename Packet>
1242 void Teuchos::broadcast(
1244 const int rootRank, Packet *
object 1247 broadcast<Ordinal,Packet>(comm,rootRank,1,object);
1251 template<
typename Ordinal,
typename Packet>
1252 void Teuchos::broadcast(
1257 broadcast<Ordinal,Packet>(comm,rootRank,1,
object.getRawPtr());
1261 template<
typename Ordinal,
typename Packet>
1262 void Teuchos::broadcast(
1264 const int rootRank,
const Ordinal count, Packet*
const buffer[]
1267 TEUCHOS_COMM_TIME_MONITOR(
1268 "Teuchos::CommHelpers: broadcast<" 1270 <<
">( reference type )" 1273 charBuffer(serializer, count, buffer);
1280 template<
typename Ordinal,
typename Packet>
1281 void Teuchos::broadcast(
1287 for (
int i = 0; i < buffer.
size(); ++i) {
1288 bufferPtrArray.
push_back(buffer[i].getRawPtr());
1290 broadcast<Ordinal,Packet>(comm, serializer, rootRank,
1294 template<
typename Ordinal,
typename Packet,
typename Serializer>
1295 void Teuchos::broadcast(
1298 const int rootRank,
const Ordinal count, Packet buffer[]
1301 TEUCHOS_COMM_TIME_MONITOR(
1302 "Teuchos::CommHelpers: broadcast<" 1307 charBuffer(count,buffer,
rcp(&serializer,
false));
1309 rootRank,charBuffer.getBytes(),charBuffer.getCharBuffer()
1314 template<
typename Ordinal,
typename Packet>
1315 void Teuchos::gatherAll(
1317 const Ordinal sendCount,
const Packet sendBuffer[],
1318 const Ordinal recvCount, Packet recvBuffer[]
1321 TEUCHOS_COMM_TIME_MONITOR(
1322 "Teuchos::CommHelpers: gatherAll<" 1327 charSendBuffer(sendCount,sendBuffer);
1329 charRecvBuffer(recvCount,recvBuffer);
1331 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1332 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
1336 template<
typename Ordinal,
typename Packet>
1338 Teuchos::gather (
const Packet sendBuf[],
1339 const Ordinal sendCount,
1341 const Ordinal recvCount,
1345 TEUCHOS_COMM_TIME_MONITOR(
1346 "Teuchos::CommHelpers: gather<" 1351 charSendBuffer (sendCount, sendBuf);
1353 charRecvBuffer (recvCount, recvBuf);
1354 comm.
gather (charSendBuffer.getBytes (),
1355 charSendBuffer.getCharBuffer (),
1356 charRecvBuffer.getBytes (),
1357 charRecvBuffer.getCharBuffer (),
1361 template<
typename Ordinal,
typename Packet>
1363 Teuchos::gatherv (
const Packet sendBuf[],
1364 const Ordinal sendCount,
1366 const Ordinal recvCounts[],
1367 const Ordinal displs[],
1392 "Teuchos::gatherv: The general case is not implemented.");
1395 template<
typename Ordinal,
typename Packet>
1396 void Teuchos::gatherAll(
1398 const Ordinal sendCount,
const Packet*
const sendBuffer[],
1399 const Ordinal recvCount, Packet*
const recvBuffer[]
1405 template<
typename Ordinal,
typename Packet,
typename Serializer>
1406 void Teuchos::gatherAll(
1409 const Ordinal sendCount,
const Packet sendBuffer[],
1410 const Ordinal recvCount, Packet recvBuffer[]
1413 TEUCHOS_COMM_TIME_MONITOR(
1414 "Teuchos::CommHelpers: gatherAll<" 1419 charSendBuffer(sendCount,sendBuffer,
rcp(&serializer,
false));
1421 charRecvBuffer(recvCount,recvBuffer,
rcp(&serializer,
false));
1423 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1424 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
1429 template<
typename Ordinal,
typename Packet>
1431 Teuchos::reduce (
const Packet sendBuf[],
1433 const Ordinal count,
1434 const EReductionType reductType,
1442 (
true, std::logic_error,
"Teuchos::reduce<" <<
1444 <<
">: Generic version not implemented. We only implement this function " 1445 "for Ordinal = int and Packet = specific types.");
1449 template<
typename Ordinal,
typename Packet>
1452 ,
const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
1455 TEUCHOS_COMM_TIME_MONITOR(
1456 "Teuchos::CommHelpers: reduceAll<" 1458 <<
">( value type, user-defined op )" 1461 charSendBuffer(count,sendBuffer);
1463 charGlobalReducts(count,globalReducts);
1465 charReductOp(
rcp(&reductOp,
false));
1467 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
1468 ,charGlobalReducts.getCharBuffer()
1473 template<
typename Ordinal,
typename Packet>
1476 const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
1479 TEUCHOS_COMM_TIME_MONITOR(
1480 "Teuchos::CommHelpers: reduceAll<" 1482 <<
">( value type, "<<toString(reductType)<<
" )" 1486 createOp<Ordinal, Packet> (reductType);
1488 reduceAll(comm,*reductOp,count,sendBuffer,globalReducts);
1490 catch (std::exception& e) {
1506 #ifdef HAVE_TEUCHOS_COMPLEX 1509 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1510 reduceAll<int, std::complex<double> > (
const Comm<int>& comm,
1511 const EReductionType reductType,
1513 const std::complex<double> sendBuffer[],
1514 std::complex<double> globalReducts[]);
1517 ireceive<int, std::complex<double> > (
const Comm<int>& comm,
1519 const int sourceRank);
1523 const int sourceRank,
1527 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1528 send<int, std::complex<double> > (
const Comm<int>& comm,
1530 const std::complex<double> sendBuffer[],
1531 const int destRank);
1533 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1534 send<int, std::complex<double> > (
const std::complex<double> sendBuffer[],
1548 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1549 reduceAll<int, std::complex<float> > (
const Comm<int>& comm,
1550 const EReductionType reductType,
1552 const std::complex<float> sendBuffer[],
1553 std::complex<float> globalReducts[]);
1556 ireceive<int, std::complex<float> > (
const Comm<int>& comm,
1558 const int sourceRank);
1562 const int sourceRank,
1566 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1567 send<int, std::complex<float> > (
const Comm<int>& comm,
1569 const std::complex<float> sendBuffer[],
1570 const int destRank);
1572 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1573 send<int, std::complex<float> > (
const std::complex<float> sendBuffer[],
1584 #endif // HAVE_TEUCHOS_COMPLEX 1589 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1590 reduceAll<int, double> (
const Comm<int>& comm,
1591 const EReductionType reductType,
1593 const double sendBuffer[],
1594 double globalReducts[]);
1597 ireceive<int, double> (
const Comm<int>& comm,
1599 const int sourceRank);
1603 const int sourceRank,
1607 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1608 send<int, double> (
const Comm<int>& comm,
1610 const double sendBuffer[],
1611 const int destRank);
1613 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1614 send<int, double> (
const double sendBuffer[],
1628 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1629 reduceAll<int, float> (
const Comm<int>& comm,
1630 const EReductionType reductType,
1632 const float sendBuffer[],
1633 float globalReducts[]);
1636 ireceive<int, float> (
const Comm<int>& comm,
1638 const int sourceRank);
1642 const int sourceRank,
1646 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1647 send<int, float> (
const Comm<int>& comm,
1649 const float sendBuffer[],
1650 const int destRank);
1652 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1653 send<int, float> (
const float sendBuffer[],
1665 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 1668 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1669 gather<int, long long> (
const long long sendBuf[],
1670 const int sendCount,
1671 long long recvBuf[],
1672 const int recvCount,
1676 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1677 gatherv<int, long long> (
const long long sendBuf[],
1678 const int sendCount,
1679 long long recvBuf[],
1680 const int recvCounts[],
1685 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1686 reduceAll<int, long long> (
const Comm<int>& comm,
1687 const EReductionType reductType,
1689 const long long sendBuffer[],
1690 long long globalReducts[]);
1693 ireceive<int, long long> (
const Comm<int>& comm,
1695 const int sourceRank);
1699 const int sourceRank,
1703 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1704 send<int, long long> (
const Comm<int>& comm,
1706 const long long sendBuffer[],
1707 const int destRank);
1709 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1710 send<int, long long> (
const long long sendBuffer[],
1724 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1725 gather<int, unsigned long long> (
const unsigned long long sendBuf[],
1726 const int sendCount,
1727 unsigned long long recvBuf[],
1728 const int recvCount,
1732 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1733 gatherv<int, unsigned long long> (
const unsigned long long sendBuf[],
1734 const int sendCount,
1735 unsigned long long recvBuf[],
1736 const int recvCounts[],
1741 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1742 reduceAll<int, unsigned long long> (
const Comm<int>& comm,
1743 const EReductionType reductType,
1745 const unsigned long long sendBuffer[],
1746 unsigned long long globalReducts[]);
1749 ireceive<int, unsigned long long> (
const Comm<int>& comm,
1751 const int sourceRank);
1755 const int sourceRank,
1759 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1760 send<int, unsigned long long> (
const Comm<int>& comm,
1762 const unsigned long long sendBuffer[],
1763 const int destRank);
1765 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1766 send<int, unsigned long long> (
const unsigned long long sendBuffer[],
1777 #endif // HAVE_TEUCHOS_LONG_LONG_INT 1781 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1782 gather<int, long> (
const long sendBuf[],
1783 const int sendCount,
1785 const int recvCount,
1789 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1790 gatherv<int, long> (
const long sendBuf[],
1791 const int sendCount,
1793 const int recvCounts[],
1798 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1799 reduceAll<int, long> (
const Comm<int>& comm,
1800 const EReductionType reductType,
1802 const long sendBuffer[],
1803 long globalReducts[]);
1806 ireceive<int, long> (
const Comm<int>& comm,
1808 const int sourceRank);
1812 const int sourceRank,
1816 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1819 const long sendBuffer[],
1820 const int destRank);
1822 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1823 send<int, long> (
const long sendBuffer[],
1837 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1838 gather<int, unsigned long> (
const unsigned long sendBuf[],
1839 const int sendCount,
1840 unsigned long recvBuf[],
1841 const int recvCount,
1845 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1846 gatherv<int, unsigned long> (
const unsigned long sendBuf[],
1847 const int sendCount,
1848 unsigned long recvBuf[],
1849 const int recvCounts[],
1854 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1855 reduceAll<int, unsigned long> (
const Comm<int>& comm,
1856 const EReductionType reductType,
1858 const unsigned long sendBuffer[],
1859 unsigned long globalReducts[]);
1862 ireceive<int, unsigned long> (
const Comm<int>& comm,
1864 const int sourceRank);
1868 const int sourceRank,
1872 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1873 send<int, unsigned long> (
const Comm<int>& comm,
1875 const unsigned long sendBuffer[],
1876 const int destRank);
1878 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1879 send<int, unsigned long> (
const unsigned long sendBuffer[],
1893 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1894 gather<int, int> (
const int sendBuf[],
1895 const int sendCount,
1897 const int recvCount,
1901 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1902 gatherv<int, int> (
const int sendBuf[],
1903 const int sendCount,
1905 const int recvCounts[],
1910 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1911 scatter (
const int sendBuf[],
1912 const int sendCount,
1914 const int recvCount,
1918 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1919 reduce<int, int> (
const int sendBuf[],
1922 const EReductionType reductType,
1926 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1927 reduceAll<int, int> (
const Comm<int>& comm,
1928 const EReductionType reductType,
1930 const int sendBuffer[],
1931 int globalReducts[]);
1935 ireceive<int, int> (
const Comm<int>& comm,
1937 const int sourceRank);
1941 const int sourceRank,
1945 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1948 const int sendBuffer[],
1949 const int destRank);
1951 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1952 send<int, int> (
const int sendBuffer[],
1966 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1967 gather<int, unsigned int> (
const unsigned int sendBuf[],
1968 const int sendCount,
1969 unsigned int recvBuf[],
1970 const int recvCount,
1974 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1975 gatherv<int, unsigned int> (
const unsigned int sendBuf[],
1976 const int sendCount,
1977 unsigned int recvBuf[],
1978 const int recvCounts[],
1983 TEUCHOSCOMM_LIB_DLL_EXPORT
void 1984 reduceAll<int, unsigned int> (
const Comm<int>& comm,
1985 const EReductionType reductType,
1987 const unsigned int sendBuffer[],
1988 unsigned int globalReducts[]);
1991 ireceive<int, unsigned int> (
const Comm<int>& comm,
1993 const int sourceRank);
1997 const int sourceRank,
2001 TEUCHOSCOMM_LIB_DLL_EXPORT
void 2002 send<int, unsigned int> (
const Comm<int>& comm,
2004 const unsigned int sendBuffer[],
2005 const int destRank);
2007 TEUCHOSCOMM_LIB_DLL_EXPORT
void 2008 send<int, unsigned int> (
const unsigned int sendBuffer[],
2022 TEUCHOSCOMM_LIB_DLL_EXPORT
void 2023 gather<int, short> (
const short sendBuf[],
2024 const int sendCount,
2026 const int recvCount,
2030 TEUCHOSCOMM_LIB_DLL_EXPORT
void 2031 gatherv<int, short> (
const short sendBuf[],
2032 const int sendCount,
2034 const int recvCounts[],
2039 TEUCHOSCOMM_LIB_DLL_EXPORT
void 2040 reduceAll<int, short> (
const Comm<int>& comm,
2041 const EReductionType reductType,
2043 const short sendBuffer[],
2044 short globalReducts[]);
2047 ireceive<int, short> (
const Comm<int>& comm,
2049 const int sourceRank);
2053 const int sourceRank,
2057 TEUCHOSCOMM_LIB_DLL_EXPORT
void 2058 send<int, short> (
const Comm<int>& comm,
2060 const short sendBuffer[],
2061 const int destRank);
2063 TEUCHOSCOMM_LIB_DLL_EXPORT
void 2064 send<int, short> (
const short sendBuffer[],
2087 TEUCHOSCOMM_LIB_DLL_EXPORT
void 2088 reduceAll<int, char> (
const Comm<int>& comm,
2089 const EReductionType reductType,
2091 const char sendBuffer[],
2092 char globalReducts[]);
2097 template<
typename Ordinal,
typename Packet>
2105 reduceAll<Ordinal,Packet>(comm, reductType, 1, &
send, &*globalReduct);
2109 template<
typename Ordinal,
typename Packet>
2113 const Ordinal count,
const Packet*
const sendBuffer[], Packet*
const globalReducts[]
2116 TEUCHOS_COMM_TIME_MONITOR(
2117 "Teuchos::CommHelpers: reduceAll<" 2119 <<
">( reference type )" 2122 charSendBuffer(serializer,count,sendBuffer);
2124 charGlobalReducts(serializer,count,globalReducts);
2126 charReductOp(
rcp(&serializer,
false),
rcp(&reductOp,
false));
2133 template<
typename Ordinal,
typename Packet,
typename Serializer>
2138 const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
2141 TEUCHOS_COMM_TIME_MONITOR(
2142 "Teuchos::CommHelpers: reduceAll<" 2144 <<
">( value type, user-defined op )" 2147 charSendBuffer(count,sendBuffer,
rcp(&serializer,
false));
2149 charGlobalReducts(count,globalReducts,
rcp(&serializer,
false));
2151 charReductOp(
rcp(&reductOp,
false),
rcp(&serializer,
false));
2153 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2154 ,charGlobalReducts.getCharBuffer()
2159 template<
typename Ordinal,
typename Packet,
typename Serializer>
2163 const EReductionType reductType,
2164 const Ordinal count,
const Packet sendBuffer[], Packet globalReducts[]
2167 TEUCHOS_COMM_TIME_MONITOR(
2168 "Teuchos::CommHelpers: reduceAll<" 2170 <<
">( value type, "<<toString(reductType)<<
" )" 2174 createOp<Ordinal, Packet> (reductType);
2176 reduceAll(comm,serializer,*reductOp,count,sendBuffer,globalReducts);
2178 catch (std::exception& e) {
2186 template<
typename Ordinal,
typename Packet>
2189 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
2192 TEUCHOS_COMM_TIME_MONITOR(
2193 "Teuchos::CommHelpers: scan<" 2195 <<
">( value type, user-defined op )" 2198 charSendBuffer(count,sendBuffer);
2200 charScanReducts(count,scanReducts);
2202 charReductOp(
rcp(&reductOp,
false));
2204 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2205 ,charScanReducts.getCharBuffer()
2210 template<
typename Ordinal,
typename Packet>
2213 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
2216 TEUCHOS_COMM_TIME_MONITOR(
2217 "Teuchos::CommHelpers: scan<" 2219 <<
">( value type, "<<toString(reductType)<<
" )" 2223 createOp<Ordinal, Packet> (reductType);
2225 scan(comm,*reductOp,count,sendBuffer,scanReducts);
2227 catch (std::exception& e) {
2235 template<
typename Ordinal,
typename Packet>
2241 scan<Ordinal,Packet>(comm, reductType, 1, &
send, &*scanReduct);
2245 template<
typename Ordinal,
typename Packet>
2249 const Ordinal count,
const Packet*
const sendBuffer[], Packet*
const scanReducts[]
2255 template<
typename Ordinal,
typename Packet,
typename Serializer>
2260 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
2263 TEUCHOS_COMM_TIME_MONITOR(
2264 "Teuchos::CommHelpers: scan<" 2266 <<
">( value type, user-defined op )" 2269 charSendBuffer(count,sendBuffer,
rcp(&serializer,
false));
2271 charScanReducts(count,scanReducts,
rcp(&serializer,
false));
2273 charReductOp(
rcp(&reductOp,
false),
rcp(&serializer,
false));
2275 charReductOp,charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2276 ,charScanReducts.getCharBuffer()
2281 template<
typename Ordinal,
typename Packet,
typename Serializer>
2285 const EReductionType reductType,
2286 const Ordinal count,
const Packet sendBuffer[], Packet scanReducts[]
2289 TEUCHOS_COMM_TIME_MONITOR(
2290 "Teuchos::CommHelpers: scan<" 2292 <<
">( value type, "<<toString(reductType)<<
" )" 2296 createOp<Ordinal, Packet> (reductType);
2298 scan(comm,serializer,*reductOp,count,sendBuffer,scanReducts);
2300 catch (std::exception& e) {
2307 template<
typename Ordinal,
typename Packet>
2310 const Ordinal count,
const Packet sendBuffer[],
const int destRank
2313 TEUCHOS_COMM_TIME_MONITOR(
2314 "Teuchos::CommHelpers: send<" 2319 charSendBuffer(count,sendBuffer);
2321 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2326 template<
typename Ordinal,
typename Packet>
2329 const Ordinal count,
2334 TEUCHOS_COMM_TIME_MONITOR(
2335 "Teuchos::CommHelpers: send<" 2340 comm.
send (charSendBuffer.getBytes (), charSendBuffer.getCharBuffer (), destRank, tag);
2343 template<
typename Ordinal,
typename Packet>
2346 const Ordinal count,
const Packet sendBuffer[],
const int destRank
2349 TEUCHOS_COMM_TIME_MONITOR(
2350 "Teuchos::CommHelpers: ssend<" 2355 charSendBuffer(count,sendBuffer);
2357 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2362 template<
typename Ordinal,
typename Packet>
2365 const Ordinal count,
2370 TEUCHOS_COMM_TIME_MONITOR(
2371 "Teuchos::CommHelpers: ssend<" 2376 buf_type charSendBuffer (count, sendBuffer);
2377 comm.
ssend (charSendBuffer.getBytes (),
2378 charSendBuffer.getCharBuffer (),
2382 template<
typename Ordinal,
typename Packet>
2385 const Packet &
send,
const int destRank
2388 Teuchos::send<Ordinal,Packet>(comm,1,&
send,destRank);
2391 template<
typename Ordinal,
typename Packet>
2394 const Packet &
send,
const int destRank
2397 Teuchos::ssend<Ordinal,Packet>(comm,1,&
send,destRank);
2400 template<
typename Ordinal,
typename Packet>
2403 const Ordinal count,
const Packet*
const sendBuffer[],
const int destRank
2409 template<
typename Ordinal,
typename Packet,
typename Serializer>
2413 const Ordinal count,
const Packet sendBuffer[],
const int destRank
2416 TEUCHOS_COMM_TIME_MONITOR(
2417 "Teuchos::CommHelpers: send<" 2422 charSendBuffer(count,sendBuffer,
rcp(&serializer,
false));
2424 charSendBuffer.getBytes(),charSendBuffer.getCharBuffer()
2429 template<
typename Ordinal,
typename Packet>
2430 int Teuchos::receive(
2432 const int sourceRank,
const Ordinal count, Packet recvBuffer[]
2435 TEUCHOS_COMM_TIME_MONITOR(
2436 "Teuchos::CommHelpers: receive<" 2441 charRecvBuffer(count,recvBuffer);
2444 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
2449 template<
typename Ordinal,
typename Packet>
2450 int Teuchos::receive(
2452 const int sourceRank, Packet *recv
2455 return Teuchos::receive<Ordinal,Packet>(comm,sourceRank,1,recv);
2459 template<
typename Ordinal,
typename Packet>
2460 int Teuchos::receive(
2462 const int sourceRank,
const Ordinal count, Packet*
const recvBuffer[]
2468 template<
typename Ordinal,
typename Packet,
typename Serializer>
2469 int Teuchos::receive(
2472 const int sourceRank,
const Ordinal count, Packet recvBuffer[]
2475 TEUCHOS_COMM_TIME_MONITOR(
2476 "Teuchos::CommHelpers: receive<" 2481 charRecvBuffer(count,recvBuffer,
rcp(&serializer,
false));
2484 ,charRecvBuffer.getBytes(),charRecvBuffer.getCharBuffer()
2488 template<
typename Ordinal,
typename Packet>
2495 TEUCHOS_COMM_TIME_MONITOR(
2496 "Teuchos::CommHelpers: readySend<" 2502 comm.
readySend( charSendBuffer.getCharBufferView(), destRank );
2505 template<
typename Ordinal,
typename Packet>
2508 const Ordinal count,
2513 TEUCHOS_COMM_TIME_MONITOR(
2514 "Teuchos::CommHelpers: readySend<" 2519 buf_type charSendBuffer (count, sendBuffer);
2520 comm.
readySend (charSendBuffer.getBytes (),
2521 charSendBuffer.getCharBuffer (),
2525 template<
typename Ordinal,
typename Packet>
2532 readySend<Ordinal, Packet>( comm, arrayView(&
send,1), destRank );
2535 template<
typename Ordinal,
typename Packet,
typename Serializer>
2543 TEUCHOS_COMM_TIME_MONITOR(
2544 "Teuchos::CommHelpers: readySend<" 2549 charSendBuffer(sendBuffer.
size(), sendBuffer.
getRawPtr(), serializer);
2550 comm.
readySend( charSendBuffer.getCharBufferView(), destRank );
2553 template<
typename Ordinal,
typename Packet>
2561 TEUCHOS_COMM_TIME_MONITOR(
2562 "Teuchos::CommHelpers: isend<" 2569 charSendBuffer.getCharBufferView(), destRank );
2570 set_extra_data( sendBuffer,
"buffer", inOutArg(commRequest) );
2574 template<
typename Ordinal,
typename Packet>
2581 TEUCHOS_COMM_TIME_MONITOR(
2585 charSendBuffer (sendBuffer.
size (), sendBuffer.
getRawPtr ());
2587 comm.
isend (charSendBuffer.getCharBufferView (), destRank, tag);
2588 set_extra_data (sendBuffer,
"buffer", inOutArg (commRequest));
2592 template<
typename Ordinal,
typename Packet>
2601 arcpWithEmbeddedObj( send.
get(), 0, 1,
send, false );
2604 return isend<Ordinal, Packet>( comm, sendBuffer, destRank );
2607 template<
typename Ordinal,
typename Packet,
typename Serializer>
2616 TEUCHOS_COMM_TIME_MONITOR(
2617 "Teuchos::CommHelpers: isend<" 2622 charSendBuffer(sendBuffer.
size(), sendBuffer.
getRawPtr(), serializer);
2624 charSendBuffer.getCharBufferView(), destRank );
2625 set_extra_data( sendBuffer,
"buffer", inOutArg(commRequest) );
2629 template<
typename Ordinal,
typename Packet>
2634 const int sourceRank
2637 TEUCHOS_COMM_TIME_MONITOR(
2642 charRecvBuffer.getCharBufferView(), sourceRank );
2643 set_extra_data( recvBuffer,
"buffer", inOutArg(commRequest) );
2647 template<
typename Ordinal,
typename Packet>
2650 const int sourceRank,
2654 TEUCHOS_COMM_TIME_MONITOR(
2657 charRecvBuffer (recvBuffer.
size (), recvBuffer.
getRawPtr ());
2659 comm.
ireceive (charRecvBuffer.getCharBufferView (), sourceRank, tag);
2660 set_extra_data (recvBuffer,
"buffer", inOutArg (commRequest));
2664 template<
typename Ordinal,
typename Packet>
2669 const int sourceRank
2673 arcpWithEmbeddedObj( recv.
get(), 0, 1, recv, false );
2676 return ireceive<Ordinal, Packet>( comm, recvBuffer, sourceRank );
2679 template<
typename Ordinal,
typename Packet,
typename Serializer>
2685 const int sourceRank
2688 TEUCHOS_COMM_TIME_MONITOR(
2689 "Teuchos::CommHelpers: ireceive<" 2694 charRecvBuffer(recvBuffer.
size(), recvBuffer.
getRawPtr(), serializer);
2696 charRecvBuffer.getCharBufferView(), sourceRank );
2697 set_extra_data( recvBuffer,
"buffer", inOutArg(commRequest) );
2701 template<
typename Ordinal>
2702 void Teuchos::waitAll(
2711 template<
typename Ordinal>
2717 comm.
waitAll (requests, statuses);
2721 template<
typename Ordinal>
2726 return comm.
wait (request);
2730 #endif // TEUCHOS_COMM_HELPERS_HPP virtual void reduceAll(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char globalReducts[]) const =0
Global reduction.
Strategy interface for the indirect serializing and deserializing objects of a given type handled usi...
char * getCharBuffer() const
Encapsulate how an array of non-const objects with reference sematics is serialized into a char[] arr...
virtual void readySend(const ArrayView< const char > &sendBuffer, const int destRank) const =0
Ready send of data from this process to another process.
EReductionType
Enumeration for selecting from a set of pre-defined reduction operations.
virtual RCP< CommStatus< Ordinal > > wait(const Ptr< RCP< CommRequest< Ordinal > > > &request) const =0
Wait on a single communication request, and return its status.
virtual void scan(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char scanReducts[]) const =0
Scan reduction.
size_type size() const
The total number of entries in the array.
virtual RCP< CommRequest< Ordinal > > ireceive(const ArrayView< char > &recvBuffer, const int sourceRank) const =0
Non-blocking receive.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
virtual void send(const Ordinal bytes, const char sendBuffer[], const int destRank) const =0
Possibly blocking send of data from this process to another process.
size_type size() const
The total number of items in the managed array.
T * getRawPtr()
Return a raw pointer to beginning of array or NULL if unsized.
Standard logical AND operator for booleans.
Standard min operator for types with value semantics.
T * get() const
Get the raw C++ pointer to the underlying object.
This structure defines some basic traits for a scalar field type.
Decorator class that uses traits to convert to and from char[] to typed buffers for objects that use ...
virtual void waitAll(const ArrayView< RCP< CommRequest< Ordinal > > > &requests) const =0
Wait on a set of communication requests.
void scatter(const Packet sendBuf[], const Ordinal sendCount, Packet recvBuf[], const Ordinal recvCount, const Ordinal root, const Comm< Ordinal > &comm)
Wrapper for MPI_Scatter; scatter collective.
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
Standard summation operator for types with value semantics.
const char * getCharBuffer() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
virtual void gather(const Ordinal sendBytes, const char sendBuffer[], const Ordinal recvBytes, char recvBuffer[], const int root) const =0
Gather values from all processes to the root process.
virtual void ssend(const Ordinal bytes, const char sendBuffer[], const int destRank) const =0
Always blocking send of data from this process to another process.
TEUCHOS_DEPRECATED void scan(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *scanReduct)
Deprecated.
Encapsulate how an array of const objects with reference sematics is serialized into a char[] array...
virtual int getRank() const =0
Returns the rank of this process.
Standard Max operator for types with value semantics.
Decorator class that uses a strategy object to convert to and from char[] to typed buffers for object...
Implementation of Teuchos wrappers for MPI.
virtual RCP< CommRequest< Ordinal > > isend(const ArrayView< const char > &sendBuffer, const int destRank) const =0
Non-blocking send.
This structure defines some basic traits for the ordinal field type.
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
Deprecated .
Encapsulation of the result of a receive (blocking or nonblocking).
void send(const Packet sendBuffer[], const Ordinal count, const int destRank, const int tag, const Comm< Ordinal > &comm)
Variant of send() that takes a tag (and restores the correct order of arguments). ...
virtual void barrier() const =0
Pause every process in *this communicator until all the processes reach this point.
Encapsulate how an array of non-const objects with value sematics is serialized into a char[] array...
RCP< CommRequest< Ordinal > > ireceive(const ArrayRCP< Packet > &recvBuffer, const int sourceRank, const int tag, const Comm< Ordinal > &comm)
Variant of ireceive that takes a tag argument (and restores the correct order of arguments).
Templated array class derived from the STL std::vector.
Abstract interface for distributed-memory communication.
void push_back(const value_type &x)
T * getRawPtr() const
Return a raw pointer to beginning of array or NULL if unsized.
Defines basic traits for the ordinal field type.
Default traits class that just returns typeid(T).name().
virtual void broadcast(const int rootRank, const Ordinal bytes, char buffer[]) const =0
Broadcast values from the root process to the slave processes.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
Base interface class for user-defined reduction operations for objects that use reference semantics...
virtual void gatherAll(const Ordinal sendBytes, const char sendBuffer[], const Ordinal recvBytes, char recvBuffer[]) const =0
Gather values from each process to collect on all processes.
void ssend(const Packet sendBuffer[], const Ordinal count, const int destRank, const int tag, const Comm< Ordinal > &comm)
Variant of ssend() that takes a tag (and restores the correct order of arguments).
Defines basic traits for the scalar field type.
Smart reference counting pointer class for automatic garbage collection.
RCP< CommRequest< Ordinal > > isend(const ArrayRCP< const Packet > &sendBuffer, const int destRank, const int tag, const Comm< Ordinal > &comm)
Variant of isend() that takes a tag (and restores the correct order of arguments).
virtual int receive(const int sourceRank, const Ordinal bytes, char recvBuffer[]) const =0
Blocking receive of data from this process to another process.
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
Encapsulation of a pending nonblocking communication operation.
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
Defines basic traits returning the name of a type in a portable and readable way. ...
Definition of Teuchos::as, for conversions between types.
void reduce(const Ordinal count, const Packet inBuffer[], Packet inoutBuffer[]) const
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...
virtual int getSize() const =0
Returns the number of processes that make up this communicator.
Encapsulate how an array of const objects with value sematics is serialized into a const char[] array...
Reference-counted smart pointer for managing arrays.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...