Commit 83340393 authored by Victor Yu's avatar Victor Yu
Browse files

Avoid overflow in wstat_memory_report

Memory was computed as `dim1 * dim2 * ... / MB`. In a large calculation
`dim1 * dim2 * ...` can easily overflow. To avoid overflow, now we do
`1.0 / MB * dim1 * dim2 * ...`.
parent ac576911
!
! Copyright (C) 2015-2017 M. Govoni
! Copyright (C) 2015-2017 M. Govoni
! 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,
......@@ -7,32 +7,30 @@
!
! This file is part of WEST.
!
! Contributors to this file:
! Contributors to this file:
! Marco Govoni
!
!-----------------------------------------------------------------------
SUBROUTINE wstat_memory_report()
!----------------------------------------------------------------------------
!
USE kinds, ONLY : DP
USE io_global, ONLY : stdout
USE wvfct, ONLY : npwx, nbnd, nbndx
USE basis, ONLY : natomwfc
USE fft_base, ONLY : dfftp,dffts
USE gvect, ONLY : ngl, ngm, ngm_g
USE gvecs, ONLY : ngms_g, ngms
USE uspp, ONLY : nkb
USE control_flags, ONLY : isolve, nmix, gamma_only, lscf
USE mp_global, ONLY : np_ortho
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 : noncolin,npol
USE json_module, ONLY : json_file
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
!
IMPLICIT NONE
!
TYPE(json_file) :: json
TYPE(json_file) :: json
INTEGER :: iunit
INTEGER, PARAMETER :: Mb=1024*1024, complex_size=16, real_size=8
REAL(DP) :: mem_tot, mem_partial
......@@ -41,48 +39,48 @@ SUBROUTINE wstat_memory_report()
WRITE(stdout,'(5x,"[MEM] **Memory** analysis: QE")')
WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
!
IF( mpime == root ) THEN
IF( mpime == root ) THEN
!
CALL json%initialize()
CALL json%load_file(filename=TRIM(logfile))
CALL json%add( 'memory.units', 'Mb' )
CALL json%add( 'memory.units', 'Mb' )
!
ENDIF
ENDIF
!
! the conversions to double prevent integer overflow in very large run
!
mem_tot = 0._DP
mem_tot = 0.0_DP
WRITE(stdout,'(5x,"[MEM] Allocated arrays ",5x,"est. size (Mb)", 5x,"dimensions")')
WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
!
mem_partial = DBLE(complex_size*nbnd*npwx)/DBLE(Mb)
mem_partial = (1.0_DP/Mb)*complex_size*nbnd*npwx
WRITE( stdout, '(5x,"[MEM] Kohn-Sham Wavefunctions ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
mem_partial, npwx,nbnd
IF( mpime == root ) CALL json%add( 'memory.evc', mem_partial )
IF( mpime == root ) CALL json%add( 'memory.evc', mem_partial )
mem_tot = mem_tot + mem_partial
!
mem_partial = DBLE(complex_size*nkb*npwx)/DBLE(Mb)
mem_partial = (1.0_DP/Mb)*complex_size*nkb*npwx
WRITE( stdout, '(5x,"[MEM] NL pseudopotentials ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
mem_partial, npwx, nkb
IF( mpime == root ) CALL json%add( 'memory.nlpp', mem_partial )
IF( mpime == root ) CALL json%add( 'memory.nlpp', mem_partial )
mem_tot = mem_tot + mem_partial
!
mem_partial = DBLE(complex_size*dfftp%nnr)/DBLE(Mb)
mem_partial = (1.0_DP/Mb)*complex_size*dfftp%nnr
WRITE( stdout, '(5x,"[MEM] Each V/rho on FFT grid ",f10.2," Mb", 5x,"(",i7,")")') &
mem_partial, dfftp%nnr
IF( mpime == root ) CALL json%add( 'memory.rhor', mem_partial )
IF( mpime == root ) CALL json%add( 'memory.rhor', mem_partial )
mem_tot = mem_tot + mem_partial
!
mem_partial = DBLE(real_size*ngms)/DBLE(Mb)
mem_partial = (1.0_DP/Mb)*real_size*ngms
WRITE( stdout, '(5x,"[MEM] Each G-vector array ",f10.2," Mb", 5x,"(",i7,")")') &
mem_partial, ngms
IF( mpime == root ) CALL json%add( 'memory.rhog', mem_partial )
IF( mpime == root ) CALL json%add( 'memory.rhog', mem_partial )
mem_tot = mem_tot + mem_partial
!
mem_partial = DBLE(real_size*ngl)/DBLE(Mb)
mem_partial = (1.0_DP/Mb)*real_size*ngl
WRITE( stdout, '(5x,"[MEM] G-vector shells ",f10.2," Mb", 5x,"(",i7,")")') &
mem_partial, ngl
IF( mpime == root ) CALL json%add( 'memory.gshells', mem_partial )
IF( mpime == root ) CALL json%add( 'memory.gshells', mem_partial )
mem_tot = mem_tot + mem_partial
WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
WRITE( stdout, '(5x,"[MEM] TOT ",f10.2," Mb", 5x)') mem_tot
......@@ -94,48 +92,48 @@ SUBROUTINE wstat_memory_report()
WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
WRITE(stdout,'(5x,"[MEM] **Memory** analysis: WSTAT global")')
WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
mem_tot = 0._DP
mem_tot = 0.0_DP
WRITE(stdout,'(5x,"[MEM] Allocated arrays ",5x,"est. size (Mb)", 5x,"dimensions")')
WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
!
mem_partial = DBLE(complex_size*npwqx*pert%nlocx)/DBLE(Mb)
mem_partial = (1.0_DP/Mb)*complex_size*npwqx*pert%nlocx
WRITE( stdout, '(5x,"[MEM] dvg ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
mem_partial, npwqx, pert%nlocx
IF( mpime == root ) CALL json%add( 'memory.dvg', mem_partial )
IF( mpime == root ) CALL json%add( 'memory.dvg', mem_partial )
mem_tot = mem_tot + mem_partial
!
mem_partial = DBLE(complex_size*npwqx*pert%nlocx)/DBLE(Mb)
mem_partial = (1.0_DP/Mb)*complex_size*npwqx*pert%nlocx
WRITE( stdout, '(5x,"[MEM] dng ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
mem_partial, npwqx, pert%nlocx
IF( mpime == root ) CALL json%add( 'memory.dng', mem_partial )
IF( mpime == root ) CALL json%add( 'memory.dng', mem_partial )
mem_tot = mem_tot + mem_partial
!
IF( gamma_only ) THEN
mem_partial = DBLE(real_size*n_pdep_basis*pert%nlocx)/DBLE(Mb)
IF( gamma_only ) THEN
mem_partial = (1.0_DP/Mb)*real_size*n_pdep_basis*pert%nlocx
ELSE
mem_partial = DBLE(complex_size*n_pdep_basis*pert%nlocx)/DBLE(Mb)
mem_partial = (1.0_DP/Mb)*complex_size*n_pdep_basis*pert%nlocx
ENDIF
WRITE( stdout, '(5x,"[MEM] hr_distr ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
mem_partial, n_pdep_basis, pert%nlocx
IF( mpime == root ) CALL json%add( 'memory.hr_distr', mem_partial )
mem_tot = mem_tot + mem_partial
IF( mpime == root ) CALL json%add( 'memory.hr_distr', mem_partial )
mem_tot = mem_tot + mem_partial
!
IF( gamma_only ) THEN
mem_partial = DBLE(real_size*n_pdep_basis*pert%nlocx)/DBLE(Mb)
IF( gamma_only ) THEN
mem_partial = (1.0_DP/Mb)*real_size*n_pdep_basis*pert%nlocx
ELSE
mem_partial = DBLE(complex_size*n_pdep_basis*pert%nlocx)/DBLE(Mb)
mem_partial = (1.0_DP/Mb)*complex_size*n_pdep_basis*pert%nlocx
ENDIF
WRITE( stdout, '(5x,"[MEM] vr_distr ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
mem_partial, n_pdep_basis, pert%nlocx
IF( mpime == root ) CALL json%add( 'memory.vr_distr', mem_partial )
mem_tot = mem_tot + mem_partial
IF( mpime == root ) CALL json%add( 'memory.vr_distr', mem_partial )
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] ")')
!
!
mem_tot = 0._DP
mem_tot = 0.0_DP
!
WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
WRITE(stdout,'(5x,"[MEM] **Memory** analysis: WSTAT temporary")')
......@@ -143,36 +141,36 @@ SUBROUTINE wstat_memory_report()
WRITE(stdout,'(5x,"[MEM] Allocated arrays ",5x,"est. size (Mb)", 5x,"dimensions")')
WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
!
mem_partial = DBLE(complex_size*npwx*npol*nbnd_occ(1))/DBLE(Mb)
mem_partial = (1.0_DP/Mb)*complex_size*npwx*npol*nbnd_occ(1)
WRITE( stdout, '(5x,"[MEM] dvpsi ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
mem_partial, npwx*npol, nbnd_occ(1)
IF( mpime == root ) CALL json%add( 'memory.dvpsi', mem_partial )
mem_tot = mem_tot + mem_partial
IF( mpime == root ) CALL json%add( 'memory.dvpsi', mem_partial )
mem_tot = mem_tot + mem_partial
!
mem_partial = DBLE(complex_size*npwx*npol*nbnd_occ(1))/DBLE(Mb)
mem_partial = (1.0_DP/Mb)*complex_size*npwx*npol*nbnd_occ(1)
WRITE( stdout, '(5x,"[MEM] dpsi ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
mem_partial, npwx*npol, nbnd_occ(1)
IF( mpime == root ) CALL json%add( 'memory.dpsi', mem_partial )
IF( mpime == root ) CALL json%add( 'memory.dpsi', mem_partial )
mem_tot = mem_tot + mem_partial
!
! mem_partial = DBLE(complex_size*dffts%nnr)/DBLE(Mb)
! mem_partial = (1.0_DP/Mb)*complex_size*dffts%nnr
! WRITE( stdout, '(5x,"[MEM] aux_r ",f10.2," Mb", 5x,"(",i7,")")') &
! mem_partial, dffts%nnr
! mem_tot1 = mem_tot1 + mem_partial
! mem_tot1 = mem_tot1 + mem_partial
! !
! mem_partial = DBLE(complex_size*npwx)/DBLE(Mb)
! mem_partial = (1.0_DP/Mb)*complex_size*npwx
! WRITE( stdout, '(5x,"[MEM] aux_g ",f10.2," Mb", 5x,"(",i7,")")') &
! mem_partial, npwx
! mem_tot1 = mem_tot1 + mem_partial
! mem_tot1 = mem_tot1 + mem_partial
! !
! IF(.NOT.gamma_only) THEN
! mem_partial = DBLE(complex_size*npwx)/DBLE(Mb)
! mem_partial = (1.0_DP/Mb)*complex_size*npwx
! WRITE( stdout, '(5x,"[MEM] dpsic ",f10.2," Mb", 5x,"(",i7,")")') &
! mem_partial, dffts%nnr
! mem_tot1 = mem_tot1 + mem_partial
! mem_tot1 = mem_tot1 + mem_partial
! ENDIF
! !
! mem_partial = DBLE(complex_size*npwx*pert%nlocx)/DBLE(Mb)
! mem_partial = (1.0_DP/Mb)*complex_size*npwx*pert%nlocx
! WRITE( stdout, '(5x,"[MEM] dhg ",f10.2," Mb", 5x,"(",i7,",",i5,")")') &
! mem_partial, npwx, pert%nlocx
! mem_tot2 = mem_tot2 + mem_partial
......@@ -182,13 +180,13 @@ SUBROUTINE wstat_memory_report()
WRITE(stdout,'(5x,"[MEM] ----------------------------------------------------------")')
WRITE(stdout,*)
!
IF( mpime == root ) THEN
IF( mpime == root ) THEN
!
OPEN( NEWUNIT=iunit,FILE=TRIM(logfile) )
CALL json%print_file( iunit )
CLOSE( iunit )
CALL json%destroy()
!
ENDIF
ENDIF
!
END SUBROUTINE
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment