/*! \file DissectionMatrix.hpp \brief management of threads for factorization and Fw/Bw substitution \author Atsushi Suzuki, Laboratoire Jacques-Louis Lions \date Jun. 20th 2014 \date Jul. 12th 2015 \date Nov. 30th 2016 */ // This file is part of Dissection // // Dissection is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Linking Dissection statically or dynamically with other modules is making // a combined work based on Disssection. Thus, the terms and conditions of // the GNU General Public License cover the whole combination. // // As a special exception, the copyright holders of Dissection give you // permission to combine Dissection program with free software programs or // libraries that are released under the GNU LGPL and with independent modules // that communicate with Dissection solely through the Dissection-fortran // interface. You may copy and distribute such a system following the terms of // the GNU GPL for Dissection and the licenses of the other code concerned, // provided that you include the source code of that other code when and as // the GNU GPL requires distribution of source code and provided that you do // not modify the Dissection-fortran interface. // // Note that people who make modified versions of Dissection are not obligated // to grant this special exception for their modified versions; it is their // choice whether to do so. The GNU General Public License gives permission to // release a modified version without this exception; this exception also makes // it possible to release a modified version which carries forward this // exception. If you modify the Dissection-fortran interface, this exception // does not apply to your modified version of Dissection, and you must remove // this exception when you distribute your modified version. // // This exception is an additional permission under section 7 of the GNU // General Public License, version 3 ("GPLv3") // // Dissection is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Dissection. If not, see . // # ifndef _DRIVER_DISSECTIONMATRIX_ # define _DRIVER_DISSECTIONMATRIX_ #include #include #include "Splitters/BisectionTree.hpp" #include "Algebra/PlainMatrix.hpp" #include "Algebra/SquareMatrix.hpp" #include "Algebra/SquareBlockMatrix.hpp" #include "Algebra/RectBlockMatrix.hpp" #include "Algebra/SparseMatrix.hpp" #include "Algebra/ColumnMatrix.hpp" #include "Driver/TridiagBlockMatrix.hpp" #include "Driver/C_threads_tasks.hpp" using std::vector; template class DissectionMatrix { public: DissectionMatrix(Dissection::Tree *btree, const int nb, const bool isSym, const bool verbose, FILE *fp); DissectionMatrix(const DissectionMatrix & im) { (*this) = im; } ~DissectionMatrix() { if (_islast) { delete [] _color_mask; for (int i = 0; i < _colors; i++) { _tridiag[i]->free(); delete _tridiag[i]; } delete [] _tridiag; } _diag->free(); // free() is compatible to zero-sized matrix _lower->free(); _upper->free(); _localSchur->free(); // this may be redundant : 26 Jun.2014 delete _factorize_LDLt; delete _diag; delete _lower; delete _upper; delete _localSchur; } DissectionMatrix& operator = ( const DissectionMatrix &im) { if ( &im != this) { _nb = im._nb; _level = im._level; _nrow = im._nrow; _ncol_offdiag = im._ncol_offdiag; _nop = im._nop; _diag = im._diag->clone(); if (!_isSym) { _lower->copy(*im._lower); } _upper->copy(*im._upper); _isSym = im._isSym; _localSchur = &im.localSchurBlock(); _factorize_LDLt = im._factorize_LDLt; // _factorize_LDLt_diag = im._factorize_LDLt_diag; _csr_diag = im._csr_diag; _csr_offdiag = im._csr_offdiag; _alignedFather = im._alignedFather; } return *this; } int ColorTridiagBlockMatrix() { return _colors ; } void setColorTridiagBlockMatrix(int colors) { _colors = colors; } int nrow() { return _nrow; } SquareBlockMatrix* addrdiagBlock() { return _diag; } SquareBlockMatrix*& paddrdiagBlock() { return _diag; } SquareBlockMatrix& diagBlock() { return *_diag; } const SquareBlockMatrix& diagBlock() const { return *_diag;} TridiagBlockMatrix **addrtridiagBlock() { return _tridiag; } TridiagBlockMatrix **&paddrtridiagBlock() { return _tridiag; } RectBlockMatrix* addrupperBlock() { return _upper; } RectBlockMatrix*& paddrupperBlock() { return _upper; } RectBlockMatrix& upperBlock() { return *_upper; } const RectBlockMatrix& upperBlock() const { return *_upper; } RectBlockMatrix* addrlowerBlock() { return _lower; } RectBlockMatrix*& paddrlowerBlock() { return _lower; } RectBlockMatrix& lowerBlock() { return *_lower; } const RectBlockMatrix& lowerBlock() const { return *_lower; } bool isSym() const { return _isSym; } void setAlignedFather() { _alignedFather = true; } bool isAlignedFather() const { return _alignedFather; } bool isFactorized() const { return _diag->isFactorized(); } PlainMatrix& loclSchurBlock(); const vector& singIdxPermute() const { return _diag->getSingIdx(); } vector& singIdxPermute() { return _diag->getSingIdx(); } const vector& singIdx() const { return _diag->getSingIdx0(); } vector& singIdx() { return _diag->getSingIdx0(); } int KernelDetected() const { return _diag->KernelDetected(); } int KernelDim() const { return _diag->dim_kern(); } void SetKernelDim(int nsing) { _diag->set_dim_kernel(nsing); } SquareMatrix& localSchurBlock() { return *_localSchur; } const SquareMatrix& localSchurBlock() const { return *_localSchur; } T getLastPivot() const { return _diag->lastPivot(); } void setLastPivot(T pivot_val) { _diag->set_lastPivot(pivot_val); } void C_SparseSymbFact_queue(vector& queue, Dissection::Tree *btree, const bool verbose, FILE **fp); void C_SparseNumFact_queue(vector& queue, Dissection::Tree *btree, int nnz, T *coefs, double *eps_pivot, double *pivot, bool *kernel_detection, bool *higher_precision, int *aug_dim, U *eps_machine, vector& task_q, const bool verbose, FILE **fp); void C_SparseLocalSchur_queue(vector& queue, Dissection::Tree *btree, int nnz, T *cofes, vector& task_p, const bool verbose, FILE **fp); void C_FillMatrix_queue(vector& queue, int nnz, T *cofes, const bool verbose, FILE **fp); int C_DFullLDLt_queue(vector& queue, vector& task_indcol, vector& task_ptr, double *eps_piv, bool *kernel_detection, int *aug_dim, U *eps_machine, double *pivot, double *pivot0, double *pivot1, vector& task_p, const bool isChldrnAlgnd, const bool verbose, FILE **fp); int C_DTRSMScale_queue(vector &queue, vector > &queue_parents_index, vector &queue_index, vector& indcol, vector& ptr, Dissection::Tree *btree, vector& task_o, vector& task_indcol, vector& task_ptr, vector& task_p, const bool verbose, FILE **fp); void C_DTRSMScale_rearrange(vector &queue, vector > &queue_parents_index, vector &queue_index, vector& indcol, vector& ptr, const bool verbose, FILE *fp); int C_DGEMM_local_queue(vector &queue, vector &indcol, RectBlockMatrix *upper1, RectBlockMatrix *lower1, bool isSkip, bool isDirect, SquareBlockMatrix* fdiag, vector &task_p, vector &task_p_index, vector &task_p_indcol, vector &task_p_ptr, vector &task_q, vector &task_q_index, vector &task_q_indcol, vector &task_q_ptr, vector *task_s, const bool verbose, FILE **fp); void C_deallocLocalSchur_queue(vector &queue, vector &indcol, const bool verbose, FILE **fp); void ChildContrib(list > *child_contribs, Dissection::Tree *btree, vector* >& dissectionMatrix, const bool verbose, FILE **fp); void deallocLower_queue(C_task*& queue, bool isSym, vector &task_p, bool isDirect, vector &task_q); int getUpperNRow() const { return upperBlock().nbRows(); } int getUpperNCol() const { return upperBlock().nbColumns(); } unsigned nb() const { return _nb; } unsigned level() const { return _level; } int ncol_offdiag() const {return _ncol_offdiag; } int nop() const { return _nop; } bool islast() const { return _islast; } bool alignedFather() const { return _alignedFather; } void setNb(unsigned nb) { _nb = nb; } void setLevel(unsigned level) { _level = level; } void setNrow(int nrow) { _nrow = nrow; } void setNcol_offdiag(int ncol_offdiag) { _ncol_offdiag = ncol_offdiag; } void setNop(int nop) { _nop = nop; } void setIsSym(bool isSym) { _isSym = isSym; } void setIslast(bool islast) { _islast = islast; } void setAlignedFather(bool alignedFather) { _alignedFather = alignedFather; } private: unsigned _nb; unsigned _level; int _nrow; int _ncol_offdiag; int _nop; // complexity of factorization SquareBlockMatrix* _diag; // pointer to the diagonal block TridiagBlockMatrix** _tridiag; // pointer to the tridiagonal blocks RectBlockMatrix* _lower; // pointer to lower off-diagonal block RectBlockMatrix* _upper; // pointer to upper off-diagonal block bool _isSym; bool _islast; bool _alignedFather; int _colors; int *_color_mask; SquareBlockMatrix *_localSchur; ColumnMatrix *_factorize_LDLt; // ColumnMatrix *_factorize_LDLt_diag; const CSR_indirect *_csr_diag; const CSR_indirect *_csr_offdiag; }; template class SchurMatrix { public: SchurMatrix() { _full_pivoting = false;} ~SchurMatrix() { } void free() { _sldu.free(); _sldu_list.clear(); // _sldu_list_left.clear(); delete _arow; delete _acol; _scol.free(); _schur.free(); } SubSquareMatrix& getSldu() { return _sldu; } vector& getSlduList() { return _sldu_list; } vector& getSlduListLeft() { return _full_pivoting ? _sldu_list_left : _sldu_list; } SparseMatrix*& getArow() { return _arow; } SparseMatrix*& getAcol() { return _acol; } ColumnMatrix& getScol() { return _scol; } ColumnMatrix& getSchur() { return _schur; } // for debugging bool isFullPivoting() { return _full_pivoting; } void setFullPivoting(const bool full_pivoting) { _full_pivoting = full_pivoting; } private: SubSquareMatrix _sldu; vector _sldu_list; // _sldu_list_right; vector _sldu_list_left; SparseMatrix* _arow; SparseMatrix* _acol; ColumnMatrix _scol; ColumnMatrix _schur; bool _full_pivoting; }; template class KernelMatrix { public: KernelMatrix(int dimension = 0) : _dimension(dimension), _full_pivoting(false) { } ~KernelMatrix() { } void free() { _singIdx.clear(); _kern_list_eq.clear(); _kern_basis.free(); _tkern_basis.free(); _kern_proj.free(); _tkern_proj.free(); _ntkern_proj.free(); } int dimension() const { return _dimension; } void set_dimension(int dimension){ _dimension = dimension; } vector& getSingIdx() { return _singIdx; } vector& getKernListEq() { return _kern_list_eq; } vector& getKernListEqLeft() { return _full_pivoting ? _kern_list_eq_left : _kern_list_eq; } ColumnMatrix& getKernBasis() {return _kern_basis; } ColumnMatrix& getTKernBasis() { return _tkern_basis; } SquareMatrix& getKernProj() { return _kern_proj; } SquareMatrix& getTKernProj() { return _tkern_proj; } SquareMatrix& getNTKernProj() { return _ntkern_proj; } void setFullPivoting(const bool full_pivoting) { _full_pivoting = full_pivoting; } private: int _dimension; vector _singIdx; vector _kern_list_eq; vector _kern_list_eq_left; ColumnMatrix _kern_basis; ColumnMatrix _tkern_basis; SquareMatrix _kern_proj; SquareMatrix _tkern_proj; SquareMatrix _ntkern_proj; bool _full_pivoting; }; #endif