12#ifndef BELFEM_CL_SOLVERDISTMATRIX_HPP
13#define BELFEM_CL_SOLVERDISTMATRIX_HPP
131 create_matrix(
SpMatrix * aMatrix );
137 order_graph(
Graph & aGraph );
140 compute_index_permutation(
const SpMatrix * aMatrix );
145 template<
typename T >
158 const real * mMyValuesData = nullptr ;
185 tData[ tCount++ ] = tValues[ k ] ;
192 mMyValuesData = tData ;
209 return mMyPointers.data();
215 return mMyIndices.data();
230 "values() called before distribute_values()" );
234 return mMyValuesData ;
238 return mMyValues.data();
265 int_t nnz = tPtrs[b] - tPtrs[a];
272 for (
int_t i = a; i < b; ++i )
278 nnz = tPtrs[i+1] - tPtrs[i];
280 tPointers( r+1 ) = tPointers( r ) + nnz;
282 for (
int_t j = tPtrs[i]; j < tPtrs[i+1]; ++j )
284 tIndices( k++ ) = tIdx[j];
293 mMyPointers = std::move( mAllPointers(
mCommRank ) );
294 mMyIndices = std::move( mAllIndices(
mCommRank ) );
301 mAllPointers.clear();
314 mMyValues.set_size( mMyIndices.length(), 0 );
322 template<
typename T >
343 const bool mUseLocalIndices ;
370 tData[ tCount++ ] = tValues[ k ] ;
385 for (
int_t i=a; i<b; ++i )
387 int_t n = tPtrs[i+1] - tPtrs[i];
389 for (
int_t j=0; j<n; ++j )
391 int_t k = tIdx[ tPtrs[i] + j ];
393 if ( k < a || k >= b )
395 tOffDiagValues( o++ ) = tData[ tCount++ ];
399 tDiagValues( d++ ) = tData[ tCount++ ];
414 receive( mMyOffDiagonalValues );
422 return mMyDiagonalPointers.data();
428 return mMyOffDiagonalPointers.data();
434 return mMyDiagonalIndices.data();
440 return mMyOffDiagonalIndices.data();
447 return mMyGarray.data();
453 return mMyGarray.length();
467 return mAllDiagonalValues( 0 ).data();
471 return mMyDiagonalValues.data();
480 return mAllOffDiagonalValues( 0 ).data();
484 return mMyOffDiagonalValues.data();
495 mAllDiagonalPointers.set_size(
mCommSize, {} );
496 mAllOffDiagonalPointers.set_size(
mCommSize, {} );
497 mAllDiagonalIndices.set_size(
mCommSize, {} );
498 mAllOffDiagonalIndices.set_size(
mCommSize, {} );
499 mAllDiagonalValues.set_size(
mCommSize, {} );
500 mAllOffDiagonalValues.set_size(
mCommSize, {} );
515 std::set< int_t > tUniqueOffDiagCols;
523 for (
int_t i = a; i < b; ++i )
525 for (
int_t j=tPtrs[i]; j<tPtrs[i+1]; ++j )
528 if ( a <=k && k < b )
535 tUniqueOffDiagCols.insert( k );
543 tGarray.
set_size( tUniqueOffDiagCols.size() );
546 for (
int_t globalCol : tUniqueOffDiagCols )
548 tGarray( garrayIdx ) = globalCol;
549 tGlobalToLocal[ globalCol ] = garrayIdx++ ;
554 Vector< T > & tDiagPointers = mAllDiagonalPointers( p );
555 Vector< T > & tOffDiagPointers = mAllOffDiagonalPointers( p );
556 Vector< T > & tDiagIndices = mAllDiagonalIndices( p );
557 Vector< T > & tOffDiagIndices = mAllOffDiagonalIndices( p );
562 tOffDiagPointers.
set_size( n + 1, 0 );
571 for (
int_t i=a; i<b; ++i )
580 for (
int_t j=tPtrs[i]; j<tPtrs[i+1]; ++j )
583 if ( a <=k && k < b )
585 tDiagIndices( d++ ) = k - a ;
591 if ( mUseLocalIndices )
594 auto it = tGlobalToLocal.
find( k );
596 "Failed to find global column %lu in garray map for rank %lu",
597 (
long unsigned int) k, (
long unsigned int) p );
598 tOffDiagIndices( o++ ) = it->second;
603 tOffDiagIndices( o++ ) = k;
609 tDiagPointers( r+1 ) = tDiagPointers( r ) + nd;
610 tOffDiagPointers( r+1 ) = tOffDiagPointers( r ) + no;
617 mMyDiagonalPointers = std::move( mAllDiagonalPointers(
mCommRank ) );
618 mMyOffDiagonalPointers = std::move( mAllOffDiagonalPointers(
mCommRank ) );
619 mMyDiagonalIndices = std::move( mAllDiagonalIndices(
mCommRank ) );
620 mMyOffDiagonalIndices = std::move( mAllOffDiagonalIndices(
mCommRank ) );
621 mMyGarray = std::move( mAllGarrays(
mCommRank ) );
631 mAllDiagonalPointers.clear();
632 mAllOffDiagonalPointers.clear();
633 mAllDiagonalIndices.clear();
634 mAllOffDiagonalIndices.clear();
641 receive( mMyDiagonalPointers );
642 receive( mMyOffDiagonalPointers );
644 receive( mMyOffDiagonalIndices );
648 mMyDiagonalValues.set_size( mMyDiagonalIndices.length(), 0 );
649 mMyOffDiagonalValues.set_size( mMyOffDiagonalIndices.length(), 0 );
650 mMyNumRows = mMyDiagonalPointers.length() - 1;
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Sorted map (ordered key-value).
Definition cl_OrderedMap.hpp:32
auto find(const Key &tKey) const -> decltype(mMap.find(tKey))
Definition cl_OrderedMap.hpp:139
auto end() const -> decltype(mMap.end())
Definition cl_OrderedMap.hpp:133
Configuration for a Solver.
Definition cl_SolverParameters.hpp:27
Sparse matrix in CSR or CSC format.
Definition cl_SpMatrix.hpp:52
void set_indexing_base(const enum SpMatrixIndexingBase &aBasis)
change the indexing base
Definition cl_SpMatrix.cpp:814
int_t * indices()
expose the index array
Definition cl_SpMatrix.hpp:701
real * data()
expose the data container
Definition cl_SpMatrix.hpp:787
int_t * pointers()
expose the pointers
Definition cl_SpMatrix.hpp:771
T * data()
expose the underlying raw pointer ( writable version )
Definition cl_AR_Vector.hpp:182
void set_size(const size_t aNumRows)
change the size of the vector
Definition cl_AR_Vector.hpp:237
T * diagonal_pointers()
Definition cl_SolverDistMatrix.hpp:420
T * garray()
Definition cl_SolverDistMatrix.hpp:445
void distribute_sparsity_pattern() override
Definition cl_SolverDistMatrix.hpp:491
T garray_size() const
Definition cl_SolverDistMatrix.hpp:451
T * diagonal_indices()
Definition cl_SolverDistMatrix.hpp:432
T * offdiagonal_pointers()
Definition cl_SolverDistMatrix.hpp:426
real * offdiagonal_values()
Definition cl_SolverDistMatrix.hpp:476
DistMatrixAIJ(const SolverParameters *aParams, SpMatrix *aMatrix)
Definition cl_SolverDistMatrix.hpp:346
real * diagonal_values()
Definition cl_SolverDistMatrix.hpp:463
T n_rows() const
Definition cl_SolverDistMatrix.hpp:457
void distribute_values(SpMatrix *aMatrix) override
Definition cl_SolverDistMatrix.hpp:354
T * offdiagonal_indices()
Definition cl_SolverDistMatrix.hpp:438
void distribute_sparsity_pattern() override
Definition cl_SolverDistMatrix.hpp:245
const T * indices() const
Definition cl_SolverDistMatrix.hpp:213
void distribute_values(SpMatrix *aMatrix) override
Definition cl_SolverDistMatrix.hpp:169
const T n_rows() const
Definition cl_SolverDistMatrix.hpp:219
const real * values() const
Definition cl_SolverDistMatrix.hpp:225
DistMatrixCSR(const SolverParameters *aParams, SpMatrix *aMatrix)
Definition cl_SolverDistMatrix.hpp:162
const T * pointers() const
Definition cl_SolverDistMatrix.hpp:207
const ReorderingMethod mReorderingMethod
Definition cl_SolverDistMatrix.hpp:39
virtual void distribute_sparsity_pattern()=0
Vector< real > & lhs_vector()
Definition cl_SolverDistMatrix.hpp:93
const int_t * dist() const
Definition cl_SolverDistMatrix.hpp:69
Cell< index_t > mIndexPermutation
Definition cl_SolverDistMatrix.hpp:45
Vector< int_t > mDist
Definition cl_SolverDistMatrix.hpp:48
void determine_sizes_and_offsets()
Definition cl_SolverDistMatrix.cpp:232
const bool mPermutationSwitch
Definition cl_SolverDistMatrix.hpp:35
const real * rhs() const
Definition cl_SolverDistMatrix.hpp:75
Vector< real > mMyRhs
Definition cl_SolverDistMatrix.hpp:52
Cell< index_t > mForwardPermutation
Definition cl_SolverDistMatrix.hpp:43
void distribute_lhs(const Vector< real > &aLhs)
Definition cl_SolverDistMatrix.cpp:333
index_t mNumRows
Definition cl_SolverDistMatrix.hpp:56
Vector< int_t > mOffsets
Definition cl_SolverDistMatrix.hpp:49
const proc_t mCommSize
Definition cl_SolverDistMatrix.hpp:34
void distribute_rhs(const Vector< real > &aRhs)
Definition cl_SolverDistMatrix.cpp:289
real * lhs()
Definition cl_SolverDistMatrix.hpp:81
index_t size() const
Definition cl_SolverDistMatrix.hpp:87
virtual void distribute_values(SpMatrix *aMatrix)=0
Vector< real > mRhs
Definition cl_SolverDistMatrix.hpp:51
index_t mMyNumRows
Definition cl_SolverDistMatrix.hpp:57
Vector< real > mMyLhs
Definition cl_SolverDistMatrix.hpp:54
SpMatrix * mMatrix
Definition cl_SolverDistMatrix.hpp:41
const proc_t mCommRank
Definition cl_SolverDistMatrix.hpp:33
Vector< int_t > mSizes
Definition cl_SolverDistMatrix.hpp:47
Cell< index_t > mBackwardPermutation
Definition cl_SolverDistMatrix.hpp:44
void collect_lhs(Vector< real > &aLhs)
Definition cl_SolverDistMatrix.cpp:377
Vector< real > mLhs
Definition cl_SolverDistMatrix.hpp:53
DistMatrix(const SolverParameters *aParams, SpMatrix *aMatrix=nullptr)
Definition cl_SolverDistMatrix.cpp:23
Vector< real > & rhs_vector()
Definition cl_SolverDistMatrix.hpp:99
Definition cl_SolverDistMatrix.cpp:21
USER GUIDES:
Definition cl_Capacitor.cpp:16
void receive(string &aMessage, const proc_t aSource)
Definition commtools.cpp:348
void share(Vector< T > &aData)
Definition commtools.hpp:1671
Cell< graph::Vertex * > Graph
Definition cl_Graph_Vertex.hpp:329
@ Cpp
Definition cl_SpMatrix.hpp:39
void comm_barrier()
Synchronizes all processes in the communicator.
Definition commtools.cpp:57
int proc_t
Definition commtypes.hpp:29
SolverType
Definition en_SolverEnums.hpp:23
@ STRUMPACK
Definition en_SolverEnums.hpp:27
void distribute(Cell< T > &aData)
Distributes elements of a cell to other processes.
Definition commtools.hpp:804
ReorderingMethod
Definition en_SolverEnums.hpp:116
uint32_t index_t
Definition typedefs.hpp:52
double real
Definition typedefs.hpp:36
int32_t int_t
Definition typedefs.hpp:51