Module fd4_mpitype_mod


Uses:
    module fd4_globaldef_mod
    module mrgrnk_mod
Types:
    public type fd4_mpitype
Variables:
    type (fd4_mpitype), public, save :: sortmdt
Subroutines and functions:
    public subroutine fd4_mpitype_add (mdt, index, blen, displ, mpitype, is_min)
    public subroutine fd4_mpitype_commit (mdt, err, startdispl)
    public subroutine fd4_mpitype_allocate (mdt, length, is_sortmdt)
    public subroutine fd4_mpitype_free (mdt, free_memory, free_types)

Helper for MPI_Type_create_struct

 
  call fd4_mpitype_add(mdt, index, blen, displ, ...)    ! add a memory location to the type
  call fd4_mpitype_add(mdt, index, blen, displ, ...)    ! add a memory location to the type
  call fd4_mpitype_add(mdt, index, blen, displ, ...)    ! add a memory location to the type
  ...
  call fd4_mpitype_commit(mdt, err)           ! call mpi_type_create_struct and ..._commit
  ...
  call MPI_Send( ... , mdt%datatype ... )
  ...
  call fd4_mpitype_free(mdt)
 

Note: index is an 8 byte integer!

Note: sortmdt is a global variable which will be allocated, but not deallocated. This is intented behavior.

Author: Matthias Lieber


Description of Types

fd4_mpitype

public type fd4_mpitype
    integer :: datatype = MPI_DATATYPE_NULL
    integer (kind=i8k), pointer, dimension (:) :: indexes => null ()
    integer, pointer, dimension (:) :: blens => null ()
    integer, pointer, dimension (:) :: types => null ()
    integer (kind=MPI_ADDRESS_KIND), pointer, dimension (:) :: displ => null ()
    integer (kind=MPI_ADDRESS_KIND) :: mindispl = -1
    integer :: count = 0
    integer (kind=i_k), pointer, dimension (:) :: sort => null ()
end type fd4_mpitype
Components:
sort used in sortmdt only

Description of Subroutines and Functions

fd4_mpitype_add

public subroutine fd4_mpitype_add (mdt, index, blen, displ, mpitype, is_min)
    type (fd4_mpitype), intent(inout) :: mdt
    integer (kind=i8k), intent(in) :: index
    integer, intent(in) :: blen
    integer (kind=MPI_ADDRESS_KIND), intent(in) :: displ
    integer, intent(in) :: mpitype
    logical, optional, intent(out) :: is_min
end subroutine fd4_mpitype_add
Parameters:
mdt the fd4_mpitype
index index used for sorting
blen block length for constructing datatype
displ displacement for constructing datatype
mpitype type for constructing datatype
is_min true if the displacement is the lowest of (currently) all
Add a component to the fd4_mpitype mdt.

Use the is_min parameter if you need to know the component with the lowest displacement This is the one you should use in mpi_send etc. when using the resulting mpi datatype. fd4_mpitype_commit calculates the displacements relative to the minimal displacement to avoid negative displacements.

The index is used for sorting in fd4_mpitype_commit to allow sender-receiver matching of the types.


fd4_mpitype_commit

public subroutine fd4_mpitype_commit (mdt, err, startdispl)
    type (fd4_mpitype), intent(inout) :: mdt
    integer (kind=i_k), intent(out) :: err
    integer (kind=MPI_ADDRESS_KIND), optional, intent(in) :: startdispl
end subroutine fd4_mpitype_commit
Parameters:
mdt the fd4_mpitype
err error status: 0...ok
startdispl start address of the type
Construct and commit the MPI dataype. The MPI datatype is stored in mdt%datatype.

Notes about startdispl:

TODO:

fd4_mpitype_allocate

public subroutine fd4_mpitype_allocate (mdt, length, is_sortmdt)
    type (fd4_mpitype), intent(inout) :: mdt
    integer (kind=i_k), intent(in) :: length
    logical, optional, intent(in) :: is_sortmdt
end subroutine fd4_mpitype_allocate
Parameters:
mdt the fd4_mpitype
length size to allocate (max number of components)
is_sortmdt internal option only, do not use!
Allocate an fd4_mpitype.

fd4_mpitype_free

public subroutine fd4_mpitype_free (mdt, free_memory, free_types)
    type (fd4_mpitype), intent(inout) :: mdt
    logical, intent(in) :: free_memory
    logical, intent(in) :: free_types
end subroutine fd4_mpitype_free
Parameters:
mdt the fd4_mpitype
free_memory free the arrays used to construct the MPI datatype
free_types free the basic types used to construct the MPI datatype
Free the mpi datatype, reset the component counter to zero and, if free_memory is true, deallocate all memory.

free_memory does not imply free_types or vice versa!