Skip to content

Commit 3936d5f

Browse files
committed
Improved prepare util
1 parent da0cf6a commit 3936d5f

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/prepare_utils.f90

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ subroutine allocate_array()
4949

5050
! Local variable
5151
integer :: kmax_max
52+
integer(kind=8) :: bytes
53+
real(8) :: gigabytes
54+
character(len=256) :: msg
5255

5356
allocate(saved%offset(3, nmax%atoms_per_residue))
5457
allocate(saved%com(3))
@@ -58,39 +61,50 @@ subroutine allocate_array()
5861
allocate(ewald%Ak(1:ewald%param%nkvec))
5962
allocate(ewald%Ak_old(1:ewald%param%nkvec))
6063
allocate(ewald%form_factor(ewald%param%nkvec)) ! Note, there is no need for such as large vector
61-
ewald%kweights = zero
62-
ewald%Ak = zero
63-
ewald%Ak_old = zero
64-
ewald%form_factor = zero
6564

6665
! Allocate complex arrays for wave vector components
6766
kmax_max = maxval(ewald%param%kmax)
6867
allocate(ewald%phase%factor(3, res%number, 0:NB_MAX_MOLECULE, 1:nmax%atoms_per_residue, -kmax_max:kmax_max)) ! TOFIX, do not use NB_MAX_MOLECULE systematical ?
6968
allocate(ewald%phase%factor_old(3, 1:nmax%atoms_per_residue, -kmax_max:kmax_max))
70-
ewald%phase%factor = zero
71-
ewald%phase%factor_old = zero
69+
70+
bytes = size(ewald%phase%factor, kind=8) * storage_size(ewald%phase%factor) / 8
71+
gigabytes = real(bytes, kind=8) / (1024.0d0**3)
72+
73+
if (gigabytes > 1.0d0) then
74+
write(msg,'(A,I0,A,F6.2,A)') "Large allocation detected: ", bytes, " bytes (", gigabytes, " GB)"
75+
call warn_user(trim(msg))
76+
end if
7277

7378
! Allocate temporary arrays once
7479
allocate(ewald%phase%axis(-kmax_max:kmax_max))
7580
allocate(ewald%phase%new(nmax%atoms_per_residue))
7681
allocate(ewald%phase%old(nmax%atoms_per_residue))
7782
allocate(ewald%q_buffer(nmax%atoms_per_residue))
83+
84+
! Allocate kvectors
85+
allocate(ewald%kvectors(ewald%param%nkvec))
86+
87+
! Initialize to zero
88+
ewald%kweights = zero
89+
ewald%Ak = zero
90+
ewald%Ak_old = zero
91+
ewald%form_factor = zero
92+
ewald%phase%factor = zero
93+
ewald%phase%factor_old = zero
7894
ewald%phase%axis = zero
7995
ewald%phase%new = zero
8096
ewald%phase%old = zero
8197
ewald%q_buffer = zero
8298

83-
! Allocate kvectors
84-
allocate(ewald%kvectors(ewald%param%nkvec))
85-
8699
! Allocate widom
87100
if (proba%widom > 0) then
88101
allocate(statistic%weight(res%number))
89102
allocate(statistic%sample(res%number))
90103
allocate(statistic%mu_ex(res%number))
91104
allocate(statistic%mu_tot(res%number))
92-
statistic%weight(:) = 0
93-
statistic%sample(:) = 0
105+
! Initialize to zero
106+
statistic%weight(:) = zero
107+
statistic%sample(:) = zero
94108
end if
95109

96110
end subroutine allocate_array

0 commit comments

Comments
 (0)