MESH: Add a common workspace to be used in various modules.

This workspace removes the necessity of allocating the local subroutine
arrays. It is allocated once in initialize_mesh() and can be used in any
place of the code. By default, the size of this workspace is controlled
by the block dimensions, the number of variables, and the simulation
dimension, but it can be controlled by a parameter 'workspace_size'.

Additionally, there is a logical flag 'work_in_use' exported from this
module to permit the verification if the workspace is currently in use.

Signed-off-by: Grzegorz Kowal <grzegorz@amuncode.org>
This commit is contained in:
Grzegorz Kowal 2021-11-12 08:07:59 -03:00
parent 58605eb177
commit 024fd4b82f

View File

@ -43,27 +43,36 @@ module mesh
integer , save :: imi, ims, img, imu, ima, imp, imr
#endif /* PROFILE */
! file handler for the mesh statistics
! the handler of the mesh statistics file
!
integer, save :: funit = 11
! flag indicating that the block structure or distribution has changed
! the size of the common workspace
!
integer, save :: nwork = 0
! the flag indicating that the workspace is in use
!
logical, save :: work_in_use = .false.
! the flag indicating that the block structure or distribution has changed
!
logical, save :: changed = .true.
! dimensions of the temporary array used in the block prolongation
! the dimensions of the temporary array used in the block prolongation
!
integer, dimension(3), save :: pm = 1
! by default everything is private
! the common workspace to use for local arrays
!
real(kind=8), dimension(:), allocatable, target :: work
private
! declare public subroutines
!
public :: initialize_mesh, finalize_mesh
public :: generate_mesh, update_mesh
public :: redistribute_blocks, store_mesh_stats
public :: work, work_in_use
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!
@ -91,8 +100,12 @@ module mesh
!
subroutine initialize_mesh(nrun, status)
use coordinates, only : ni => ncells, ng => nghosts, toplev
use mpitools , only : master, nprocs
use coordinates , only : nn => bcells, ni => ncells, ng => nghosts
use coordinates , only : toplev
use equations , only : nf
use iso_fortran_env, only : error_unit
use mpitools , only : master, nprocs
use parameters , only : get_parameter
implicit none
@ -102,6 +115,8 @@ module mesh
character(len=64) :: fn
integer :: l, n
character(len=*), parameter :: loc = 'MESH::initialize_mesh()'
!-------------------------------------------------------------------------------
!
#ifdef PROFILE
@ -158,10 +173,24 @@ module mesh
end if ! master
! prepare dimensions of the prolongation array
! prepare the dimensions of the prolongation array
!
pm(1:NDIMS) = 2 * (ni + ng)
! get the requested size of the workspace
!
call get_parameter('workspace_size', nwork)
nwork = max(nwork, (2 * NDIMS + 1) * nf * nn**NDIMS)
! allocate the workspace
!
allocate(work(nwork), stat=status)
if (status /= 0) then
write(error_unit,"('[',a,']: ',a)") trim(loc) &
, "Cannot allocate the common workspace!"
end if
#ifdef PROFILE
call stop_timer(imi)
#endif /* PROFILE */
@ -201,6 +230,8 @@ module mesh
if (master) close(funit)
if (allocated(work)) deallocate(work)
#ifdef PROFILE
call stop_timer(imi)
#endif /* PROFILE */