CPPLapack
 All Classes Files Functions Variables Friends Pages
dgsmatrix-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 dgsmatrix::pardiso(dcovector& b) const
8 {CPPL_VERBOSE_REPORT;
9 #ifndef __INTEL_COMPILER
10  ERROR_REPORT;
11  std::cerr << "dgsmatrix::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 #else //__INTEL_COMPILER
16 
17 
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  //////// convert matrix storage into compressed sparse row format ////////
28  //std::cerr << "converting" << std::endl;
29  std::vector<double> a(data.size());
30  std::vector<MKL_INT> ja(data.size());
31  std::vector<MKL_INT> ia(m+1);
32  ia[0] =0;
33  MKL_INT k=0;
34  for(CPPL_INT i=0; i<m; i++){
35  //// make map ////
36  const std::vector<CPPL_INT>::const_iterator rows_i_end =rows[i].end();
37  std::map<CPPL_INT,CPPL_INT> jc;
38  for(std::vector<CPPL_INT>::const_iterator rit=rows[i].begin(); rit!=rows_i_end; rit++){
39  jc.insert( std::make_pair(data[*rit].j, *rit) );
40  }
41  //// assign ////
42  const std::map<CPPL_INT,CPPL_INT>::const_iterator jc_end =jc.end();
43  for(std::map<CPPL_INT,CPPL_INT>::const_iterator jcit=jc.begin(); jcit!=jc_end; jcit++){
44  a[k] =data[(*jcit).second].v;
45  ja[k] =MKL_INT((*jcit).first);
46  k++;
47  }
48  ia[i+1] =k;
49  }
50 
51  //////// pardisoinit ////////
52  //std::cerr << "initializing" << std::endl;
53  _MKL_DSS_HANDLE_t pt[64];
54  MKL_INT mtype =11;//real unsymmetric
55  MKL_INT iparm[64];
56  PARDISOINIT(pt, &mtype, iparm);
57  iparm[1] =3;//parallel fill-in reducing ordering
58  iparm[23] =1;//use two-level scheduling factorization algorithm
59  iparm[26] =0;//disable matrix checker
60  iparm[34] =-1;//use zero-base array index
61 
62  //////// pardiso ////////
63  //std::cerr << "solving" << std::endl;
64  MKL_INT maxfct =1;
65  MKL_INT mnum =1;
66  MKL_INT phase =13;
67  MKL_INT MKL_INT_n =MKL_INT(n);
68  std::vector<MKL_INT> perm(n);
69  MKL_INT nrhs =1;
70  MKL_INT msglvl =0;
71  dcovector x(b.l);
72  MKL_INT error =1;
73  PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &MKL_INT_n, &a[0], &ia[0], &ja[0], &perm[0], &nrhs, iparm, &msglvl, b.array, x.array, &error);
74  swap(b,x);//set b as x
75  if(error!=0){
76  WARNING_REPORT;
77  std::cerr << "Serious trouble happend. error = " << error << "." << std::endl;
78  }
79 
80  //////// release memory ////////
81  phase =-1;
82  MKL_INT error2 =1;
83  PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &MKL_INT_n, &a[0], &ia[0], &ja[0], &perm[0], &nrhs, iparm, &msglvl, b.array, x.array, &error2);
84 
85  return error;
86 #endif //__INTEL_COMPILER
87 }
CPPL_INT pardiso(dcovector &) const
std::vector< dcomponent > data
matrix data
Definition: dgsmatrix.hpp:11
CPPL_INT n
matrix column size
Definition: dgsmatrix.hpp:10
CPPL_INT l
vector size
Definition: dcovector.hpp:9
_dgematrix i(const _dgbmatrix &mat)
double * array
1D array to store vector data
Definition: dcovector.hpp:11
friend void swap(dgsmatrix &, dgsmatrix &)
Real Double-precision Column Vector Class.
Definition: dcovector.hpp:3
std::vector< std::vector< CPPL_INT > > rows
array of vector to store the entry information of component for each row
Definition: dgsmatrix.hpp:12
CPPL_INT m
matrix row size
Definition: dgsmatrix.hpp:9