1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
/* pcgl.c */
#include "../Iter.h"
/*--------------------------------------------------------------------*/
/*
---------------------------------------------------------------------
purpose -- to solve a symmetric nonnegative matrix equation
Ax=b
using left preconditioned conjugate gradient method
x -- Initial guess
A -- Input matrix
M -- Front Matrix as the preconditioner
b -- Right-hand side
tol -- Convergence tolerance
type -- type of entries
SPOOLES_REAL or SPOOLES_COMPLEX
symmetryflag -- symmetry of the matrix
SPOOLES_SYMMETRIC, SPOOLES_HERMITIAN or SPOOLES_NONSYMMETRIC
nrhs -- number of right hand sides
msglvl -- message level
msgFile -- message file
created -- Oct. 27, 1998 Wei-Pai Tang
---------------------------------------------------------------------
*/
int
pcgl (
int n_matrixSize,
int type,
int symmetryflag,
InpMtx *mtxA,
FrontMtx *Precond,
DenseMtx *mtxX,
DenseMtx *mtxB,
int itermax,
double convergetol,
int msglvl,
FILE *msgFile
)
{
Chv *chv, *rootchv ;
ChvManager *chvmanager ;
DenseMtx *mtxZ ;
DenseMtx *vecP, *vecR, *vecQ ;
DenseMtx *vecX, *vecZ ;
double Alpha, Beta, Rho, Rho0, Init_norm, ratio, Res_norm, Rtmp ;
double t1, t2, cpus[9] ;
double one[2] = {1.0, 0.0}, zero[2] = {0.0, 0.0} ;
double Tiny = 0.1e-28;
int Iter, neqns;
int stats[6] ;
if (symmetryflag != SPOOLES_SYMMETRIC){
fprintf(msgFile, "\n\n Fatal Error, \n"
" Matrix is not symmetric in PCGL !!") ;
return (-1);
};
neqns = n_matrixSize;
/*
--------------------
init the vectors in bicgstab
--------------------
*/
vecP = DenseMtx_new() ;
DenseMtx_init(vecP, type, 0, 0, neqns, 1, 1, neqns) ;
vecR = DenseMtx_new() ;
DenseMtx_init(vecR, type, 0, 0, neqns, 1, 1, neqns) ;
vecX = DenseMtx_new() ;
DenseMtx_init(vecX, type, 0, 0, neqns, 1, 1, neqns) ;
vecQ = DenseMtx_new() ;
DenseMtx_init(vecQ, type, 0, 0, neqns, 1, 1, neqns) ;
vecZ = DenseMtx_new() ;
DenseMtx_init(vecZ, type, 0, 0, neqns, 1, 1, neqns) ;
/*
--------------------------
Initialize the iterations
--------------------------
*/
FrontMtx_solve(Precond, vecR, mtxB, Precond->manager,
cpus, msglvl, msgFile) ;
Init_norm = DenseMtx_twoNormOfColumn(vecR,0);
if ( Init_norm == 0.0 ){
Init_norm = 1.0; };
ratio = 1.0;
DenseMtx_zero(vecX) ;
/* DenseMtx_copy(vecR, mtxB); */
MARKTIME(t1) ;
Iter = 0;
/*
------------------------------
Main Loop of the iterations
------------------------------
*/
while ( ratio > convergetol && Iter <= itermax )
{
Iter++;
/* */
DenseMtx_colDotProduct(vecR, 0, vecR, 0, &Rho);
/* */
if ( Iter == 1 ) {
DenseMtx_colCopy(vecP, 0, vecR, 0);
} else {
Beta = Rho /(Rho0 + Tiny);
DenseMtx_colGenAxpy(&Beta, vecP, 0, one, vecR, 0);
};
InpMtx_sym_gmmm(mtxA, zero, vecZ, one, vecP) ;
FrontMtx_solve(Precond, vecQ, vecZ, Precond->manager,
cpus, msglvl, msgFile) ;
DenseMtx_colDotProduct(vecP, 0, vecQ, 0, &Rtmp);
Alpha = Rho/(Rtmp+Tiny);
DenseMtx_colGenAxpy(one, vecX, 0, &Alpha, vecP, 0);
Rtmp=-Alpha;
DenseMtx_colGenAxpy(one, vecR, 0, &Rtmp, vecQ, 0);
Rho0 = Rho;
/* */
Res_norm = DenseMtx_twoNormOfColumn(vecR,0);
ratio = Res_norm/Init_norm;
fprintf(msgFile, "\n\n At iteration %d"
" the convergence ratio is %12.4e",
Iter, ratio) ;
}
/* End of while loop */
MARKTIME(t2) ;
fprintf(msgFile, "\n CPU : Converges in time: %8.3f ", t2 - t1) ;
fprintf(msgFile, "\n # iterations = %d", Iter) ;
fprintf(msgFile, "\n\n after PCGL") ;
DenseMtx_colCopy(mtxX, 0, vecX, 0);
/*
------------------------
free the working storage
------------------------
*/
end:
DenseMtx_free(vecP) ;
DenseMtx_free(vecR) ;
DenseMtx_free(vecX) ;
DenseMtx_free(vecQ) ;
DenseMtx_free(vecZ) ;
fprintf(msgFile, "\n") ;
return(1) ; }
/*--------------------------------------------------------------------*/
|