/[escript]/trunk/paso/src/SparseMatrix.h
ViewVC logotype

Annotation of /trunk/paso/src/SparseMatrix.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6651 - (hide annotations)
Wed Feb 7 02:12:08 2018 UTC (20 months, 1 week ago) by jfenwick
File MIME type: text/plain
File size: 6666 byte(s)
Make everyone sad by touching all the files

Copyright dates update

1 ksteube 1313
2 jfenwick 3981 /*****************************************************************************
3 ksteube 1811 *
4 jfenwick 6651 * Copyright (c) 2003-2018 by The University of Queensland
5 jfenwick 3981 * http://www.uq.edu.au
6 ksteube 1811 *
7     * Primary Business: Queensland, Australia
8 jfenwick 6112 * Licensed under the Apache License, version 2.0
9     * http://www.apache.org/licenses/LICENSE-2.0
10 ksteube 1811 *
11 jfenwick 3981 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 * Development 2012-2013 by School of Earth Sciences
13     * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 jfenwick 3981 *
15     *****************************************************************************/
16 ksteube 1313
17 ksteube 1811
18 caltinay 4795 /****************************************************************************/
19 ksteube 1313
20 caltinay 4829 /* Paso: SparseMatrix */
21 ksteube 1313
22 caltinay 4795 /****************************************************************************/
23 ksteube 1313
24 gross 1363 /* Author: lgross@uq.edu.au */
25 ksteube 1313
26 caltinay 4795 /****************************************************************************/
27 ksteube 1313
28 caltinay 4829 #ifndef __PASO_SPARSEMATRIX_H__
29     #define __PASO_SPARSEMATRIX_H__
30 ksteube 1313
31     #include "Pattern.h"
32    
33 caltinay 4797 namespace paso {
34 ksteube 1313
35 caltinay 4829 struct SparseMatrix;
36     typedef boost::shared_ptr<SparseMatrix> SparseMatrix_ptr;
37     typedef boost::shared_ptr<const SparseMatrix> const_SparseMatrix_ptr;
38    
39 caltinay 4797 typedef int SparseMatrixType;
40 ksteube 1313
41 caltinay 4829 // this struct holds a sparse matrix
42     struct SparseMatrix : boost::enable_shared_from_this<SparseMatrix>
43     {
44     SparseMatrix(SparseMatrixType type, Pattern_ptr pattern,
45     dim_t rowBlockSize, dim_t colBlockSize,
46     bool patternIsUnrolled);
47 ksteube 1313
48 caltinay 4829 ~SparseMatrix();
49 ksteube 1313
50 caltinay 4829 void setValues(double value);
51 ksteube 1313
52 caltinay 4829 void copyFromMainDiagonal(double* out) const;
53 gross 3005
54 caltinay 4829 void copyToMainDiagonal(const double* in);
55 gross 3283
56 caltinay 4829 void copyBlockFromMainDiagonal(double* out) const;
57 gross 3283
58 caltinay 4829 void copyBlockToMainDiagonal(const double* in);
59 ksteube 1313
60 caltinay 5179 void applyBlockMatrix(double* block_diag, index_t* pivot, double* x,
61 caltinay 4829 const double* b) const;
62 gross 3303
63 caltinay 5179 void invMain(double* inv_diag, index_t* pivot) const;
64 caltinay 4795
65 caltinay 4829 SparseMatrix_ptr unroll(SparseMatrixType type) const;
66     SparseMatrix_ptr getSubmatrix(dim_t n_row_sub,
67     dim_t n_col_sub,
68     const index_t* row_list,
69     const index_t* new_col_index) const;
70 artak 2659
71 caltinay 4829 SparseMatrix_ptr getBlock(int blockid) const;
72 lgao 3498
73 caltinay 4829 SparseMatrix_ptr getTranspose() const;
74 artak 2760
75 caltinay 4836 void saveHB_CSC(const char* filename) const;
76 gross 3283
77 caltinay 4829 void saveMM(const char* filename) const;
78 ksteube 1313
79 caltinay 4829 inline index_t* borrowMainDiagonalPointer() const
80     {
81     return pattern->borrowMainDiagonalPointer();
82     }
83 caltinay 4797
84 caltinay 4829 inline index_t* borrowColoringPointer() const
85     {
86     return pattern->borrowColoringPointer();
87     }
88 caltinay 4797
89 caltinay 4829 inline dim_t getNumColors() const
90     {
91     return pattern->getNumColors();
92     }
93 caltinay 4797
94 caltinay 4829 inline dim_t maxDeg() const
95     {
96     return pattern->maxDeg();
97     }
98 caltinay 4797
99 caltinay 4829 inline dim_t getTotalNumRows() const
100     {
101     return numRows * row_block_size;
102     }
103 caltinay 4797
104 caltinay 4829 inline dim_t getTotalNumCols() const
105     {
106     return numCols * col_block_size;
107     }
108 caltinay 4797
109 caltinay 4829 inline dim_t getNumRows() const
110     {
111     return numRows;
112     }
113 caltinay 4797
114 caltinay 4829 inline dim_t getNumCols() const
115     {
116     return numCols;
117     }
118 caltinay 4797
119 caltinay 4829 inline double getSize() const
120     {
121 caltinay 4869 return (double)len;
122 caltinay 4829 }
123 caltinay 4797
124 caltinay 4829 inline double getSparsity() const
125     {
126 caltinay 4869 return getSize() / ((double)getTotalNumRows()*getTotalNumCols());
127 caltinay 4829 }
128 caltinay 4797
129 caltinay 4829 static SparseMatrix_ptr loadMM_toCSR(const char* filename);
130 caltinay 4797
131    
132 caltinay 4829 void nullifyRowsAndCols_CSC_BLK1(const double* mask_row,
133     const double* mask_col,
134     double main_diagonal_value);
135 caltinay 4797
136 caltinay 4829 void nullifyRowsAndCols_CSR_BLK1(const double* mask_row,
137     const double* mask_col,
138     double main_diagonal_value);
139 caltinay 4797
140 caltinay 4829 void nullifyRowsAndCols_CSC(const double* mask_row, const double* mask_col,
141     double main_diagonal_value);
142 caltinay 4797
143 caltinay 4829 void nullifyRowsAndCols_CSR(const double* mask_row, const double* mask_col,
144     double main_diagonal_value);
145 caltinay 4797
146 caltinay 4829 void nullifyRows_CSR_BLK1(const double* mask_row,
147     double main_diagonal_value);
148 caltinay 4797
149 caltinay 4829 void nullifyRows_CSR(const double* mask_row, double main_diagonal_value);
150 caltinay 4797
151 caltinay 4829 void maxAbsRow_CSR_OFFSET0(double* array) const;
152 caltinay 4797
153 caltinay 4829 void addAbsRow_CSR_OFFSET0(double* array) const;
154 caltinay 4797
155 caltinay 4829 void addRow_CSR_OFFSET0(double* array) const;
156 caltinay 4797
157 caltinay 4829 void applyDiagonal_CSR_OFFSET0(const double* left, const double* right);
158 caltinay 4797
159 caltinay 4829 SparseMatrixType type;
160     dim_t row_block_size;
161     dim_t col_block_size;
162     dim_t block_size;
163     dim_t numRows;
164     dim_t numCols;
165     Pattern_ptr pattern;
166     dim_t len;
167 caltinay 4797
168 caltinay 4829 /// this is used for classical CSR or CSC
169     double *val;
170 caltinay 4797
171 caltinay 4829 /// package controlling the solver pointer
172     index_t solver_package;
173 caltinay 4797
174 caltinay 4829 /// pointer to data needed by a solver
175     void* solver_p;
176     };
177 caltinay 4797
178 caltinay 4829 // interfaces:
179 caltinay 4797
180 caltinay 4829 void SparseMatrix_MatrixVector_CSC_OFFSET0(const double alpha,
181     const_SparseMatrix_ptr A,
182     const double* in,
183     const double beta, double* out);
184 caltinay 4797
185 caltinay 4829 void SparseMatrix_MatrixVector_CSC_OFFSET1(const double alpha,
186     const_SparseMatrix_ptr A,
187     const double* in,
188     const double beta, double* out);
189 caltinay 4797
190 caltinay 4829 void SparseMatrix_MatrixVector_CSR_OFFSET0(const double alpha,
191     const_SparseMatrix_ptr A,
192     const double* in,
193     const double beta, double* out);
194 caltinay 4797
195 caltinay 4829 void SparseMatrix_MatrixVector_CSR_OFFSET1(const double alpha,
196     const_SparseMatrix_ptr A,
197     const double* in,
198     const double beta, double* out);
199 caltinay 4797
200 caltinay 4829 void SparseMatrix_MatrixVector_CSR_OFFSET0_DIAG(const double alpha,
201     const_SparseMatrix_ptr A,
202     const double* in,
203     const double beta, double* out);
204    
205     SparseMatrix_ptr SparseMatrix_MatrixMatrix(const_SparseMatrix_ptr A,
206     const_SparseMatrix_ptr B);
207    
208     SparseMatrix_ptr SparseMatrix_MatrixMatrixTranspose(const_SparseMatrix_ptr A,
209     const_SparseMatrix_ptr B,
210     const_SparseMatrix_ptr T);
211    
212 caltinay 4797 } // namespace paso
213    
214 caltinay 4829 #endif // __PASO_SPARSEMATRIX_H__
215 caltinay 4797

  ViewVC Help
Powered by ViewVC 1.1.26