wstat_memory_report.f90 7.98 KB
Newer Older
Marco Govoni's avatar
Marco Govoni committed
1
!
2
! Copyright (C) 2015-2017 M. Govoni
Marco Govoni's avatar
Marco Govoni committed
3
4
5
6
7
8
9
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
! This file is part of WEST.
!
10
! Contributors to this file:
Marco Govoni's avatar
Marco Govoni committed
11
12
13
14
15
16
! Marco Govoni
!
!-----------------------------------------------------------------------
SUBROUTINE wstat_memory_report()
  !----------------------------------------------------------------------------
  !
17
18
19
20
21
22
23
24
25
26
27
28
29
  USE kinds,               ONLY : DP
  USE io_global,           ONLY : stdout
  USE wvfct,               ONLY : npwx, nbnd
  USE fft_base,            ONLY : dfftp
  USE gvect,               ONLY : ngl
  USE gvecs,               ONLY : ngms
  USE uspp,                ONLY : nkb
  USE control_flags,       ONLY : gamma_only
  USE mp_world,            ONLY : mpime,root
  USE westcom,             ONLY : nbnd_occ,n_pdep_basis,npwqx,logfile
  USE distribution_center, ONLY : pert
  USE noncollin_module,    ONLY : npol
  USE json_module,         ONLY : json_file
Marco Govoni's avatar
Marco Govoni committed
30
31
32
  !
  IMPLICIT NONE
  !
33
  TYPE(json_file) :: json
Marco Govoni's avatar
Marco Govoni committed
34
  INTEGER :: iunit
Marco Govoni's avatar
Marco Govoni committed
35
36
37
38
39
40
41
  INTEGER, PARAMETER :: Mb=1024*1024, complex_size=16, real_size=8
  REAL(DP) :: mem_tot, mem_partial
  !
  WRITE(stdout,'(/,5x,"[MEM] ----------------------------------------------------------")')
  WRITE(stdout,'(5x,"[MEM] **Memory** analysis: QE")')
  WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
  !
42
  IF( mpime == root ) THEN
Marco Govoni's avatar
Marco Govoni committed
43
44
45
     !
     CALL json%initialize()
     CALL json%load_file(filename=TRIM(logfile))
46
     CALL json%add( 'memory.units', 'Mb' )
Marco Govoni's avatar
Marco Govoni committed
47
     !
48
  ENDIF
Marco Govoni's avatar
Marco Govoni committed
49
  !
Marco Govoni's avatar
Marco Govoni committed
50
51
  ! the conversions to double prevent integer overflow in very large run
  !
52
  mem_tot = 0.0_DP
Marco Govoni's avatar
Marco Govoni committed
53
54
55
  WRITE(stdout,'(5x,"[MEM] Allocated arrays      ",5x,"est. size (Mb)", 5x,"dimensions")')
  WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
  !
56
  mem_partial = (1.0_DP/Mb)*complex_size*nbnd*npwx
Marco Govoni's avatar
Marco Govoni committed
57
58
  WRITE( stdout, '(5x,"[MEM] Kohn-Sham Wavefunctions ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
     mem_partial, npwx,nbnd
59
  IF( mpime == root ) CALL json%add( 'memory.evc', mem_partial )
Marco Govoni's avatar
Marco Govoni committed
60
61
  mem_tot = mem_tot + mem_partial
  !
62
  mem_partial = (1.0_DP/Mb)*complex_size*nkb*npwx
Marco Govoni's avatar
Marco Govoni committed
63
64
  WRITE( stdout, '(5x,"[MEM] NL pseudopotentials     ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
     mem_partial, npwx, nkb
65
  IF( mpime == root ) CALL json%add( 'memory.nlpp', mem_partial )
Marco Govoni's avatar
Marco Govoni committed
66
67
  mem_tot = mem_tot + mem_partial
  !
68
  mem_partial = (1.0_DP/Mb)*complex_size*dfftp%nnr
Marco Govoni's avatar
Marco Govoni committed
69
70
  WRITE( stdout, '(5x,"[MEM] Each V/rho on FFT grid  ",f10.2," Mb", 5x,"(",i7,")")') &
     mem_partial, dfftp%nnr
71
  IF( mpime == root ) CALL json%add( 'memory.rhor', mem_partial )
Marco Govoni's avatar
Marco Govoni committed
72
73
  mem_tot = mem_tot + mem_partial
  !
74
  mem_partial = (1.0_DP/Mb)*real_size*ngms
Marco Govoni's avatar
Marco Govoni committed
75
76
  WRITE( stdout, '(5x,"[MEM] Each G-vector array     ",f10.2," Mb", 5x,"(",i7,")")') &
     mem_partial, ngms
77
  IF( mpime == root ) CALL json%add( 'memory.rhog', mem_partial )
Marco Govoni's avatar
Marco Govoni committed
78
79
  mem_tot = mem_tot + mem_partial
  !
80
  mem_partial = (1.0_DP/Mb)*real_size*ngl
Marco Govoni's avatar
Marco Govoni committed
81
82
  WRITE( stdout, '(5x,"[MEM] G-vector shells         ",f10.2," Mb", 5x,"(",i7,")")') &
     mem_partial, ngl
83
  IF( mpime == root ) CALL json%add( 'memory.gshells', mem_partial )
Marco Govoni's avatar
Marco Govoni committed
84
85
86
87
88
89
90
91
92
93
94
  mem_tot = mem_tot + mem_partial
  WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
  WRITE( stdout, '(5x,"[MEM] TOT                     ",f10.2," Mb", 5x)') mem_tot
  WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
  WRITE(stdout,'(5x,"[MEM] ")')
  !
  !
  !
  WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
  WRITE(stdout,'(5x,"[MEM] **Memory** analysis: WSTAT global")')
  WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
95
  mem_tot = 0.0_DP
Marco Govoni's avatar
Marco Govoni committed
96
97
98
  WRITE(stdout,'(5x,"[MEM] Allocated arrays      ",5x,"est. size (Mb)", 5x,"dimensions")')
  WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
  !
99
  mem_partial = (1.0_DP/Mb)*complex_size*npwqx*pert%nlocx
Marco Govoni's avatar
Marco Govoni committed
100
  WRITE( stdout, '(5x,"[MEM] dvg                     ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
101
     mem_partial, npwqx, pert%nlocx
102
  IF( mpime == root ) CALL json%add( 'memory.dvg', mem_partial )
Marco Govoni's avatar
Marco Govoni committed
103
104
  mem_tot = mem_tot + mem_partial
  !
105
  mem_partial = (1.0_DP/Mb)*complex_size*npwqx*pert%nlocx
Marco Govoni's avatar
Marco Govoni committed
106
  WRITE( stdout, '(5x,"[MEM] dng                     ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
107
     mem_partial, npwqx, pert%nlocx
108
  IF( mpime == root ) CALL json%add( 'memory.dng', mem_partial )
Marco Govoni's avatar
Marco Govoni committed
109
110
  mem_tot = mem_tot + mem_partial
  !
111
112
  IF( gamma_only ) THEN
     mem_partial = (1.0_DP/Mb)*real_size*n_pdep_basis*pert%nlocx
Marco Govoni's avatar
Marco Govoni committed
113
  ELSE
114
     mem_partial = (1.0_DP/Mb)*complex_size*n_pdep_basis*pert%nlocx
Marco Govoni's avatar
Marco Govoni committed
115
116
117
  ENDIF
  WRITE( stdout, '(5x,"[MEM] hr_distr                ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
     mem_partial, n_pdep_basis, pert%nlocx
118
119
  IF( mpime == root ) CALL json%add( 'memory.hr_distr', mem_partial )
  mem_tot = mem_tot + mem_partial
Marco Govoni's avatar
Marco Govoni committed
120
  !
121
122
  IF( gamma_only ) THEN
     mem_partial = (1.0_DP/Mb)*real_size*n_pdep_basis*pert%nlocx
Marco Govoni's avatar
Marco Govoni committed
123
  ELSE
124
     mem_partial = (1.0_DP/Mb)*complex_size*n_pdep_basis*pert%nlocx
Marco Govoni's avatar
Marco Govoni committed
125
126
127
  ENDIF
  WRITE( stdout, '(5x,"[MEM] vr_distr                ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
     mem_partial, n_pdep_basis, pert%nlocx
128
129
  IF( mpime == root ) CALL json%add( 'memory.vr_distr', mem_partial )
  mem_tot = mem_tot + mem_partial
Marco Govoni's avatar
Marco Govoni committed
130
131
132
133
134
135
  WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
  WRITE( stdout, '(5x,"[MEM] TOT                     ",f10.2," Mb", 5x)') mem_tot
  WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
  WRITE(stdout,'(5x,"[MEM] ")')
  !
  !
136
  mem_tot = 0.0_DP
Marco Govoni's avatar
Marco Govoni committed
137
138
139
140
141
142
143
  !
  WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
  WRITE(stdout,'(5x,"[MEM] **Memory** analysis: WSTAT temporary")')
  WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
  WRITE(stdout,'(5x,"[MEM] Allocated arrays      ",5x,"est. size (Mb)", 5x,"dimensions")')
  WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
  !
144
  mem_partial = (1.0_DP/Mb)*complex_size*npwx*npol*nbnd_occ(1)
Marco Govoni's avatar
Marco Govoni committed
145
146
  WRITE( stdout, '(5x,"[MEM] dvpsi                   ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
     mem_partial, npwx*npol, nbnd_occ(1)
147
148
  IF( mpime == root ) CALL json%add( 'memory.dvpsi', mem_partial )
  mem_tot = mem_tot + mem_partial
Marco Govoni's avatar
Marco Govoni committed
149
  !
150
  mem_partial = (1.0_DP/Mb)*complex_size*npwx*npol*nbnd_occ(1)
Marco Govoni's avatar
Marco Govoni committed
151
152
  WRITE( stdout, '(5x,"[MEM] dpsi                    ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
     mem_partial, npwx*npol, nbnd_occ(1)
153
  IF( mpime == root ) CALL json%add( 'memory.dpsi', mem_partial )
Marco Govoni's avatar
Marco Govoni committed
154
155
  mem_tot = mem_tot + mem_partial
  !
156
!  mem_partial = (1.0_DP/Mb)*complex_size*dffts%nnr
Marco Govoni's avatar
Marco Govoni committed
157
158
!  WRITE( stdout, '(5x,"[MEM] aux_r                   ",f10.2," Mb", 5x,"(",i7,")")') &
!     mem_partial, dffts%nnr
159
!  mem_tot1 = mem_tot1 + mem_partial
Marco Govoni's avatar
Marco Govoni committed
160
!  !
161
!  mem_partial = (1.0_DP/Mb)*complex_size*npwx
Marco Govoni's avatar
Marco Govoni committed
162
163
!  WRITE( stdout, '(5x,"[MEM] aux_g                   ",f10.2," Mb", 5x,"(",i7,")")') &
!     mem_partial, npwx
164
!  mem_tot1 = mem_tot1 + mem_partial
Marco Govoni's avatar
Marco Govoni committed
165
166
!  !
!  IF(.NOT.gamma_only) THEN
167
!     mem_partial = (1.0_DP/Mb)*complex_size*npwx
Marco Govoni's avatar
Marco Govoni committed
168
169
!     WRITE( stdout, '(5x,"[MEM] dpsic                   ",f10.2," Mb", 5x,"(",i7,")")') &
!        mem_partial, dffts%nnr
170
!     mem_tot1 = mem_tot1 + mem_partial
Marco Govoni's avatar
Marco Govoni committed
171
172
!  ENDIF
!  !
173
!  mem_partial = (1.0_DP/Mb)*complex_size*npwx*pert%nlocx
Marco Govoni's avatar
Marco Govoni committed
174
175
176
177
178
179
180
!  WRITE( stdout, '(5x,"[MEM] dhg                     ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
!     mem_partial, npwx, pert%nlocx
!  mem_tot2 = mem_tot2 + mem_partial
  !
  WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
  WRITE( stdout, '(5x,"[MEM] Total estimate          ",f10.2," Mb", 5x)') mem_tot
  WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
181
  WRITE(stdout,*)
Marco Govoni's avatar
Marco Govoni committed
182
  !
183
  IF( mpime == root ) THEN
Marco Govoni's avatar
Marco Govoni committed
184
185
186
187
188
189
     !
     OPEN( NEWUNIT=iunit,FILE=TRIM(logfile) )
     CALL json%print_file( iunit )
     CLOSE( iunit )
     CALL json%destroy()
     !
190
  ENDIF
Marco Govoni's avatar
Marco Govoni committed
191
  !
Marco Govoni's avatar
Marco Govoni committed
192
END SUBROUTINE