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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4869 - (show annotations)
Mon Apr 14 10:39:22 2014 UTC (5 years, 5 months ago) by caltinay
File MIME type: text/plain
File size: 6706 byte(s)
all of paso now lives in its own namespace.

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
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, int* pivot, double* x,
61 const double* b) const;
62
63 void invMain(double* inv_diag, int* 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_CSC(FILE* handle) const;
78
79 void saveMM(const char* filename) const;
80
81 inline index_t* borrowMainDiagonalPointer() const
82 {
83 return pattern->borrowMainDiagonalPointer();
84 }
85
86 inline index_t* borrowColoringPointer() const
87 {
88 return pattern->borrowColoringPointer();
89 }
90
91 inline dim_t getNumColors() const
92 {
93 return pattern->getNumColors();
94 }
95
96 inline dim_t maxDeg() const
97 {
98 return pattern->maxDeg();
99 }
100
101 inline dim_t getTotalNumRows() const
102 {
103 return numRows * row_block_size;
104 }
105
106 inline dim_t getTotalNumCols() const
107 {
108 return numCols * col_block_size;
109 }
110
111 inline dim_t getNumRows() const
112 {
113 return numRows;
114 }
115
116 inline dim_t getNumCols() const
117 {
118 return numCols;
119 }
120
121 inline double getSize() const
122 {
123 return (double)len;
124 }
125
126 inline double getSparsity() const
127 {
128 return getSize() / ((double)getTotalNumRows()*getTotalNumCols());
129 }
130
131 static SparseMatrix_ptr loadMM_toCSR(const char* filename);
132
133
134 void nullifyRowsAndCols_CSC_BLK1(const double* mask_row,
135 const double* mask_col,
136 double main_diagonal_value);
137
138 void nullifyRowsAndCols_CSR_BLK1(const double* mask_row,
139 const double* mask_col,
140 double main_diagonal_value);
141
142 void nullifyRowsAndCols_CSC(const double* mask_row, const double* mask_col,
143 double main_diagonal_value);
144
145 void nullifyRowsAndCols_CSR(const double* mask_row, const double* mask_col,
146 double main_diagonal_value);
147
148 void nullifyRows_CSR_BLK1(const double* mask_row,
149 double main_diagonal_value);
150
151 void nullifyRows_CSR(const double* mask_row, double main_diagonal_value);
152
153 void maxAbsRow_CSR_OFFSET0(double* array) const;
154
155 void addAbsRow_CSR_OFFSET0(double* array) const;
156
157 void addRow_CSR_OFFSET0(double* array) const;
158
159 void applyDiagonal_CSR_OFFSET0(const double* left, const double* right);
160
161 SparseMatrixType type;
162 dim_t row_block_size;
163 dim_t col_block_size;
164 dim_t block_size;
165 dim_t numRows;
166 dim_t numCols;
167 Pattern_ptr pattern;
168 dim_t len;
169
170 /// this is used for classical CSR or CSC
171 double *val;
172
173 /// package controlling the solver pointer
174 index_t solver_package;
175
176 /// pointer to data needed by a solver
177 void* solver_p;
178 };
179
180 // interfaces:
181
182 void SparseMatrix_MatrixVector_CSC_OFFSET0(const double alpha,
183 const_SparseMatrix_ptr A,
184 const double* in,
185 const double beta, double* out);
186
187 void SparseMatrix_MatrixVector_CSC_OFFSET1(const double alpha,
188 const_SparseMatrix_ptr A,
189 const double* in,
190 const double beta, double* out);
191
192 void SparseMatrix_MatrixVector_CSR_OFFSET0(const double alpha,
193 const_SparseMatrix_ptr A,
194 const double* in,
195 const double beta, double* out);
196
197 void SparseMatrix_MatrixVector_CSR_OFFSET1(const double alpha,
198 const_SparseMatrix_ptr A,
199 const double* in,
200 const double beta, double* out);
201
202 void SparseMatrix_MatrixVector_CSR_OFFSET0_DIAG(const double alpha,
203 const_SparseMatrix_ptr A,
204 const double* in,
205 const double beta, double* out);
206
207 SparseMatrix_ptr SparseMatrix_MatrixMatrix(const_SparseMatrix_ptr A,
208 const_SparseMatrix_ptr B);
209
210 SparseMatrix_ptr SparseMatrix_MatrixMatrixTranspose(const_SparseMatrix_ptr A,
211 const_SparseMatrix_ptr B,
212 const_SparseMatrix_ptr T);
213
214 } // namespace paso
215
216 #endif // __PASO_SPARSEMATRIX_H__
217

  ViewVC Help
Powered by ViewVC 1.1.26