10#ifndef PASTIX_INTERFACE_H
11#define PASTIX_INTERFACE_H
13#include <Eigen/SparseCore>
25 #define PASTIX_COMPLEX COMPLEX
26 #define PASTIX_DCOMPLEX DCOMPLEX
28 #define PASTIX_COMPLEX std::complex<float>
29 #define PASTIX_DCOMPLEX std::complex<double>
33template<
typename _MatrixType,
bool IsStrSym = false>
class PastixLU;
34template<
typename _MatrixType,
int Options>
class PastixLLT;
35template<
typename _MatrixType,
int Options>
class PastixLDLT;
42 template<
typename _MatrixType>
46 typedef typename _MatrixType::Scalar
Scalar;
51 template<
typename _MatrixType,
int Options>
55 typedef typename _MatrixType::Scalar
Scalar;
60 template<
typename _MatrixType,
int Options>
64 typedef typename _MatrixType::Scalar
Scalar;
69 inline int eigen_pastix(pastix_data_t **pastix_data, PASTIX_Comm pastix_comm,
int n,
int *ptr,
int *idx,
float *vals,
int *perm,
int * invp,
float *x,
int nbrhs,
int *iparm,
double *dparm)
71 if (n == 0) { ptr = NULL; idx = NULL; vals = NULL; }
72 if (nbrhs == 0) {x = NULL; nbrhs=1;}
73 return pastix(pastix_data, pastix_comm, n, ptr, idx, vals, perm, invp, x, nbrhs, iparm, dparm);
76 inline int eigen_pastix(pastix_data_t **pastix_data, PASTIX_Comm pastix_comm,
int n,
int *ptr,
int *idx,
double *vals,
int *perm,
int * invp,
double *x,
int nbrhs,
int *iparm,
double *dparm)
78 if (n == 0) { ptr = NULL; idx = NULL; vals = NULL; }
79 if (nbrhs == 0) {x = NULL; nbrhs=1;}
80 return pastix(pastix_data, pastix_comm, n, ptr, idx, vals, perm, invp, x, nbrhs, iparm, dparm);
83 inline int eigen_pastix(pastix_data_t **pastix_data, PASTIX_Comm pastix_comm,
int n,
int *ptr,
int *idx, std::complex<float> *vals,
int *perm,
int * invp, std::complex<float> *x,
int nbrhs,
int *iparm,
double *dparm)
85 if (n == 0) { ptr = NULL; idx = NULL; vals = NULL; }
86 if (nbrhs == 0) {x = NULL; nbrhs=1;}
87 return pastix(pastix_data, pastix_comm, n, ptr, idx,
reinterpret_cast<PASTIX_COMPLEX*
>(vals), perm, invp,
reinterpret_cast<PASTIX_COMPLEX*
>(x), nbrhs, iparm, dparm);
90 inline int eigen_pastix(pastix_data_t **pastix_data, PASTIX_Comm pastix_comm,
int n,
int *ptr,
int *idx, std::complex<double> *vals,
int *perm,
int * invp, std::complex<double> *x,
int nbrhs,
int *iparm,
double *dparm)
92 if (n == 0) { ptr = NULL; idx = NULL; vals = NULL; }
93 if (nbrhs == 0) {x = NULL; nbrhs=1;}
94 return pastix(pastix_data, pastix_comm, n, ptr, idx,
reinterpret_cast<PASTIX_DCOMPLEX*
>(vals), perm, invp,
reinterpret_cast<PASTIX_DCOMPLEX*
>(x), nbrhs, iparm, dparm);
98 template <
typename MatrixType>
101 if ( !(
mat.outerIndexPtr()[0]) )
104 for(
i = 0;
i <=
mat.rows(); ++
i)
105 ++
mat.outerIndexPtr()[
i];
106 for(
i = 0;
i <
mat.nonZeros(); ++
i)
107 ++
mat.innerIndexPtr()[
i];
112 template <
typename MatrixType>
116 if (
mat.outerIndexPtr()[0] == 1 )
119 for(
i = 0;
i <=
mat.rows(); ++
i)
120 --
mat.outerIndexPtr()[
i];
121 for(
i = 0;
i <
mat.nonZeros(); ++
i)
122 --
mat.innerIndexPtr()[
i];
129template <
class Derived>
133 typedef SparseSolverBase<Derived>
Base;
135 using Base::m_isInitialized;
137 using Base::_solve_impl;
141 typedef typename MatrixType::Scalar
Scalar;
163 template<
typename Rhs,
typename Dest>
164 bool _solve_impl(
const MatrixBase<Rhs> &b, MatrixBase<Dest> &x)
const;
216 eigen_assert(m_isInitialized &&
"Decomposition is not initialized.");
221 void init(
double eps_refinement = -1.0,
double eps_ctrl = -1.0);
236 eigen_assert(
m_initisOk &&
"The Pastix structure should be allocated first");
237 m_iparm(IPARM_START_TASK) = PastixTaskClean;
238 m_iparm(IPARM_END_TASK) = PastixTaskClean;
253 mutable Matrix<StorageIndex,Dynamic,1>
m_perm;
254 mutable Matrix<StorageIndex,Dynamic,1>
m_invp;
262template <
class Derived>
266 m_iparm.setZero(IPARM_SIZE);
267 m_dparm.setZero(DPARM_SIZE);
269 m_iparm(IPARM_MODIFY_PARAMETER) = 0;
270 pastix(&m_pastixdata, MPI_COMM_WORLD,
272 0, 0, 0, 1, m_iparm.data(), m_dparm.data());
275 m_iparm[IPARM_FLOAT] = PastixDouble;
276 m_iparm[IPARM_MTX_TYPE] = PastixGeneral;
277 m_iparm[IPARM_VERBOSE] = PastixVerboseNot;
278 m_iparm[IPARM_ORDERING] = PastixOrderScotch;
279 m_iparm[IPARM_INCOMPLETE] = 0;
285 m_iparm[IPARM_ITERMAX] = 2000;
286 if( eps_refinement >= 0.0) {
287 m_dparm[DPARM_EPSILON_REFINEMENT] = eps_refinement;
289 if( eps_ctrl >= 0.0) {
290 m_dparm[DPARM_EPSILON_MAGN_CTRL] = eps_ctrl;
293 m_iparm(IPARM_START_TASK) = PastixTaskInit;
294 m_iparm(IPARM_END_TASK) = PastixTaskInit;
296 0, 0, 0, 0, m_iparm.data(), m_dparm.data());
299 if(rc != PASTIX_SUCCESS) {
300 m_info = InvalidInput;
309template <
class Derived>
312 eigen_assert(
mat.rows() ==
mat.cols() &&
"The input matrix should be squared");
321template <
class Derived>
324 eigen_assert(m_initisOk &&
"The initialization of PaSTiX failed");
330 m_size = internal::convert_index<int>(
mat.rows());
331 m_perm.resize(m_size);
332 m_invp.resize(m_size);
334 m_iparm(IPARM_START_TASK) = PastixTaskOrdering;
335 m_iparm(IPARM_END_TASK) = PastixTaskAnalyze;
337 mat.valuePtr(), m_perm.data(), m_invp.data(), 0, 0, m_iparm.data(), m_dparm.data());
340 if(rc != PASTIX_SUCCESS)
342 m_info = NumericalIssue;
343 m_analysisIsOk =
false;
348 m_analysisIsOk =
true;
352template <
class Derived>
356 eigen_assert(m_analysisIsOk &&
"The analysis phase should be called before the factorization phase");
357 m_iparm(IPARM_START_TASK) = PastixTaskNumfact;
358 m_iparm(IPARM_END_TASK) = PastixTaskNumfact;
359 m_size = internal::convert_index<int>(
mat.rows());
362 mat.valuePtr(), m_perm.data(), m_invp.data(), 0, 0, m_iparm.data(), m_dparm.data());
365 if(rc != PASTIX_SUCCESS)
367 m_info = NumericalIssue;
368 m_factorizationIsOk =
false;
369 m_isInitialized =
false;
374 m_factorizationIsOk =
true;
375 m_isInitialized =
true;
380template<
typename Base>
381template<
typename Rhs,
typename Dest>
384 eigen_assert(m_isInitialized &&
"The matrix should be factorized first");
385 EIGEN_STATIC_ASSERT((Dest::Flags&RowMajorBit)==0,
386 THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
391 for (
int i = 0;
i < b.cols();
i++){
392 m_iparm[IPARM_START_TASK] = PastixTaskSolve;
393 m_iparm[IPARM_END_TASK] = PastixTaskRefine;
396 m_perm.data(), m_invp.data(), &x(0,
i), rhs, m_iparm.data(), m_dparm.data());
422template<
typename _MatrixType,
bool IsStrSym>
479 void init(
double eps_refinement = -1.0,
double eps_ctrl = -1.0)
482 m_iparm(IPARM_FACTORIZATION) = PastixFactLU;
483 if( eps_refinement >= 0.0) {
484 m_dparm[DPARM_EPSILON_REFINEMENT] = eps_refinement;
486 if( eps_ctrl >= 0.0) {
487 m_dparm[DPARM_EPSILON_MAGN_CTRL] = eps_ctrl;
541template<
typename _MatrixType,
int _UpLo>
596 m_iparm[IPARM_MTX_TYPE] = PastixSymmetric;
597 m_iparm(IPARM_FACTORIZATION) = PastixFactLLT;
602 out.resize(matrix.rows(), matrix.cols());
604 out.template selfadjointView<Lower>() = matrix.template selfadjointView<UpLo>();
622template<
typename _MatrixType,
int _UpLo>
678 m_iparm[IPARM_MTX_TYPE] = PastixSymmetric;
679 m_iparm(IPARM_FACTORIZATION) = PastixFactLDLT;
685 out.resize(matrix.rows(), matrix.cols());
686 out.template selfadjointView<Lower>() = matrix.template selfadjointView<UpLo>();
Definition PastixInterface.hpp:131
Class to invoke the Pastix LDLT solver.
Definition PastixInterface.hpp:624
Array< int, IPARM_SIZE, 1 > m_iparm
Definition PastixInterface.hpp:251
Class to invoke the Pastix LLT solver.
Definition PastixInterface.hpp:543
Array< int, IPARM_SIZE, 1 > m_iparm
Definition PastixInterface.hpp:251
Class to invoke the Pastix LU solver.
Definition PastixInterface.hpp:424
Array< double, DPARM_SIZE, 1 > m_dparm
Definition PastixInterface.hpp:252
Array< int, IPARM_SIZE, 1 > m_iparm
Definition PastixInterface.hpp:251
mat
Definition compute_eigs.m:7
Compute max and min eigenvalues of all matrices for i
Definition compute_eigs.m:5
void analyzePattern(const MatrixType &matrix)
Definition PastixInterface.hpp:657
Index rows() const
Definition PastixInterface.hpp:204
_MatrixType::StorageIndex StorageIndex
Definition PastixInterface.hpp:57
PastixLLT()
Definition PastixInterface.hpp:551
Array< double, DPARM_SIZE, 1 > m_dparm
Definition PastixInterface.hpp:252
_MatrixType::RealScalar RealScalar
Definition PastixInterface.hpp:56
void factorize(const MatrixType &matrix)
Definition PastixInterface.hpp:666
_MatrixType::StorageIndex StorageIndex
Definition PastixInterface.hpp:48
PastixLU()
Definition PastixInterface.hpp:432
void analyzePattern(ColSpMatrix &mat)
Definition PastixInterface.hpp:322
int m_factorizationIsOk
Definition PastixInterface.hpp:247
Base::ColSpMatrix ColSpMatrix
Definition PastixInterface.hpp:628
void fortran_to_c_numbering(MatrixType &mat)
Definition PastixInterface.hpp:113
Matrix< StorageIndex, Dynamic, 1 > m_invp
Definition PastixInterface.hpp:254
void grabMatrix(const MatrixType &matrix, ColSpMatrix &out)
Definition PastixInterface.hpp:498
MatrixType::StorageIndex StorageIndex
Definition PastixInterface.hpp:143
double & dparm(int idxparam)
Definition PastixInterface.hpp:198
_MatrixType::RealScalar RealScalar
Definition PastixInterface.hpp:65
MatrixType::StorageIndex StorageIndex
Definition PastixInterface.hpp:429
internal::pastix_traits< Derived >::MatrixType _MatrixType
Definition PastixInterface.hpp:139
_MatrixType MatrixType
Definition PastixInterface.hpp:426
Matrix< StorageIndex, Dynamic, 1 > m_perm
Definition PastixInterface.hpp:253
MatrixType::RealScalar RealScalar
Definition PastixInterface.hpp:142
void c_to_fortran_numbering(MatrixType &mat)
Definition PastixInterface.hpp:99
void compute(ColSpMatrix &mat)
Definition PastixInterface.hpp:310
ComputationInfo info() const
Reports whether previous computation was successful.
Definition PastixInterface.hpp:214
int eigen_pastix(pastix_data_t **pastix_data, PASTIX_Comm pastix_comm, int n, int *ptr, int *idx, float *vals, int *perm, int *invp, float *x, int nbrhs, int *iparm, double *dparm)
Definition PastixInterface.hpp:69
void init()
Definition PastixInterface.hpp:594
PastixBase()
Definition PastixInterface.hpp:153
#define PASTIX_DCOMPLEX
Definition PastixInterface.hpp:29
void compute(const MatrixType &matrix)
Definition PastixInterface.hpp:565
void grabMatrix(const MatrixType &matrix, ColSpMatrix &out)
Definition PastixInterface.hpp:682
Array< int, IPARM_SIZE, 1 > m_iparm
Definition PastixInterface.hpp:251
void init(double eps_refinement=-1.0, double eps_ctrl=-1.0)
Definition PastixInterface.hpp:479
_MatrixType MatrixType
Definition PastixInterface.hpp:54
bool _solve_impl(const MatrixBase< Rhs > &b, MatrixBase< Dest > &x) const
Definition PastixInterface.hpp:382
void factorize(const MatrixType &matrix)
Definition PastixInterface.hpp:585
void analyzePattern(const MatrixType &matrix)
Definition PastixInterface.hpp:576
Index cols() const
Definition PastixInterface.hpp:203
_MatrixType MatrixType
Definition PastixInterface.hpp:140
#define PASTIX_COMPLEX
Definition PastixInterface.hpp:28
PastixBase< PastixLDLT< MatrixType, _UpLo > > Base
Definition PastixInterface.hpp:627
PastixLU(const MatrixType &matrix)
Definition PastixInterface.hpp:437
PastixLDLT(const MatrixType &matrix)
Definition PastixInterface.hpp:637
PastixLDLT()
Definition PastixInterface.hpp:632
void init(double eps_refinement=-1.0, double eps_ctrl=-1.0)
Definition PastixInterface.hpp:263
void grabMatrix(const MatrixType &matrix, ColSpMatrix &out)
Definition PastixInterface.hpp:600
_MatrixType MatrixType
Definition PastixInterface.hpp:545
Array< StorageIndex, IPARM_SIZE, 1 > & iparm()
Definition PastixInterface.hpp:171
_MatrixType::Scalar Scalar
Definition PastixInterface.hpp:46
int m_analysisIsOk
Definition PastixInterface.hpp:246
_MatrixType::Scalar Scalar
Definition PastixInterface.hpp:64
MatrixType::Scalar Scalar
Definition PastixInterface.hpp:141
_MatrixType::StorageIndex StorageIndex
Definition PastixInterface.hpp:66
Matrix< Scalar, Dynamic, 1 > Vector
Definition PastixInterface.hpp:144
Array< double, DPARM_SIZE, 1 > & dparm()
Definition PastixInterface.hpp:189
int m_initisOk
Definition PastixInterface.hpp:245
void clean()
Definition PastixInterface.hpp:234
Base::ColSpMatrix ColSpMatrix
Definition PastixInterface.hpp:428
int m_size
Definition PastixInterface.hpp:255
_MatrixType::RealScalar RealScalar
Definition PastixInterface.hpp:47
void analyzePattern(const MatrixType &matrix)
Definition PastixInterface.hpp:459
void compute(const MatrixType &matrix)
Definition PastixInterface.hpp:646
~PastixBase()
Definition PastixInterface.hpp:158
void factorize(const MatrixType &matrix)
Definition PastixInterface.hpp:472
_MatrixType::Scalar Scalar
Definition PastixInterface.hpp:55
void factorize(ColSpMatrix &mat)
Definition PastixInterface.hpp:353
PastixBase< PastixLU< MatrixType > > Base
Definition PastixInterface.hpp:427
_MatrixType MatrixType
Definition PastixInterface.hpp:45
ColSpMatrix m_transposedStructure
Definition PastixInterface.hpp:525
void init()
Definition PastixInterface.hpp:676
bool m_structureIsUptodate
Definition PastixInterface.hpp:526
Base::ColSpMatrix ColSpMatrix
Definition PastixInterface.hpp:547
void compute(const MatrixType &matrix)
Definition PastixInterface.hpp:447
pastix_data_t * m_pastixdata
Definition PastixInterface.hpp:249
_MatrixType MatrixType
Definition PastixInterface.hpp:626
ComputationInfo m_info
Definition PastixInterface.hpp:248
_MatrixType MatrixType
Definition PastixInterface.hpp:63
SparseMatrix< Scalar, ColMajor > ColSpMatrix
Definition PastixInterface.hpp:145
int m_comm
Definition PastixInterface.hpp:250
PastixLLT(const MatrixType &matrix)
Definition PastixInterface.hpp:556
PastixBase< PastixLLT< MatrixType, _UpLo > > Base
Definition PastixInterface.hpp:546
int & iparm(int idxparam)
Definition PastixInterface.hpp:180
SparseSolverBase< Derived > Base
Definition PastixInterface.hpp:133
@ UpLo
Definition PastixInterface.hpp:550
@ UpLo
Definition PastixInterface.hpp:631
@ ColsAtCompileTime
Definition PastixInterface.hpp:147
@ MaxColsAtCompileTime
Definition PastixInterface.hpp:148
std::vector< std::vector< std::size_t > > Array
Type definition for a matrix of unsigned ints.
Definition DirectedGraph.hpp:30
for j
Definition mmread.m:174
Definition PastixInterface.hpp:16
Definition PastixInterface.hpp:40