|
|
|
@ -61,10 +61,10 @@ subroutine psb_dbgmres_multivect(a, prec, b, x, eps, desc_a, info, itmax, iter,
|
|
|
|
|
integer(psb_ipk_), Optional, Intent(out) :: iter
|
|
|
|
|
real(psb_dpk_), Optional, Intent(out) :: err
|
|
|
|
|
|
|
|
|
|
real(psb_dpk_), allocatable :: aux(:), h(:,:), beta(:,:), beta_e1(:,:)
|
|
|
|
|
real(psb_dpk_), allocatable :: aux(:), h(:,:), vt(:,:), beta(:,:), y(:,:)
|
|
|
|
|
|
|
|
|
|
type(psb_d_multivect_type), allocatable :: v(:)
|
|
|
|
|
type(psb_d_multivect_type) :: v_tot, w
|
|
|
|
|
type(psb_d_multivect_type) :: w, xt, r
|
|
|
|
|
|
|
|
|
|
real(psb_dpk_) :: t1, t2
|
|
|
|
|
|
|
|
|
@ -72,13 +72,14 @@ subroutine psb_dbgmres_multivect(a, prec, b, x, eps, desc_a, info, itmax, iter,
|
|
|
|
|
integer(psb_ipk_) :: litmax, naux, itrace_, n_row, n_col, nrhs, nrep
|
|
|
|
|
integer(psb_lpk_) :: mglob, n_add
|
|
|
|
|
|
|
|
|
|
integer(psb_ipk_) :: i, j, k, istop_, err_act, idx_i, idx_j, idx
|
|
|
|
|
integer(psb_ipk_) :: i, j, k, col, istop_, err_act, idx_i, idx_j, idx
|
|
|
|
|
integer(psb_ipk_) :: debug_level, debug_unit
|
|
|
|
|
|
|
|
|
|
type(psb_ctxt_type) :: ctxt
|
|
|
|
|
integer(psb_ipk_) :: np, me, itx
|
|
|
|
|
real(psb_dpk_) :: rni, xni, bni, ani, bn2, r0n2
|
|
|
|
|
real(psb_dpk_) :: errnum, errden, deps, derr
|
|
|
|
|
real(psb_dpk_), allocatable :: r0n2(:), rmn2(:)
|
|
|
|
|
real(psb_dpk_), allocatable :: errnum(:), errden(:)
|
|
|
|
|
real(psb_dpk_) :: deps, derr
|
|
|
|
|
character(len=20) :: name
|
|
|
|
|
character(len=*), parameter :: methdname='BGMRES'
|
|
|
|
|
|
|
|
|
@ -112,10 +113,10 @@ subroutine psb_dbgmres_multivect(a, prec, b, x, eps, desc_a, info, itmax, iter,
|
|
|
|
|
if (present(istop)) then
|
|
|
|
|
istop_ = istop
|
|
|
|
|
else
|
|
|
|
|
istop_ = 2
|
|
|
|
|
istop_ = 1
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
if ((istop_ < 1 ).or.(istop_ > 2 ) ) then
|
|
|
|
|
if (istop_ /= 1) then
|
|
|
|
|
info=psb_err_invalid_istop_
|
|
|
|
|
err=info
|
|
|
|
|
call psb_errpush(info,name,i_err=(/istop_/))
|
|
|
|
@ -167,13 +168,17 @@ subroutine psb_dbgmres_multivect(a, prec, b, x, eps, desc_a, info, itmax, iter,
|
|
|
|
|
|
|
|
|
|
naux = 4*n_col
|
|
|
|
|
nrhs = x%get_ncols()
|
|
|
|
|
allocate(aux(naux),h((nrep+1)*nrhs,nrep*nrhs),stat=info)
|
|
|
|
|
allocate(aux(naux),h((nrep+1)*nrhs,nrep*nrhs),y(nrep*nrhs,nrhs),&
|
|
|
|
|
& vt(n_row,(nrep+1)*nrhs),r0n2(nrhs),rmn2(nrhs),&
|
|
|
|
|
& errnum(nrhs),errden(nrhs),stat=info)
|
|
|
|
|
if (info == psb_success_) call psb_geall(v,desc_a,info,m=nrep+1,n=nrhs)
|
|
|
|
|
if (info == psb_success_) call psb_geall(v_tot,desc_a,info,n=nrep*nrhs)
|
|
|
|
|
if (info == psb_success_) call psb_geall(w,desc_a,info,n=nrhs)
|
|
|
|
|
if (info == psb_success_) call psb_geall(xt,desc_a,info,n=nrhs)
|
|
|
|
|
if (info == psb_success_) call psb_geall(r,desc_a,info,n=nrhs)
|
|
|
|
|
if (info == psb_success_) call psb_geasb(v,desc_a,info,mold=x%v,n=nrhs)
|
|
|
|
|
if (info == psb_success_) call psb_geasb(v_tot,desc_a,info,mold=x%v,n=nrep*nrhs)
|
|
|
|
|
if (info == psb_success_) call psb_geasb(w,desc_a,info,mold=x%v,n=nrhs)
|
|
|
|
|
if (info == psb_success_) call psb_geasb(xt,desc_a,info,mold=x%v,n=nrhs)
|
|
|
|
|
if (info == psb_success_) call psb_geasb(r,desc_a,info,mold=x%v,n=nrhs)
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
|
call psb_errpush(info,name)
|
|
|
|
@ -185,11 +190,21 @@ subroutine psb_dbgmres_multivect(a, prec, b, x, eps, desc_a, info, itmax, iter,
|
|
|
|
|
& ' Size of V,W ',v(1)%get_nrows(),size(v),&
|
|
|
|
|
& w%get_nrows()
|
|
|
|
|
|
|
|
|
|
! Compute norm2 of R(0)
|
|
|
|
|
if (istop_ == 1) then
|
|
|
|
|
ani = psb_spnrmi(a,desc_a,info)
|
|
|
|
|
bni = psb_geamax(b,desc_a,info)
|
|
|
|
|
else if (istop_ == 2) then
|
|
|
|
|
bn2 = psb_genrm2(b,desc_a,info)
|
|
|
|
|
call psb_geaxpby(done,b,dzero,r,desc_a,info)
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
|
call psb_errpush(info,name)
|
|
|
|
|
goto 9999
|
|
|
|
|
end if
|
|
|
|
|
call psb_spmm(-done,a,x,done,r,desc_a,info,work=aux)
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
|
call psb_errpush(info,name)
|
|
|
|
|
goto 9999
|
|
|
|
|
end if
|
|
|
|
|
r0n2 = psb_genrm2(r,desc_a,info)
|
|
|
|
|
endif
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
@ -198,6 +213,7 @@ subroutine psb_dbgmres_multivect(a, prec, b, x, eps, desc_a, info, itmax, iter,
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
h = dzero
|
|
|
|
|
y = dzero
|
|
|
|
|
errnum = dzero
|
|
|
|
|
errden = done
|
|
|
|
|
deps = eps
|
|
|
|
@ -208,8 +224,10 @@ subroutine psb_dbgmres_multivect(a, prec, b, x, eps, desc_a, info, itmax, iter,
|
|
|
|
|
|
|
|
|
|
! BGMRES algorithm
|
|
|
|
|
|
|
|
|
|
! TODO QR fact seriale per ora
|
|
|
|
|
! TODO Con tanti ITRS NaN (forse genera righe dipendenti (vedere pargen))
|
|
|
|
|
! TODO Con tanti ITRS e tanti NRHS si ottengono NaN
|
|
|
|
|
! TODO Deflazione e restart dopo aver trovato una colonna, difficile...
|
|
|
|
|
|
|
|
|
|
! TODO L'algo converge abbastanza bene. Capire come fare check residui
|
|
|
|
|
|
|
|
|
|
! STEP 1: Compute R(0) = B - A*X(0)
|
|
|
|
|
|
|
|
|
@ -237,31 +255,15 @@ subroutine psb_dbgmres_multivect(a, prec, b, x, eps, desc_a, info, itmax, iter,
|
|
|
|
|
goto 9999
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
! Add V(1) to VT
|
|
|
|
|
vt(:,1:nrhs) = v(1)%get_vect()
|
|
|
|
|
|
|
|
|
|
! STEP 3: Outer loop
|
|
|
|
|
outer: do j=1,nrep
|
|
|
|
|
|
|
|
|
|
! TODO Check convergence
|
|
|
|
|
! if (istop_ == 1) then
|
|
|
|
|
! rni = psb_geamax(v(1),desc_a,info)
|
|
|
|
|
! xni = psb_geamax(x,desc_a,info)
|
|
|
|
|
! errnum = rni
|
|
|
|
|
! errden = (ani*xni+bni)
|
|
|
|
|
! else if (istop_ == 2) then
|
|
|
|
|
! rni = psb_genrm2(v(1),desc_a,info)
|
|
|
|
|
! errnum = rni
|
|
|
|
|
! errden = bn2
|
|
|
|
|
! endif
|
|
|
|
|
! if (info /= psb_success_) then
|
|
|
|
|
! info=psb_err_from_subroutine_non_
|
|
|
|
|
! call psb_errpush(info,name)
|
|
|
|
|
! goto 9999
|
|
|
|
|
! end if
|
|
|
|
|
|
|
|
|
|
! if (errnum <= eps*errden) exit outer
|
|
|
|
|
|
|
|
|
|
! if (itrace_ > 0) call log_conv(methdname,me,itx,itrace_,errnum,errden,deps)
|
|
|
|
|
|
|
|
|
|
! Update itx counter
|
|
|
|
|
itx = itx + 1
|
|
|
|
|
if (itx >= litmax) exit outer
|
|
|
|
|
|
|
|
|
|
! Compute j index for H operations
|
|
|
|
|
idx_j = (j-1)*nrhs+1
|
|
|
|
@ -274,15 +276,13 @@ subroutine psb_dbgmres_multivect(a, prec, b, x, eps, desc_a, info, itmax, iter,
|
|
|
|
|
goto 9999
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
if (itx >= litmax) exit outer
|
|
|
|
|
|
|
|
|
|
! STEP 5: Inner loop
|
|
|
|
|
inner: do i=1,j
|
|
|
|
|
|
|
|
|
|
! Compute i index for H operations
|
|
|
|
|
idx_i = (i-1)*nrhs+1
|
|
|
|
|
|
|
|
|
|
! STEP 6: Compute H(i,j) = V(i)_T*W
|
|
|
|
|
! STEP 6: Compute H(i,j) = (V(i)**T)*W
|
|
|
|
|
h(idx_i:idx_i+n_add,idx_j:idx_j+n_add) = psb_geprod(v(i),w,desc_a,info,trans=.true.)
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
@ -292,8 +292,8 @@ subroutine psb_dbgmres_multivect(a, prec, b, x, eps, desc_a, info, itmax, iter,
|
|
|
|
|
|
|
|
|
|
! STEP 7: Compute W = W - V(i)*H(i,j)
|
|
|
|
|
call psb_geaxpby(-done,&
|
|
|
|
|
& psb_geprod(v(i),h(idx_i:idx_i+n_add,idx_j:idx_j+n_add),desc_a,info,global=.false.),&
|
|
|
|
|
& done,w,desc_a,info)
|
|
|
|
|
& psb_geprod(v(i),h(idx_i:idx_i+n_add,idx_j:idx_j+n_add),desc_a,info,global=.false.),&
|
|
|
|
|
& done,w,desc_a,info)
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
|
call psb_errpush(info,name)
|
|
|
|
@ -320,41 +320,154 @@ subroutine psb_dbgmres_multivect(a, prec, b, x, eps, desc_a, info, itmax, iter,
|
|
|
|
|
goto 9999
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
end do outer
|
|
|
|
|
! Add V(j+1) to VT
|
|
|
|
|
idx = j*nrhs+1
|
|
|
|
|
vt(:,idx:idx+n_add) = v(j+1)%get_vect()
|
|
|
|
|
|
|
|
|
|
! STEP 9: Compute Y(m)
|
|
|
|
|
call frobenius_norm_min()
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
|
call psb_errpush(info,name)
|
|
|
|
|
goto 9999
|
|
|
|
|
end if
|
|
|
|
|
! STEP 9: Compute Y(j)
|
|
|
|
|
call frobenius_norm_min(j)
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
|
call psb_errpush(info,name)
|
|
|
|
|
goto 9999
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
! STEP 10: Compute V = {V(1),...,V(m)}
|
|
|
|
|
do i=1,nrep
|
|
|
|
|
idx = (i-1)*nrhs+1
|
|
|
|
|
v_tot%v%v(1:n_row,idx:idx+n_add) = v(i)%v%v(1:n_row,1:nrhs)
|
|
|
|
|
enddo
|
|
|
|
|
! Compute residues
|
|
|
|
|
if (istop_ == 1) then
|
|
|
|
|
|
|
|
|
|
! STEP 11: X(m) = X(0) + V*Y(m)
|
|
|
|
|
call psb_geaxpby(done,psb_geprod(v_tot,beta_e1,desc_a,info,global=.false.),done,x,desc_a,info)
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
|
call psb_errpush(info,name)
|
|
|
|
|
goto 9999
|
|
|
|
|
end if
|
|
|
|
|
! TODO Compute R(j) = R(0) - VT(j+1)*H(j)*Y(j)
|
|
|
|
|
call psb_geaxpby(-done,psb_geprod(psb_geprod(vt(:,1:(j+1)*nrhs),h(1:(j+1)*nrhs,1:j*nrhs),&
|
|
|
|
|
& desc_a,info,global=.false.),&
|
|
|
|
|
& y(1:j*nrhs,1:nrhs),desc_a,info,global=.false.),done,r,desc_a,info)
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
|
call psb_errpush(info,name)
|
|
|
|
|
goto 9999
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
write(*,*)
|
|
|
|
|
do col=1,r%get_nrows()
|
|
|
|
|
write(*,*) r%v%v(col,:)
|
|
|
|
|
end do
|
|
|
|
|
write(*,*)
|
|
|
|
|
|
|
|
|
|
! TODO Calcolo soluzione al passo J e vedo i residui (se minore esco dal ciclo)
|
|
|
|
|
! TODO Compute R(j) = B - A*X(j)
|
|
|
|
|
|
|
|
|
|
! Copy X in XT
|
|
|
|
|
call psb_geaxpby(done,x,dzero,xt,desc_a,info)
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
|
call psb_errpush(info,name)
|
|
|
|
|
goto 9999
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
! Compute current solution X(j) = X(0) + VT(j)*Y(j)
|
|
|
|
|
call psb_geaxpby(done,psb_geprod(vt(:,1:j*nrhs),y(1:j*nrhs,:),desc_a,info,global=.false.),done,xt,desc_a,info)
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
|
call psb_errpush(info,name)
|
|
|
|
|
goto 9999
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
! Copy B in R
|
|
|
|
|
call psb_geaxpby(done,b,dzero,r,desc_a,info)
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
|
call psb_errpush(info,name)
|
|
|
|
|
goto 9999
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
! Compute R(j) = B - A*X(j)
|
|
|
|
|
call psb_spmm(-done,a,xt,done,r,desc_a,info,work=aux)
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
|
call psb_errpush(info,name)
|
|
|
|
|
goto 9999
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
write(*,*)
|
|
|
|
|
do col=1,r%get_nrows()
|
|
|
|
|
write(*,*) r%v%v(col,:)
|
|
|
|
|
end do
|
|
|
|
|
write(*,*)
|
|
|
|
|
|
|
|
|
|
! Compute nrm2 of each column of R(j)
|
|
|
|
|
rmn2 = psb_genrm2(r,desc_a,info)
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
|
call psb_errpush(info,name)
|
|
|
|
|
goto 9999
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
! Set error num and den
|
|
|
|
|
errnum = rmn2
|
|
|
|
|
errden = r0n2
|
|
|
|
|
|
|
|
|
|
! TODO Ogni entrata della norma2 di R(m) deve essere più piccola di tolleranza*nrm2(r0)
|
|
|
|
|
do col=1,nrhs
|
|
|
|
|
write(*,*) rmn2(col), r0n2(col)
|
|
|
|
|
end do
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
! TODO Norma dei residui con Xm devono essere minori di tolleranza * nrm2(R0)?
|
|
|
|
|
! Check convergence
|
|
|
|
|
if (maxval(errnum) <= eps*maxval(errden)) then
|
|
|
|
|
|
|
|
|
|
! Compute result and exit
|
|
|
|
|
if (istop_ == 1) then
|
|
|
|
|
|
|
|
|
|
! Compute X(j) = X(0) + VT(j)*Y(j)
|
|
|
|
|
! call psb_geaxpby(done,psb_geprod(vt(:,1:j*nrhs),y(1:j*nrhs,:),desc_a,info,global=.false.),done,x,desc_a,info)
|
|
|
|
|
! if (info /= psb_success_) then
|
|
|
|
|
! info=psb_err_from_subroutine_non_
|
|
|
|
|
! call psb_errpush(info,name)
|
|
|
|
|
! goto 9999
|
|
|
|
|
! end if
|
|
|
|
|
|
|
|
|
|
! Copy current solution XT in X
|
|
|
|
|
call psb_geaxpby(done,xt,dzero,x,desc_a,info)
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
|
call psb_errpush(info,name)
|
|
|
|
|
goto 9999
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
! Exit algorithm
|
|
|
|
|
exit outer
|
|
|
|
|
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
! Log update
|
|
|
|
|
if (itrace_ > 0) call log_conv(methdname,me,itx,ione,maxval(errnum),maxval(errden),deps)
|
|
|
|
|
|
|
|
|
|
end do outer
|
|
|
|
|
|
|
|
|
|
! STEP 10: X(m) = X(0) + VT(m)*Y(m)
|
|
|
|
|
! call psb_geaxpby(done,psb_geprod(vt(:,1:nrep*nrhs),y,desc_a,info,global=.false.),done,x,desc_a,info)
|
|
|
|
|
! if (info /= psb_success_) then
|
|
|
|
|
! info=psb_err_from_subroutine_non_
|
|
|
|
|
! call psb_errpush(info,name)
|
|
|
|
|
! goto 9999
|
|
|
|
|
! end if
|
|
|
|
|
|
|
|
|
|
! END algorithm
|
|
|
|
|
|
|
|
|
|
if (itrace_ > 0) call log_conv(methdname,me,itx,ione,errnum,errden,deps)
|
|
|
|
|
! TODO log_conv passa scalari errnum,errden,deps (servono vettori)
|
|
|
|
|
! TODO Inizialmente versione verbosa che stampa errore per tutte le colonne
|
|
|
|
|
! TODO Versione finale che stampa errore massimo (si può usare log_conv con questo)
|
|
|
|
|
if (itrace_ > 0) call log_conv(methdname,me,itx,ione,maxval(errnum),maxval(errden),deps)
|
|
|
|
|
|
|
|
|
|
call log_end(methdname,me,itx,itrace_,errnum,errden,deps,err=derr,iter=iter)
|
|
|
|
|
call log_end(methdname,me,itx,itrace_,maxval(errnum),maxval(errden),deps,err=derr,iter=iter)
|
|
|
|
|
if (present(err)) err = derr
|
|
|
|
|
|
|
|
|
|
if (info == psb_success_) call psb_gefree(v,desc_a,info)
|
|
|
|
|
if (info == psb_success_) call psb_gefree(v_tot,desc_a,info)
|
|
|
|
|
if (info == psb_success_) call psb_gefree(w,desc_a,info)
|
|
|
|
|
if (info == psb_success_) deallocate(aux,h,stat=info)
|
|
|
|
|
if (info == psb_success_) call psb_gefree(xt,desc_a,info)
|
|
|
|
|
if (info == psb_success_) call psb_gefree(r,desc_a,info)
|
|
|
|
|
if (info == psb_success_) deallocate(aux,h,y,vt,stat=info)
|
|
|
|
|
if (info /= psb_success_) then
|
|
|
|
|
info=psb_err_from_subroutine_non_
|
|
|
|
|
call psb_errpush(info,name)
|
|
|
|
@ -370,36 +483,39 @@ subroutine psb_dbgmres_multivect(a, prec, b, x, eps, desc_a, info, itmax, iter,
|
|
|
|
|
contains
|
|
|
|
|
|
|
|
|
|
! Minimize Frobenius norm
|
|
|
|
|
subroutine frobenius_norm_min()
|
|
|
|
|
subroutine frobenius_norm_min(rep)
|
|
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
|
|
integer(psb_ipk_), intent(in) :: rep
|
|
|
|
|
|
|
|
|
|
integer(psb_ipk_) :: lwork
|
|
|
|
|
real(psb_dpk_), allocatable :: work(:), beta_temp(:,:)
|
|
|
|
|
real(psb_dpk_), allocatable :: work(:), beta_e1(:,:)
|
|
|
|
|
|
|
|
|
|
integer(psb_ipk_) :: m_h, n_h, mn
|
|
|
|
|
real(psb_dpk_), allocatable :: h_temp(:,:)
|
|
|
|
|
integer(psb_ipk_) :: m_h, n_h, mn
|
|
|
|
|
|
|
|
|
|
! Initialize params
|
|
|
|
|
m_h = (nrep+1)*nrhs
|
|
|
|
|
n_h = nrep*nrhs
|
|
|
|
|
mn = min(m_h,n_h)
|
|
|
|
|
lwork = max(1,mn+max(mn,nrhs))
|
|
|
|
|
h_temp = h
|
|
|
|
|
m_h = (rep+1)*nrhs
|
|
|
|
|
n_h = rep*nrhs
|
|
|
|
|
mn = min(m_h,n_h)
|
|
|
|
|
lwork = max(1,mn+max(mn,nrhs))
|
|
|
|
|
allocate(work(lwork))
|
|
|
|
|
|
|
|
|
|
! Compute E1*beta
|
|
|
|
|
allocate(beta_temp(m_h,nrhs))
|
|
|
|
|
beta_temp = dzero
|
|
|
|
|
beta_temp(1:nrhs,1:nrhs) = beta
|
|
|
|
|
allocate(beta_e1(m_h,nrhs))
|
|
|
|
|
beta_e1 = dzero
|
|
|
|
|
beta_e1(1:nrhs,1:nrhs) = beta
|
|
|
|
|
|
|
|
|
|
! Compute min Frobenius norm
|
|
|
|
|
call dgels('N',m_h,n_h,nrhs,h,m_h,beta_temp,m_h,work,lwork,info)
|
|
|
|
|
call dgels('N',m_h,n_h,nrhs,h_temp(1:m_h,1:n_h),m_h,beta_e1,m_h,work,lwork,info)
|
|
|
|
|
|
|
|
|
|
! Set solution
|
|
|
|
|
allocate(beta_e1(n_h,nrhs))
|
|
|
|
|
beta_e1 = beta_temp(1:n_h,1:nrhs)
|
|
|
|
|
y = beta_e1(1:n_h,1:nrhs)
|
|
|
|
|
|
|
|
|
|
! Deallocate
|
|
|
|
|
deallocate(work,beta,beta_temp)
|
|
|
|
|
deallocate(work,h_temp,beta_e1)
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|