10 #ifndef TPETRA_DETAILS_CRSPADDING_HPP
11 #define TPETRA_DETAILS_CRSPADDING_HPP
27 template<
class LocalOrdinal,
class GlobalOrdinal>
30 using LO = LocalOrdinal;
31 using GO = GlobalOrdinal;
53 const LO targetLocalIndex,
55 const size_t origNumTgtEnt,
56 const bool tgtIsUnique,
58 const size_t origNumSrcEnt,
59 const bool srcIsUnique)
61 const LO whichSame = targetLocalIndex;
62 update_impl(Phase::SAME, whichSame, targetLocalIndex,
63 tgtGblColInds, origNumTgtEnt, tgtIsUnique,
64 srcGblColInds, origNumSrcEnt, srcIsUnique);
69 const LO whichPermute,
70 const LO targetLocalIndex,
72 const size_t origNumTgtEnt,
73 const bool tgtIsUnique,
75 const size_t origNumSrcEnt,
76 const bool srcIsUnique)
78 update_impl(Phase::PERMUTE, whichPermute, targetLocalIndex,
79 tgtGblColInds, origNumTgtEnt, tgtIsUnique,
80 srcGblColInds, origNumSrcEnt, srcIsUnique);
86 const LO targetLocalIndex,
88 const size_t origNumTgtEnt,
89 const bool tgtIsUnique,
91 const size_t origNumSrcEnt,
92 const bool srcIsUnique)
94 update_impl(Phase::IMPORT, whichImport, targetLocalIndex,
95 tgtGblColInds, origNumTgtEnt, tgtIsUnique,
96 srcGblColInds, origNumSrcEnt, srcIsUnique);
99 void print(std::ostream& out)
const {
100 const size_t maxNumToPrint =
102 const size_t size = entries_.size();
105 for (
const auto& keyval : entries_) {
106 if (k > maxNumToPrint) {
110 out <<
"(" << keyval.first <<
", ";
112 "Global column indices", maxNumToPrint);
114 if (k +
size_t(1) < size) {
123 size_t numInSrcNotInTgt;
137 auto it = entries_.find(targetLocalIndex);
138 if (it == entries_.end()) {
142 return {it->second.size(),
true};
150 const LO whichImport,
151 const LO targetLocalIndex,
153 const size_t origNumTgtEnt,
154 const bool tgtIsUnique,
156 const size_t origNumSrcEnt,
157 const bool srcIsUnique)
160 std::unique_ptr<std::string> prefix;
162 prefix = createPrefix(
"update_impl");
163 std::ostringstream os;
164 os << *prefix <<
"Start: "
165 <<
"targetLocalIndex=" << targetLocalIndex
166 <<
", origNumTgtEnt=" << origNumTgtEnt
167 <<
", origNumSrcEnt=" << origNumSrcEnt << endl;
168 std::cerr << os.str();
173 size_t newNumTgtEnt = origNumTgtEnt;
174 auto tgtEnd = tgtGblColInds + origNumTgtEnt;
177 tgtEnd = std::unique(tgtGblColInds, tgtEnd);
178 newNumTgtEnt = size_t(tgtEnd - tgtGblColInds);
179 TEUCHOS_ASSERT( newNumTgtEnt <= origNumTgtEnt );
183 std::ostringstream os;
184 os << *prefix <<
"finished src; process tgt" << endl;
185 std::cerr << os.str();
188 size_t newNumSrcEnt = origNumSrcEnt;
189 auto srcEnd = srcGblColInds + origNumSrcEnt;
192 srcEnd = std::unique(srcGblColInds, srcEnd);
193 newNumSrcEnt = size_t(srcEnd - srcGblColInds);
194 TEUCHOS_ASSERT( newNumSrcEnt <= origNumSrcEnt );
197 merge_with_current_state(phase, whichImport, targetLocalIndex,
198 tgtGblColInds, newNumTgtEnt,
199 srcGblColInds, newNumSrcEnt);
201 std::ostringstream os;
202 os << *prefix <<
"Done" << endl;
203 std::cerr << os.str();
208 get_difference_col_inds(
const Phase ,
210 const LO tgtLclRowInd)
212 return entries_[tgtLclRowInd];
216 merge_with_current_state(
219 const LO tgtLclRowInd,
220 const GO tgtColInds[],
221 const size_t numTgtEnt,
222 const GO srcColInds[],
223 const size_t numSrcEnt)
226 std::unique_ptr<std::string> prefix;
228 prefix = createPrefix(
"merge_with_current_state");
229 std::ostringstream os;
230 os << *prefix <<
"Start: "
231 <<
"tgtLclRowInd=" << tgtLclRowInd
232 <<
", numTgtEnt=" << numTgtEnt
233 <<
", numSrcEnt=" << numSrcEnt << endl;
234 std::cerr << os.str();
253 auto tgtEnd = tgtColInds + numTgtEnt;
254 auto srcEnd = srcColInds + numSrcEnt;
257 std::vector<GO>& diffColInds =
258 get_difference_col_inds(phase, whichIndex, tgtLclRowInd);
259 const size_t oldDiffNumEnt = diffColInds.size();
261 if (oldDiffNumEnt == 0) {
263 std::ostringstream os;
264 os << *prefix <<
"oldDiffNumEnt=0; call "
265 "set_difference(src,tgt,diff)" << endl;
266 std::cerr << os.str();
268 diffColInds.resize(numSrcEnt);
269 auto diffEnd = std::set_difference(srcColInds, srcEnd,
271 diffColInds.begin());
272 const size_t newLen(diffEnd - diffColInds.begin());
273 TEUCHOS_ASSERT( newLen <= numSrcEnt );
274 diffColInds.resize(newLen);
280 const size_t maxUnionSize = numSrcEnt + oldDiffNumEnt;
282 std::ostringstream os;
283 os << *prefix <<
"oldDiffNumEnt=" << oldDiffNumEnt
284 <<
", maxUnionSize=" << maxUnionSize
285 <<
"; call set_union(src,diff,union)" << endl;
286 std::cerr << os.str();
288 if (scratchColInds_.size() < maxUnionSize) {
289 scratchColInds_.resize(maxUnionSize);
291 auto unionBeg = scratchColInds_.begin();
292 auto unionEnd = std::set_union(srcColInds, srcEnd,
293 diffColInds.begin(), diffColInds.end(),
295 const size_t unionSize(unionEnd - unionBeg);
296 TEUCHOS_ASSERT( unionSize <= maxUnionSize );
299 std::ostringstream os;
300 os << *prefix <<
"oldDiffNumEnt=" << oldDiffNumEnt
301 <<
", unionSize=" << unionSize <<
"; call "
302 "set_difference(union,tgt,diff)" << endl;
303 std::cerr << os.str();
305 diffColInds.resize(unionSize);
306 auto diffEnd = std::set_difference(unionBeg, unionEnd,
308 diffColInds.begin());
309 const size_t diffLen(diffEnd - diffColInds.begin());
310 TEUCHOS_ASSERT( diffLen <= unionSize );
311 diffColInds.resize(diffLen);
315 std::ostringstream os;
316 os << *prefix <<
"Done" << endl;
317 std::cerr << os.str();
321 std::unique_ptr<std::string>
322 createPrefix(
const char funcName[])
324 std::ostringstream os;
325 os <<
"Proc " << myRank_ <<
": CrsPadding::" << funcName
327 return std::unique_ptr<std::string>(
new std::string(os.str()));
332 std::map<LO, std::vector<GO> > entries_;
333 std::vector<GO> scratchColInds_;
340 #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.
void sort(View &view, const size_t &size)
Convenience wrapper for std::sort for host-accessible views.
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.