CPPLapack
 All Classes Files Functions Variables Friends Pages
dgrmatrix-pardiso.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! solve A*x=b for real and unsymmetric matrix using Intel PARDISO.\n
3  The argument is dcovector b.
4  b is overwritten and become the solution x.
5  A is not overwritten.
6 */
7 inline CPPL_INT dgrmatrix::pardiso(dcovector& b) const
8 {CPPL_VERBOSE_REPORT;
9 #ifndef __INTEL_COMPILER
10  ERROR_REPORT;
11  std::cerr << "dgrmatrix::pardiso is only for intel c++ compiler (icpc)." << std::endl;
12  std::cerr << "Recompile your code with icpc to use pardiso." << std::endl;
13  (void)b;
14  exit(1);
15 
16 
17 #else //__INTEL_COMPILER is defined.
18  //#ifdef CPPL_DEBUG
19  if(m!=n || m!=b.l){
20  ERROR_REPORT;
21  std::cerr << "These matrix and vector cannot be solved." << std::endl
22  << "Your input was (" << m << "x" << n << ") and (" << b.l << ")." << std::endl;
23  exit(1);
24  }
25  //#endif//CPPL_DEBUG
26 
27  //////// pardisoinit ////////
28  //std::cerr << "initializing" << std::endl;
29  _MKL_DSS_HANDLE_t pt[64];
30  MKL_INT mtype =11;//real unsymmetric
31  MKL_INT iparm[64];
32  PARDISOINIT(pt, &mtype, iparm);
33  iparm[1] =3;//parallel fill-in reducing ordering
34  iparm[23] =1;//use two-level scheduling factorization algorithm
35  iparm[26] =0;//disable matrix checker
36  iparm[34] =0;//use one-base array index
37 
38  //////// pardiso ////////
39  //std::cerr << "solving" << std::endl;
40  MKL_INT maxfct =1;
41  MKL_INT mnum =1;
42  MKL_INT phase =13;
43  MKL_INT MKL_INT_n =MKL_INT(n);
44  double* a0 = const_cast<double*>(&a[0]);
45  MKL_INT* ia0 = const_cast<MKL_INT*>(&ia[0]);
46  MKL_INT* ja0 = const_cast<MKL_INT*>(&ja[0]);
47  std::vector<MKL_INT> perm(n);
48  MKL_INT nrhs =1;
49  MKL_INT msglvl =0;
50  dcovector x(b.l);
51  MKL_INT error =1;
52  PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &MKL_INT_n, a0, ia0, ja0, &perm[0], &nrhs, iparm, &msglvl, b.array, x.array, &error);
53  swap(b,x);//set b as x
54  if(error!=0){
55  WARNING_REPORT;
56  std::cerr << "Serious trouble happend. error = " << error << "." << std::endl;
57  }
58 
59  //////// release memory ////////
60  phase =-1;
61  MKL_INT error2 =1;
62  PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &MKL_INT_n, a0, ia0, ja0, &perm[0], &nrhs, iparm, &msglvl, b.array, x.array, &error2);
63 
64  return error;
65 #endif //__INTEL_COMPILER
66 }
std::vector< double > a
matrix component values
Definition: dgrmatrix.hpp:11
friend void swap(dgrmatrix &, dgrmatrix &)
CPPL_INT l
vector size
Definition: dcovector.hpp:9
std::vector< CPPL_INT > ia
rowIndex (NOT zero-based BUT one-based indexing)
Definition: dgrmatrix.hpp:12
CPPL_INT n
matrix column size
Definition: dgrmatrix.hpp:10
double * array
1D array to store vector data
Definition: dcovector.hpp:11
CPPL_INT pardiso(dcovector &) const
Real Double-precision Column Vector Class.
Definition: dcovector.hpp:3
CPPL_INT m
matrix row size
Definition: dgrmatrix.hpp:9
std::vector< CPPL_INT > ja
columns (NOT zero-based BUT one-based indexing)
Definition: dgrmatrix.hpp:13