OOFEM 3.0
Loading...
Searching...
No Matches
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 - 2025 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
47namespace oofem {
49
50PardisoProjectOrgSolver :: PardisoProjectOrgSolver(Domain *d, EngngModel *m) : SparseLinearSystemNM(d, m) { }
51
52PardisoProjectOrgSolver :: ~PardisoProjectOrgSolver() { }
53
54ConvergedReason PardisoProjectOrgSolver :: solve(SparseMtrx &A, FloatArray &b, FloatArray &x)
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 CR_CONVERGED;
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 CR_FAILED;
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 CR_FAILED;
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 CR_FAILED;
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 CR_FAILED;
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 return CR_CONVERGED;
215}
216
217#if 0
219ConvergedReason PardisoProjectOrgSolver :: solve(SparseMtrx &A, FloatMatrix &B, FloatMatrix &X)
220{
222}
223#endif
224} // end namespace oofem
#define REGISTER_SparseLinSolver(class, type)
FloatArray & giveValues()
Definition compcol.h:126
IntArray & giveColPtr()
Definition compcol.h:128
IntArray & giveRowIndex()
Definition compcol.h:127
void resize(Index s)
Definition floatarray.C:94
double computeSquaredNorm() const
Definition floatarray.C:867
Index giveSize() const
Returns the size of receiver.
Definition floatarray.h:261
const double * givePointer() const
Definition floatarray.h:506
const int * givePointer() const
Definition intarray.h:345
SparseLinearSystemNM(Domain *d, EngngModel *m)
Constructor.
int giveNumberOfRows() const
Returns number of rows of receiver.
Definition sparsemtrx.h:114
double getUtime()
Returns total user time elapsed in seconds.
Definition timer.C:105
void startTimer()
Definition timer.C:69
void stopTimer()
Definition timer.C:77
#define OOFEM_WARNING(...)
Definition error.h:80
#define OOFEM_ERROR(...)
Definition error.h:79
#define OOFEM_LOG_INFO(...)
Definition logger.h:143
#define OOFEM_LOG_DEBUG(...)
Definition logger.h:144
@ ST_PardisoProjectOrg
void pardisoinit(void *, int *, int *, int *, double *, int *)
void pardiso(void *, int *, int *, int *, int *, int *, double *, int *, int *, int *, int *, int *, int *, double *, double *, int *, double *)

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011