!> 内存报告 module spx_memory use spx_kinds, only: rk use spx_pif_h5part, only: pif_obj use spx_logger, only: lgr_obj use fffc_module, only: terminal_obj, display use spx_math, only: dim use spx_nnps_pairs, only: nnps_grid implicit none private public :: mem_obj !> 内存报告 type memory_type integer :: region !! 粒子域内存, MBytes integer :: nnps !! 近邻搜索结构内存, MBytes integer :: total !! 总内存, MBytes integer :: maxpairs = 0 !! 最大近邻对数 contains procedure :: report, init, check end type memory_type type(memory_type) :: mem_obj !! 内存报告对象 contains !> 初始化 subroutine init(self) class(memory_type), intent(inout) :: self self%region = pif_obj%numbers(4)*14*rk/1000000 ! self%nnps = storage_size(nnps_grid%grids)/8*size(nnps_grid%grids)/mb ! self%total = self%region + self%nnps end subroutine init !> 报告 subroutine report(self) class(memory_type), intent(in) :: self call terminal_obj%info('post-report') call display(self%maxpairs, 'max pairs:', inline=.true.) call display(self%region, 'memory usage by region (MB):', inline=.true.) ! call display(self%nnps, 'memory_type usage by nnps (MB):', inline=.true.) ! call display(self%total, 'total memory_type usage (MB, approximate):', inline=.true.) end subroutine report !> 检查是否粒子发生坍塌聚集 subroutine check(self, pairs, particles) class(memory_type), intent(inout) :: self integer, intent(in) :: pairs, particles if (pairs > self%maxpairs) then self%maxpairs = pairs if (pairs/particles > dim*8) then call terminal_obj%error('too many pairs, please check the model') end if end if end subroutine check end module spx_memory