99 void print(std::ostream&
out)
const {
102 const size_t size = entries_.size();
105 for (
const auto&
keyval : entries_) {
114 if (
k +
size_t(1) <
size) {
123 size_t numInSrcNotInTgt;
138 if (
it == entries_.end()) {
142 return {
it->second.size(),
true};
160 std::unique_ptr<std::string>
prefix;
162 prefix = createPrefix(
"update_impl");
163 std::ostringstream
os;
168 std::cerr <<
os.str();
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;
190 std::sort(srcGblColInds, srcEnd);
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_;
void verbosePrintArray(std::ostream &out, const ArrayType &x, const char name[], const size_t maxNumToPrint)
Print min(x.size(), maxNumToPrint) entries of x.