escript
Revision_
|
00001 00002 /***************************************************************************** 00003 * 00004 * Copyright (c) 2003-2014 by University of Queensland 00005 * http://www.uq.edu.au 00006 * 00007 * Primary Business: Queensland, Australia 00008 * Licensed under the Open Software License version 3.0 00009 * http://www.opensource.org/licenses/osl-3.0.php 00010 * 00011 * Development until 2012 by Earth Systems Science Computational Center (ESSCC) 00012 * Development 2012-2013 by School of Earth Sciences 00013 * Development from 2014 by Centre for Geoscience Computing (GeoComp) 00014 * 00015 *****************************************************************************/ 00016 00017 00018 /****************************************************************************/ 00019 00020 /* Paso: SparseMatrix */ 00021 00022 /****************************************************************************/ 00023 00024 /* Author: lgross@uq.edu.au */ 00025 00026 /****************************************************************************/ 00027 00028 #ifndef __PASO_SPARSEMATRIX_H__ 00029 #define __PASO_SPARSEMATRIX_H__ 00030 00031 #include "Pattern.h" 00032 00033 namespace paso { 00034 00035 struct SparseMatrix; 00036 typedef boost::shared_ptr<SparseMatrix> SparseMatrix_ptr; 00037 typedef boost::shared_ptr<const SparseMatrix> const_SparseMatrix_ptr; 00038 00039 typedef int SparseMatrixType; 00040 00041 // this struct holds a sparse matrix 00042 struct SparseMatrix : boost::enable_shared_from_this<SparseMatrix> 00043 { 00044 SparseMatrix(SparseMatrixType type, Pattern_ptr pattern, 00045 dim_t rowBlockSize, dim_t colBlockSize, 00046 bool patternIsUnrolled); 00047 00048 ~SparseMatrix(); 00049 00050 void setValues(double value); 00051 00052 void copyFromMainDiagonal(double* out) const; 00053 00054 void copyToMainDiagonal(const double* in); 00055 00056 void copyBlockFromMainDiagonal(double* out) const; 00057 00058 void copyBlockToMainDiagonal(const double* in); 00059 00060 void applyBlockMatrix(double* block_diag, int* pivot, double* x, 00061 const double* b) const; 00062 00063 void invMain(double* inv_diag, int* pivot) const; 00064 00065 SparseMatrix_ptr unroll(SparseMatrixType type) const; 00066 SparseMatrix_ptr getSubmatrix(dim_t n_row_sub, 00067 dim_t n_col_sub, 00068 const index_t* row_list, 00069 const index_t* new_col_index) const; 00070 00071 SparseMatrix_ptr getBlock(int blockid) const; 00072 00073 SparseMatrix_ptr getTranspose() const; 00074 00075 void saveHB_CSC(const char* filename) const; 00076 00077 void saveMM_CSC(FILE* handle) const; 00078 00079 void saveMM(const char* filename) const; 00080 00081 inline index_t* borrowMainDiagonalPointer() const 00082 { 00083 return pattern->borrowMainDiagonalPointer(); 00084 } 00085 00086 inline index_t* borrowColoringPointer() const 00087 { 00088 return pattern->borrowColoringPointer(); 00089 } 00090 00091 inline dim_t getNumColors() const 00092 { 00093 return pattern->getNumColors(); 00094 } 00095 00096 inline dim_t maxDeg() const 00097 { 00098 return pattern->maxDeg(); 00099 } 00100 00101 inline dim_t getTotalNumRows() const 00102 { 00103 return numRows * row_block_size; 00104 } 00105 00106 inline dim_t getTotalNumCols() const 00107 { 00108 return numCols * col_block_size; 00109 } 00110 00111 inline dim_t getNumRows() const 00112 { 00113 return numRows; 00114 } 00115 00116 inline dim_t getNumCols() const 00117 { 00118 return numCols; 00119 } 00120 00121 inline double getSize() const 00122 { 00123 return (double)len; 00124 } 00125 00126 inline double getSparsity() const 00127 { 00128 return getSize() / ((double)getTotalNumRows()*getTotalNumCols()); 00129 } 00130 00131 static SparseMatrix_ptr loadMM_toCSR(const char* filename); 00132 00133 00134 void nullifyRowsAndCols_CSC_BLK1(const double* mask_row, 00135 const double* mask_col, 00136 double main_diagonal_value); 00137 00138 void nullifyRowsAndCols_CSR_BLK1(const double* mask_row, 00139 const double* mask_col, 00140 double main_diagonal_value); 00141 00142 void nullifyRowsAndCols_CSC(const double* mask_row, const double* mask_col, 00143 double main_diagonal_value); 00144 00145 void nullifyRowsAndCols_CSR(const double* mask_row, const double* mask_col, 00146 double main_diagonal_value); 00147 00148 void nullifyRows_CSR_BLK1(const double* mask_row, 00149 double main_diagonal_value); 00150 00151 void nullifyRows_CSR(const double* mask_row, double main_diagonal_value); 00152 00153 void maxAbsRow_CSR_OFFSET0(double* array) const; 00154 00155 void addAbsRow_CSR_OFFSET0(double* array) const; 00156 00157 void addRow_CSR_OFFSET0(double* array) const; 00158 00159 void applyDiagonal_CSR_OFFSET0(const double* left, const double* right); 00160 00161 SparseMatrixType type; 00162 dim_t row_block_size; 00163 dim_t col_block_size; 00164 dim_t block_size; 00165 dim_t numRows; 00166 dim_t numCols; 00167 Pattern_ptr pattern; 00168 dim_t len; 00169 00171 double *val; 00172 00174 index_t solver_package; 00175 00177 void* solver_p; 00178 }; 00179 00180 // interfaces: 00181 00182 void SparseMatrix_MatrixVector_CSC_OFFSET0(const double alpha, 00183 const_SparseMatrix_ptr A, 00184 const double* in, 00185 const double beta, double* out); 00186 00187 void SparseMatrix_MatrixVector_CSC_OFFSET1(const double alpha, 00188 const_SparseMatrix_ptr A, 00189 const double* in, 00190 const double beta, double* out); 00191 00192 void SparseMatrix_MatrixVector_CSR_OFFSET0(const double alpha, 00193 const_SparseMatrix_ptr A, 00194 const double* in, 00195 const double beta, double* out); 00196 00197 void SparseMatrix_MatrixVector_CSR_OFFSET1(const double alpha, 00198 const_SparseMatrix_ptr A, 00199 const double* in, 00200 const double beta, double* out); 00201 00202 void SparseMatrix_MatrixVector_CSR_OFFSET0_DIAG(const double alpha, 00203 const_SparseMatrix_ptr A, 00204 const double* in, 00205 const double beta, double* out); 00206 00207 SparseMatrix_ptr SparseMatrix_MatrixMatrix(const_SparseMatrix_ptr A, 00208 const_SparseMatrix_ptr B); 00209 00210 SparseMatrix_ptr SparseMatrix_MatrixMatrixTranspose(const_SparseMatrix_ptr A, 00211 const_SparseMatrix_ptr B, 00212 const_SparseMatrix_ptr T); 00213 00214 } // namespace paso 00215 00216 #endif // __PASO_SPARSEMATRIX_H__ 00217