17 #include <unordered_map>
18 #include <unordered_set>
21 #include <span/span.hpp>
63 template<
typename TIndexType=std::
size_t>
89 mGraph.
resize(GraphSize,
false);
90 mLocks = decltype(mLocks)(GraphSize);
96 mGraph[
i] = std::unordered_set<IndexType>();
113 mpComm = rOther.mpComm;
114 mGraph.
resize(rOther.mGraph.size());
116 mGraph[
i] = std::unordered_set<IndexType>();
118 mLocks = decltype(mLocks)(rOther.mLocks.size());
142 return mGraph.size();
147 const auto&
row = mGraph[I];
148 return (
row.find(
J) !=
row.end());
166 mLocks[RowIndex].lock();
167 mGraph[RowIndex].insert(ColIndex);
168 mLocks[RowIndex].unlock();
171 template<
class TContainerType>
174 mLocks[RowIndex].lock();
175 mGraph[RowIndex].insert(rColIndices.begin(), rColIndices.end());
176 mLocks[RowIndex].unlock();
179 template<
class TIteratorType>
181 const TIteratorType& rColBegin,
182 const TIteratorType& rColEnd
185 mLocks[RowIndex].lock();
186 mGraph[RowIndex].insert(rColBegin, rColEnd);
187 mLocks[RowIndex].unlock();
191 template<
class TContainerType>
194 for(
auto I : rIndices){
196 <<
" exceeds the graph size : " <<
Size() << std::endl;
198 mGraph[I].insert(rIndices.begin(), rIndices.end());
203 template<
class TContainerType>
204 void AddEntries(
const TContainerType& rRowIndices,
const TContainerType& rColIndices)
206 for(
auto I : rRowIndices){
230 template<
class TVectorType=DenseVector<IndexType>>
232 TVectorType& rRowIndices,
233 TVectorType& rColIndices
240 ExportCSRArrays(pRowIndicesData,RowIndicesDataSize,pColIndicesData,ColIndicesDataSize);
241 if(rRowIndices.size() != RowIndicesDataSize)
242 rRowIndices.resize(RowIndicesDataSize);
247 delete [] pRowIndicesData;
248 if(rColIndices.size() != ColIndicesDataSize)
249 rColIndices.resize(ColIndicesDataSize);
253 delete [] pColIndicesData;
255 return rRowIndices.size();
259 Kratos::span<IndexType>& rRowIndices,
260 Kratos::span<IndexType>& rColIndices
275 pRowIndicesData =
new IndexType[nrows+1];
276 rRowDataSize=nrows+1;
277 Kratos::span<IndexType> row_indices(pRowIndicesData, nrows+1);
292 row_indices[
i+1] = mGraph[
i].size();
296 for(
IndexType i = 1; i<static_cast<IndexType>(row_indices.size()); ++
i){
297 row_indices[
i] += row_indices[
i-1];
304 Kratos::span<IndexType> col_indices(pColIndicesData,nnz);
317 for(
auto index : mGraph[
i]){
325 std::sort(col_indices.begin()+row_indices[
i], col_indices.begin()+row_indices[
i+1]);
337 std::vector< IndexType > IJ;
339 for(
unsigned int I=0; I<
GetGraph().size(); ++I)
342 IJ.push_back(mGraph[I].size());
343 for(
auto J : mGraph[I])
351 auto graph_size = rSingleVectorRepresentation[0];
352 KRATOS_ERROR_IF(graph_size >
GetGraph().size() ) <<
"mismatching size - attempting to add a graph with more rows than the ones allowed in graph" << std::endl;
354 while(
counter < rSingleVectorRepresentation.size())
356 auto I = rSingleVectorRepresentation[
counter++];
357 auto nrow = rSingleVectorRepresentation[
counter++];
385 : map_iterator(it.map_iterator),mbegin(it.mbegin) {}
389 {
return map_iterator ==
rhs.map_iterator; }
391 {
return map_iterator !=
rhs.map_iterator; }
398 return map_iterator-mbegin;
424 std::stringstream buffer;
425 buffer <<
"SparseContiguousRowGraph" ;
430 void PrintInfo(std::ostream& rOStream)
const {rOStream <<
"SparseContiguousRowGraph";}
489 std::vector<LockObject> mLocks;
499 rSerializer.
save(
"GraphSize",
N);
503 rSerializer.
save(
"row_size",row_size);
504 for(
auto J : mGraph[I]){
505 rSerializer.
save(
"J",
J);
513 rSerializer.load(
"GraphSize",size);
515 mLocks = decltype(mLocks)(size);
521 rSerializer.load(
"row_size",row_size);
524 rSerializer.load(
"J",
J);
569 template<
class TIndexType=std::
size_t>
576 template<
class TIndexType=std::
size_t>
581 rOStream << std::endl;
Serial (do-nothing) version of a wrapper class for MPI communication.
Definition: data_communicator.h:318
This class is useful for index iteration over containers.
Definition: parallel_utilities.h:451
void for_each(TUnaryFunction &&f)
Definition: parallel_utilities.h:514
Definition: amatrix_interface.h:41
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
iterator end()
Definition: amatrix_interface.h:243
void clear()
Definition: amatrix_interface.h:284
iterator begin()
Definition: amatrix_interface.h:241
TDataType value_type
Definition: amatrix_interface.h:56
AMatrix::RandomAccessIterator< const TDataType > const_iterator
Definition: amatrix_interface.h:53
static DataCommunicator & GetDataCommunicator(const std::string &rName)
Retrieve a registered DataCommunicator instance.
Definition: parallel_environment.cpp:26
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
void save(std::string const &rTag, std::array< TDataType, TDataSize > const &rObject)
Definition: serializer.h:545
Definition: sparse_contiguous_row_graph.h:373
const_iterator_adaptor & operator++()
Definition: sparse_contiguous_row_graph.h:386
const_iterator_adaptor(const_row_iterator it)
Definition: sparse_contiguous_row_graph.h:383
IndexType GetRowIndex() const
Definition: sparse_contiguous_row_graph.h:397
typename GraphType::value_type * pointer
Definition: sparse_contiguous_row_graph.h:380
const_row_iterator & base()
Definition: sparse_contiguous_row_graph.h:395
std::forward_iterator_tag iterator_category
Definition: sparse_contiguous_row_graph.h:377
typename GraphType::value_type value_type
Definition: sparse_contiguous_row_graph.h:379
typename GraphType::value_type & reference
Definition: sparse_contiguous_row_graph.h:381
const_row_iterator const & base() const
Definition: sparse_contiguous_row_graph.h:396
bool operator==(const const_iterator_adaptor &rhs) const
Definition: sparse_contiguous_row_graph.h:388
const_iterator_adaptor operator++(int)
Definition: sparse_contiguous_row_graph.h:387
const GraphType::value_type & operator->() const
Definition: sparse_contiguous_row_graph.h:394
const_iterator_adaptor(const const_iterator_adaptor &it)
Definition: sparse_contiguous_row_graph.h:384
bool operator!=(const const_iterator_adaptor &rhs) const
Definition: sparse_contiguous_row_graph.h:390
std::ptrdiff_t difference_type
Definition: sparse_contiguous_row_graph.h:378
const GraphType::value_type & operator*() const
Definition: sparse_contiguous_row_graph.h:393
Short class definition.
Definition: sparse_contiguous_row_graph.h:65
void Finalize()
Definition: sparse_contiguous_row_graph.h:220
void AddEntries(const TContainerType &rIndices)
Definition: sparse_contiguous_row_graph.h:192
void AddEntries(const SparseContiguousRowGraph &rOtherGraph)
Definition: sparse_contiguous_row_graph.h:212
void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: sparse_contiguous_row_graph.h:430
void AddEntries(const TContainerType &rRowIndices, const TContainerType &rColIndices)
Definition: sparse_contiguous_row_graph.h:204
void Clear()
Definition: sparse_contiguous_row_graph.h:135
const DataCommunicator * pGetComm() const
Definition: sparse_contiguous_row_graph.h:127
bool Has(const IndexType I, const IndexType J) const
Definition: sparse_contiguous_row_graph.h:145
IndexType GlobalIndex(const IndexType LocalIndex) const
Definition: sparse_contiguous_row_graph.h:160
IndexType LocalIndex(const IndexType GlobalIndex) const
Definition: sparse_contiguous_row_graph.h:156
std::vector< IndexType > ExportSingleVectorRepresentation()
Definition: sparse_contiguous_row_graph.h:335
SparseContiguousRowGraph()
Default constructor. - needs to be public for communicator, but it will fail if used in any other mod...
Definition: sparse_contiguous_row_graph.h:81
IndexType ExportCSRArrays(TVectorType &rRowIndices, TVectorType &rColIndices) const
Definition: sparse_contiguous_row_graph.h:231
SparseContiguousRowGraph(const SparseContiguousRowGraph &rOther)
Copy constructor.
Definition: sparse_contiguous_row_graph.h:111
GraphType::const_iterator const_row_iterator
Definition: sparse_contiguous_row_graph.h:71
void AddEntries(const IndexType RowIndex, const TIteratorType &rColBegin, const TIteratorType &rColEnd)
Definition: sparse_contiguous_row_graph.h:180
void AddEntry(const IndexType RowIndex, const IndexType ColIndex)
Definition: sparse_contiguous_row_graph.h:164
void AddEntries(const IndexType RowIndex, const TContainerType &rColIndices)
Definition: sparse_contiguous_row_graph.h:172
const_iterator_adaptor end() const
Definition: sparse_contiguous_row_graph.h:406
KRATOS_CLASS_POINTER_DEFINITION(SparseContiguousRowGraph)
Pointer definition of SparseContiguousRowGraph.
SparseContiguousRowGraph & operator=(SparseContiguousRowGraph const &rOther)=delete
Assignment operator. TODO: decide if we do want to allow it.
void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: sparse_contiguous_row_graph.h:433
DenseVector< std::unordered_set< IndexType > > GraphType
Definition: sparse_contiguous_row_graph.h:70
IndexType ExportCSRArrays(IndexType *&pRowIndicesData, IndexType &rRowDataSize, IndexType *&pColIndicesData, IndexType &rColDataSize) const
Definition: sparse_contiguous_row_graph.h:265
SparseContiguousRowGraph(IndexType GraphSize)
Definition: sparse_contiguous_row_graph.h:86
const DataCommunicator & GetComm() const
Definition: sparse_contiguous_row_graph.h:122
IndexType Size() const
Definition: sparse_contiguous_row_graph.h:141
void AddFromSingleVectorRepresentation(const std::vector< IndexType > &rSingleVectorRepresentation)
Definition: sparse_contiguous_row_graph.h:349
friend class Serializer
Definition: sparse_contiguous_row_graph.h:494
std::string Info() const
Turn back information as a string.
Definition: sparse_contiguous_row_graph.h:422
const GraphType::value_type & operator[](const IndexType &Key) const
Definition: sparse_contiguous_row_graph.h:151
~SparseContiguousRowGraph()
Destructor.
Definition: sparse_contiguous_row_graph.h:101
TIndexType IndexType
Definition: sparse_contiguous_row_graph.h:69
const_iterator_adaptor begin() const
Definition: sparse_contiguous_row_graph.h:402
const GraphType & GetGraph() const
Definition: sparse_contiguous_row_graph.h:225
IndexType ExportCSRArrays(Kratos::span< IndexType > &rRowIndices, Kratos::span< IndexType > &rColIndices) const =delete
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
start
Definition: DEM_benchmarks.py:17
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
AMatrix::MatrixRow< const TExpressionType > row(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression, std::size_t RowIndex)
Definition: amatrix_interface.h:649
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
rhs
Definition: generate_frictional_mortar_condition.py:297
tuple tmp
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:98
def load(f)
Definition: ode_solve.py:307
int k
Definition: quadrature.py:595
int counter
Definition: script_THERMAL_CORRECT.py:218
J
Definition: sensitivityMatrix.py:58
N
Definition: sensitivityMatrix.py:29
integer i
Definition: TensorModule.f:17