1 #ifndef TPETRA_DETAILS_CRSPADDING_HPP 
    2 #define TPETRA_DETAILS_CRSPADDING_HPP 
   18     template<
class LocalOrdinal, 
class GlobalOrdinal>
 
   21       using LO = LocalOrdinal;
 
   22       using GO = GlobalOrdinal;
 
   44         const LO targetLocalIndex,
 
   46         const size_t origNumTgtEnt,
 
   47         const bool tgtIsUnique,
 
   49         const size_t origNumSrcEnt,
 
   50         const bool srcIsUnique)
 
   52         const LO whichSame = targetLocalIndex;
 
   53         update_impl(Phase::SAME, whichSame, targetLocalIndex,
 
   54                     tgtGblColInds, origNumTgtEnt, tgtIsUnique,
 
   55                     srcGblColInds, origNumSrcEnt, srcIsUnique);
 
   60         const LO whichPermute, 
 
   61         const LO targetLocalIndex,
 
   63         const size_t origNumTgtEnt,
 
   64         const bool tgtIsUnique,
 
   66         const size_t origNumSrcEnt,
 
   67         const bool srcIsUnique)
 
   69         update_impl(Phase::PERMUTE, whichPermute, targetLocalIndex,
 
   70                     tgtGblColInds, origNumTgtEnt, tgtIsUnique,
 
   71                     srcGblColInds, origNumSrcEnt, srcIsUnique);
 
   77         const LO targetLocalIndex,
 
   79         const size_t origNumTgtEnt,
 
   80         const bool tgtIsUnique,
 
   82         const size_t origNumSrcEnt,
 
   83         const bool srcIsUnique)
 
   85         update_impl(Phase::IMPORT, whichImport, targetLocalIndex,
 
   86                     tgtGblColInds, origNumTgtEnt, tgtIsUnique,
 
   87                     srcGblColInds, origNumSrcEnt, srcIsUnique);
 
   90       void print(std::ostream& out)
 const {
 
   91         const size_t maxNumToPrint =
 
   93         const size_t size = entries_.size();
 
   96         for (
const auto& keyval : entries_) {
 
   97           if (k > maxNumToPrint) {
 
  101           out << 
"(" << keyval.first << 
", ";
 
  103             "Global column indices", maxNumToPrint);
 
  105           if (k + 
size_t(1) < size) {
 
  114         size_t numInSrcNotInTgt;
 
  128         auto it = entries_.find(targetLocalIndex);
 
  129         if (it == entries_.end()) {
 
  133           return {it->second.size(), 
true};
 
  141         const LO whichImport,
 
  142         const LO targetLocalIndex,
 
  144         const size_t origNumTgtEnt,
 
  145         const bool tgtIsUnique,
 
  147         const size_t origNumSrcEnt,
 
  148         const bool srcIsUnique)
 
  151         std::unique_ptr<std::string> prefix;
 
  153           prefix = createPrefix(
"update_impl");
 
  154           std::ostringstream os;
 
  155           os << *prefix << 
"Start: " 
  156              << 
"targetLocalIndex=" << targetLocalIndex
 
  157              << 
", origNumTgtEnt=" << origNumTgtEnt
 
  158              << 
", origNumSrcEnt=" << origNumSrcEnt << endl;
 
  159           std::cerr << os.str();
 
  164         size_t newNumTgtEnt = origNumTgtEnt;
 
  165         auto tgtEnd = tgtGblColInds + origNumTgtEnt;
 
  166         std::sort(tgtGblColInds, tgtEnd);
 
  168           tgtEnd = std::unique(tgtGblColInds, tgtEnd);
 
  169           newNumTgtEnt = size_t(tgtEnd - tgtGblColInds);
 
  170           TEUCHOS_ASSERT( newNumTgtEnt <= origNumTgtEnt );
 
  174           std::ostringstream os;
 
  175           os << *prefix << 
"finished src; process tgt" << endl;
 
  176           std::cerr << os.str();
 
  179         size_t newNumSrcEnt = origNumSrcEnt;
 
  180         auto srcEnd = srcGblColInds + origNumSrcEnt;
 
  181         std::sort(srcGblColInds, srcEnd);
 
  183           srcEnd = std::unique(srcGblColInds, srcEnd);
 
  184           newNumSrcEnt = size_t(srcEnd - srcGblColInds);
 
  185           TEUCHOS_ASSERT( newNumSrcEnt <= origNumSrcEnt );
 
  188         merge_with_current_state(phase, whichImport, targetLocalIndex,
 
  189                                  tgtGblColInds, newNumTgtEnt,
 
  190                                  srcGblColInds, newNumSrcEnt);
 
  192           std::ostringstream os;
 
  193           os << *prefix << 
"Done" << endl;
 
  194           std::cerr << os.str();
 
  199       get_difference_col_inds(
const Phase ,
 
  201                               const LO tgtLclRowInd)
 
  203         return entries_[tgtLclRowInd];
 
  207       merge_with_current_state(
 
  210         const LO tgtLclRowInd,
 
  211         const GO tgtColInds[], 
 
  212         const size_t numTgtEnt,
 
  213         const GO srcColInds[], 
 
  214         const size_t numSrcEnt)
 
  217         std::unique_ptr<std::string> prefix;
 
  219           prefix = createPrefix(
"merge_with_current_state");
 
  220           std::ostringstream os;
 
  221           os << *prefix << 
"Start: " 
  222              << 
"tgtLclRowInd=" << tgtLclRowInd
 
  223              << 
", numTgtEnt=" << numTgtEnt
 
  224              << 
", numSrcEnt=" << numSrcEnt << endl;
 
  225           std::cerr << os.str();
 
  244         auto tgtEnd = tgtColInds + numTgtEnt;
 
  245         auto srcEnd = srcColInds + numSrcEnt;
 
  248         std::vector<GO>& diffColInds =
 
  249           get_difference_col_inds(phase, whichIndex, tgtLclRowInd);
 
  250         const size_t oldDiffNumEnt = diffColInds.size();
 
  252         if (oldDiffNumEnt == 0) {
 
  254             std::ostringstream os;
 
  255             os << *prefix << 
"oldDiffNumEnt=0; call " 
  256               "set_difference(src,tgt,diff)" << endl;
 
  257             std::cerr << os.str();
 
  259           diffColInds.resize(numSrcEnt);
 
  260           auto diffEnd = std::set_difference(srcColInds, srcEnd,
 
  262                                              diffColInds.begin());
 
  263           const size_t newLen(diffEnd - diffColInds.begin());
 
  264           TEUCHOS_ASSERT( newLen <= numSrcEnt );
 
  265           diffColInds.resize(newLen);
 
  271           const size_t maxUnionSize = numSrcEnt + oldDiffNumEnt;
 
  273             std::ostringstream os;
 
  274             os << *prefix << 
"oldDiffNumEnt=" << oldDiffNumEnt
 
  275                << 
", maxUnionSize=" << maxUnionSize
 
  276                << 
"; call set_union(src,diff,union)" << endl;
 
  277             std::cerr << os.str();
 
  279           if (scratchColInds_.size() < maxUnionSize) {
 
  280             scratchColInds_.resize(maxUnionSize);
 
  282           auto unionBeg = scratchColInds_.begin();
 
  283           auto unionEnd = std::set_union(srcColInds, srcEnd,
 
  284              diffColInds.begin(), diffColInds.end(),
 
  286           const size_t unionSize(unionEnd - unionBeg);
 
  287           TEUCHOS_ASSERT( unionSize <= maxUnionSize );
 
  290             std::ostringstream os;
 
  291             os << *prefix << 
"oldDiffNumEnt=" << oldDiffNumEnt
 
  292                << 
", unionSize=" << unionSize << 
"; call " 
  293               "set_difference(union,tgt,diff)" << endl;
 
  294             std::cerr << os.str();
 
  296           diffColInds.resize(unionSize);
 
  297           auto diffEnd = std::set_difference(unionBeg, unionEnd,
 
  299                                              diffColInds.begin());
 
  300           const size_t diffLen(diffEnd - diffColInds.begin());
 
  301           TEUCHOS_ASSERT( diffLen <= unionSize );
 
  302           diffColInds.resize(diffLen);
 
  306           std::ostringstream os;
 
  307           os << *prefix << 
"Done" << endl;
 
  308           std::cerr << os.str();
 
  312       std::unique_ptr<std::string>
 
  313       createPrefix(
const char funcName[])
 
  315         std::ostringstream os;
 
  316         os << 
"Proc " << myRank_ << 
": CrsPadding::" << funcName
 
  318         return std::unique_ptr<std::string>(
new std::string(os.str()));
 
  323       std::map<LO, std::vector<GO> > entries_;
 
  324       std::vector<GO> scratchColInds_;
 
  331 #endif // TPETRA_DETAILS_CRSPADDING_HPP 
Result get_result(const LO targetLocalIndex) const 
For a given target matrix local row index, return the number of unique source column indices to merge...
void verbosePrintArray(std::ostream &out, const ArrayType &x, const char name[], const size_t maxNumToPrint)
Print min(x.size(), maxNumToPrint) entries of x. 
Keep track of how much more space a CrsGraph or CrsMatrix needs, when the graph or matrix is the targ...
static bool verbose()
Whether Tpetra is in verbose mode. 
Stand-alone utility functions and macros. 
static size_t verbosePrintCountThreshold()
Number of entries below which arrays, lists, etc. will be printed in debug mode. 
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.