Skip to content

Commit 49238a8

Browse files
SorBaldaclaude
andcommitted
memopt(safe): drop dead zz/vv/ww arrays and iden in get_odd_straight_with_v4
Bitwise-identical memory optimization of get_odd_straight_with_v4. - Remove zz(nl,nl), vv(nl*(nl+1)/2) and ww(nl): declared and allocated but never read/written anywhere in the subroutine (verified by grep on the v1.5 source). They were also never deallocated -> a memory leak. zz alone is one full nl x nl array (= 1 "v4 unit"). - Remove the iden(nl,nl) scratch matrix. Instead of building iden and copying "maux = iden", initialize maux directly: maux = 0.0d0 ; do x=1,nl: maux(x,x)=1.0d0 Same value, same bit pattern; saves one nl x nl allocation. No BLAS call, no operation order, no numerics changed. Standalone Fortran test (n_mode=6, symmetrized v3/v4): max|phi_new-phi_orig| = 0.0 exactly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 084c1b2 commit 49238a8

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

SCHAModules/get_odd_straight_with_v4.f90

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ subroutine get_odd_straight_with_v4 ( a, wr, er, transmode, amass, ityp_sc, T, v
2020

2121

2222
integer :: nat_sc, n_mode, nl, ns, ntyp
23-
double precision, dimension(:,:), allocatable :: l, g, phi_aux, v1, v2, v32, iden
23+
double precision, dimension(:,:), allocatable :: l, g, phi_aux, v1, v2, v32
2424
double precision :: lsum
2525
double precision, dimension(:), allocatable :: laux1, lres1, veclong
2626
double precision, dimension(:), allocatable :: laux2, lres2
@@ -30,9 +30,6 @@ subroutine get_odd_straight_with_v4 ( a, wr, er, transmode, amass, ityp_sc, T, v
3030
integer, dimension(:), allocatable :: ipiv
3131
integer :: info
3232

33-
double precision, dimension(:), allocatable :: vv
34-
double precision, dimension(:), allocatable :: ww
35-
double precision, dimension(:,:), allocatable :: zz
3633
double precision, dimension(:,:), allocatable :: cf
3734

3835
integer :: mu, nu, alpha
@@ -67,15 +64,10 @@ subroutine get_odd_straight_with_v4 ( a, wr, er, transmode, amass, ityp_sc, T, v
6764
allocate(ipiv(nl))
6865
allocate(work(nl))
6966
allocate(v32(n_mode,n_mode*n_mode))
70-
allocate(iden(nl,nl))
7167

7268
allocate(cf(nl,ns))
7369

74-
allocate(vv(nl*(nl+1)/2))
75-
allocate(ww(nl))
76-
allocate(zz(nl,nl))
77-
78-
! Get lambda matrix
70+
! Get lambda matrix
7971

8072
call get_cmat ( a, wr, er, transmode, amass, ityp_sc, T, .true., lamat,n_mode, nat_sc, ntyp )
8173

@@ -100,21 +92,20 @@ subroutine get_odd_straight_with_v4 ( a, wr, er, transmode, amass, ityp_sc, T, v
10092
end do
10193
end do
10294

103-
! Prepare identity matrix
95+
! Prepare identity matrix directly in maux (was: iden then maux = iden;
96+
! bitwise identical, avoids one nl x nl temporary)
10497

105-
iden = 0.0d0
98+
maux = 0.0d0
10699

107100
do x = 1, nl
108-
iden(x,x) = 1.0d0
101+
maux(x,x) = 1.0d0
109102
end do
110103

111104
! Calculate ** iden - v4 lamat ** matrix
112105

113106
!print *, "BEFORE I - V4Lambda"
114107
!call flush()
115108

116-
maux = iden
117-
118109
call dgemm('N','N',nl,nl,nl,-1.0d0,v42,nl,lamat,nl,1.0d0,maux,nl)
119110

120111
! Invert ** iden - lamat v4 **

0 commit comments

Comments
 (0)