/usr/include/trilinos/Tpetra_DistObject_def.hpp is in libtrilinos-tpetra-dev 12.4.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 | // @HEADER
// ***********************************************************************
//
// Tpetra: Templated Linear Algebra Services Package
// Copyright (2008) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
//
// ************************************************************************
// @HEADER
#ifndef TPETRA_DISTOBJECT_DEF_HPP
#define TPETRA_DISTOBJECT_DEF_HPP
/// \file Tpetra_DistObject_def.hpp
/// \brief Definition of the Tpetra::DistObject class
///
/// If you want to use Tpetra::DistObject, include
/// "Tpetra_DistObject.hpp" (a file which CMake generates and installs
/// for you). If you only want the declaration of Tpetra::DistObject,
/// include "Tpetra_DistObject_decl.hpp".
#include "Tpetra_Distributor.hpp"
namespace Tpetra {
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
DistObject (const Teuchos::RCP<const map_type>& map) :
map_ (map)
{
#ifdef HAVE_TPETRA_TRANSFER_TIMERS
using Teuchos::RCP;
using Teuchos::Time;
using Teuchos::TimeMonitor;
RCP<Time> doXferTimer =
TimeMonitor::lookupCounter ("Tpetra::DistObject::doTransfer");
if (doXferTimer.is_null ()) {
doXferTimer =
TimeMonitor::getNewCounter ("Tpetra::DistObject::doTransfer");
}
doXferTimer_ = doXferTimer;
RCP<Time> copyAndPermuteTimer =
TimeMonitor::lookupCounter ("Tpetra::DistObject::copyAndPermute");
if (copyAndPermuteTimer.is_null ()) {
copyAndPermuteTimer =
TimeMonitor::getNewCounter ("Tpetra::DistObject::copyAndPermute");
}
copyAndPermuteTimer_ = copyAndPermuteTimer;
RCP<Time> packAndPrepareTimer =
TimeMonitor::lookupCounter ("Tpetra::DistObject::packAndPrepare");
if (packAndPrepareTimer.is_null ()) {
packAndPrepareTimer =
TimeMonitor::getNewCounter ("Tpetra::DistObject::packAndPrepare");
}
packAndPrepareTimer_ = packAndPrepareTimer;
RCP<Time> doPostsAndWaitsTimer =
TimeMonitor::lookupCounter ("Tpetra::DistObject::doPostsAndWaits");
if (doPostsAndWaitsTimer.is_null ()) {
doPostsAndWaitsTimer =
TimeMonitor::getNewCounter ("Tpetra::DistObject::doPostsAndWaits");
}
doPostsAndWaitsTimer_ = doPostsAndWaitsTimer;
RCP<Time> unpackAndCombineTimer =
TimeMonitor::lookupCounter ("Tpetra::DistObject::unpackAndCombine");
if (unpackAndCombineTimer.is_null ()) {
unpackAndCombineTimer =
TimeMonitor::getNewCounter ("Tpetra::DistObject::unpackAndCombine");
}
unpackAndCombineTimer_ = unpackAndCombineTimer;
#endif // HAVE_TPETRA_TRANSFER_TIMERS
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
DistObject (const DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>& rhs)
: map_ (rhs.map_)
{}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
~DistObject ()
{}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
std::string
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
description () const
{
using Teuchos::TypeNameTraits;
std::ostringstream os;
os << "\"Tpetra::DistObject\": {"
<< "Packet: " << TypeNameTraits<packet_type>::name ()
<< ", LocalOrdinal: " << TypeNameTraits<local_ordinal_type>::name ()
<< ", GlobalOrdinal: " << TypeNameTraits<global_ordinal_type>::name ()
<< ", Node: " << TypeNameTraits<Node>::name ();
if (this->getObjectLabel () != "") {
os << "Label: \"" << this->getObjectLabel () << "\"";
}
os << "}";
return os.str ();
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
void
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
describe (Teuchos::FancyOStream &out,
const Teuchos::EVerbosityLevel verbLevel) const
{
using Teuchos::rcpFromRef;
using Teuchos::TypeNameTraits;
using std::endl;
const Teuchos::EVerbosityLevel vl = (verbLevel == Teuchos::VERB_DEFAULT) ?
Teuchos::VERB_LOW : verbLevel;
Teuchos::RCP<const Teuchos::Comm<int> > comm = this->getMap ()->getComm ();
const int myRank = comm.is_null () ? 0 : comm->getRank ();
const int numProcs = comm.is_null () ? 1 : comm->getSize ();
if (vl != Teuchos::VERB_NONE) {
Teuchos::OSTab tab0 (out);
if (myRank == 0) {
out << "\"Tpetra::DistObject\":" << endl;
}
Teuchos::OSTab tab1 (out);
if (myRank == 0) {
out << "Template parameters:" << endl;
{
Teuchos::OSTab tab2 (out);
out << "Packet: " << TypeNameTraits<packet_type>::name () << endl
<< "LocalOrdinal: " << TypeNameTraits<local_ordinal_type>::name () << endl
<< "GlobalOrdinal: " << TypeNameTraits<global_ordinal_type>::name () << endl
<< "Node: " << TypeNameTraits<node_type>::name () << endl;
}
if (this->getObjectLabel () != "") {
out << "Label: \"" << this->getObjectLabel () << "\"" << endl;
}
} // if myRank == 0
// Describe the Map.
{
if (myRank == 0) {
out << "Map:" << endl;
}
Teuchos::OSTab tab2 (out);
map_->describe (out, vl);
}
// At verbosity > VERB_LOW, each process prints something.
if (vl > Teuchos::VERB_LOW) {
for (int p = 0; p < numProcs; ++p) {
if (myRank == p) {
out << "Process " << myRank << ":" << endl;
Teuchos::OSTab tab2 (out);
out << "Export buffer size (in packets): " << exports_.size ()
<< endl
<< "Import buffer size (in packets): " << imports_.size ()
<< endl;
}
if (! comm.is_null ()) {
comm->barrier (); // give output time to finish
comm->barrier ();
comm->barrier ();
}
} // for each process rank p
} // if vl > VERB_LOW
} // if vl != VERB_NONE
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
void
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap)
{
TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
"Tpetra::DistObject::removeEmptyProcessesInPlace: Not implemented");
}
/* These are provided in base DistObject template
template<class DistObjectType>
void
removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input,
const Teuchos::RCP<const Map<typename DistObjectType::local_ordinal_type,
typename DistObjectType::global_ordinal_type,
typename DistObjectType::node_type> >& newMap)
{
input->removeEmptyProcessesInPlace (newMap);
if (newMap.is_null ()) { // my process is excluded
input = Teuchos::null;
}
}
template<class DistObjectType>
void
removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input)
{
using Teuchos::RCP;
typedef typename DistObjectType::local_ordinal_type LO;
typedef typename DistObjectType::global_ordinal_type GO;
typedef typename DistObjectType::node_type NT;
typedef Map<LO, GO, NT> map_type;
RCP<const map_type> newMap = input->getMap ()->removeEmptyProcesses ();
removeEmptyProcessesInPlace<DistObjectType> (input, newMap);
}
*/
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
void
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
doImport (const SrcDistObject& source,
const Import<LocalOrdinal, GlobalOrdinal, Node>& importer,
CombineMode CM)
{
TEUCHOS_TEST_FOR_EXCEPTION(*getMap() != *importer.getTargetMap(),
std::invalid_argument, "doImport: The target DistObject's Map is not "
"identical to the Import's target Map.");
#ifdef HAVE_TPETRA_DEBUG
{
const this_type* srcDistObj = dynamic_cast<const this_type*> (&source);
TEUCHOS_TEST_FOR_EXCEPTION(
srcDistObj != NULL && * (srcDistObj->getMap ()) != *importer.getSourceMap(),
std::invalid_argument, "doImport: The source is a DistObject, yet its "
"Map is not identical to the Import's source Map.");
}
#endif // HAVE_TPETRA_DEBUG
size_t numSameIDs = importer.getNumSameIDs ();
typedef Teuchos::ArrayView<const LocalOrdinal> view_type;
const view_type exportLIDs = importer.getExportLIDs();
const view_type remoteLIDs = importer.getRemoteLIDs();
const view_type permuteToLIDs = importer.getPermuteToLIDs();
const view_type permuteFromLIDs = importer.getPermuteFromLIDs();
this->doTransfer (source, CM, numSameIDs, permuteToLIDs, permuteFromLIDs,
remoteLIDs, exportLIDs, importer.getDistributor (),
DoForward);
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
void
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
doExport (const SrcDistObject& source,
const Export<LocalOrdinal, GlobalOrdinal, Node>& exporter,
CombineMode CM)
{
TEUCHOS_TEST_FOR_EXCEPTION(
*getMap() != *exporter.getTargetMap(), std::invalid_argument,
"doExport: The target DistObject's Map is not identical to the Export's "
"target Map.");
#ifdef HAVE_TPETRA_DEBUG
{
const this_type* srcDistObj = dynamic_cast<const this_type*> (&source);
TEUCHOS_TEST_FOR_EXCEPTION(
srcDistObj != NULL && * (srcDistObj->getMap ()) != *exporter.getSourceMap(),
std::invalid_argument, "doExport: The source is a DistObject, yet its "
"Map is not identical to the Export's source Map.");
}
#endif // HAVE_TPETRA_DEBUG
size_t numSameIDs = exporter.getNumSameIDs();
typedef ArrayView<const LocalOrdinal> view_type;
view_type exportLIDs = exporter.getExportLIDs();
view_type remoteLIDs = exporter.getRemoteLIDs();
view_type permuteToLIDs = exporter.getPermuteToLIDs();
view_type permuteFromLIDs = exporter.getPermuteFromLIDs();
doTransfer (source, CM, numSameIDs, permuteToLIDs, permuteFromLIDs, remoteLIDs,
exportLIDs, exporter.getDistributor (), DoForward);
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
void
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
doImport (const SrcDistObject& source,
const Export<LocalOrdinal, GlobalOrdinal, Node> & exporter,
CombineMode CM)
{
TEUCHOS_TEST_FOR_EXCEPTION(
*getMap() != *exporter.getSourceMap(), std::invalid_argument,
"doImport (reverse mode): The target DistObject's Map is not identical "
"to the Export's source Map.");
#ifdef HAVE_TPETRA_DEBUG
{
const this_type* srcDistObj = dynamic_cast<const this_type*> (&source);
TEUCHOS_TEST_FOR_EXCEPTION(
srcDistObj != NULL && * (srcDistObj->getMap ()) != *exporter.getTargetMap(),
std::invalid_argument,
"doImport (reverse mode): The source is a DistObject, yet its "
"Map is not identical to the Export's target Map.");
}
#endif // HAVE_TPETRA_DEBUG
size_t numSameIDs = exporter.getNumSameIDs();
typedef ArrayView<const LocalOrdinal> view_type;
view_type exportLIDs = exporter.getRemoteLIDs();
view_type remoteLIDs = exporter.getExportLIDs();
view_type permuteToLIDs = exporter.getPermuteFromLIDs();
view_type permuteFromLIDs = exporter.getPermuteToLIDs();
doTransfer (source, CM, numSameIDs, permuteToLIDs, permuteFromLIDs, remoteLIDs,
exportLIDs, exporter.getDistributor (), DoReverse);
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
void
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
doExport (const SrcDistObject& source,
const Import<LocalOrdinal, GlobalOrdinal, Node> & importer,
CombineMode CM)
{
TEUCHOS_TEST_FOR_EXCEPTION(
*getMap() != *importer.getSourceMap(), std::invalid_argument,
"doExport (reverse mode): The target object's Map "
"is not identical to the Import's source Map.");
#ifdef HAVE_TPETRA_DEBUG
{
const this_type* srcDistObj = dynamic_cast<const this_type*> (&source);
TEUCHOS_TEST_FOR_EXCEPTION(
srcDistObj != NULL && * (srcDistObj->getMap ()) != *importer.getTargetMap(),
std::invalid_argument,
"doExport (reverse mode): The source is a DistObject, yet its "
"Map is not identical to the Import's target Map.");
}
#endif // HAVE_TPETRA_DEBUG
size_t numSameIDs = importer.getNumSameIDs();
typedef ArrayView<const LocalOrdinal> view_type;
view_type exportLIDs = importer.getRemoteLIDs();
view_type remoteLIDs = importer.getExportLIDs();
view_type permuteToLIDs = importer.getPermuteFromLIDs();
view_type permuteFromLIDs = importer.getPermuteToLIDs();
doTransfer (source, CM, numSameIDs, permuteToLIDs, permuteFromLIDs, remoteLIDs,
exportLIDs, importer.getDistributor (), DoReverse);
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
bool
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
isDistributed () const {
return map_->isDistributed ();
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
size_t
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
constantNumberOfPackets () const {
return 0; // default implementation; subclasses may override
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
void
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
doTransfer (const SrcDistObject& src,
CombineMode CM,
size_t numSameIDs,
const Teuchos::ArrayView<const LocalOrdinal>& permuteToLIDs_,
const Teuchos::ArrayView<const LocalOrdinal>& permuteFromLIDs_,
const Teuchos::ArrayView<const LocalOrdinal>& remoteLIDs_,
const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs_,
Distributor &distor,
ReverseOption revOp)
{
if (this->useNewInterface()) {
doTransferNew(src, CM, numSameIDs, permuteToLIDs_, permuteFromLIDs_, remoteLIDs_, exportLIDs_, distor, revOp);
}
else {
doTransferOld(src, CM, numSameIDs, permuteToLIDs_, permuteFromLIDs_, remoteLIDs_, exportLIDs_, distor, revOp);
}
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
void
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
doTransferOld (const SrcDistObject& src,
CombineMode CM,
size_t numSameIDs,
const Teuchos::ArrayView<const LocalOrdinal>& permuteToLIDs,
const Teuchos::ArrayView<const LocalOrdinal>& permuteFromLIDs,
const Teuchos::ArrayView<const LocalOrdinal>& remoteLIDs,
const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
Distributor &distor,
ReverseOption revOp)
{
#ifdef HAVE_TPETRA_TRANSFER_TIMERS
Teuchos::TimeMonitor doXferMon (*doXferTimer_);
#endif // HAVE_TPETRA_TRANSFER_TIMERS
TEUCHOS_TEST_FOR_EXCEPTION(
! checkSizes (src), std::invalid_argument,
"Tpetra::DistObject::doTransfer(): checkSizes() indicates that the "
"destination object is not a legal target for redistribution from the "
"source object. This probably means that they do not have the same "
"dimensions. For example, MultiVectors must have the same number of "
"rows and columns.");
KokkosClassic::ReadWriteOption rwo = KokkosClassic::ReadWrite;
if (CM == INSERT || CM == REPLACE) {
const size_t numIDsToWrite = numSameIDs +
static_cast<size_t> (permuteToLIDs.size ()) +
static_cast<size_t> (remoteLIDs.size ());
if (numIDsToWrite == this->getMap ()->getNodeNumElements ()) {
// We're overwriting all of our local data in the destination
// object, so a write-only view suffices.
//
// FIXME (mfh 10 Apr 2012) This doesn't make sense for a
// CrsMatrix with a dynamic graph. INSERT mode could mean
// that we're adding new entries to the object, but we don't
// want to get rid of the old ones.
rwo = KokkosClassic::WriteOnly;
}
}
// Tell the source to create a read-only view of its data. On a
// discrete accelerator such as a GPU, this brings EVERYTHING from
// device memory to host memory.
//
// FIXME (mfh 23 Mar 2012) By passing in the list of GIDs (or
// rather, local LIDs to send) and packet counts, createViews()
// could create a "sparse view" that only brings in the necessary
// data from device to host memory.
const this_type* srcDistObj = dynamic_cast<const this_type*> (&src);
if (srcDistObj != NULL) {
srcDistObj->createViews ();
}
// Tell the target to create a view of its data. Depending on
// rwo, this could be a write-only view or a read-and-write view.
// On a discrete accelerator such as a GPU, a write-only view only
// requires a transfer from host to device memory. A
// read-and-write view requires a two-way transfer. This has the
// same problem as createViews(): it transfers EVERYTHING, not
// just the necessary data.
//
// FIXME (mfh 23 Mar 2012) By passing in the list of GIDs (or
// rather, local LIDs into which to receive) and packet counts,
// createViewsNonConst() could create a "sparse view" that only
// transfers the necessary data.
this->createViewsNonConst (rwo);
if (numSameIDs + permuteToLIDs.size()) {
#ifdef HAVE_TPETRA_TRANSFER_TIMERS
Teuchos::TimeMonitor copyAndPermuteMon (*copyAndPermuteTimer_);
#endif // HAVE_TPETRA_TRANSFER_TIMERS
// There is at least one GID to copy or permute.
copyAndPermute (src, numSameIDs, permuteToLIDs, permuteFromLIDs);
}
// The method may return zero even if the implementation actually
// does have a constant number of packets per LID. However, if it
// returns nonzero, we may use this information to avoid
// (re)allocating num{Ex,Im}portPacketsPerLID_. packAndPrepare()
// will set this to its final value.
//
// We only need this if CM != ZERO, but it has to be lifted out of
// that scope because there are multiple tests for CM != ZERO.
size_t constantNumPackets = this->constantNumberOfPackets ();
// We only need to pack communication buffers if the combine mode
// is not ZERO. A "ZERO combine mode" means that the results are
// the same as if we had received all zeros, and added them to the
// existing values. That means we don't need to communicate.
if (CM != ZERO) {
if (constantNumPackets == 0) {
numExportPacketsPerLID_old_.resize (exportLIDs.size ());
numImportPacketsPerLID_old_.resize (remoteLIDs.size ());
}
{
#ifdef HAVE_TPETRA_TRANSFER_TIMERS
Teuchos::TimeMonitor packAndPrepareMon (*packAndPrepareTimer_);
#endif // HAVE_TPETRA_TRANSFER_TIMERS
// Ask the source to pack data. Also ask it whether there are a
// constant number of packets per element (constantNumPackets is
// an output argument). If there are, constantNumPackets will
// come back nonzero. Otherwise, the source will fill the
// numExportPacketsPerLID_ array.
packAndPrepare (src, exportLIDs, exports_old_, numExportPacketsPerLID_old_ (),
constantNumPackets, distor);
}
}
// We don't need the source's data anymore, so it can let go of
// its views. On an accelerator device with a separate memory
// space (like a GPU), this frees host memory, since device memory
// has the "master" version of the data.
if (srcDistObj != NULL) {
srcDistObj->releaseViews ();
}
// We only need to send data if the combine mode is not ZERO.
if (CM != ZERO) {
if (constantNumPackets != 0) {
// There are a constant number of packets per element. We
// already know (from the number of "remote" (incoming)
// elements) how many incoming elements we expect, so we can
// resize the buffer accordingly.
const size_t rbufLen = remoteLIDs.size() * constantNumPackets;
if (static_cast<size_t> (imports_old_.size()) != rbufLen) {
imports_old_.resize (rbufLen);
}
}
// Do we need to do communication (via doPostsAndWaits)?
bool needCommunication = true;
if (revOp == DoReverse && ! isDistributed ()) {
needCommunication = false;
}
// FIXME (mfh 30 Jun 2013): Checking whether the source object
// is distributed requires a cast to DistObject. If it's not a
// DistObject, then I'm not quite sure what to do. Perhaps it
// would be more appropriate for SrcDistObject to have an
// isDistributed() method. For now, I'll just assume that we
// need to do communication unless the cast succeeds and the
// source is not distributed.
else if (revOp == DoForward && srcDistObj != NULL &&
! srcDistObj->isDistributed ()) {
needCommunication = false;
}
if (needCommunication) {
if (revOp == DoReverse) {
#ifdef HAVE_TPETRA_TRANSFER_TIMERS
Teuchos::TimeMonitor doPostsAndWaitsMon (*doPostsAndWaitsTimer_);
#endif // HAVE_TPETRA_TRANSFER_TIMERS
if (constantNumPackets == 0) { //variable num-packets-per-LID:
distor.doReversePostsAndWaits (numExportPacketsPerLID_old_().getConst(),
1,
numImportPacketsPerLID_old_());
size_t totalImportPackets = 0;
for (Array_size_type i = 0; i < numImportPacketsPerLID_old_.size(); ++i) {
totalImportPackets += numImportPacketsPerLID_old_[i];
}
imports_old_.resize(totalImportPackets);
distor.doReversePostsAndWaits (exports_old_().getConst(),
numExportPacketsPerLID_old_(),
imports_old_(),
numImportPacketsPerLID_old_());
}
else {
distor.doReversePostsAndWaits (exports_old_ ().getConst (),
constantNumPackets,
imports_old_ ());
}
}
else { // revOp == DoForward
#ifdef HAVE_TPETRA_TRANSFER_TIMERS
Teuchos::TimeMonitor doPostsAndWaitsMon (*doPostsAndWaitsTimer_);
#endif // HAVE_TPETRA_TRANSFER_TIMERS
if (constantNumPackets == 0) { //variable num-packets-per-LID:
distor.doPostsAndWaits (numExportPacketsPerLID_old_().getConst(), 1,
numImportPacketsPerLID_old_());
size_t totalImportPackets = 0;
for (Array_size_type i = 0; i < numImportPacketsPerLID_old_.size(); ++i) {
totalImportPackets += numImportPacketsPerLID_old_[i];
}
imports_old_.resize(totalImportPackets);
distor.doPostsAndWaits (exports_old_().getConst(),
numExportPacketsPerLID_old_(),
imports_old_(),
numImportPacketsPerLID_old_());
}
else {
distor.doPostsAndWaits (exports_old_ ().getConst (),
constantNumPackets,
imports_old_ ());
}
}
{
#ifdef HAVE_TPETRA_TRANSFER_TIMERS
Teuchos::TimeMonitor unpackAndCombineMon (*unpackAndCombineTimer_);
#endif // HAVE_TPETRA_TRANSFER_TIMERS
unpackAndCombine (remoteLIDs, imports_old_(), numImportPacketsPerLID_old_(),
constantNumPackets, distor, CM);
}
}
} // if (CM != ZERO)
this->releaseViews ();
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
void
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
doTransferNew (const SrcDistObject& src,
CombineMode CM,
size_t numSameIDs,
const Teuchos::ArrayView<const LocalOrdinal>& permuteToLIDs_,
const Teuchos::ArrayView<const LocalOrdinal>& permuteFromLIDs_,
const Teuchos::ArrayView<const LocalOrdinal>& remoteLIDs_,
const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs_,
Distributor &distor,
ReverseOption revOp)
{
using Kokkos::Compat::getArrayView;
using Kokkos::Compat::getConstArrayView;
using Kokkos::Compat::getKokkosViewDeepCopy;
using Kokkos::Compat::create_const_view;
#ifdef HAVE_TPETRA_TRANSFER_TIMERS
Teuchos::TimeMonitor doXferMon (*doXferTimer_);
#endif // HAVE_TPETRA_TRANSFER_TIMERS
// Convert arguments to Kokkos::View's (involves deep copy to device)
//
// FIXME (mfh 17 Feb 2014) getKokkosViewDeepCopy _always_ does a
// deep copy. It has to, since it returns a managed Kokkos::View,
// but the input Teuchos::ArrayView is unmanaged. One way to fix
// this would be to change the interface by replacing the
// Teuchos::ArrayView inputs with Kokkos::View inputs. This is
// the approach taken by Kokkos::DistObjectKA. Some points:
//
// 1. It's perfectly OK to change the interface of doTransfer.
// It should take Kokkos::View by default, and convert to
// Teuchos::Array{RCP,View} if needed internally.
// 2. Recall that Teuchos::ArrayView is an unmanaged view.
// 3. If DistObject ever gets a nonblocking interface, that
// interface should take managed views.
typedef Kokkos::View<const LocalOrdinal*, execution_space> lo_const_view_type;
lo_const_view_type permuteToLIDs =
getKokkosViewDeepCopy<execution_space> (permuteToLIDs_);
lo_const_view_type permuteFromLIDs =
getKokkosViewDeepCopy<execution_space> (permuteFromLIDs_);
lo_const_view_type remoteLIDs =
getKokkosViewDeepCopy<execution_space> (remoteLIDs_);
lo_const_view_type exportLIDs =
getKokkosViewDeepCopy<execution_space> (exportLIDs_);
TEUCHOS_TEST_FOR_EXCEPTION(
! checkSizes (src), std::invalid_argument,
"Tpetra::DistObject::doTransfer(): checkSizes() indicates that the "
"destination object is not a legal target for redistribution from the "
"source object. This probably means that they do not have the same "
"dimensions. For example, MultiVectors must have the same number of "
"rows and columns.");
KokkosClassic::ReadWriteOption rwo = KokkosClassic::ReadWrite;
if (CM == INSERT || CM == REPLACE) {
const size_t numIDsToWrite = numSameIDs +
static_cast<size_t> (permuteToLIDs.size ()) +
static_cast<size_t> (remoteLIDs.size ());
if (numIDsToWrite == this->getMap ()->getNodeNumElements ()) {
// We're overwriting all of our local data in the destination
// object, so a write-only view suffices.
//
// FIXME (mfh 10 Apr 2012) This doesn't make sense for a
// CrsMatrix with a dynamic graph. INSERT mode could mean
// that we're adding new entries to the object, but we don't
// want to get rid of the old ones.
rwo = KokkosClassic::WriteOnly;
}
}
// FIXME (mfh 17 Feb 2014) We're assuming that MPI can read device
// memory (that's even pre-UVM), so there is no need to create
// host views of the source object's data.
// Tell the source to create a read-only view of its data. On a
// discrete accelerator such as a GPU, this brings EVERYTHING from
// device memory to host memory.
//
// FIXME (mfh 23 Mar 2012) By passing in the list of GIDs (or
// rather, local LIDs to send) and packet counts, createViews()
// could create a "sparse view" that only brings in the necessary
// data from device to host memory.
const this_type* srcDistObj = dynamic_cast<const this_type*> (&src);
if (srcDistObj != NULL) {
srcDistObj->createViews ();
}
// FIXME (mfh 17 Feb 2014) We're assuming that MPI can read device
// memory (that's even pre-UVM), so there is no need to create
// host views of the target object's data.
// Tell the target to create a view of its data. Depending on
// rwo, this could be a write-only view or a read-and-write view.
// On a discrete accelerator such as a GPU, a write-only view only
// requires a transfer from host to device memory. A
// read-and-write view requires a two-way transfer. This has the
// same problem as createViews(): it transfers EVERYTHING, not
// just the necessary data.
//
// FIXME (mfh 23 Mar 2012) By passing in the list of GIDs (or
// rather, local LIDs into which to receive) and packet counts,
// createViewsNonConst() could create a "sparse view" that only
// transfers the necessary data.
this->createViewsNonConst (rwo);
if (numSameIDs + permuteToLIDs.size()) {
#ifdef HAVE_TPETRA_TRANSFER_TIMERS
Teuchos::TimeMonitor copyAndPermuteMon (*copyAndPermuteTimer_);
#endif // HAVE_TPETRA_TRANSFER_TIMERS
// FIXME (mfh 17 Feb 2014) Nobody implements DistObject
// subclasses but Tpetra developers anyway, so don't bother with
// this "new" business. Just write the interface you want.
// There is at least one GID to copy or permute.
copyAndPermuteNew (src, numSameIDs, permuteToLIDs, permuteFromLIDs);
}
// The method may return zero even if the implementation actually
// does have a constant number of packets per LID. However, if it
// returns nonzero, we may use this information to avoid
// (re)allocating num{Ex,Im}portPacketsPerLID_. packAndPrepare()
// will set this to its final value.
//
// We only need this if CM != ZERO, but it has to be lifted out of
// that scope because there are multiple tests for CM != ZERO.
size_t constantNumPackets = this->constantNumberOfPackets ();
// We only need to pack communication buffers if the combine mode
// is not ZERO. A "ZERO combine mode" means that the results are
// the same as if we had received all zeros, and added them to the
// existing values. That means we don't need to communicate.
if (CM != ZERO) {
if (constantNumPackets == 0) {
// FIXME (mfh 17 Feb 2014) Don't "realloc" unless you really
// need to. That will avoid a bit of time for reinitializing
// the Views' data.
Kokkos::Compat::realloc (numExportPacketsPerLID_, exportLIDs.size ());
Kokkos::Compat::realloc (numImportPacketsPerLID_, remoteLIDs.size ());
}
{
#ifdef HAVE_TPETRA_TRANSFER_TIMERS
Teuchos::TimeMonitor packAndPrepareMon (*packAndPrepareTimer_);
#endif // HAVE_TPETRA_TRANSFER_TIMERS
// Ask the source to pack data. Also ask it whether there are a
// constant number of packets per element (constantNumPackets is
// an output argument). If there are, constantNumPackets will
// come back nonzero. Otherwise, the source will fill the
// numExportPacketsPerLID_ array.
packAndPrepareNew (src, exportLIDs, exports_, numExportPacketsPerLID_,
constantNumPackets, distor);
}
}
// FIXME (mfh 17 Feb 2014) See comments above; there is no need to
// create host views of the source object's data.
// We don't need the source's data anymore, so it can let go of
// its views. On an accelerator device with a separate memory
// space (like a GPU), this frees host memory, since device memory
// has the "master" version of the data.
if (srcDistObj != NULL) {
srcDistObj->releaseViews ();
}
// We only need to send data if the combine mode is not ZERO.
if (CM != ZERO) {
if (constantNumPackets != 0) {
// There are a constant number of packets per element. We
// already know (from the number of "remote" (incoming)
// elements) how many incoming elements we expect, so we can
// resize the buffer accordingly.
const size_t rbufLen = remoteLIDs.size() * constantNumPackets;
if (static_cast<size_t> (imports_.size()) != rbufLen) {
Kokkos::Compat::realloc (imports_, rbufLen);
}
}
// FIXME (mfh 17 Feb 2014) Why do we need to create mirror
// views? Furthermore, if we do need to do this, we should only
// do it _once_, since the arrays are constant (they come from
// the Import / Export object, which is constant).
// Create mirror views of [import|export]PacketsPerLID
typename Kokkos::View<size_t*,execution_space>::HostMirror host_numExportPacketsPerLID =
Kokkos::create_mirror_view (numExportPacketsPerLID_);
typename Kokkos::View<size_t*,execution_space>::HostMirror host_numImportPacketsPerLID =
Kokkos::create_mirror_view (numImportPacketsPerLID_);
// Copy numExportPacketsPerLID to host
Kokkos::deep_copy (host_numExportPacketsPerLID, numExportPacketsPerLID_);
// Do we need to do communication (via doPostsAndWaits)?
bool needCommunication = true;
if (revOp == DoReverse && ! isDistributed ()) {
needCommunication = false;
}
// FIXME (mfh 30 Jun 2013): Checking whether the source object
// is distributed requires a cast to DistObject. If it's not a
// DistObject, then I'm not quite sure what to do. Perhaps it
// would be more appropriate for SrcDistObject to have an
// isDistributed() method. For now, I'll just assume that we
// need to do communication unless the cast succeeds and the
// source is not distributed.
else if (revOp == DoForward && srcDistObj != NULL &&
! srcDistObj->isDistributed ()) {
needCommunication = false;
}
// FIXME (mfh 17 Feb 2014) Distributor doesn't actually inspect
// the contents of the "exports" or "imports" arrays, other than
// to do a deep copy in the (should be technically unnecessary,
// but isn't for some odd reason) "self-message" case.
// Distributor thus doesn't need host views; it could do just
// fine with device views, assuming that MPI knows how to read
// device memory (which doesn't even require UVM).
if (needCommunication) {
if (revOp == DoReverse) {
#ifdef HAVE_TPETRA_TRANSFER_TIMERS
Teuchos::TimeMonitor doPostsAndWaitsMon (*doPostsAndWaitsTimer_);
#endif // HAVE_TPETRA_TRANSFER_TIMERS
if (constantNumPackets == 0) { //variable num-packets-per-LID:
distor.doReversePostsAndWaits (create_const_view (host_numExportPacketsPerLID),
1,
host_numImportPacketsPerLID);
size_t totalImportPackets = 0;
// FIXME (mfh 17 Feb 2014) This would be a good place for
// a Kokkos reduction. numImportPacketsPerLID_ has as
// many entries as the number of LIDs on the calling
// process.
for (view_size_type i = 0; i < numImportPacketsPerLID_.size(); ++i) {
totalImportPackets += host_numImportPacketsPerLID[i];
}
// FIXME (mfh 17 Feb 2014) Only realloc if necessary.
Kokkos::Compat::realloc (imports_, totalImportPackets);
distor.doReversePostsAndWaits (create_const_view (exports_),
getArrayView (host_numExportPacketsPerLID),
imports_,
getArrayView (host_numImportPacketsPerLID));
}
else {
distor.doReversePostsAndWaits (create_const_view (exports_),
constantNumPackets,
imports_);
}
}
else { // revOp == DoForward
#ifdef HAVE_TPETRA_TRANSFER_TIMERS
Teuchos::TimeMonitor doPostsAndWaitsMon (*doPostsAndWaitsTimer_);
#endif // HAVE_TPETRA_TRANSFER_TIMERS
if (constantNumPackets == 0) { //variable num-packets-per-LID:
distor.doPostsAndWaits (create_const_view (host_numExportPacketsPerLID), 1,
host_numImportPacketsPerLID);
size_t totalImportPackets = 0;
// FIXME (mfh 17 Feb 2014) This would be a good place for
// a Kokkos reduction. numImportPacketsPerLID_ has as
// many entries as the number of LIDs on the calling
// process.
for (view_size_type i = 0; i < numImportPacketsPerLID_.size(); ++i) {
totalImportPackets += host_numImportPacketsPerLID[i];
}
// FIXME (mfh 17 Feb 2014) Only realloc if necessary.
Kokkos::Compat::realloc (imports_, totalImportPackets);
distor.doPostsAndWaits (create_const_view (exports_),
getArrayView (host_numExportPacketsPerLID),
imports_,
getArrayView (host_numImportPacketsPerLID));
}
else {
distor.doPostsAndWaits (create_const_view (exports_),
constantNumPackets,
imports_);
}
}
// FIXME (mfh 17 Feb 2014) This array should just live on the
// device and stay there. There is no need for a host view,
// as long as unpackAndCombine(new) knows what to do with a
// device view.
//
// Copy numImportPacketsPerLID to device
Kokkos::deep_copy (numImportPacketsPerLID_, host_numImportPacketsPerLID);
{
#ifdef HAVE_TPETRA_TRANSFER_TIMERS
Teuchos::TimeMonitor unpackAndCombineMon (*unpackAndCombineTimer_);
#endif // HAVE_TPETRA_TRANSFER_TIMERS
unpackAndCombineNew (remoteLIDs, imports_, numImportPacketsPerLID_,
constantNumPackets, distor, CM);
}
}
} // if (CM != ZERO)
// FIXME (mfh 17 Dec(??? probably Feb) 2014) We don't have to call
// releaseViews() on the destination object any more, since MPI
// knows how to read device memory.
this->releaseViews ();
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
void
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
print (std::ostream &os) const
{
using Teuchos::FancyOStream;
using Teuchos::getFancyOStream;
using Teuchos::RCP;
using Teuchos::rcpFromRef;
using std::endl;
RCP<FancyOStream> out = getFancyOStream (rcpFromRef (os));
this->describe (*out, Teuchos::VERB_DEFAULT);
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
void
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
createViews () const
{}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
void
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
createViewsNonConst (KokkosClassic::ReadWriteOption /*rwo*/)
{}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
void
DistObject<Packet, LocalOrdinal, GlobalOrdinal, Node, classic>::
releaseViews () const
{}
template<class DistObjectType>
void
removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input,
const Teuchos::RCP<const Map<typename DistObjectType::local_ordinal_type,
typename DistObjectType::global_ordinal_type,
typename DistObjectType::node_type> >& newMap)
{
input->removeEmptyProcessesInPlace (newMap);
if (newMap.is_null ()) { // my process is excluded
input = Teuchos::null;
}
}
template<class DistObjectType>
void
removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input)
{
using Teuchos::RCP;
typedef typename DistObjectType::local_ordinal_type LO;
typedef typename DistObjectType::global_ordinal_type GO;
typedef typename DistObjectType::node_type NT;
typedef Map<LO, GO, NT> map_type;
RCP<const map_type> newMap = input->getMap ()->removeEmptyProcesses ();
removeEmptyProcessesInPlace<DistObjectType> (input, newMap);
}
// Explicit instantiation macro for general DistObject.
#define TPETRA_DISTOBJECT_INSTANT(SCALAR, LO, GO, NODE) \
template class DistObject< SCALAR , LO , GO , NODE >;
// Explicit instantiation macro for DistObject<char, ...>.
// The "SLGN" stuff above doesn't work for Packet=char.
#define TPETRA_DISTOBJECT_INSTANT_CHAR(LO, GO, NODE) \
template class DistObject< char , LO , GO , NODE >;
} // namespace Tpetra
#endif // TPETRA_DISTOBJECT_DEF_HPP
|