94 void print(std::ostream&
out)
const {
97 const size_t size = entries_.size();
100 for (
const auto&
keyval : entries_) {
109 if (
k +
size_t(1) <
size) {
118 size_t numInSrcNotInTgt;
132 if (
it == entries_.end()) {
135 return {
it->second.size(),
true};
152 std::unique_ptr<std::string>
prefix;
154 prefix = createPrefix(
"update_impl");
155 std::ostringstream
os;
160 std::cerr <<
os.str();
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;
182 std::sort(srcGblColInds, srcEnd);
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_;
void verbosePrintArray(std::ostream &out, const ArrayType &x, const char name[], const size_t maxNumToPrint)
Print min(x.size(), maxNumToPrint) entries of x.