OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
mklpardisosolver.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 
35 #include "mklpardisosolver.h"
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 #include <mkl.h>
47 
48 namespace oofem {
49 REGISTER_SparseLinSolver(MKLPardisoSolver, ST_MKLPardiso);
50 
52 
54 
56 {
57  int neqs = b.giveSize();
58  x.resize(neqs);
59 
60  int mtype = -2; // Real symmetric positive definite matrix
61  CompCol *mat = dynamic_cast< SymCompCol * >(&A);
62  if ( !mat ) {
63  mtype = 11; // Real unsymmetric matrix
64  mat = dynamic_cast< CompCol * >(&A);
65  if ( !mat ) {
66  OOFEM_ERROR("CompCol matrix needed for Pardiso solver");
67  }
68  }
69 
70  // Pardiso's CGS-implementation can't handle b = 0.
71  if ( b.computeSquaredNorm() == 0 ) {
72  return NM_Success;
73  }
74 
75  const int *ia = mat->giveColPtr().givePointer();
76  const int *ja = mat->giveRowIndex().givePointer();
77  const double *a = mat->giveValues().givePointer();
78 
79  Timer timer;
80  timer.startTimer();
81 
82  // RHS and solution vectors.
83  int nrhs = 1; // Number of right hand sides.
84 
85  // Internal solver memory pointer pt,
86  // 32-bit: int pt[64]; 64-bit: long int pt[64]
87  // or void *pt[64] should be OK on both architectures
88  void *pt[64];
89 
90  // Pardiso control parameters.
91  IntArray iparm(64);
92  int maxfct, mnum, phase, error, msglvl;
93 
94  double ddum = 0.; // Double dummy
95  int idum = 0; // Integer dummy.
96 
97  // Setup Pardiso control parameters
98  /* -------------------------------------------------------------------- */
99  error = 0;
100  pardisoinit(pt, &mtype, iparm.givePointer()); // INITIALIZATION!
101  // Settings are here:
102  // https://software.intel.com/en-us/articles/pardiso-parameter-table#table2
103 
104  iparm[0] = 1;
106  //iparm[4-1] = 32; // 10*L + K. K = 1 implies CGS (instead of LU), K = 2 implies CG. L specifies exponent tolerance.
107  iparm[8-1] = 2; /* Max numbers of iterative refinement steps. */
108  iparm[12-1] = 2; // Transpose (we have a CSC matrix representation here instead of the expected CSR)
109  iparm[35-1] = 1; // 1 implies 0-indexing
110  //iparm[27-1] = 1; // Checks the matrix (only in MKL)
112 
113  maxfct = 1; // Maximum number of numerical factorizations.
114  mnum = 1; // Which factorization to use.
115  msglvl = 0; // Print statistical information
116  error = 0; // Initialize error flag
117 
118  /* -------------------------------------------------------------------- */
119  /* .. Reordering and Symbolic Factorization. This step also allocates */
120  /* all memory that is necessary for the factorization. */
121  /* -------------------------------------------------------------------- */
122  phase = 11;
123 
124  pardiso(pt, &maxfct, &mnum, &mtype, &phase, &neqs,
125  (void*)a, (int*)ia, (int*)ja,
126  &idum, &nrhs, iparm.givePointer(), &msglvl, &ddum, &ddum, &error); // FACTORIZATION!
127 
128  if ( error != 0 ) {
129  OOFEM_WARNING("Error during symbolic factorization: %d", error);
130  return NM_NoSuccess;
131  }
132  OOFEM_LOG_DEBUG("Reordering completed: %d nonzero factors, %d factorization MFLOPS\n", iparm[17-1], iparm[18-1]);
133 
134  /* -------------------------------------------------------------------- */
135  /* .. Numerical factorization. */
136  /* -------------------------------------------------------------------- */
137  phase = 22;
138 
139  pardiso(pt, &maxfct, &mnum, &mtype, &phase, &neqs,
140  (void*)a, (int*)ia, (int*)ja,
141  &idum, &nrhs, iparm.givePointer(), &msglvl, &ddum, &ddum, &error);
142 
143  if ( error != 0 ) {
144  OOFEM_WARNING("ERROR during numerical factorization: %d", error);
145  return NM_NoSuccess;
146  }
147  OOFEM_LOG_DEBUG("Factorization completed ...\n");
148 
149  /* -------------------------------------------------------------------- */
150  /* .. Back substitution and iterative refinement. */
151  /* -------------------------------------------------------------------- */
152  phase = 33;
153 
154  pardiso(pt, &maxfct, &mnum, &mtype, &phase, &neqs,
155  (void*)a, (int*)ia, (int*)ja,
156  &idum, &nrhs, iparm.givePointer(), &msglvl, (void*)b.givePointer(), (void*)x.givePointer(), &error);
157 
158  printf("iparm(20) = %d\n", iparm[20]);
159  if ( error != 0 ) {
160  OOFEM_WARNING("ERROR during solution: %d, iparm(20) = %d", error, iparm[20-1]);
161  return NM_NoSuccess;
162  }
163 
164  OOFEM_LOG_DEBUG("Solve completed ... \n");
165 
166  /* -------------------------------------------------------------------- */
167  /* .. Termination and release of memory. */
168  /* -------------------------------------------------------------------- */
169  phase = -1; /* Release internal memory. */
170 
171  pardiso(pt, &maxfct, &mnum, &mtype, &phase,
172  &neqs, &ddum, &idum, &idum, &idum, &nrhs,
173  iparm.givePointer(), &msglvl, &ddum, &ddum, &error);
174 
175  timer.stopTimer();
176  OOFEM_LOG_INFO( "MKLPardisoSolver: User time consumed by solution: %.2fs\n", timer.getUtime() );
177 
178  NM_Status s = NM_Success;
179  return s;
180 }
181 
182 #if 0
185 {
187 }
188 #endif
189 } // 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
virtual NM_Status solve(SparseMtrx &A, FloatArray &b, FloatArray &x)
Solves the given sparse linear system of equations .
#define NM_NoSuccess
Numerical method failed to solve problem.
Definition: nmstatus.h:48
#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
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.
MKLPardisoSolver(Domain *d, EngngModel *m)
Constructor.
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