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;
51 const LO targetLocalIndex,
53 const size_t origNumTgtEnt,
54 const bool tgtIsUnique,
56 const size_t origNumSrcEnt,
57 const bool srcIsUnique) {
58 const LO whichSame = targetLocalIndex;
59 update_impl(Phase::SAME, whichSame, targetLocalIndex,
60 tgtGblColInds, origNumTgtEnt, tgtIsUnique,
61 srcGblColInds, origNumSrcEnt, srcIsUnique);
66 const LO whichPermute,
67 const LO targetLocalIndex,
69 const size_t origNumTgtEnt,
70 const bool tgtIsUnique,
72 const size_t origNumSrcEnt,
73 const bool srcIsUnique) {
74 update_impl(Phase::PERMUTE, whichPermute, targetLocalIndex,
75 tgtGblColInds, origNumTgtEnt, tgtIsUnique,
76 srcGblColInds, origNumSrcEnt, srcIsUnique);
82 const LO targetLocalIndex,
84 const size_t origNumTgtEnt,
85 const bool tgtIsUnique,
87 const size_t origNumSrcEnt,
88 const bool srcIsUnique) {
89 update_impl(Phase::IMPORT, whichImport, targetLocalIndex,
90 tgtGblColInds, origNumTgtEnt, tgtIsUnique,
91 srcGblColInds, origNumSrcEnt, srcIsUnique);
94 void print(std::ostream& out)
const {
95 const size_t maxNumToPrint =
97 const size_t size = entries_.size();
100 for (
const auto& keyval : entries_) {
101 if (k > maxNumToPrint) {
105 out <<
"(" << keyval.first <<
", ";
107 "Global column indices", maxNumToPrint);
109 if (k +
size_t(1) < size) {
118 size_t numInSrcNotInTgt;
131 auto it = entries_.find(targetLocalIndex);
132 if (it == entries_.end()) {
135 return {it->second.size(),
true};
143 const LO whichImport,
144 const LO targetLocalIndex,
146 const size_t origNumTgtEnt,
147 const bool tgtIsUnique,
149 const size_t origNumSrcEnt,
150 const bool srcIsUnique) {
152 std::unique_ptr<std::string> prefix;
154 prefix = createPrefix(
"update_impl");
155 std::ostringstream os;
156 os << *prefix <<
"Start: "
157 <<
"targetLocalIndex=" << targetLocalIndex
158 <<
", origNumTgtEnt=" << origNumTgtEnt
159 <<
", origNumSrcEnt=" << origNumSrcEnt << endl;
160 std::cerr << os.str();
165 size_t newNumTgtEnt = origNumTgtEnt;
166 auto tgtEnd = tgtGblColInds + origNumTgtEnt;
169 tgtEnd = std::unique(tgtGblColInds, tgtEnd);
170 newNumTgtEnt = size_t(tgtEnd - tgtGblColInds);
171 TEUCHOS_ASSERT(newNumTgtEnt <= origNumTgtEnt);
175 std::ostringstream os;
176 os << *prefix <<
"finished src; process tgt" << endl;
177 std::cerr << os.str();
180 size_t newNumSrcEnt = origNumSrcEnt;
181 auto srcEnd = srcGblColInds + origNumSrcEnt;
184 srcEnd = std::unique(srcGblColInds, srcEnd);
185 newNumSrcEnt = size_t(srcEnd - srcGblColInds);
186 TEUCHOS_ASSERT(newNumSrcEnt <= origNumSrcEnt);
189 merge_with_current_state(phase, whichImport, targetLocalIndex,
190 tgtGblColInds, newNumTgtEnt,
191 srcGblColInds, newNumSrcEnt);
193 std::ostringstream os;
194 os << *prefix <<
"Done" << endl;
195 std::cerr << os.str();
200 get_difference_col_inds(
const Phase ,
202 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) {
216 std::unique_ptr<std::string> prefix;
218 prefix = createPrefix(
"merge_with_current_state");
219 std::ostringstream os;
220 os << *prefix <<
"Start: "
221 <<
"tgtLclRowInd=" << tgtLclRowInd
222 <<
", numTgtEnt=" << numTgtEnt
223 <<
", numSrcEnt=" << numSrcEnt << endl;
224 std::cerr << os.str();
243 auto tgtEnd = tgtColInds + numTgtEnt;
244 auto srcEnd = srcColInds + numSrcEnt;
247 std::vector<GO>& diffColInds =
248 get_difference_col_inds(phase, whichIndex, tgtLclRowInd);
249 const size_t oldDiffNumEnt = diffColInds.size();
251 if (oldDiffNumEnt == 0) {
253 std::ostringstream os;
254 os << *prefix <<
"oldDiffNumEnt=0; call "
255 "set_difference(src,tgt,diff)"
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);
270 const size_t maxUnionSize = numSrcEnt + oldDiffNumEnt;
272 std::ostringstream os;
273 os << *prefix <<
"oldDiffNumEnt=" << oldDiffNumEnt
274 <<
", maxUnionSize=" << maxUnionSize
275 <<
"; call set_union(src,diff,union)" << endl;
276 std::cerr << os.str();
278 if (scratchColInds_.size() < maxUnionSize) {
279 scratchColInds_.resize(maxUnionSize);
281 auto unionBeg = scratchColInds_.begin();
282 auto unionEnd = std::set_union(srcColInds, srcEnd,
283 diffColInds.begin(), diffColInds.end(),
285 const size_t unionSize(unionEnd - unionBeg);
286 TEUCHOS_ASSERT(unionSize <= maxUnionSize);
289 std::ostringstream os;
290 os << *prefix <<
"oldDiffNumEnt=" << oldDiffNumEnt
291 <<
", unionSize=" << unionSize <<
"; call "
292 "set_difference(union,tgt,diff)"
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[]) {
314 std::ostringstream os;
315 os <<
"Proc " << myRank_ <<
": CrsPadding::" << funcName
317 return std::unique_ptr<std::string>(
new std::string(os.str()));
322 std::map<LO, std::vector<GO> > entries_;
323 std::vector<GO> scratchColInds_;
330 #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.