Module fd4_block_mod


Uses:
    module fd4_globaldef_mod
    module fd4_vartab_mod
    module fd4_mpi_mod
    module rbtree_int_mod
Types:
    public type fd4_data_link
    public type fd4_block_link
    public type fd4_cell_link
    public type fd4_r_k_link
    public type fd4_block
Variables:
    integer (kind=i4k), public, parameter, dimension (3,2) :: BLOCK_EMPTY = reshape ((/ 2, 4, 8, 16, 32, 64 /), (/ 3, 2 /))
Subroutines and functions:
    public subroutine fd4_block_allocate (b, bext, vartab, varinfo, init, build_type, alloc_face, err)
    public subroutine fd4_block_reset (b, vartab, varinfo, init)
    public subroutine fd4_block_deallocate (b)
    public subroutine fd4_block_empty (b, vartab, varinfo, idx, st, emptyplanes)
    private subroutine fd4_block_build_type (b, err)

Module for a single block containing several 4D data arrays.

A block is a rectangular subset of the spatial grid. It is the smallest unit for load balancing.

Blocks have an additional field weight which respects their computational weight. Load balancing routines (should) use this weight. The default value of the weight is the number of grid cells of the block.

Preprocessor options:

TODO:

Author: Matthias Lieber


Description of Types

fd4_data_link

public type fd4_data_link
    real (kind=r_k), pointer, dimension (:,:,:,:) :: l => null ()
end type fd4_data_link
A helper to build an array of pointers to data fields.

fd4_block_link

public type fd4_block_link
    type (fd4_block), pointer :: l => null ()
end type fd4_block_link
A helper to build an array of pointers to blocks.

fd4_cell_link

public type fd4_cell_link
    real (kind=r_k), pointer, dimension (:) :: l => null ()
end type fd4_cell_link
A helper to build an array of pointers to cells.

fd4_r_k_link

public type fd4_r_k_link
    real (kind=r_k), pointer :: l => NULL ()
end type fd4_r_k_link
A helper used to build an array of pointers (not used in fd4_block, but elsewhere)

fd4_block

public type fd4_block
    integer (kind=i_k), dimension (3) :: pos
    integer (kind=i_k), dimension (3,2) :: bnd
    integer (kind=i_k), dimension (3) :: ext
    type (fd4_block_link), dimension (3,2) :: neigh
    type (fd4_data_link), pointer, dimension (:,:) :: fields => null ()
    type (fd4_data_link), dimension (0:4) :: sdata
    integer (kind=i4k), pointer, dimension (:,:) :: empty => null ()
    integer (kind=i4k) :: sempty
    real (kind=r4k) :: weight
    integer :: bltype = MPI_DATATYPE_NULL
    integer (kind=MPI_ADDRESS_KIND) :: bladdr = 0
end type fd4_block
Components:
pos position of the block in the block decomposition
bnd bounds of the block in global grid coordinates
ext extents of the block
neigh array of pointers to spatial neighbors of this block
fields array of pointers to array sections of sdata, representing the data fields
sdata storage arrays for static data fields (allocated at block creation)
empty tells which fields and boundaries are empty (< vthres of vartab)
sempty summarized empty info (all vars and time steps) of me
weight computational weight of the block
bltype MPI datatype for this block
bladdr address of block%empty(1,1)
Derived Type for a block.

The actual data fields are allocated in sdata:

The field bounds are: ( vars * timesteps_per_var * bins_per_var , x, y, z)

CAUTION: fields contains pointers to non-continuous array sections of sdata(0:3)%l. Be careful to avoid creation of temporary arrays!

TODO:

See also: module fd4_vartab_mod


Description of Subroutines and Functions

fd4_block_allocate

public subroutine fd4_block_allocate (b, bext, vartab, varinfo, init, build_type, alloc_face, err)
    type (fd4_block), pointer :: b
    integer (kind=i_k), intent(in), dimension (3) :: bext
    type (fd4_vartab), intent(in), dimension (:) :: vartab
    type (fd4_varinfo), intent(in) :: varinfo
    logical, intent(in) :: init
    logical, intent(in) :: build_type
    logical, intent(in) :: alloc_face
    integer (kind=i_k), intent(out) :: err
end subroutine fd4_block_allocate
Parameters:
b the block to allocate
bext spatial extent of the block
vartab variable table containing the definitions of fields to allocate
varinfo variable table info
init init data fields with vnull?
build_type built an MPI type for the block?
alloc_face allocate face variables?
err error status, 0 on sucess
Allocates all of the static arrays of the block.

The block itself must be allocated! For internal use only. Error checks require level 3.


fd4_block_reset

public subroutine fd4_block_reset (b, vartab, varinfo, init)
    type (fd4_block), pointer :: b
    type (fd4_vartab), intent(in), dimension (:) :: vartab
    type (fd4_varinfo), intent(in) :: varinfo
    logical, intent(in) :: init
end subroutine fd4_block_reset
Parameters:
b the block to allocate
vartab variable table containing the definitions of fields to allocate
varinfo variable table info
init if false: do not init data fields (faster)
Reset data fields of the block with initial values. Block must exist.

fd4_block_deallocate

public subroutine fd4_block_deallocate (b)
    type (fd4_block), pointer :: b
end subroutine fd4_block_deallocate
Parameters:
b the block to deallocate
Deallocate all arrays of a block and also the block itself.

Nullifies the block pointer. For internal use only.


fd4_block_empty

public subroutine fd4_block_empty (b, vartab, varinfo, idx, st, emptyplanes)
    type (fd4_block), pointer :: b
    type (fd4_vartab), intent(in), dimension (:) :: vartab
    type (fd4_varinfo), intent(in) :: varinfo
    integer (kind=i_k), intent(in) :: idx
    integer (kind=i_k), intent(in) :: st
    integer (kind=i_k), intent(in), dimension (3) :: emptyplanes
end subroutine fd4_block_empty
Parameters:
b the block
vartab variable table
varinfo variable info
idx field index in vartab
st time step index
emptyplanes number of "null" cell planes required to the phase boundary, i.e. to not create new block
Check if a field is empty.

Fills block component empty of variable idx at time step st. For internal use only.


fd4_block_build_type

private subroutine fd4_block_build_type (b, err)
    type (fd4_block), pointer :: b
    integer (kind=i_k), intent(out) :: err
end subroutine fd4_block_build_type
Parameters:
b the block
err error status: 0...ok
Routine to build an MPI datatype to migrate the block.

Build an MPI datatype for the fd4_block components: