90 void print(std::ostream&
out)
const {
93 const size_t size = entries_.size();
96 for (
const auto&
keyval : entries_) {
105 if (
k +
size_t(1) <
size) {
114 size_t numInSrcNotInTgt;
129 if (
it == entries_.end()) {
133 return {
it->second.size(),
true};
151 std::unique_ptr<std::string>
prefix;
153 prefix = createPrefix(
"update_impl");
154 std::ostringstream
os;
159 std::cerr <<
os.str();
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_;
void verbosePrintArray(std::ostream &out, const ArrayType &x, const char name[], const size_t maxNumToPrint)
Print min(x.size(), maxNumToPrint) entries of x.