NeoPZ
pzysmp.h
Go to the documentation of this file.
1 
6 #ifndef YSMPMATH
7 #define YSMPMATH
8 
9 #include "pz_config.h"
10 
11 #ifdef USING_BLAS
12 #ifdef USING_MKL
13 #include <mkl.h>
14 #elif MACOSX
15 #include <Accelerate/Accelerate.h>
16 #else
17 #ifdef MACOSX
18 #include <Accelerate/Accelerate.h>
19 #else
20 extern "C"{
21  #include "cblas.h"
22  };
23 #endif
24 #endif
25 #endif
26 
27 template<class TVar>
29 
30 #include "pzmatrix.h"
31 #include "pzfmatrix.h"
32 
33 #ifdef USING_MKL
34 #include "TPZPardisoControl.h"
35 #endif
36 
44 template<class TVar>
45 class TPZFYsmpMatrix : public TPZMatrix<TVar> {
46 
47 #ifdef USING_MKL
48  friend class TPZPardisoControl<TVar>;
49 #endif
50 
51  public :
52 
57  struct TPZMThread {
59  int64_t fFirsteq;
60  int64_t fLasteq;
63  TVar fAlpha;
64  int fOpt;
65  };
66 
67 private:
68 
69  static void * ExecuteMT(void *entrydata);
70 
71 public:
72 
74 
75  TPZFYsmpMatrix(const int64_t rows,const int64_t cols );
76 
78 
80 
82 
84 
85  virtual ~TPZFYsmpMatrix();
86 
89  void AutoFill(int64_t nrow, int64_t ncol, int symmetric);
90 
91 
92 
94  virtual const TVar &GetVal(const int64_t row,const int64_t col ) const override;
95 
96  int64_t NumTerms()
97  {
98  return fIA[this->Rows()];
99  }
100 
101  int PutVal(const int64_t row, const int64_t col, const TVar &Value) override;
102 
103  virtual void MultAdd(const TPZFMatrix<TVar> &x,const TPZFMatrix<TVar> &y, TPZFMatrix<TVar> &z,
104  const TVar alpha=1.,const TVar beta = 0., const int opt = 0) const override;
105 
106  virtual void MultAddMT(const TPZFMatrix<TVar> &x,const TPZFMatrix<TVar> &y, TPZFMatrix<TVar> &z,
107  const TVar alpha=1.,const TVar beta = 0., const int opt = 0);
108 
109  virtual int GetSub(const int64_t sRow,const int64_t sCol,const int64_t rowSize,
110  const int64_t colSize, TPZFMatrix<TVar> & A ) const override;
111 
112  void GetSub(const TPZVec<int64_t> &indices,TPZFMatrix<TVar> &block) const override;
113 
115  virtual void SetData( int64_t *IA, int64_t *JA, TVar *A );
116 
118  virtual void SetData( TPZVec<int64_t> &IA, TPZVec<int64_t> &JA, TPZVec<TVar> &A );
119 
121  virtual void Print(const char *title, std::ostream &out = std::cout , const MatrixOutputFormat form = EFormatted) const override;
122 
141  virtual void SolveJacobi(int64_t & numiterations, const TPZFMatrix<TVar> & F, TPZFMatrix<TVar> & result,
142  TPZFMatrix<TVar> * residual, TPZFMatrix<TVar> & scratch, REAL & tol, const int FromCurrent = 0) override;
143 
144  void SolveSOR(int64_t &numiterations, const TPZFMatrix<TVar> &rhs, TPZFMatrix<TVar> &x,
145  TPZFMatrix<TVar> *residual, TPZFMatrix<TVar> &scratch,
146  const REAL overrelax, REAL &tol,
147  const int FromCurrent = 0,const int direction = 1 ) override;
148  // @}
149 
154  virtual void AddKelOld(
155  TPZFMatrix<TVar> & elmat
156  , TPZVec < int > & destinationindex
157  );
158 
159  virtual void AddKel(TPZFMatrix<TVar> & elmat, TPZVec<int64_t> & destinationindex) override;
160 
161  virtual void AddKel(TPZFMatrix<TVar> & elmat, TPZVec<int64_t> & sourceindex, TPZVec<int64_t> & destinationindex) override;
162 
164 
165  virtual int Zero() override;
166 
175  virtual int Decompose_LU(std::list<int64_t> &singular) override;
176  virtual int Decompose_LU() override;
177 
179 
189  virtual int Substitution( TPZFMatrix<TVar> * B ) const override;
190 
192 
193  public:
194 int ClassId() const override;
195 
196 private:
197 
198  void ComputeDiagonal();
199 
200  /*
201  * @brief Perform row update of the sparse matrix
202  */
203  void RowLUUpdate(int64_t sourcerow, int64_t destrow);
204 
205 protected:
209 
211 
213 
214 #ifdef USING_MKL
215  TPZPardisoControl<TVar> fPardisoControl;
216 #endif
217 protected:
218 
227  void InitializeData();
228 };
229 
230 
231 template<class TVar>
232 inline void TPZFYsmpMatrix<TVar>::SetData( int64_t *IA, int64_t *JA, TVar *A ) {
233  // Pass the data to the class.
234  int nel = this->Rows()+1;
235  fIA.resize(nel);
236  memccpy(&fIA[0], IA, nel, sizeof(int64_t));
237  int64_t nval = fIA[nel-1];
238  fJA.resize(nval);
239  memccpy(&fJA[0], JA, nval, sizeof(int64_t));
240  fA.resize(nval);
241  memccpy(&fA[0], A, nval, sizeof(TVar));
242  ComputeDiagonal();
243 }
244 
246 template<class TVar>
248 
249  if (IA.size() != this->Rows() + 1 ) {
250  DebugStop();
251  }
252 
253  if (JA.size() != IA[this->Rows()]) {
254  DebugStop();
255  }
256 
257  fIA = IA;
258  fJA = JA;
259  fA = A;
260 }
261 
262 #endif
void AutoFill(int64_t nrow, int64_t ncol, int symmetric)
Fill matrix storage with randomic values.
Definition: pzysmp.cpp:899
TPZVec< TVar > fA
Definition: pzysmp.h:208
void MultiplyDummy(TPZFYsmpMatrix< TVar > &B, TPZFYsmpMatrix< TVar > &Res)
Definition: pzysmp.cpp:35
virtual int Substitution(TPZFMatrix< TVar > *B) const override
Computes Forward and Backward substitution for a "LU" decomposed matrix.
Definition: pzysmp.cpp:979
int64_t NumTerms()
Definition: pzysmp.h:96
An auxiliary structure to hold the data of the subset of equations used to multiply in a multi-thre...
Definition: pzysmp.h:57
virtual void Print(const char *title, std::ostream &out=std::cout, const MatrixOutputFormat form=EFormatted) const override
Print the matrix along with a identification title.
Definition: pzysmp.cpp:588
virtual void AddKel(TPZFMatrix< TVar > &elmat, TPZVec< int64_t > &destinationindex) override
Add a contribution of a stiffness matrix.
Definition: pzysmp.cpp:162
virtual void resize(const int64_t newsize)
Definition: pzvec.h:213
virtual void AddKelOld(TPZFMatrix< TVar > &elmat, TPZVec< int > &destinationindex)
Add a contribution of a stiffness matrix putting it on destination indexes position.
Definition: pzysmp.cpp:248
int PutVal(const int64_t row, const int64_t col, const TVar &Value) override
Put values without bounds checking This method is faster than "Put" if DEBUG is defined.
Definition: pzysmp.cpp:140
MatrixOutputFormat
Defines output format.
Definition: pzmatrix.h:55
void RowLUUpdate(int64_t sourcerow, int64_t destrow)
Definition: pzysmp.cpp:848
virtual ~TPZFYsmpMatrix()
Definition: pzysmp.cpp:349
Implements a non symmetric sparse matrix (Yale Sparse Matrix Storage). Matrix.
Definition: pzysmp.h:45
virtual int Zero() override
Zeroes the matrix.
Definition: pzysmp.cpp:664
virtual void SetData(int64_t *IA, int64_t *JA, TVar *A)
Pass the data to the class.
Definition: pzysmp.h:232
virtual void MultAdd(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar alpha=1., const TVar beta=0., const int opt=0) const override
It computes z = beta * y + alpha * opt(this)*x but z and x can not overlap in memory.
Definition: pzysmp.cpp:486
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
void InitializeData()
Implements a initialization method for the sparse structure. It sets the initial value for the fIA an...
Definition: pzysmp.cpp:32
static const double tol
Definition: pzgeoprism.cpp:23
virtual int Decompose_LU() override
Definition: pzysmp.cpp:946
Contains TPZMatrixclass which implements full matrix (using column major representation).
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
Implements a matrix whose nonzero elements are stored in binary tree. Matrix.
Definition: pzfmatrix.h:33
static void * ExecuteMT(void *entrydata)
Definition: pzysmp.cpp:730
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
TPZVec< TVar > fDiag
Definition: pzysmp.h:210
int fSymmetric
Definition: pzysmp.h:212
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
virtual void MultAddMT(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar alpha=1., const TVar beta=0., const int opt=0)
Definition: pzysmp.cpp:388
virtual int GetSub(const int64_t sRow, const int64_t sCol, const int64_t rowSize, const int64_t colSize, TPZFMatrix< TVar > &A) const override
Gets submatrix storing it on Target.
Definition: pzysmp.cpp:803
Contains TPZMatrix<TVar>class, root matrix class.
virtual const TVar & GetVal(const int64_t row, const int64_t col) const override
Get the matrix entry at (row,col) without bound checking.
Definition: pzysmp.cpp:363
TPZVec< int64_t > fJA
Definition: pzysmp.h:207
#define CLONEDEF(A)
To create clone matrix.
Definition: pzmatrix.h:28
TPZVec< int64_t > fIA
Definition: pzysmp.h:206
const TPZFMatrix< TVar > * fX
Definition: pzysmp.h:61
virtual void SolveJacobi(int64_t &numiterations, const TPZFMatrix< TVar > &F, TPZFMatrix< TVar > &result, TPZFMatrix< TVar > *residual, TPZFMatrix< TVar > &scratch, REAL &tol, const int FromCurrent=0) override
Solves the linear system using Jacobi method. .
Definition: pzysmp.cpp:683
int ClassId() const override
Define the class id associated with the class.
Definition: pzysmp.cpp:1042
void SolveSOR(int64_t &numiterations, const TPZFMatrix< TVar > &rhs, TPZFMatrix< TVar > &x, TPZFMatrix< TVar > *residual, TPZFMatrix< TVar > &scratch, const REAL overrelax, REAL &tol, const int FromCurrent=0, const int direction=1) override
Solves the linear system using Successive Over Relaxation method (Gauss Seidel). ...
Definition: pzysmp.cpp:629
const TPZFYsmpMatrix< TVar > * target
Definition: pzysmp.h:58
TPZFYsmpMatrix & operator=(const TPZFYsmpMatrix< TVar > &copy)
Definition: pzysmp.cpp:79
TPZFMatrix< TVar > * fZ
Definition: pzysmp.h:62
Root matrix class (abstract). Matrix.
Definition: pzmatrix.h:60
void ComputeDiagonal()
Definition: pzysmp.cpp:619