10 #ifndef EIGEN_PASTIXSUPPORT_H 11 #define EIGEN_PASTIXSUPPORT_H 16 #define PASTIX_COMPLEX COMPLEX 17 #define PASTIX_DCOMPLEX DCOMPLEX 19 #define PASTIX_COMPLEX std::complex<float> 20 #define PASTIX_DCOMPLEX std::complex<double> 31 template<
typename _MatrixType,
bool IsStrSym = false>
class PastixLU;
32 template<
typename _MatrixType,
int Options>
class PastixLLT;
33 template<
typename _MatrixType,
int Options>
class PastixLDLT;
40 template<
typename _MatrixType>
43 typedef _MatrixType MatrixType;
44 typedef typename _MatrixType::Scalar Scalar;
45 typedef typename _MatrixType::RealScalar RealScalar;
46 typedef typename _MatrixType::StorageIndex StorageIndex;
49 template<
typename _MatrixType,
int Options>
52 typedef _MatrixType MatrixType;
53 typedef typename _MatrixType::Scalar Scalar;
54 typedef typename _MatrixType::RealScalar RealScalar;
55 typedef typename _MatrixType::StorageIndex StorageIndex;
58 template<
typename _MatrixType,
int Options>
61 typedef _MatrixType MatrixType;
62 typedef typename _MatrixType::Scalar Scalar;
63 typedef typename _MatrixType::RealScalar RealScalar;
64 typedef typename _MatrixType::StorageIndex StorageIndex;
67 void eigen_pastix(pastix_data_t **pastix_data,
int pastix_comm,
int n,
int *ptr,
int *idx,
float *vals,
int *perm,
int * invp,
float *x,
int nbrhs,
int *iparm,
double *dparm)
69 if (n == 0) { ptr = NULL; idx = NULL; vals = NULL; }
70 if (nbrhs == 0) {x = NULL; nbrhs=1;}
71 s_pastix(pastix_data, pastix_comm, n, ptr, idx, vals, perm, invp, x, nbrhs, iparm, dparm);
74 void eigen_pastix(pastix_data_t **pastix_data,
int pastix_comm,
int n,
int *ptr,
int *idx,
double *vals,
int *perm,
int * invp,
double *x,
int nbrhs,
int *iparm,
double *dparm)
76 if (n == 0) { ptr = NULL; idx = NULL; vals = NULL; }
77 if (nbrhs == 0) {x = NULL; nbrhs=1;}
78 d_pastix(pastix_data, pastix_comm, n, ptr, idx, vals, perm, invp, x, nbrhs, iparm, dparm);
81 void eigen_pastix(pastix_data_t **pastix_data,
int 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)
83 if (n == 0) { ptr = NULL; idx = NULL; vals = NULL; }
84 if (nbrhs == 0) {x = NULL; nbrhs=1;}
85 c_pastix(pastix_data, pastix_comm, n, ptr, idx, reinterpret_cast<PASTIX_COMPLEX*>(vals), perm, invp, reinterpret_cast<PASTIX_COMPLEX*>(x), nbrhs, iparm, dparm);
88 void eigen_pastix(pastix_data_t **pastix_data,
int 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)
90 if (n == 0) { ptr = NULL; idx = NULL; vals = NULL; }
91 if (nbrhs == 0) {x = NULL; nbrhs=1;}
92 z_pastix(pastix_data, pastix_comm, n, ptr, idx, reinterpret_cast<PASTIX_DCOMPLEX*>(vals), perm, invp, reinterpret_cast<PASTIX_DCOMPLEX*>(x), nbrhs, iparm, dparm);
96 template <
typename MatrixType>
97 void c_to_fortran_numbering (MatrixType& mat)
99 if ( !(mat.outerIndexPtr()[0]) )
102 for(i = 0; i <= mat.rows(); ++i)
103 ++mat.outerIndexPtr()[i];
104 for(i = 0; i < mat.nonZeros(); ++i)
105 ++mat.innerIndexPtr()[i];
110 template <
typename MatrixType>
111 void fortran_to_c_numbering (MatrixType& mat)
114 if ( mat.outerIndexPtr()[0] == 1 )
117 for(i = 0; i <= mat.rows(); ++i)
118 --mat.outerIndexPtr()[i];
119 for(i = 0; i < mat.nonZeros(); ++i)
120 --mat.innerIndexPtr()[i];
127 template <
class Derived>
133 using Base::m_isInitialized;
135 using Base::_solve_impl;
138 typedef _MatrixType MatrixType;
139 typedef typename MatrixType::Scalar Scalar;
140 typedef typename MatrixType::RealScalar RealScalar;
141 typedef typename MatrixType::StorageIndex StorageIndex;
145 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
146 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
151 PastixBase() : m_initisOk(
false), m_analysisIsOk(
false), m_factorizationIsOk(
false), m_pastixdata(0), m_size(0)
161 template<
typename Rhs,
typename Dest>
180 return m_iparm(idxparam);
198 return m_dparm(idxparam);
201 inline Index cols()
const {
return m_size; }
202 inline Index rows()
const {
return m_size; }
214 eigen_assert(m_isInitialized &&
"Decomposition is not initialized.");
224 void analyzePattern(ColSpMatrix& mat);
227 void factorize(ColSpMatrix& mat);
232 eigen_assert(m_initisOk &&
"The Pastix structure should be allocated first");
233 m_iparm(IPARM_START_TASK) = API_TASK_CLEAN;
234 m_iparm(IPARM_END_TASK) = API_TASK_CLEAN;
235 internal::eigen_pastix(&m_pastixdata, MPI_COMM_WORLD, 0, 0, 0, (Scalar*)0,
236 m_perm.data(), m_invp.data(), 0, 0, m_iparm.data(), m_dparm.data());
239 void compute(ColSpMatrix& mat);
243 int m_factorizationIsOk;
245 mutable pastix_data_t *m_pastixdata;
258 template <
class Derived>
262 m_iparm.setZero(IPARM_SIZE);
263 m_dparm.setZero(DPARM_SIZE);
265 m_iparm(IPARM_MODIFY_PARAMETER) = API_NO;
266 pastix(&m_pastixdata, MPI_COMM_WORLD,
268 0, 0, 0, 1, m_iparm.data(), m_dparm.data());
270 m_iparm[IPARM_MATRIX_VERIFICATION] = API_NO;
271 m_iparm[IPARM_VERBOSE] = API_VERBOSE_NOT;
272 m_iparm[IPARM_ORDERING] = API_ORDER_SCOTCH;
273 m_iparm[IPARM_INCOMPLETE] = API_NO;
274 m_iparm[IPARM_OOC_LIMIT] = 2000;
275 m_iparm[IPARM_RHS_MAKING] = API_RHS_B;
276 m_iparm(IPARM_MATRIX_VERIFICATION) = API_NO;
278 m_iparm(IPARM_START_TASK) = API_TASK_INIT;
279 m_iparm(IPARM_END_TASK) = API_TASK_INIT;
280 internal::eigen_pastix(&m_pastixdata, MPI_COMM_WORLD, 0, 0, 0, (Scalar*)0,
281 0, 0, 0, 0, m_iparm.data(), m_dparm.data());
284 if(m_iparm(IPARM_ERROR_NUMBER)) {
294 template <
class Derived>
297 eigen_assert(mat.
rows() == mat.
cols() &&
"The input matrix should be squared");
302 m_iparm(IPARM_MATRIX_VERIFICATION) = API_NO;
306 template <
class Derived>
309 eigen_assert(m_initisOk &&
"The initialization of PaSTiX failed");
315 m_size = internal::convert_index<int>(mat.
rows());
316 m_perm.resize(m_size);
317 m_invp.resize(m_size);
319 m_iparm(IPARM_START_TASK) = API_TASK_ORDERING;
320 m_iparm(IPARM_END_TASK) = API_TASK_ANALYSE;
322 mat.
valuePtr(), m_perm.data(), m_invp.data(), 0, 0, m_iparm.data(), m_dparm.data());
325 if(m_iparm(IPARM_ERROR_NUMBER))
328 m_analysisIsOk =
false;
333 m_analysisIsOk =
true;
337 template <
class Derived>
341 eigen_assert(m_analysisIsOk &&
"The analysis phase should be called before the factorization phase");
342 m_iparm(IPARM_START_TASK) = API_TASK_NUMFACT;
343 m_iparm(IPARM_END_TASK) = API_TASK_NUMFACT;
344 m_size = internal::convert_index<int>(mat.
rows());
347 mat.
valuePtr(), m_perm.data(), m_invp.data(), 0, 0, m_iparm.data(), m_dparm.data());
350 if(m_iparm(IPARM_ERROR_NUMBER))
353 m_factorizationIsOk =
false;
354 m_isInitialized =
false;
359 m_factorizationIsOk =
true;
360 m_isInitialized =
true;
365 template<
typename Base>
366 template<
typename Rhs,
typename Dest>
369 eigen_assert(m_isInitialized &&
"The matrix should be factorized first");
371 THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
376 for (
int i = 0; i < b.cols(); i++){
377 m_iparm[IPARM_START_TASK] = API_TASK_SOLVE;
378 m_iparm[IPARM_END_TASK] = API_TASK_REFINE;
380 internal::eigen_pastix(&m_pastixdata, MPI_COMM_WORLD, internal::convert_index<int>(x.rows()), 0, 0, 0,
381 m_perm.data(), m_invp.data(), &x(0, i), rhs, m_iparm.data(), m_dparm.data());
387 return m_iparm(IPARM_ERROR_NUMBER)==0;
411 template<
typename _MatrixType,
bool IsStrSym>
415 typedef _MatrixType MatrixType;
418 typedef typename MatrixType::StorageIndex StorageIndex;
426 explicit PastixLU(
const MatrixType& matrix):Base()
438 m_structureIsUptodate =
false;
440 grabMatrix(matrix, temp);
450 m_structureIsUptodate =
false;
452 grabMatrix(matrix, temp);
453 Base::analyzePattern(temp);
464 grabMatrix(matrix, temp);
465 Base::factorize(temp);
471 m_structureIsUptodate =
false;
472 m_iparm(IPARM_SYM) = API_SYM_NO;
473 m_iparm(IPARM_FACTORIZATION) = API_FACT_LU;
476 void grabMatrix(
const MatrixType& matrix, ColSpMatrix& out)
482 if(!m_structureIsUptodate)
485 m_transposedStructure = matrix.transpose();
488 for (
Index j=0; j<m_transposedStructure.outerSize(); ++j)
489 for(
typename ColSpMatrix::InnerIterator it(m_transposedStructure, j); it; ++it)
492 m_structureIsUptodate =
true;
495 out = m_transposedStructure + matrix;
497 internal::c_to_fortran_numbering(out);
503 ColSpMatrix m_transposedStructure;
504 bool m_structureIsUptodate;
523 template<
typename _MatrixType,
int _UpLo>
527 typedef _MatrixType MatrixType;
532 enum { UpLo = _UpLo };
538 explicit PastixLLT(
const MatrixType& matrix):Base()
550 grabMatrix(matrix, temp);
561 grabMatrix(matrix, temp);
562 Base::analyzePattern(temp);
570 grabMatrix(matrix, temp);
571 Base::factorize(temp);
578 m_iparm(IPARM_SYM) = API_SYM_YES;
579 m_iparm(IPARM_FACTORIZATION) = API_FACT_LLT;
582 void grabMatrix(
const MatrixType& matrix, ColSpMatrix& out)
584 out.
resize(matrix.rows(), matrix.cols());
586 out.template selfadjointView<Lower>() = matrix.template selfadjointView<UpLo>();
587 internal::c_to_fortran_numbering(out);
607 template<
typename _MatrixType,
int _UpLo>
611 typedef _MatrixType MatrixType;
616 enum { UpLo = _UpLo };
622 explicit PastixLDLT(
const MatrixType& matrix):Base()
634 grabMatrix(matrix, temp);
645 grabMatrix(matrix, temp);
646 Base::analyzePattern(temp);
654 grabMatrix(matrix, temp);
655 Base::factorize(temp);
663 m_iparm(IPARM_SYM) = API_SYM_YES;
664 m_iparm(IPARM_FACTORIZATION) = API_FACT_LDLT;
667 void grabMatrix(
const MatrixType& matrix, ColSpMatrix& out)
670 out.
resize(matrix.rows(), matrix.cols());
671 out.template selfadjointView<Lower>() = matrix.template selfadjointView<UpLo>();
672 internal::c_to_fortran_numbering(out);
const Scalar * valuePtr() const
Definition: SparseMatrix.h:144
void compute(const MatrixType &matrix)
Compute the LU supernodal factorization of matrix.
Definition: PaStiXSupport.h:436
A base class for sparse solvers.
Definition: SparseSolverBase.h:67
void factorize(const MatrixType &matrix)
Compute the LU supernodal factorization of matrix WARNING The matrix matrix should have the same stru...
Definition: PaStiXSupport.h:461
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
void factorize(const MatrixType &matrix)
Compute the LDL^T supernodal numerical factorization of matrix.
Definition: PaStiXSupport.h:651
Index cols() const
Definition: SparseMatrix.h:134
void compute(const MatrixType &matrix)
Compute the L factor of the LL^T supernodal factorization of matrix.
Definition: PaStiXSupport.h:547
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:61
void compute(const MatrixType &matrix)
Compute the L and D factors of the LDL^T factorization of matrix.
Definition: PaStiXSupport.h:631
void init()
Initialize the PaStiX data structure.
Definition: PaStiXSupport.h:259
double & dparm(int idxparam)
Return a reference to a particular index parameter of the DPARM vector.
Definition: PaStiXSupport.h:196
void analyzePattern(const MatrixType &matrix)
Compute the LL^T symbolic factorization of matrix using its sparsity pattern The result of this opera...
Definition: PaStiXSupport.h:558
A sparse direct supernodal Cholesky (LLT) factorization and solver based on the PaStiX library...
Definition: PaStiXSupport.h:33
Definition: PaStiXSupport.h:128
The provided data did not satisfy the prerequisites.
Definition: Constants.h:434
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Index rows() const
Definition: SparseMatrix.h:132
void resize(Index rows, Index cols)
Resizes the matrix to a rows x cols matrix and initializes it to zero.
Definition: SparseMatrix.h:617
int & iparm(int idxparam)
Return a reference to a particular index parameter of the IPARM vector.
Definition: PaStiXSupport.h:178
Definition: PaStiXSupport.h:38
Array< double, DPARM_SIZE, 1 > & dparm()
Returns a reference to the double vector DPARM of PaStiX parameters The statistics related to the dif...
Definition: PaStiXSupport.h:187
The inputs are invalid, or the algorithm has been improperly called.
Definition: Constants.h:439
Computation was successful.
Definition: Constants.h:432
void analyzePattern(const MatrixType &matrix)
Compute the LU symbolic factorization of matrix using its sparsity pattern.
Definition: PaStiXSupport.h:448
const StorageIndex * innerIndexPtr() const
Definition: SparseMatrix.h:153
Definition: BandTriangularSolver.h:13
Definition: TutorialInplaceLU.cpp:2
const StorageIndex * outerIndexPtr() const
Definition: SparseMatrix.h:162
void factorize(const MatrixType &matrix)
Compute the LL^T supernodal numerical factorization of matrix.
Definition: PaStiXSupport.h:567
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:45
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: PaStiXSupport.h:212
Interface to the PaStix solver.
Definition: PaStiXSupport.h:31
A sparse direct supernodal Cholesky (LLT) factorization and solver based on the PaStiX library...
Definition: PaStiXSupport.h:32
Array< StorageIndex, IPARM_SIZE, 1 > & iparm()
Returns a reference to the integer vector IPARM of PaStiX parameters to modify the default parameters...
Definition: PaStiXSupport.h:169
ComputationInfo
Enum for reporting the status of a computation.
Definition: Constants.h:430
void analyzePattern(const MatrixType &matrix)
Compute the LDL^T symbolic factorization of matrix using its sparsity pattern The result of this oper...
Definition: PaStiXSupport.h:642
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48