Skip to content

Commit

Permalink
Fix uninitialized variable in LBFGS (dftbplus#1525)
Browse files Browse the repository at this point in the history
* Fix uninitialized variable in LBFGS

Additionally macro used for debugging added.
  • Loading branch information
aradi authored Aug 28, 2024
1 parent 3f8a8d1 commit 376642a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/dftbp/geoopt/lbfgs.F90
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,10 @@ subroutine TLineSearch_getOptimalStep(this, phi, dphi, dx, xNew, tConverged)
!> Whether line minimisation converged
logical, intent(out) :: tConverged

tConverged = .false.
xNew(:) = 0.0_dp
this%tZoom = .false.

if (this%iter == 0) then
this%phi0 = phi
this%dx0(:) = dx
Expand Down Expand Up @@ -817,6 +821,8 @@ subroutine TLineSearch_zoom(this, phi, dphi, dx, xNew, tConverged)

real(dp) :: cCheck, qCheck, dAlpha

tConverged = .false.

if (this%iter > this%mIter) then
if (abs(this%alphaLo * maxval(this%d0)) < this%minAlpha) then
if (abs(this%alphaNew * maxval(this%d0)) < this%minAlpha) then
Expand Down Expand Up @@ -903,7 +909,7 @@ subroutine TLineSearch_zoom(this, phi, dphi, dx, xNew, tConverged)
end if

this%xNew = this%x0 + this%alphaNew * this%d0
xNew = this%xNew
xNew(:) = this%xNew

end subroutine TLineSearch_zoom

Expand Down
10 changes: 10 additions & 0 deletions src/dftbp/include/common.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,15 @@ block
end block
#:enddef


#! Simple macro to print (with flushing) to a unit
#:def PRINT_ITEMS(format, *items)
block
use iso_fortran_env, only : output_unit
write(output_unit, ${format}$) ${", ".join(items)}$
flush(output_unit)
end block
#:enddef

#:endif
#:endmute

0 comments on commit 376642a

Please sign in to comment.