55 using ParentType = BCRSMatrix;
61 using Entries = std::vector<std::set<Index> >;
64 using ColIterator =
typename ParentType::ColIterator;
65 using ConstColIterator =
typename ParentType::ConstColIterator;
66 using block_type =
typename ParentType::block_type;
67 using field_type =
typename ParentType::field_type;
74 template <
class NativeBCRSMatrix>
80 overlap_ = std::make_shared<Overlap>(
nativeMatrix, borderList, blackList, overlapSize);
95 typename BCRSMatrix::BuildMode)
96 {
throw std::logic_error(
"OverlappingBCRSMatrix objects cannot be build from scratch!"); }
100 if (overlap_.use_count() == 0)
104 const PeerSet& peerSet = overlap_->peerSet();
105 typename PeerSet::const_iterator
peerIt = peerSet.begin();
106 typename PeerSet::const_iterator
peerEndIt = peerSet.end();
110 delete rowSizesRecvBuff_[peerRank];
111 delete rowIndicesRecvBuff_[peerRank];
112 delete entryColIndicesRecvBuff_[peerRank];
113 delete entryValuesRecvBuff_[peerRank];
115 delete numRowsSendBuff_[peerRank];
116 delete rowSizesSendBuff_[peerRank];
117 delete rowIndicesSendBuff_[peerRank];
118 delete entryColIndicesSendBuff_[peerRank];
119 delete entryValuesSendBuff_[peerRank];
123 ParentType& asParent()
126 const ParentType& asParent()
const
133 {
return *overlap_; }
153 template <
class NativeBCRSMatrix>
170 for (
unsigned i = 0; i <
idMatrix.size(); ++i)
173 int numLocal = overlap_->numLocal();
174 int numDomestic = overlap_->numDomestic();
188 for (
int i = 0; i < this->N(); ++i) {
189 if (overlap_->isLocal(i))
193 std::cout <<
"row " << i <<
" ";
195 using ColIt =
typename BCRSMatrix::ConstColIterator;
198 for (
int j = 0; j < this->M(); ++j) {
201 if (overlap_->isBorder(j))
203 else if (overlap_->isLocal(j))
211 std::cout <<
"\n" << std::flush;
213 Dune::printSparseMatrix(std::cout,
214 *
static_cast<const BCRSMatrix *
>(
this),
219 template <
class NativeBCRSMatrix>
223 BCRSMatrix::operator=(0.0);
254 for (
unsigned i = 0; i <
src.rows; ++i) {
255 for (
unsigned j = 0; j <
src.cols; ++j) {
256 dest[i][j] =
static_cast<field_type
>(
src[i][j]);
267 const PeerSet& peerSet = overlap_->peerSet();
268 typename PeerSet::const_iterator
peerIt = peerSet.begin();
269 typename PeerSet::const_iterator
peerEndIt = peerSet.end();
273 sendEntries_(peerRank);
281 receiveAddEntries_(peerRank);
289 entryValuesSendBuff_[peerRank]->wait();
298 const PeerSet& peerSet = overlap_->peerSet();
299 typename PeerSet::const_iterator
peerIt = peerSet.begin();
300 typename PeerSet::const_iterator
peerEndIt = peerSet.end();
304 sendEntries_(peerRank);
312 receiveCopyEntries_(peerRank);
320 entryValuesSendBuff_[peerRank]->wait();
325 template <
class NativeBCRSMatrix>
328 size_t numDomestic = overlap_->numDomestic();
331 this->
setSize(numDomestic, numDomestic);
338 template <
class NativeBCRSMatrix>
344 entries_.resize(overlap_->numDomestic());
374 const PeerSet& peerSet = overlap_->peerSet();
375 typename PeerSet::const_iterator
peerIt = peerSet.begin();
376 typename PeerSet::const_iterator
peerEndIt = peerSet.end();
386 receiveIndices_(peerRank);
394 numRowsSendBuff_[peerRank]->wait();
395 rowSizesSendBuff_[peerRank]->wait();
396 rowIndicesSendBuff_[peerRank]->wait();
397 entryColIndicesSendBuff_[peerRank]->wait();
401 globalToDomesticBuff_(*rowIndicesSendBuff_[peerRank]);
402 globalToDomesticBuff_(*entryColIndicesSendBuff_[peerRank]);
410 size_t numDomestic = overlap_->numDomestic();
413 const auto& colIndices = entries_[
rowIdx];
430 const auto& colIndices = entries_[
rowIdx];
449 template <
class NativeBCRSMatrix>
457 (*numRowsSendBuff_[peerRank])[0] =
static_cast<unsigned>(
numOverlapRows);
458 numRowsSendBuff_[peerRank]->send(peerRank);
511 auto*
rssb = rowSizesSendBuff_[peerRank];
522 rowSizesSendBuff_[peerRank]->send(peerRank);
523 rowIndicesSendBuff_[peerRank]->send(peerRank);
524 entryColIndicesSendBuff_[peerRank]->send(peerRank);
533 void receiveIndices_([[
maybe_unused]] ProcessRank peerRank)
547 rowSizesRecvBuff_[peerRank]->receive(peerRank);
548 rowIndicesRecvBuff_[peerRank]->receive(peerRank);
561 entryColIndicesRecvBuff_[peerRank]->receive(peerRank);
565 globalToDomesticBuff_(*rowIndicesRecvBuff_[peerRank]);
566 globalToDomesticBuff_(*entryColIndicesRecvBuff_[peerRank]);
572 for (
unsigned j = 0; j < (*rowSizesRecvBuff_[peerRank])[i]; ++j) {
581 void sendEntries_([[
maybe_unused]] ProcessRank peerRank)
584 auto &
mpiSendBuff = *entryValuesSendBuff_[peerRank];
610 void receiveAddEntries_([[
maybe_unused]] ProcessRank peerRank)
613 auto &
mpiRecvBuff = *entryValuesRecvBuff_[peerRank];
668 for (
unsigned i = 0; i <
idxBuff.size(); ++i)
674 std::shared_ptr<Overlap> overlap_;
676 std::map<ProcessRank, MpiBuffer<unsigned> *> numRowsSendBuff_;
677 std::map<ProcessRank, MpiBuffer<unsigned> *> rowSizesSendBuff_;
678 std::map<ProcessRank, MpiBuffer<Index> *> rowIndicesSendBuff_;
679 std::map<ProcessRank, MpiBuffer<Index> *> entryColIndicesSendBuff_;
680 std::map<ProcessRank, MpiBuffer<block_type> *> entryValuesSendBuff_;
682 std::map<ProcessRank, MpiBuffer<unsigned> > numRowsRecvBuff_;
683 std::map<ProcessRank, MpiBuffer<unsigned> *> rowSizesRecvBuff_;
684 std::map<ProcessRank, MpiBuffer<Index> *> rowIndicesRecvBuff_;
685 std::map<ProcessRank, MpiBuffer<Index> *> entryColIndicesRecvBuff_;
686 std::map<ProcessRank, MpiBuffer<block_type> *> entryValuesRecvBuff_;