OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
pardisoprojectorgsolver.C
Go to the documentation of this file.
1 /*
2  *
3  * ##### ##### ###### ###### ### ###
4  * ## ## ## ## ## ## ## ### ##
5  * ## ## ## ## #### #### ## # ##
6  * ## ## ## ## ## ## ## ##
7  * ## ## ## ## ## ## ## ##
8  * ##### ##### ## ###### ## ##
9  *
10  *
11  * OOFEM : Object Oriented Finite Element Code
12  *
13  * Copyright (C) 1993 - 2013 Borek Patzak
14  *
15  *
16  *
17  * Czech Technical University, Faculty of Civil Engineering,
18  * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19  *
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Lesser General Public
22  * License as published by the Free Software Foundation; either
23  * version 2.1 of the License, or (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28  * Lesser General Public License for more details.
29  *
30  * You should have received a copy of the GNU Lesser General Public
31  * License along with this library; if not, write to the Free Software
32  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33  */
34 
36 
37 #include "compcol.h"
38 #include "symcompcol.h"
39 #include "engngm.h"
40 #include "floatarray.h"
41 #include "verbose.h"
42 #include "timer.h"
43 #include "error.h"
44 #include "classfactory.h"
45 
46 
47 namespace oofem {
48 REGISTER_SparseLinSolver(PardisoProjectOrgSolver, ST_PardisoProjectOrg);
49 
51 
53 
55 {
56  int neqs = b.giveSize();
57  x.resize(neqs);
58 
59  int mtype = -2; // Real symmetric positive definite matrix
60  CompCol *mat = dynamic_cast< SymCompCol * >(& A);
61  if ( !mat ) {
62  mtype = 11; // Real unsymmetric matrix
63  mat = dynamic_cast< CompCol * >(& A);
64  if ( !mat ) {
65  OOFEM_ERROR("CompCol matrix needed for Pardiso solver");
66  }
67  }
68 
69  // Pardiso's CGS-implementation can't handle b = 0.
70  if ( b.computeSquaredNorm() == 0 ) {
71  return NM_Success;
72  }
73 
74  int *ia = mat->giveColPtr().givePointer();
75  int *ja = mat->giveRowIndex().givePointer();
76  double *a = mat->giveValues().givePointer();
77 
78 
79  /* -------------------------------------------------------------------- */
80  /* .. Convert matrix from 0-based C-notation to Fortran 1-based */
81  /* notation. */
82  /* -------------------------------------------------------------------- */
83  int n = mat->giveNumberOfRows();
84  for ( int i = 0; i < n + 1; i++ ) {
85  ia [ i ] += 1;
86  }
87  int nnz = ia [ n ];
88  for ( int i = 0; i < nnz; i++ ) {
89  ja [ i ] += 1;
90  }
91 
92 
93 
94 
95  Timer timer;
96  timer.startTimer();
97 
98  // RHS and solution vectors.
99  int nrhs = 1; // Number of right hand sides.
100 
101  // Internal solver memory pointer pt,
102  // 32-bit: int pt[64]; 64-bit: long int pt[64]
103  // or void *pt[64] should be OK on both architectures
104  void *pt [ 64 ];
105 
106  // Pardiso control parameters.
107  IntArray iparm(64);
108  FloatArray dparm(64);
109  int maxfct, mnum, phase, error, msglvl;
110 
111  double ddum = 0.; // Double dummy
112  int idum = 0; // Integer dummy.
113 
114  // Setup Pardiso control parameters
115  /* -------------------------------------------------------------------- */
116  error = 0;
117  int solver = 0; // sparse direct
118  pardisoinit(pt, & mtype, & solver, iparm.givePointer(), dparm.givePointer(), & error); // INITIALIZATION!
119  if ( error != 0 ) {
120  OOFEM_WARNING("Error during pardiso init, error code: %d", error);
121  return NM_NoSuccess;
122  }
123  // Settings are here:
124  // https://software.intel.com/en-us/articles/pardiso-parameter-table#table2
125 
126  iparm [ 0 ] = 1;
128  //iparm[4-1] = 32; // 10*L + K. K = 1 implies CGS (instead of LU), K = 2 implies CG. L specifies exponent tolerance.
129  iparm [ 8 - 1 ] = 2; /* Max numbers of iterative refinement steps. */
130  iparm [ 12 - 1 ] = 2; // Transpose (we have a CSC matrix representation here instead of the expected CSR)
131  iparm [ 35 - 1 ] = 1; // 1 implies 0-indexing
132  //iparm[27-1] = 1; // Checks the matrix (only in MKL)
134 
135  maxfct = 1; // Maximum number of numerical factorizations.
136  mnum = 1; // Which factorization to use.
137  msglvl = 0; // Print statistical information
138  error = 0; // Initialize error flag
139 
140  /* -------------------------------------------------------------------- */
141  /* .. Reordering and Symbolic Factorization. This step also allocates */
142  /* all memory that is necessary for the factorization. */
143  /* -------------------------------------------------------------------- */
144  phase = 11;
145 
146  pardiso( pt, & maxfct, & mnum, & mtype, & phase, & neqs,
147  a, ( int * ) ia, ( int * ) ja,
148  & idum, & nrhs, iparm.givePointer(), & msglvl, & ddum, & ddum, & error, dparm.givePointer() ); // FACTORIZATION!
149 
150  if ( error != 0 ) {
151  OOFEM_WARNING("Error during symbolic factorization: %d", error);
152  return NM_NoSuccess;
153  }
154  OOFEM_LOG_DEBUG("Reordering completed: %d nonzero factors, %d factorization MFLOPS\n", iparm [ 17 - 1 ], iparm [ 18 - 1 ]);
155 
156  /* -------------------------------------------------------------------- */
157  /* .. Numerical factorization. */
158  /* -------------------------------------------------------------------- */
159  phase = 22;
160 
161  pardiso( pt, & maxfct, & mnum, & mtype, & phase, & neqs,
162  a, ( int * ) ia, ( int * ) ja,
163  & idum, & nrhs, iparm.givePointer(), & msglvl, & ddum, & ddum, & error, dparm.givePointer() );
164 
165  if ( error != 0 ) {
166  OOFEM_WARNING("ERROR during numerical factorization: %d", error);
167  return NM_NoSuccess;
168  }
169  OOFEM_LOG_DEBUG("Factorization completed ...\n");
170 
171  /* -------------------------------------------------------------------- */
172  /* .. Back substitution and iterative refinement. */
173  /* -------------------------------------------------------------------- */
174  phase = 33;
175 
176  pardiso( pt, & maxfct, & mnum, & mtype, & phase, & neqs,
177  a, ( int * ) ia, ( int * ) ja,
178  & idum, & nrhs, iparm.givePointer(), & msglvl, b.givePointer(), x.givePointer(), & error, dparm.givePointer() );
179 
180  printf("iparm(20) = %d\n", iparm [ 20 ]);
181  if ( error != 0 ) {
182  OOFEM_WARNING("ERROR during solution: %d, iparm(20) = %d", error, iparm [ 20 - 1 ]);
183  return NM_NoSuccess;
184  }
185 
186  OOFEM_LOG_DEBUG("Solve completed ... \n");
187 
188 
189  /* -------------------------------------------------------------------- */
190  /* .. Convert matrix back to 0-based C-notation. */
191  /* -------------------------------------------------------------------- */
192  for ( int i = 0; i < n + 1; i++ ) {
193  ia [ i ] -= 1;
194  }
195  for ( int i = 0; i < nnz; i++ ) {
196  ja [ i ] -= 1;
197  }
198 
199 
200  /* -------------------------------------------------------------------- */
201  /* .. Termination and release of memory. */
202  /* -------------------------------------------------------------------- */
203 
204 
205  phase = -1; /* Release internal memory. */
206 
207  pardiso( pt, & maxfct, & mnum, & mtype, & phase,
208  & neqs, & ddum, & idum, & idum, & idum, & nrhs,
209  iparm.givePointer(), & msglvl, & ddum, & ddum, & error, dparm.givePointer() );
210 
211  timer.stopTimer();
212  OOFEM_LOG_INFO( "MKLPardisoSolver: User time consumed by solution: %.2fs\n", timer.getUtime() );
213 
214  NM_Status s = NM_Success;
215  return s;
216 }
217 
218 #if 0
221 {
223 }
224 #endif
225 } // end namespace oofem
IntArray & giveRowIndex()
Definition: compcol.h:132
IntArray & giveColPtr()
Definition: compcol.h:133
#define NM_Success
Numerical method exited with success.
Definition: nmstatus.h:47
Class and object Domain.
Definition: domain.h:115
void pardisoinit(void *, int *, int *, int *, double *, int *)
Base class for all matrices stored in sparse format.
Definition: sparsemtrx.h:60
This base class is an abstraction for all numerical methods solving sparse linear system of equations...
const int * givePointer() const
Breaks encapsulation.
Definition: intarray.h:336
unsigned long NM_Status
Mask defining NumMetod Status; which can be asked after finishing computation by Numerical Method...
Definition: nmstatus.h:44
#define OOFEM_LOG_DEBUG(...)
Definition: logger.h:128
Class implementing an array of integers.
Definition: intarray.h:61
FloatArray & giveValues()
Definition: compcol.h:131
#define NM_NoSuccess
Numerical method failed to solve problem.
Definition: nmstatus.h:48
int giveNumberOfRows() const
Returns number of rows of receiver.
Definition: sparsemtrx.h:114
#define OOFEM_LOG_INFO(...)
Definition: logger.h:127
#define OOFEM_ERROR(...)
Definition: error.h:61
double computeSquaredNorm() const
Computes the square of the norm.
Definition: floatarray.C:846
void pardiso(void *, int *, int *, int *, int *, int *, double *, int *, int *, int *, int *, int *, int *, double *, double *, int *, double *)
Implementation of symmetric sparse matrix stored using compressed column/row storage.
Definition: symcompcol.h:81
Initializes the variable VERBOSE, in order to get a few intermediate messages on screen: beginning an...
Class representing vector of real numbers.
Definition: floatarray.h:82
Implementation of matrix containing floating point numbers.
Definition: floatmatrix.h:94
virtual NM_Status solve(SparseMtrx &A, FloatArray &b, FloatArray &x)
Solves the given sparse linear system of equations .
PardisoProjectOrgSolver(Domain *d, EngngModel *m)
Constructor.
REGISTER_SparseLinSolver(IMLSolver, ST_IML)
Definition: imlsolver.C:56
Class implementing single timer, providing wall clock and user time capabilities. ...
Definition: timer.h:46
const double * givePointer() const
Gives the pointer to the raw data, breaking encapsulation.
Definition: floatarray.h:469
Abstract base class representing the "problem" under consideration.
Definition: engngm.h:181
int giveSize() const
Returns the size of receiver.
Definition: floatarray.h:218
the oofem namespace is to define a context or scope in which all oofem names are defined.
void startTimer()
Definition: timer.C:69
double getUtime()
Returns total user time elapsed in seconds.
Definition: timer.C:105
#define OOFEM_WARNING(...)
Definition: error.h:62
void stopTimer()
Definition: timer.C:77
void resize(int s)
Resizes receiver towards requested size.
Definition: floatarray.C:631

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:30 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011