9 #ifndef __INTEL_COMPILER
11 std::cerr <<
"dgrmatrix::dfgmres is only for intel c++ compiler (icpc)." << std::endl;
12 std::cerr <<
"Recompile your code with icpc to use dfgmres." << std::endl;
18 #else //__INTEL_COMPILER is defined.
22 std::cerr <<
"These matrix and vector cannot be solved." << std::endl
23 <<
"Your input was (" <<
m <<
"x" <<
n <<
") and (" << b.
l <<
")." << std::endl;
31 MKL_INT N =MKL_INT(
n);
40 std::vector<double> tmp((2*n_res+1)*N + (n_res*(n_res+9))/2 + 1);
41 DFGMRES_INIT(&N, x.
array, b.
array, &RCI_request, ipar, dpar, &tmp[0]);
44 std::cerr <<
"dfgmres_init failed. RCI_request=" << RCI_request <<
"." << std::endl;
60 DFGMRES_CHECK(&N, x.
array, b.
array, &RCI_request, ipar, dpar, &tmp[0]);
63 std::cerr <<
"dfgmres_init failed. RCI_request=" << RCI_request <<
"." << std::endl;
69 double* A =
const_cast<double*
>(&
a[0]);
70 MKL_INT* IA =
const_cast<MKL_INT*
>(&
ia[0]);
71 MKL_INT* JA =
const_cast<MKL_INT*
>(&
ja[0]);
77 DFGMRES(&N, x.
array, b.
array, &RCI_request, ipar, dpar, &tmp[0]);
81 MKL_DCSRGEMV(&transa, &N, A, IA, JA, &tmp[ipar[21]-1], &tmp[ipar[22]-1]);
85 else if(RCI_request==2){
88 DFGMRES_GET(&N, x.
array, x_tmp.
array, &RCI_request, ipar, dpar, &tmp[0], &itercount);
89 double norm_r =fabs(
damax(b_orig-(*
this)*x_tmp));
90 std::cerr <<
"itc=" << itc <<
": norm_r = " << norm_r <<
" (eps=" << eps <<
")" << std::endl;
92 std::cerr <<
"converged (norm_r<eps)" << std::endl;
96 std::cerr <<
"failed. (itc>=itmax)" << std::endl;
101 else if(RCI_request==0){
102 std::cerr <<
"converged (RCI_request=0)" << std::endl;
107 std::cerr <<
"dfgmres failed. RCI_request=" << RCI_request <<
"." << std::endl;
112 CPPL_INT info =RCI_request;
116 DFGMRES_GET(&N, x.
array, b.
array, &RCI_request, ipar, dpar, &tmp[0], &itercount);
125 #endif //__INTEL_COMPILER
145 {CPPL_VERBOSE_REPORT;
146 #ifndef __INTEL_COMPILER
148 std::cerr <<
"dgrmatrix::ilut_dfgmres is only for intel c++ compiler (icpc)." << std::endl;
149 std::cerr <<
"Recompile your code with icpc to use ilut_dfgmres." << std::endl;
156 #else //__INTEL_COMPILER is defined.
160 std::cerr <<
"These matrix and vector cannot be solved." << std::endl
161 <<
"Your input was (" <<
m <<
"x" <<
n <<
") and (" << b.
l <<
")." << std::endl;
170 MKL_INT N =MKL_INT(
n);
171 MKL_INT MAXFIL =std::min(maxfil, N-1);
180 std::vector<double> tmp((2*n_res+1)*N + (n_res*(n_res+9))/2 + 1);
181 DFGMRES_INIT(&N, x.
array, b.
array, &RCI_request, ipar, dpar, &tmp[0]);
184 std::cerr <<
"dfgmres_init failed. RCI_request=" << RCI_request <<
"." << std::endl;
189 double* A =
const_cast<double*
>(&
a[0]);
190 MKL_INT* IA =
const_cast<MKL_INT*
>(&
ia[0]);
191 MKL_INT* JA =
const_cast<MKL_INT*
>(&
ja[0]);
192 std::vector<double> bilut((2*MAXFIL+1)*N - MAXFIL*(MAXFIL+1) + 1);
193 std::vector<MKL_INT> ibilut(N+1);
194 std::vector<MKL_INT> jbilut((2*MAXFIL+1)*N - MAXFIL*(MAXFIL+1) + 1);
203 DCSRILUT(&N, A, IA, JA, &bilut[0], &ibilut[0], &jbilut[0], &tol, &MAXFIL, ipar, dpar, &ierr);
206 std::cerr <<
"dcsrilut failed. ierr=" << ierr <<
"." << std::endl;
222 DFGMRES_CHECK(&N, x.
array, b.
array, &RCI_request, ipar, dpar, &tmp[0]);
225 std::cerr <<
"dfgmres_init failed. RCI_request=" << RCI_request <<
"." << std::endl;
242 DFGMRES(&N, x.
array, b.
array, &RCI_request, ipar, dpar, &tmp[0]);
246 MKL_DCSRGEMV(&transa, &N, A, IA, JA, &tmp[ipar[21]-1], &tmp[ipar[22]-1]);
249 else if(RCI_request==3){
250 MKL_DCSRTRSV(&uplo1, &transa1, &diag1, &N, &bilut[0], &ibilut[0], &jbilut[0], &tmp[ipar[21]-1], x_tmp.
array);
251 MKL_DCSRTRSV(&uplo2, &transa2, &diag2, &N, &bilut[0], &ibilut[0], &jbilut[0], x_tmp.
array, &tmp[ipar[22]-1]);
254 else if(RCI_request==2){
257 DFGMRES_GET(&N, x.
array, x_tmp.
array, &RCI_request, ipar, dpar, &tmp[0], &itercount);
258 double norm_r =fabs(
damax(b_orig-(*
this)*x_tmp));
259 std::cerr <<
"itc=" << itc <<
": norm_r = " << norm_r <<
" (eps=" << eps <<
")" << std::endl;
261 std::cerr <<
"converged (norm_r<eps)" << std::endl;
265 std::cerr <<
"failed. (itc>=itmax)" << std::endl;
270 else if(RCI_request==0){
271 std::cerr <<
"converged (RCI_request=0)" << std::endl;
276 std::cerr <<
"dfgmres failed. RCI_request=" << RCI_request <<
"." << std::endl;
281 CPPL_INT info =RCI_request;
285 DFGMRES_GET(&N, x.
array, b.
array, &RCI_request, ipar, dpar, &tmp[0], &itercount);
294 #endif //__INTEL_COMPILER
std::vector< double > a
matrix component values
friend void swap(dgrmatrix &, dgrmatrix &)
std::vector< CPPL_INT > ia
rowIndex (NOT zero-based BUT one-based indexing)
CPPL_INT n
matrix column size
double * array
1D array to store vector data
Real Double-precision Column Vector Class.
CPPL_INT m
matrix row size
CPPL_INT dfgmres(dcovector &, const double) const
std::vector< CPPL_INT > ja
columns (NOT zero-based BUT one-based indexing)
CPPL_INT ilut_dfgmres(dcovector &, const int, const double) const
friend double damax(const dgrmatrix &)