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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26