13#ifndef LOCALMATRICES_HH
14#define LOCALMATRICES_HH
36 template <
class Entry,
bool diagonal,
class SortedRowIdx,
class SortedColIdx>
43 : ridx_(
ridx), cidx_(
cidx), data(data_)
50 SortedRowIdx
ridx()
const {
return ridx_; }
55 SortedColIdx
cidx()
const {
return cidx_; }
65 return diagonal?
ridx().size():
ridx().size()*
cidx().size();
98 return data[row*
cidx().size()+col];
112 return data[row*
cidx().size()+col];
125 for (
int r=0; r<Aloc.N(); ++r)
126 data[r] = Aloc[r][r];
128 for (
int c=0; c<Aloc.M(); ++c)
129 for (
int r=0; r<Aloc.N(); ++r)
130 (*
this)(r,c) = Aloc[r][c];
145 template <
class Entry,
bool diagonal,
class SortedRowIdx,
class SortedColIdx>
148 int const n = A.
ridx().size();
149 int const m = A.
cidx().size();
151 for (
int i=0; i<n; ++i)
153 for (
int j=0; j<m; ++j)
154 out << (diagonal && i!=j? Entry(): A(i,j)) <<
" ";
177 template <
class Entry,
bool diagonal,
class SortedRowIdx,
class SortedColIdx,
178 class IT=void,
class IndexType=std::size_t>
189 : globalMatrix(&globalMatrix_)
190 , maxStorage(maxStorage_)
193 localData.reserve(maxStorage/
sizeof(Entry));
202 : globalMatrix(nullptr), maxStorage(0)
227 void push_back(SortedRowIdx
const& ridx, SortedColIdx
const& cidx)
230 size_t size = diagonal? ridx.size(): ridx.size()*cidx.size();
231 assert(ridx.size()==ridx.size() || !diagonal);
235 if (localData.capacity() < localData.size()+
size)
241 Entry* pos = &*localData.insert(localData.end(),
size,Entry(0));
292 return localData.size() *
sizeof(Entry);
308 std::vector<Entry> localData;
A structure for holding a sequence of several local matrices to be filled sequentially and to be scat...
std::vector< value_type > localMatrices
void scatter()
Scatters the local matrices into the global one and removes them from the local container.
value_type & operator[](int n)
A reference to the n-th local matrix.
value_type & back()
A reference to the last pushed local matrix.
void push_back(SortedRowIdx const &ridx, SortedColIdx const &cidx)
Appends another (zero-initialized) local matrix.
value_type const & back() const
void clear()
clears all the data, leaving an empty state
~LocalMatrices()
Destructor.
LocalMatrices()
Default constructor.
value_type const & operator[](int n) const
size_t size() const
The number of local matrices that are stored.
size_t storageSize() const
reports the size of the local matrices storage in bytes
size_t storageSizeLimit() const
reports the maximal desired local matrices storage size
LocalMatrices(NumaBCRSMatrix< Entry, IndexType > &globalMatrix_, size_t maxStorage_=256 *1024)
Providing a matrix or array interface to LAPACK-ordered entries.
LocalMatrix & operator=(DynamicMatrix< Entry > const &Aloc)
Assignment.
LocalMatrix(SortedRowIdx const &ridx, SortedColIdx const &cidx, Entry *data_)
void relocate(Entry *newData)
Resets the data pointer.
SortedRowIdx ridx() const
A sequence of (global row, local row) indices, sorted ascendingly by global row.
SortedColIdx cidx() const
A sequence of (global col, local col) indices, sorted ascendingly by global col.
Entry & operator()(int row, int col)
Access the matrix entries.
size_t size() const
The number of entries stored.
Entry const & operator()(int row, int col) const
A NUMA-aware compressed row storage matrix adhering mostly to the Dune ISTL interface (to complete....
std::ostream & operator<<(std::ostream &s, std::vector< Scalar > const &vec)