allocator_t Derived Type

type, public :: allocator_t

An instance of type allocator_t is responsible for the maintenance of a linked list of instances of equal size m_allocator objects:

      ---- ---- ----     ---- ---- ----
...-->|id=1|data|next|-->|id=0|data|next|-->null()
      ---- ---- ----     ---- ---- ----

the last block's next pointer being non associated.

User code can request access to a memory block by using the type bound procedure get_block. If the list is not empty, a pointer to the first block on the list is returned and the block is detached from the list. If the list is empty (i.e. all initially allocated blocks are currently referenced to) then a new block is allocated before a pointer to it is returned.

In order to reuse memory it is important that user code release blocks when they are not needed anymore. This is done by calling the type bound procedure release_block. The released block is then pushed in front of the block list.


Inherits

type~~allocator_t~~InheritsGraph type~allocator_t allocator_t type~field_t field_t type~allocator_t->type~field_t first type~mesh_t mesh_t type~allocator_t->type~mesh_t mesh type~field_t->type~field_t next type~geo_t geo_t type~mesh_t->type~geo_t geo type~grid_t grid_t type~mesh_t->type~grid_t grid type~par_t par_t type~mesh_t->type~par_t par

Inherited by

type~~allocator_t~~InheritedByGraph type~allocator_t allocator_t type~base_backend_t base_backend_t type~base_backend_t->type~allocator_t allocator type~cuda_allocator_t cuda_allocator_t type~cuda_allocator_t->type~allocator_t type~solver_t solver_t type~solver_t->type~allocator_t host_allocator type~solver_t->type~base_backend_t backend type~time_intg_t time_intg_t type~solver_t->type~time_intg_t time_integrator type~vector_calculus_t vector_calculus_t type~solver_t->type~vector_calculus_t vector_calculus type~time_intg_t->type~allocator_t allocator type~time_intg_t->type~base_backend_t backend type~base_case_t base_case_t type~base_case_t->type~solver_t solver type~cuda_backend_t cuda_backend_t type~cuda_backend_t->type~base_backend_t type~omp_backend_t omp_backend_t type~omp_backend_t->type~base_backend_t type~vector_calculus_t->type~base_backend_t backend type~case_channel_t case_channel_t type~case_channel_t->type~base_case_t type~case_generic_t case_generic_t type~case_generic_t->type~base_case_t type~case_tgv_t case_tgv_t type~case_tgv_t->type~base_case_t

Components

Type Visibility Attributes Name Initial
integer, public :: ngrid
integer, public :: next_id = 0

The id for the next allocated block. This counter is incremented each time a new block is allocated.

type(mesh_t), public, pointer :: mesh

The pointer to the first block on the list. Non associated if the list is empty

class(field_t), public, pointer :: first => null()

Constructor

public interface allocator_t

  • public function allocator_init(mesh, sz) result(allocator)

    Arguments

    Type IntentOptional Attributes Name
    type(mesh_t), intent(inout), target :: mesh
    integer, intent(in) :: sz

    Return Value type(allocator_t)


Type-Bound Procedures

procedure, public :: get_block

  • public function get_block(self, dir, data_loc) result(handle)

    Return a pointer to the first available memory block, i.e. the current head of the block list. If the list is empty, allocate a new block with create_block first.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(allocator_t), intent(inout) :: self
    integer, intent(in) :: dir
    integer, intent(in), optional :: data_loc

    Return Value class(field_t), pointer

procedure, public :: release_block

  • public subroutine release_block(self, handle)

    Release memory block pointed to by HANDLE to the block list. It is pushed to the front of the block list, in other words it is made the head block.

    Arguments

    Type IntentOptional Attributes Name
    class(allocator_t), intent(inout) :: self
    class(field_t), pointer :: handle

procedure, public :: create_block

  • public function create_block(self, next) result(ptr)

    Allocate memory for a new block and return a pointer to a new m_allocator object.

    Arguments

    Type IntentOptional Attributes Name
    class(allocator_t), intent(inout) :: self
    type(field_t), intent(in), pointer :: next

    Return Value class(field_t), pointer

procedure, public :: get_block_ids

  • public function get_block_ids(self)

    Utility function that returns a array made of the id of the block currently in the block list. Return the array [0] if block list is empty.

    Arguments

    Type IntentOptional Attributes Name
    class(allocator_t), intent(inout) :: self

    Return Value integer, allocatable, (:)

procedure, public :: destroy

  • public subroutine destroy(self)

    Go through the block list from head to tail, deallocating each memory block in turn. Deallocation of a m_allocator object automatically deallocates its internal allocatable data array.

    Arguments

    Type IntentOptional Attributes Name
    class(allocator_t), intent(inout) :: self

procedure, public :: compute_padded_dims

  • public subroutine compute_padded_dims(self, sz)

    Arguments

    Type IntentOptional Attributes Name
    class(allocator_t), intent(inout) :: self
    integer, intent(in) :: sz