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 inline 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 inline 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 inline 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 inline 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,
239 void compute(ColSpMatrix& mat);
243 int m_factorizationIsOk;
245 mutable pastix_data_t *m_pastixdata;
247 mutable Array<int,IPARM_SIZE,1> m_iparm;
248 mutable Array<double,DPARM_SIZE,1> m_dparm;
249 mutable Matrix<StorageIndex,Dynamic,1> m_perm;
250 mutable Matrix<StorageIndex,Dynamic,1> m_invp;
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>
307 void PastixBase<Derived>::analyzePattern(ColSpMatrix& mat)
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;
321 internal::eigen_pastix(&m_pastixdata, MPI_COMM_WORLD, m_size, mat.outerIndexPtr(), mat.innerIndexPtr(),
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>
338 void PastixBase<Derived>::factorize(ColSpMatrix& mat)
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());
346 internal::eigen_pastix(&m_pastixdata, MPI_COMM_WORLD, m_size, mat.outerIndexPtr(), mat.innerIndexPtr(),
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>
367 bool PastixBase<Base>::_solve_impl(
const MatrixBase<Rhs> &b, MatrixBase<Dest> &x)
const
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;
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();
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 };
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 };
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);