00001 subroutine bicgstab(n,A,b,x,tol,maxIter,k)
00002
00003
00004 implicit none
00005
00006 integer n,maxIter
00007
00008 real(8) :: A(n,n),b(n),x(n)
00009
00010 real(8) :: tol
00011
00012
00013
00014
00015 real(8) r(n)
00016
00017 real(8) rhat(n)
00018
00019 real(8) rhoZero,alpha,omegaZero
00020
00021 real(8) v(n),p(n),s(n),t(n)
00022
00023 real(8) rhoOne
00024
00025 real(8) beta
00026
00027
00028 integer decision
00029
00030 integer i,k
00031
00032
00033 r=0.d0
00034
00035 r=b-matmul(A,x)
00036
00037 rhat=r
00038
00039 if ( dot_product(r,rhat).le.epsilon(0.d0) ) then
00040
00041 print*,'r and rhat are orthogonal or r is zero'
00042
00043
00044
00045
00046
00047 print*,'kNaN stop!'
00048 stop
00049
00050
00051
00052
00053
00054
00055 end if
00056
00057
00058 rhoZero=1.d0
00059 alpha=1.d0
00060 omegaZero=1.d0
00061
00062 v=0.d0
00063 p=0.d0
00064 s=0.d0
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 do i=1,maxIter
00087
00088
00089
00090
00091
00092 rhoOne=dot_product(rhat,r)
00093
00094
00095
00096 beta=(rhoOne/rhoZero)*(alpha/omegaZero)
00097
00098
00099
00100 p=r+beta*(p-omegaZero*v)
00101
00102
00103
00104
00105
00106
00107
00108 v=matmul(A,p)
00109
00110
00111
00112 alpha=rhoOne/dot_product(rhat,v)
00113
00114
00115
00116
00117 s=r-alpha*v
00118
00119 if (dot_product(s,s).le.epsilon(0.d0)) then
00120
00121 goto 1000
00122
00123 end if
00124
00125
00126
00127
00128 t=matmul(A,s)
00129
00130
00131
00132 omegaZero=dot_product(t,s)/dot_product(t,t)
00133
00134
00135
00136 1000 x=x+alpha*p+omegaZero*s
00137
00138
00139
00140 if (dot_product(s,s).le.tol) then
00141
00142 print*,'bicgstab converged in step=',i
00143 return
00144
00145 end if
00146
00147
00148
00149 r=s-omegaZero*t
00150
00151
00152
00153 rhoZero=rhoOne
00154
00155
00156
00157 end do
00158
00159
00160
00161
00162
00163
00164
00165
00166 end subroutine bicgstab