MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
parsuperluwrap.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbwrap/parsuperluwrap.h,v 1.24 2017/01/12 14:44:25 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 2004-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 /*****************************************************************************
33  * *
34  * SuperLU C++ WRAPPER *
35  * *
36  *****************************************************************************/
37 
38 /*
39  * Wrapper for SuperLU sparse smp LU solution
40  * http://www.cs.berkeley.edu/~xiaoye/superlu_mt.html
41  */
42 
43 #ifndef PARSUPERLUWRAP_H
44 #define PARSUPERLUWRAP_H
45 
46 #ifdef USE_SUPERLU_MT
47 
48 #include <iostream>
49 #include "ac/pthread.h"
50 #include <vector>
51 
52 #include "myassert.h"
53 #include "mynewmem.h"
54 #include "except.h"
55 #include "solman.h"
56 #include "submat.h"
57 #include "spmapmh.h"
58 #include "ls.h"
59 
60 /* ParSuperLUSolver - begin */
61 
62 /*
63  * Solutore LU per matrici sparse. usa spazio messo a disposizione da altri
64  * e si aspetta le matrici gia' bell'e preparate
65  */
66 
67 struct ParSuperLUSolverData;
68 
69 class ParSuperLUSolver : public LinearSolver {
70 public:
71 private:
72  mutable integer *Aip;
73  mutable integer *App;
74  mutable doublereal *Axp;
75 
76  mutable integer iN; /* ordine della matrice */
77  mutable integer iNonZeroes;
78 
79  doublereal dPivotFactor;
80 
81  mutable bool bFirstSol; /* true se prima backsubst */
82  mutable bool bRegenerateMatrix; /* true se prima backsubst */
83 
84  ParSuperLUSolverData *sld;
85 
86  unsigned nThreads;
87 
88  enum Op {
89  FACTOR,
90  EXIT
91  };
92 
93  struct thread_data_t {
94  pthread_t thread;
95  ParSuperLUSolver *pSLUS;
96  unsigned threadNumber;
97  sem_t sem;
98  void *pdgstrf_threadarg;
99  } *thread_data;
100 
101  Op thread_operation;
102  unsigned thread_count;
103  pthread_mutex_t thread_mutex;
104  pthread_cond_t thread_cond;
105 
106  /* Thread process */
107  static void *thread_op(void *arg);
108 
109  /* Fattorizza la matrice */
110  void Factor(void);
111 
112  void EndOfOp(void);
113 
114 public:
115  /* Costruttore: si limita ad allocare la memoria */
116  ParSuperLUSolver(unsigned nt, integer iMatOrd, const doublereal &dPivot);
117 
118  /* Distruttore */
119  ~ParSuperLUSolver(void);
120 
121 #ifdef DEBUG
122  void IsValid(void) const;
123 #endif /* DEBUG */
124 
125  /* Risolve */
126  void Solve(void) const;
127 
128  /* Index Form */
130  std::vector<doublereal>& Ax,
131  std::vector<integer>& Ar,
132  std::vector<integer>& Ac,
133  std::vector<integer>& Ap) const;
134 };
135 
136 /* ParSuperLUSolver - end */
137 
138 
139 
140 /* ParSuperLUSparseSolutionManager - begin */
141 
142 /*
143  * Gestisce la soluzione del problema; alloca le matrici occorrenti
144  * e gli oggetti dedicati alla gestione delle matrici ed alla soluzione
145  */
146 
147 class ParSuperLUSparseSolutionManager : public SolutionManager {
148 protected:
149  integer iMatSize; /* ordine della matrice */
150  std::vector<integer> Ai; /* array di interi con
151  * indici di riga di ParSuperLUSolver */
152  std::vector<integer> Adummy; /* dummy */
153  std::vector<integer> Ap; /* array di interi con
154  * indici di colonna CC */
155  std::vector<doublereal> Ax; /* reali con la matrice */
156  std::vector<doublereal> xb; /* reali con residuo/soluzione */
157 
158  mutable SpMapMatrixHandler MH; /* sparse MatrixHandler */
159  mutable MyVectorHandler VH; /* puntatore a VectorHandler */
160 
161  /* Fattorizza la matrice (non viene mai chiamato direttamente,
162  * ma da Solve se la matrice ancora non e' stata fattorizzata) */
163  void Factor(void);
164 
165 #ifdef DEBUG
166  /* Usata per il debug */
167  void IsValid(void) const;
168 #endif /* DEBUG */
169 
170  virtual void MakeCompressedColumnForm(void);
171 public:
172  /* Costruttore: usa e mette a disposizione matrici che gli sono date */
173  ParSuperLUSparseSolutionManager(unsigned nt, integer iSize,
174  const doublereal& dPivotFactor = 1.0);
175 
176  /* Distruttore: dealloca le matrici e distrugge gli oggetti propri */
177  ~ParSuperLUSparseSolutionManager(void);
178 
179  /* Inizializza il gestore delle matrici */
180  void MatrReset(void);
181 
182  /* Risolve il sistema */
183  void Solve(void);
184 
185  /* Rende disponibile l'handler per la matrice */
186  MatrixHandler* pMatHdl(void) const {
187  return &MH;
188  };
189 
190  /* Rende disponibile l'handler per il termine noto */
191  VectorHandler* pResHdl(void) const {
192 #ifdef DEBUG
193  VH.IsValid();
194 #endif /* DEBUG */
195  return &VH;
196  };
197 
198  /* Rende disponibile l'handler per la soluzione (e' lo stesso
199  * del termine noto, ma concettualmente sono separati) */
200  VectorHandler* pSolHdl(void) const {
201 #ifdef DEBUG
202  VH.IsValid();
203 #endif /* DEBUG */
204  return &VH;
205  };
206 };
207 
208 /* ParSuperLUSparseSolutionManager - end */
209 
210 /* ParSuperLUSparseCCSolutionManager - begin */
211 template <class CC>
212 class ParSuperLUSparseCCSolutionManager: public ParSuperLUSparseSolutionManager {
213 protected:
214  bool CCReady;
216 
217  virtual void MatrReset(void);
218  virtual void MakeCompressedColumnForm(void);
219 
220 public:
221  ParSuperLUSparseCCSolutionManager(unsigned nt, integer Dim,
222  const doublereal &dPivot = -1.);
223  virtual ~ParSuperLUSparseCCSolutionManager(void);
224 
225  /* Inizializzatore "speciale" */
226  virtual void MatrInitialize(void);
227 
228  /* Rende disponibile l'handler per la matrice */
229  virtual MatrixHandler* pMatHdl(void) const;
230 };
231 
232 /* ParSuperLUSparseCCSolutionManager - end */
233 
234 #endif /* USE_SUPERLU_MT */
235 
236 #endif /* PARSUPERLUWRAP_H */
237 
virtual VectorHandler * pResHdl(void) const =0
virtual MatrixHandler * pMatHdl(void) const =0
virtual void MatrReset(void)=0
virtual void Solve(void)=0
virtual void Solve(void) const =0
virtual VectorHandler * pSolHdl(void) const =0
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51
virtual void MakeCompactForm(SparseMatrixHandler &mh, std::vector< doublereal > &Ax, std::vector< integer > &Ar, std::vector< integer > &Ac, std::vector< integer > &Ap) const
Definition: ls.cc:123