LCOV - code coverage report
Current view: top level - src/mpiwrap - message_passing.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:ca6acae) Lines: 60.0 % 991 595
Test Date: 2026-01-02 06:29:53 Functions: 47.9 % 140 67

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief Interface to the message passing library MPI
      10              : !> \par History
      11              : !>      JGH (02-Jan-2001): New error handling
      12              : !>                         Performance tools
      13              : !>      JGH (14-Jan-2001): New routines mp_comm_compare, mp_cart_coords,
      14              : !>                                      mp_rank_compare, mp_alltoall
      15              : !>      JGH (06-Feb-2001): New routines mp_comm_free
      16              : !>      JGH (22-Mar-2001): New routines mp_comm_dup
      17              : !>      fawzi (04-NOV-2004): storable performance info (for f77 interface)
      18              : !>      Wrapper routine for mpi_gatherv added (22.12.2005,MK)
      19              : !>      JGH (13-Feb-2006): Flexible precision
      20              : !>      JGH (15-Feb-2006): single precision mp_alltoall
      21              : !> \author JGH
      22              : ! **************************************************************************************************
      23              : MODULE message_passing
      24              :    USE ISO_C_BINDING, ONLY: C_F_POINTER, C_PTR
      25              :    USE kinds, ONLY: &
      26              :       dp, int_4, int_4_size, int_8, int_8_size, real_4, real_4_size, real_8, &
      27              :       real_8_size, default_string_length
      28              :    USE machine, ONLY: m_abort
      29              :    USE mp_perf_env, ONLY: add_perf, add_mp_perf_env, rm_mp_perf_env
      30              : #if defined(__MIMIC)
      31              :    USE mcl, ONLY: mcl_initialize, mcl_is_initialized, mcl_abort
      32              : #endif
      33              : 
      34              : #include "../base/base_uses.f90"
      35              : 
      36              : ! To simplify the transition between the old MPI module and the F08-style module, we introduce these constants to switch between the required handle types
      37              : ! Unfortunately, Fortran does not offer something like typedef in C++
      38              : #if defined(__parallel) && defined(__MPI_F08)
      39              : #define MPI_DATA_TYPE TYPE(MPI_Datatype)
      40              : #define MPI_COMM_TYPE TYPE(MPI_Comm)
      41              : #define MPI_REQUEST_TYPE TYPE(MPI_Request)
      42              : #define MPI_WIN_TYPE TYPE(MPI_Win)
      43              : #define MPI_FILE_TYPE TYPE(MPI_File)
      44              : #define MPI_INFO_TYPE TYPE(MPI_Info)
      45              : #define MPI_STATUS_TYPE TYPE(MPI_Status)
      46              : #define MPI_GROUP_TYPE TYPE(MPI_Group)
      47              : #define MPI_STATUS_EXTRACT(X) %X
      48              : #define MPI_GET_COMP %mpi_val
      49              : #else
      50              : #define MPI_DATA_TYPE INTEGER
      51              : #define MPI_COMM_TYPE INTEGER
      52              : #define MPI_REQUEST_TYPE INTEGER
      53              : #define MPI_WIN_TYPE INTEGER
      54              : #define MPI_FILE_TYPE INTEGER
      55              : #define MPI_INFO_TYPE INTEGER
      56              : #define MPI_STATUS_TYPE INTEGER, DIMENSION(MPI_STATUS_SIZE)
      57              : #define MPI_GROUP_TYPE INTEGER
      58              : #define MPI_STATUS_EXTRACT(X) (X)
      59              : #define MPI_GET_COMP
      60              : #endif
      61              : 
      62              : #if defined(__parallel)
      63              : ! subroutines: unfortunately, mpi implementations do not provide interfaces for all subroutines (problems with types and ranks explosion),
      64              : !              we do not quite know what is in the module, so we can not include any....
      65              : !              to nevertheless get checking for what is included, we use the mpi module without use clause, getting all there is
      66              : #if defined(__MPI_F08)
      67              :    USE mpi_f08
      68              : #else
      69              :    USE mpi
      70              : #endif
      71              : #endif
      72              :    IMPLICIT NONE
      73              :    PRIVATE
      74              : 
      75              :    ! parameters that might be needed
      76              : #if defined(__parallel)
      77              :    LOGICAL, PARAMETER :: cp2k_is_parallel = .TRUE.
      78              :    INTEGER, PARAMETER, PUBLIC :: mp_any_tag = MPI_ANY_TAG
      79              :    INTEGER, PARAMETER, PUBLIC :: mp_any_source = MPI_ANY_SOURCE
      80              :    MPI_COMM_TYPE, PARAMETER :: mp_comm_null_handle = MPI_COMM_NULL
      81              :    MPI_COMM_TYPE, PARAMETER :: mp_comm_self_handle = MPI_COMM_SELF
      82              :    MPI_COMM_TYPE, PARAMETER :: mp_comm_world_handle = MPI_COMM_WORLD
      83              :    MPI_REQUEST_TYPE, PARAMETER :: mp_request_null_handle = MPI_REQUEST_NULL
      84              :    MPI_WIN_TYPE, PARAMETER :: mp_win_null_handle = MPI_WIN_NULL
      85              :    MPI_FILE_TYPE, PARAMETER :: mp_file_null_handle = MPI_FILE_NULL
      86              :    MPI_INFO_TYPE, PARAMETER :: mp_info_null_handle = MPI_INFO_NULL
      87              :    MPI_DATA_TYPE, PARAMETER :: mp_datatype_null_handle = MPI_DATATYPE_NULL
      88              :    INTEGER, PARAMETER, PUBLIC :: mp_status_size = MPI_STATUS_SIZE
      89              :    INTEGER, PARAMETER, PUBLIC :: mp_proc_null = MPI_PROC_NULL
      90              :    ! Set max allocatable memory by MPI to 2 GiByte
      91              :    INTEGER(KIND=MPI_ADDRESS_KIND), PARAMETER, PRIVATE :: mp_max_memory_size = HUGE(INT(1, KIND=int_4))
      92              : 
      93              :    INTEGER, PARAMETER, PUBLIC :: mp_max_library_version_string = MPI_MAX_LIBRARY_VERSION_STRING
      94              : 
      95              :    INTEGER, PARAMETER, PUBLIC :: file_offset = MPI_OFFSET_KIND
      96              :    INTEGER, PARAMETER, PUBLIC :: address_kind = MPI_ADDRESS_KIND
      97              :    INTEGER, PARAMETER, PUBLIC :: file_amode_create = MPI_MODE_CREATE
      98              :    INTEGER, PARAMETER, PUBLIC :: file_amode_rdonly = MPI_MODE_RDONLY
      99              :    INTEGER, PARAMETER, PUBLIC :: file_amode_wronly = MPI_MODE_WRONLY
     100              :    INTEGER, PARAMETER, PUBLIC :: file_amode_rdwr = MPI_MODE_RDWR
     101              :    INTEGER, PARAMETER, PUBLIC :: file_amode_excl = MPI_MODE_EXCL
     102              :    INTEGER, PARAMETER, PUBLIC :: file_amode_append = MPI_MODE_APPEND
     103              : #else
     104              :    LOGICAL, PARAMETER :: cp2k_is_parallel = .FALSE.
     105              :    INTEGER, PARAMETER, PUBLIC :: mp_any_tag = -1
     106              :    INTEGER, PARAMETER, PUBLIC :: mp_any_source = -2
     107              :    MPI_COMM_TYPE, PARAMETER :: mp_comm_null_handle = -3
     108              :    MPI_COMM_TYPE, PARAMETER :: mp_comm_self_handle = -11
     109              :    MPI_COMM_TYPE, PARAMETER :: mp_comm_world_handle = -12
     110              :    MPI_REQUEST_TYPE, PARAMETER :: mp_request_null_handle = -4
     111              :    MPI_WIN_TYPE, PARAMETER :: mp_win_null_handle = -5
     112              :    MPI_FILE_TYPE, PARAMETER :: mp_file_null_handle = -6
     113              :    MPI_INFO_TYPE, PARAMETER :: mp_info_null_handle = -7
     114              :    MPI_DATA_TYPE, PARAMETER :: mp_datatype_null_handle = -8
     115              :    INTEGER, PARAMETER, PUBLIC :: mp_status_size = -9
     116              :    INTEGER, PARAMETER, PUBLIC :: mp_proc_null = -10
     117              :    INTEGER, PARAMETER, PUBLIC :: mp_max_library_version_string = 1
     118              : 
     119              :    INTEGER, PARAMETER, PUBLIC :: file_offset = int_8
     120              :    INTEGER, PARAMETER, PUBLIC :: address_kind = int_8
     121              :    INTEGER, PARAMETER, PUBLIC :: file_amode_create = 1
     122              :    INTEGER, PARAMETER, PUBLIC :: file_amode_rdonly = 2
     123              :    INTEGER, PARAMETER, PUBLIC :: file_amode_wronly = 4
     124              :    INTEGER, PARAMETER, PUBLIC :: file_amode_rdwr = 8
     125              :    INTEGER, PARAMETER, PUBLIC :: file_amode_excl = 64
     126              :    INTEGER, PARAMETER, PUBLIC :: file_amode_append = 128
     127              : #endif
     128              : 
     129              :    ! we need to fix this to a given number (crossing fingers)
     130              :    ! so that the serial code using Fortran stream IO and the MPI have the same sizes.
     131              :    INTEGER, PARAMETER, PUBLIC :: mpi_character_size = 1
     132              :    INTEGER, PARAMETER, PUBLIC :: mpi_integer_size = 4
     133              : 
     134              :    CHARACTER(LEN=*), PARAMETER, PRIVATE :: moduleN = 'message_passing'
     135              : 
     136              :    ! internal reference counter used to debug communicator leaks
     137              :    INTEGER, PRIVATE, SAVE :: debug_comm_count
     138              : 
     139              :    PUBLIC :: mp_comm_type
     140              :    PUBLIC :: mp_request_type
     141              :    PUBLIC :: mp_win_type
     142              :    PUBLIC :: mp_file_type
     143              :    PUBLIC :: mp_info_type
     144              :    PUBLIC :: mp_cart_type
     145              : 
     146              :    PUBLIC :: mp_para_env_type, mp_para_env_p_type, mp_para_cart_type
     147              :    PUBLIC :: mp_para_env_create, mp_para_env_release, &
     148              :              mp_para_cart_create, mp_para_cart_release
     149              : 
     150              : #if defined(__MIMIC)
     151              :    ! Stores the split world communicator to finalize a MiMiC run
     152              :    MPI_COMM_TYPE, PRIVATE, SAVE :: mimic_comm_world
     153              : #endif
     154              : 
     155              :    TYPE mp_comm_type
     156              :       PRIVATE
     157              :       MPI_COMM_TYPE :: handle = mp_comm_null_handle
     158              :       ! Number of dimensions within a Cartesian topology (useful with mp_cart_type)
     159              :       INTEGER :: ndims = 1
     160              :       ! Meta data to the communicator
     161              :       INTEGER, PUBLIC :: mepos = -1, source = -1, num_pe = -1
     162              :    CONTAINS
     163              :       ! Setters/Getters
     164              :       PROCEDURE, PASS, NON_OVERRIDABLE :: set_handle => mp_comm_type_set_handle
     165              :       PROCEDURE, PASS, NON_OVERRIDABLE :: get_handle => mp_comm_type_get_handle
     166              :       ! Comparisons
     167              :       PROCEDURE, PRIVATE, PASS, NON_OVERRIDABLE :: mp_comm_op_eq
     168              :       PROCEDURE, PRIVATE, PASS, NON_OVERRIDABLE :: mp_comm_op_neq
     169              :       GENERIC, PUBLIC :: operator(==) => mp_comm_op_eq
     170              :       GENERIC, PUBLIC :: operator(/=) => mp_comm_op_neq
     171              :       ! Communication routines
     172              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: &
     173              :          mp_sendrecv_i, mp_sendrecv_l, mp_sendrecv_r, mp_sendrecv_d, &
     174              :          mp_sendrecv_c, mp_sendrecv_z, &
     175              :          mp_sendrecv_iv, mp_sendrecv_im2, mp_sendrecv_im3, mp_sendrecv_im4, &
     176              :          mp_sendrecv_lv, mp_sendrecv_lm2, mp_sendrecv_lm3, mp_sendrecv_lm4, &
     177              :          mp_sendrecv_rv, mp_sendrecv_rm2, mp_sendrecv_rm3, mp_sendrecv_rm4, &
     178              :          mp_sendrecv_dv, mp_sendrecv_dm2, mp_sendrecv_dm3, mp_sendrecv_dm4, &
     179              :          mp_sendrecv_cv, mp_sendrecv_cm2, mp_sendrecv_cm3, mp_sendrecv_cm4, &
     180              :          mp_sendrecv_zv, mp_sendrecv_zm2, mp_sendrecv_zm3, mp_sendrecv_zm4
     181              :       GENERIC, PUBLIC :: sendrecv => mp_sendrecv_i, mp_sendrecv_l, &
     182              :          mp_sendrecv_r, mp_sendrecv_d, mp_sendrecv_c, mp_sendrecv_z, &
     183              :          mp_sendrecv_iv, mp_sendrecv_im2, mp_sendrecv_im3, mp_sendrecv_im4, &
     184              :          mp_sendrecv_lv, mp_sendrecv_lm2, mp_sendrecv_lm3, mp_sendrecv_lm4, &
     185              :          mp_sendrecv_rv, mp_sendrecv_rm2, mp_sendrecv_rm3, mp_sendrecv_rm4, &
     186              :          mp_sendrecv_dv, mp_sendrecv_dm2, mp_sendrecv_dm3, mp_sendrecv_dm4, &
     187              :          mp_sendrecv_cv, mp_sendrecv_cm2, mp_sendrecv_cm3, mp_sendrecv_cm4, &
     188              :          mp_sendrecv_zv, mp_sendrecv_zm2, mp_sendrecv_zm3, mp_sendrecv_zm4
     189              : 
     190              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_minloc_iv, &
     191              :          mp_minloc_lv, mp_minloc_rv, mp_minloc_dv
     192              :       GENERIC, PUBLIC :: minloc => mp_minloc_iv, &
     193              :          mp_minloc_lv, mp_minloc_rv, mp_minloc_dv
     194              : 
     195              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_maxloc_iv, &
     196              :          mp_maxloc_lv, mp_maxloc_rv, mp_maxloc_dv
     197              :       GENERIC, PUBLIC :: maxloc => mp_maxloc_iv, &
     198              :          mp_maxloc_lv, mp_maxloc_rv, mp_maxloc_dv
     199              : 
     200              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_shift_im, mp_shift_i, &
     201              :          mp_shift_lm, mp_shift_l, mp_shift_rm, mp_shift_r, &
     202              :          mp_shift_dm, mp_shift_d, mp_shift_cm, mp_shift_c, &
     203              :          mp_shift_zm, mp_shift_z
     204              :       GENERIC, PUBLIC :: shift => mp_shift_im, mp_shift_i, &
     205              :          mp_shift_lm, mp_shift_l, mp_shift_rm, mp_shift_r, &
     206              :          mp_shift_dm, mp_shift_d, mp_shift_cm, mp_shift_c, &
     207              :          mp_shift_zm, mp_shift_z
     208              : 
     209              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_bcast_i, mp_bcast_iv, mp_bcast_im, mp_bcast_i3, &
     210              :          mp_bcast_l, mp_bcast_lv, mp_bcast_lm, mp_bcast_l3, &
     211              :          mp_bcast_r, mp_bcast_rv, mp_bcast_rm, mp_bcast_r3, &
     212              :          mp_bcast_d, mp_bcast_dv, mp_bcast_dm, mp_bcast_d3, &
     213              :          mp_bcast_c, mp_bcast_cv, mp_bcast_cm, mp_bcast_c3, &
     214              :          mp_bcast_z, mp_bcast_zv, mp_bcast_zm, mp_bcast_z3, &
     215              :          mp_bcast_b, mp_bcast_bv, mp_bcast_av, mp_bcast_am, &
     216              :          mp_bcast_i_src, mp_bcast_iv_src, mp_bcast_im_src, mp_bcast_i3_src, &
     217              :          mp_bcast_l_src, mp_bcast_lv_src, mp_bcast_lm_src, mp_bcast_l3_src, &
     218              :          mp_bcast_r_src, mp_bcast_rv_src, mp_bcast_rm_src, mp_bcast_r3_src, &
     219              :          mp_bcast_d_src, mp_bcast_dv_src, mp_bcast_dm_src, mp_bcast_d3_src, &
     220              :          mp_bcast_c_src, mp_bcast_cv_src, mp_bcast_cm_src, mp_bcast_c3_src, &
     221              :          mp_bcast_z_src, mp_bcast_zv_src, mp_bcast_zm_src, mp_bcast_z3_src, &
     222              :          mp_bcast_b_src, mp_bcast_bv_src, mp_bcast_av_src, mp_bcast_am_src
     223              :       GENERIC, PUBLIC :: bcast => mp_bcast_i, mp_bcast_iv, mp_bcast_im, mp_bcast_i3, &
     224              :          mp_bcast_l, mp_bcast_lv, mp_bcast_lm, mp_bcast_l3, &
     225              :          mp_bcast_r, mp_bcast_rv, mp_bcast_rm, mp_bcast_r3, &
     226              :          mp_bcast_d, mp_bcast_dv, mp_bcast_dm, mp_bcast_d3, &
     227              :          mp_bcast_c, mp_bcast_cv, mp_bcast_cm, mp_bcast_c3, &
     228              :          mp_bcast_z, mp_bcast_zv, mp_bcast_zm, mp_bcast_z3, &
     229              :          mp_bcast_b, mp_bcast_bv, mp_bcast_av, mp_bcast_am, &
     230              :          mp_bcast_i_src, mp_bcast_iv_src, mp_bcast_im_src, mp_bcast_i3_src, &
     231              :          mp_bcast_l_src, mp_bcast_lv_src, mp_bcast_lm_src, mp_bcast_l3_src, &
     232              :          mp_bcast_r_src, mp_bcast_rv_src, mp_bcast_rm_src, mp_bcast_r3_src, &
     233              :          mp_bcast_d_src, mp_bcast_dv_src, mp_bcast_dm_src, mp_bcast_d3_src, &
     234              :          mp_bcast_c_src, mp_bcast_cv_src, mp_bcast_cm_src, mp_bcast_c3_src, &
     235              :          mp_bcast_z_src, mp_bcast_zv_src, mp_bcast_zm_src, mp_bcast_z3_src, &
     236              :          mp_bcast_b_src, mp_bcast_bv_src, mp_bcast_av_src, mp_bcast_am_src
     237              : 
     238              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_ibcast_i, mp_ibcast_iv, &
     239              :          mp_ibcast_l, mp_ibcast_lv, mp_ibcast_r, mp_ibcast_rv, &
     240              :          mp_ibcast_d, mp_ibcast_dv, mp_ibcast_c, mp_ibcast_cv, &
     241              :          mp_ibcast_z, mp_ibcast_zv
     242              :       GENERIC, PUBLIC :: ibcast => mp_ibcast_i, mp_ibcast_iv, &
     243              :          mp_ibcast_l, mp_ibcast_lv, mp_ibcast_r, mp_ibcast_rv, &
     244              :          mp_ibcast_d, mp_ibcast_dv, mp_ibcast_c, mp_ibcast_cv, &
     245              :          mp_ibcast_z, mp_ibcast_zv
     246              : 
     247              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: &
     248              :          mp_sum_i, mp_sum_iv, mp_sum_im, mp_sum_im3, mp_sum_im4, &
     249              :          mp_sum_l, mp_sum_lv, mp_sum_lm, mp_sum_lm3, mp_sum_lm4, &
     250              :          mp_sum_r, mp_sum_rv, mp_sum_rm, mp_sum_rm3, mp_sum_rm4, &
     251              :          mp_sum_d, mp_sum_dv, mp_sum_dm, mp_sum_dm3, mp_sum_dm4, &
     252              :          mp_sum_c, mp_sum_cv, mp_sum_cm, mp_sum_cm3, mp_sum_cm4, &
     253              :          mp_sum_z, mp_sum_zv, mp_sum_zm, mp_sum_zm3, mp_sum_zm4, &
     254              :          mp_sum_root_iv, mp_sum_root_im, mp_sum_root_lv, mp_sum_root_lm, &
     255              :          mp_sum_root_rv, mp_sum_root_rm, mp_sum_root_dv, mp_sum_root_dm, &
     256              :          mp_sum_root_cv, mp_sum_root_cm, mp_sum_root_zv, mp_sum_root_zm, &
     257              :          mp_sum_b, mp_sum_bv
     258              :       GENERIC, PUBLIC :: sum => mp_sum_i, mp_sum_iv, mp_sum_im, mp_sum_im3, mp_sum_im4, &
     259              :          mp_sum_l, mp_sum_lv, mp_sum_lm, mp_sum_lm3, mp_sum_lm4, &
     260              :          mp_sum_r, mp_sum_rv, mp_sum_rm, mp_sum_rm3, mp_sum_rm4, &
     261              :          mp_sum_d, mp_sum_dv, mp_sum_dm, mp_sum_dm3, mp_sum_dm4, &
     262              :          mp_sum_c, mp_sum_cv, mp_sum_cm, mp_sum_cm3, mp_sum_cm4, &
     263              :          mp_sum_z, mp_sum_zv, mp_sum_zm, mp_sum_zm3, mp_sum_zm4, &
     264              :          mp_sum_root_iv, mp_sum_root_im, mp_sum_root_lv, mp_sum_root_lm, &
     265              :          mp_sum_root_rv, mp_sum_root_rm, mp_sum_root_dv, mp_sum_root_dm, &
     266              :          mp_sum_root_cv, mp_sum_root_cm, mp_sum_root_zv, mp_sum_root_zm, &
     267              :          mp_sum_b, mp_sum_bv
     268              : 
     269              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_isum_iv, &
     270              :          mp_isum_lv, mp_isum_rv, mp_isum_dv, mp_isum_cv, &
     271              :          mp_isum_zv, mp_isum_bv
     272              :       GENERIC, PUBLIC :: isum => mp_isum_iv, &
     273              :          mp_isum_lv, mp_isum_rv, mp_isum_dv, mp_isum_cv, &
     274              :          mp_isum_zv, mp_isum_bv
     275              : 
     276              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_sum_partial_im, &
     277              :          mp_sum_partial_lm, mp_sum_partial_rm, mp_sum_partial_dm, &
     278              :          mp_sum_partial_cm, mp_sum_partial_zm
     279              :       GENERIC, PUBLIC :: sum_partial => mp_sum_partial_im, &
     280              :          mp_sum_partial_lm, mp_sum_partial_rm, mp_sum_partial_dm, &
     281              :          mp_sum_partial_cm, mp_sum_partial_zm
     282              : 
     283              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_max_i, mp_max_iv, &
     284              :          mp_max_l, mp_max_lv, mp_max_r, mp_max_rv, &
     285              :          mp_max_d, mp_max_dv, mp_max_c, mp_max_cv, &
     286              :          mp_max_z, mp_max_zv, mp_max_root_i, mp_max_root_l, &
     287              :          mp_max_root_r, mp_max_root_d, mp_max_root_c, mp_max_root_z, &
     288              :          mp_max_root_im, mp_max_root_lm, mp_max_root_rm, mp_max_root_dm, &
     289              :          mp_max_root_cm, mp_max_root_zm
     290              :       GENERIC, PUBLIC :: max => mp_max_i, mp_max_iv, &
     291              :          mp_max_l, mp_max_lv, mp_max_r, mp_max_rv, &
     292              :          mp_max_d, mp_max_dv, mp_max_c, mp_max_cv, &
     293              :          mp_max_z, mp_max_zv, mp_max_root_i, mp_max_root_l, &
     294              :          mp_max_root_r, mp_max_root_d, mp_max_root_c, mp_max_root_z, &
     295              :          mp_max_root_im, mp_max_root_lm, mp_max_root_rm, mp_max_root_dm, &
     296              :          mp_max_root_cm, mp_max_root_zm
     297              : 
     298              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_min_i, mp_min_iv, &
     299              :          mp_min_l, mp_min_lv, mp_min_r, mp_min_rv, &
     300              :          mp_min_d, mp_min_dv, mp_min_c, mp_min_cv, &
     301              :          mp_min_z, mp_min_zv
     302              :       GENERIC, PUBLIC :: min => mp_min_i, mp_min_iv, &
     303              :          mp_min_l, mp_min_lv, mp_min_r, mp_min_rv, &
     304              :          mp_min_d, mp_min_dv, mp_min_c, mp_min_cv, &
     305              :          mp_min_z, mp_min_zv
     306              : 
     307              :       PROCEDURE, PUBLIC, PASS(comm), NON_OVERRIDABLE :: &
     308              :          mp_sum_scatter_iv, mp_sum_scatter_lv, mp_sum_scatter_rv, &
     309              :          mp_sum_scatter_dv, mp_sum_scatter_cv, mp_sum_scatter_zv
     310              :       GENERIC, PUBLIC :: sum_scatter => &
     311              :          mp_sum_scatter_iv, mp_sum_scatter_lv, mp_sum_scatter_rv, &
     312              :          mp_sum_scatter_dv, mp_sum_scatter_cv, mp_sum_scatter_zv
     313              : 
     314              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_prod_r, mp_prod_d, mp_prod_c, mp_prod_z
     315              :       GENERIC, PUBLIC :: prod => mp_prod_r, mp_prod_d, mp_prod_c, mp_prod_z
     316              : 
     317              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_gather_i, mp_gather_iv, mp_gather_im, &
     318              :          mp_gather_l, mp_gather_lv, mp_gather_lm, &
     319              :          mp_gather_r, mp_gather_rv, mp_gather_rm, &
     320              :          mp_gather_d, mp_gather_dv, mp_gather_dm, &
     321              :          mp_gather_c, mp_gather_cv, mp_gather_cm, &
     322              :          mp_gather_z, mp_gather_zv, mp_gather_zm, &
     323              :          mp_gather_i_src, mp_gather_iv_src, mp_gather_im_src, &
     324              :          mp_gather_l_src, mp_gather_lv_src, mp_gather_lm_src, &
     325              :          mp_gather_r_src, mp_gather_rv_src, mp_gather_rm_src, &
     326              :          mp_gather_d_src, mp_gather_dv_src, mp_gather_dm_src, &
     327              :          mp_gather_c_src, mp_gather_cv_src, mp_gather_cm_src, &
     328              :          mp_gather_z_src, mp_gather_zv_src, mp_gather_zm_src
     329              :       GENERIC, PUBLIC :: gather => mp_gather_i, mp_gather_iv, mp_gather_im, &
     330              :          mp_gather_l, mp_gather_lv, mp_gather_lm, &
     331              :          mp_gather_r, mp_gather_rv, mp_gather_rm, &
     332              :          mp_gather_d, mp_gather_dv, mp_gather_dm, &
     333              :          mp_gather_c, mp_gather_cv, mp_gather_cm, &
     334              :          mp_gather_z, mp_gather_zv, mp_gather_zm, &
     335              :          mp_gather_i_src, mp_gather_iv_src, mp_gather_im_src, &
     336              :          mp_gather_l_src, mp_gather_lv_src, mp_gather_lm_src, &
     337              :          mp_gather_r_src, mp_gather_rv_src, mp_gather_rm_src, &
     338              :          mp_gather_d_src, mp_gather_dv_src, mp_gather_dm_src, &
     339              :          mp_gather_c_src, mp_gather_cv_src, mp_gather_cm_src, &
     340              :          mp_gather_z_src, mp_gather_zv_src, mp_gather_zm_src
     341              : 
     342              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_gatherv_iv, &
     343              :          mp_gatherv_lv, mp_gatherv_rv, mp_gatherv_dv, &
     344              :          mp_gatherv_cv, mp_gatherv_zv, mp_gatherv_lm2, mp_gatherv_rm2, &
     345              :          mp_gatherv_dm2, mp_gatherv_cm2, mp_gatherv_zm2, mp_gatherv_iv_src, &
     346              :          mp_gatherv_lv_src, mp_gatherv_rv_src, mp_gatherv_dv_src, &
     347              :          mp_gatherv_cv_src, mp_gatherv_zv_src, mp_gatherv_lm2_src, mp_gatherv_rm2_src, &
     348              :          mp_gatherv_dm2_src, mp_gatherv_cm2_src, mp_gatherv_zm2_src
     349              :       GENERIC, PUBLIC :: gatherv => mp_gatherv_iv, &
     350              :          mp_gatherv_lv, mp_gatherv_rv, mp_gatherv_dv, &
     351              :          mp_gatherv_cv, mp_gatherv_zv, mp_gatherv_lm2, mp_gatherv_rm2, &
     352              :          mp_gatherv_dm2, mp_gatherv_cm2, mp_gatherv_zm2, mp_gatherv_iv_src, &
     353              :          mp_gatherv_lv_src, mp_gatherv_rv_src, mp_gatherv_dv_src, &
     354              :          mp_gatherv_cv_src, mp_gatherv_zv_src, mp_gatherv_lm2_src, mp_gatherv_rm2_src, &
     355              :          mp_gatherv_dm2_src, mp_gatherv_cm2_src, mp_gatherv_zm2_src
     356              : 
     357              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_igatherv_iv, &
     358              :          mp_igatherv_lv, mp_igatherv_rv, mp_igatherv_dv, &
     359              :          mp_igatherv_cv, mp_igatherv_zv
     360              :       GENERIC, PUBLIC :: igatherv => mp_igatherv_iv, &
     361              :          mp_igatherv_lv, mp_igatherv_rv, mp_igatherv_dv, &
     362              :          mp_igatherv_cv, mp_igatherv_zv
     363              : 
     364              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_allgather_i, mp_allgather_i2, &
     365              :          mp_allgather_i12, mp_allgather_i23, mp_allgather_i34, &
     366              :          mp_allgather_i22, mp_allgather_l, mp_allgather_l2, &
     367              :          mp_allgather_l12, mp_allgather_l23, mp_allgather_l34, &
     368              :          mp_allgather_l22, mp_allgather_r, mp_allgather_r2, &
     369              :          mp_allgather_r12, mp_allgather_r23, mp_allgather_r34, &
     370              :          mp_allgather_r22, mp_allgather_d, mp_allgather_d2, &
     371              :          mp_allgather_d12, mp_allgather_d23, mp_allgather_d34, &
     372              :          mp_allgather_d22, mp_allgather_c, mp_allgather_c2, &
     373              :          mp_allgather_c12, mp_allgather_c23, mp_allgather_c34, &
     374              :          mp_allgather_c22, mp_allgather_z, mp_allgather_z2, &
     375              :          mp_allgather_z12, mp_allgather_z23, mp_allgather_z34, &
     376              :          mp_allgather_z22
     377              :       GENERIC, PUBLIC :: allgather => mp_allgather_i, mp_allgather_i2, &
     378              :          mp_allgather_i12, mp_allgather_i23, mp_allgather_i34, &
     379              :          mp_allgather_i22, mp_allgather_l, mp_allgather_l2, &
     380              :          mp_allgather_l12, mp_allgather_l23, mp_allgather_l34, &
     381              :          mp_allgather_l22, mp_allgather_r, mp_allgather_r2, &
     382              :          mp_allgather_r12, mp_allgather_r23, mp_allgather_r34, &
     383              :          mp_allgather_r22, mp_allgather_d, mp_allgather_d2, &
     384              :          mp_allgather_d12, mp_allgather_d23, mp_allgather_d34, &
     385              :          mp_allgather_d22, mp_allgather_c, mp_allgather_c2, &
     386              :          mp_allgather_c12, mp_allgather_c23, mp_allgather_c34, &
     387              :          mp_allgather_c22, mp_allgather_z, mp_allgather_z2, &
     388              :          mp_allgather_z12, mp_allgather_z23, mp_allgather_z34, &
     389              :          mp_allgather_z22
     390              : 
     391              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE ::  mp_allgatherv_iv, mp_allgatherv_lv, &
     392              :          mp_allgatherv_rv, mp_allgatherv_dv, mp_allgatherv_cv, mp_allgatherv_zv, &
     393              :          mp_allgatherv_im2, mp_allgatherv_lm2, mp_allgatherv_rm2, &
     394              :          mp_allgatherv_dm2, mp_allgatherv_cm2, mp_allgatherv_zm2
     395              :       GENERIC, PUBLIC :: allgatherv => mp_allgatherv_iv, mp_allgatherv_lv, &
     396              :          mp_allgatherv_rv, mp_allgatherv_dv, mp_allgatherv_cv, mp_allgatherv_zv, &
     397              :          mp_allgatherv_im2, mp_allgatherv_lm2, mp_allgatherv_rm2, &
     398              :          mp_allgatherv_dm2, mp_allgatherv_cm2, mp_allgatherv_zm2
     399              : 
     400              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_iallgather_i, mp_iallgather_l, &
     401              :          mp_iallgather_r, mp_iallgather_d, mp_iallgather_c, mp_iallgather_z, &
     402              :          mp_iallgather_i11, mp_iallgather_l11, mp_iallgather_r11, mp_iallgather_d11, &
     403              :          mp_iallgather_c11, mp_iallgather_z11, mp_iallgather_i13, mp_iallgather_l13, &
     404              :          mp_iallgather_r13, mp_iallgather_d13, mp_iallgather_c13, mp_iallgather_z13, &
     405              :          mp_iallgather_i22, mp_iallgather_l22, mp_iallgather_r22, mp_iallgather_d22, &
     406              :          mp_iallgather_c22, mp_iallgather_z22, mp_iallgather_i24, mp_iallgather_l24, &
     407              :          mp_iallgather_r24, mp_iallgather_d24, mp_iallgather_c24, mp_iallgather_z24, &
     408              :          mp_iallgather_i33, mp_iallgather_l33, mp_iallgather_r33, mp_iallgather_d33, &
     409              :          mp_iallgather_c33, mp_iallgather_z33
     410              :       GENERIC, PUBLIC :: iallgather => mp_iallgather_i, mp_iallgather_l, &
     411              :          mp_iallgather_r, mp_iallgather_d, mp_iallgather_c, mp_iallgather_z, &
     412              :          mp_iallgather_i11, mp_iallgather_l11, mp_iallgather_r11, mp_iallgather_d11, &
     413              :          mp_iallgather_c11, mp_iallgather_z11, mp_iallgather_i13, mp_iallgather_l13, &
     414              :          mp_iallgather_r13, mp_iallgather_d13, mp_iallgather_c13, mp_iallgather_z13, &
     415              :          mp_iallgather_i22, mp_iallgather_l22, mp_iallgather_r22, mp_iallgather_d22, &
     416              :          mp_iallgather_c22, mp_iallgather_z22, mp_iallgather_i24, mp_iallgather_l24, &
     417              :          mp_iallgather_r24, mp_iallgather_d24, mp_iallgather_c24, mp_iallgather_z24, &
     418              :          mp_iallgather_i33, mp_iallgather_l33, mp_iallgather_r33, mp_iallgather_d33, &
     419              :          mp_iallgather_c33, mp_iallgather_z33
     420              : 
     421              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_iallgatherv_iv, mp_iallgatherv_iv2, &
     422              :          mp_iallgatherv_lv, mp_iallgatherv_lv2, mp_iallgatherv_rv, mp_iallgatherv_rv2, &
     423              :          mp_iallgatherv_dv, mp_iallgatherv_dv2, mp_iallgatherv_cv, mp_iallgatherv_cv2, &
     424              :          mp_iallgatherv_zv, mp_iallgatherv_zv2
     425              :       GENERIC, PUBLIC :: iallgatherv => mp_iallgatherv_iv, mp_iallgatherv_iv2, &
     426              :          mp_iallgatherv_lv, mp_iallgatherv_lv2, mp_iallgatherv_rv, mp_iallgatherv_rv2, &
     427              :          mp_iallgatherv_dv, mp_iallgatherv_dv2, mp_iallgatherv_cv, mp_iallgatherv_cv2, &
     428              :          mp_iallgatherv_zv, mp_iallgatherv_zv2
     429              : 
     430              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_scatter_iv, mp_scatter_lv, &
     431              :          mp_scatter_rv, mp_scatter_dv, mp_scatter_cv, mp_scatter_zv
     432              :       GENERIC, PUBLIC :: scatter => mp_scatter_iv, mp_scatter_lv, &
     433              :          mp_scatter_rv, mp_scatter_dv, mp_scatter_cv, mp_scatter_zv
     434              : 
     435              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_iscatter_i, mp_iscatter_l, &
     436              :          mp_iscatter_r, mp_iscatter_d, mp_iscatter_c, mp_iscatter_z, &
     437              :          mp_iscatter_iv2, mp_iscatter_lv2, mp_iscatter_rv2, mp_iscatter_dv2, &
     438              :          mp_iscatter_cv2, mp_iscatter_zv2
     439              :       GENERIC, PUBLIC :: iscatter => mp_iscatter_i, mp_iscatter_l, &
     440              :          mp_iscatter_r, mp_iscatter_d, mp_iscatter_c, mp_iscatter_z, &
     441              :          mp_iscatter_iv2, mp_iscatter_lv2, mp_iscatter_rv2, mp_iscatter_dv2, &
     442              :          mp_iscatter_cv2, mp_iscatter_zv2
     443              : 
     444              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_iscatterv_iv, mp_iscatterv_lv, &
     445              :          mp_iscatterv_rv, mp_iscatterv_dv, mp_iscatterv_cv, mp_iscatterv_zv
     446              :       GENERIC, PUBLIC :: iscatterv => mp_iscatterv_iv, mp_iscatterv_lv, &
     447              :          mp_iscatterv_rv, mp_iscatterv_dv, mp_iscatterv_cv, mp_iscatterv_zv
     448              : 
     449              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_alltoall_i, mp_alltoall_i22, mp_alltoall_i33, &
     450              :          mp_alltoall_i44, mp_alltoall_i55, mp_alltoall_i45, mp_alltoall_i34, &
     451              :          mp_alltoall_i11v, mp_alltoall_i22v, mp_alltoall_i54, &
     452              :          mp_alltoall_l, mp_alltoall_l22, mp_alltoall_l33, &
     453              :          mp_alltoall_l44, mp_alltoall_l55, mp_alltoall_l45, mp_alltoall_l34, &
     454              :          mp_alltoall_l11v, mp_alltoall_l22v, mp_alltoall_l54, &
     455              :          mp_alltoall_r, mp_alltoall_r22, mp_alltoall_r33, &
     456              :          mp_alltoall_r44, mp_alltoall_r55, mp_alltoall_r45, mp_alltoall_r34, &
     457              :          mp_alltoall_r11v, mp_alltoall_r22v, mp_alltoall_r54, &
     458              :          mp_alltoall_d, mp_alltoall_d22, mp_alltoall_d33, &
     459              :          mp_alltoall_d44, mp_alltoall_d55, mp_alltoall_d45, mp_alltoall_d34, &
     460              :          mp_alltoall_d11v, mp_alltoall_d22v, mp_alltoall_d54, &
     461              :          mp_alltoall_c, mp_alltoall_c22, mp_alltoall_c33, &
     462              :          mp_alltoall_c44, mp_alltoall_c55, mp_alltoall_c45, mp_alltoall_c34, &
     463              :          mp_alltoall_c11v, mp_alltoall_c22v, mp_alltoall_c54, &
     464              :          mp_alltoall_z, mp_alltoall_z22, mp_alltoall_z33, &
     465              :          mp_alltoall_z44, mp_alltoall_z55, mp_alltoall_z45, mp_alltoall_z34, &
     466              :          mp_alltoall_z11v, mp_alltoall_z22v, mp_alltoall_z54
     467              :       GENERIC, PUBLIC :: alltoall => mp_alltoall_i, mp_alltoall_i22, mp_alltoall_i33, &
     468              :          mp_alltoall_i44, mp_alltoall_i55, mp_alltoall_i45, mp_alltoall_i34, &
     469              :          mp_alltoall_i11v, mp_alltoall_i22v, mp_alltoall_i54, &
     470              :          mp_alltoall_l, mp_alltoall_l22, mp_alltoall_l33, &
     471              :          mp_alltoall_l44, mp_alltoall_l55, mp_alltoall_l45, mp_alltoall_l34, &
     472              :          mp_alltoall_l11v, mp_alltoall_l22v, mp_alltoall_l54, &
     473              :          mp_alltoall_r, mp_alltoall_r22, mp_alltoall_r33, &
     474              :          mp_alltoall_r44, mp_alltoall_r55, mp_alltoall_r45, mp_alltoall_r34, &
     475              :          mp_alltoall_r11v, mp_alltoall_r22v, mp_alltoall_r54, &
     476              :          mp_alltoall_d, mp_alltoall_d22, mp_alltoall_d33, &
     477              :          mp_alltoall_d44, mp_alltoall_d55, mp_alltoall_d45, mp_alltoall_d34, &
     478              :          mp_alltoall_d11v, mp_alltoall_d22v, mp_alltoall_d54, &
     479              :          mp_alltoall_c, mp_alltoall_c22, mp_alltoall_c33, &
     480              :          mp_alltoall_c44, mp_alltoall_c55, mp_alltoall_c45, mp_alltoall_c34, &
     481              :          mp_alltoall_c11v, mp_alltoall_c22v, mp_alltoall_c54, &
     482              :          mp_alltoall_z, mp_alltoall_z22, mp_alltoall_z33, &
     483              :          mp_alltoall_z44, mp_alltoall_z55, mp_alltoall_z45, mp_alltoall_z34, &
     484              :          mp_alltoall_z11v, mp_alltoall_z22v, mp_alltoall_z54
     485              : 
     486              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_send_i, mp_send_iv, mp_send_im2, mp_send_im3, &
     487              :          mp_send_l, mp_send_lv, mp_send_lm2, mp_send_lm3, &
     488              :          mp_send_r, mp_send_rv, mp_send_rm2, mp_send_rm3, &
     489              :          mp_send_d, mp_send_dv, mp_send_dm2, mp_send_dm3, &
     490              :          mp_send_c, mp_send_cv, mp_send_cm2, mp_send_cm3, &
     491              :          mp_send_z, mp_send_zv, mp_send_zm2, mp_send_zm3
     492              :       GENERIC, PUBLIC :: send => mp_send_i, mp_send_iv, mp_send_im2, mp_send_im3, &
     493              :          mp_send_l, mp_send_lv, mp_send_lm2, mp_send_lm3, &
     494              :          mp_send_r, mp_send_rv, mp_send_rm2, mp_send_rm3, &
     495              :          mp_send_d, mp_send_dv, mp_send_dm2, mp_send_dm3, &
     496              :          mp_send_c, mp_send_cv, mp_send_cm2, mp_send_cm3, &
     497              :          mp_send_z, mp_send_zv, mp_send_zm2, mp_send_zm3
     498              : 
     499              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_recv_i, mp_recv_iv, mp_recv_im2, mp_recv_im3, &
     500              :          mp_recv_l, mp_recv_lv, mp_recv_lm2, mp_recv_lm3, &
     501              :          mp_recv_r, mp_recv_rv, mp_recv_rm2, mp_recv_rm3, &
     502              :          mp_recv_d, mp_recv_dv, mp_recv_dm2, mp_recv_dm3, &
     503              :          mp_recv_c, mp_recv_cv, mp_recv_cm2, mp_recv_cm3, &
     504              :          mp_recv_z, mp_recv_zv, mp_recv_zm2, mp_recv_zm3
     505              :       GENERIC, PUBLIC :: recv => mp_recv_i, mp_recv_iv, mp_recv_im2, mp_recv_im3, &
     506              :          mp_recv_l, mp_recv_lv, mp_recv_lm2, mp_recv_lm3, &
     507              :          mp_recv_r, mp_recv_rv, mp_recv_rm2, mp_recv_rm3, &
     508              :          mp_recv_d, mp_recv_dv, mp_recv_dm2, mp_recv_dm3, &
     509              :          mp_recv_c, mp_recv_cv, mp_recv_cm2, mp_recv_cm3, &
     510              :          mp_recv_z, mp_recv_zv, mp_recv_zm2, mp_recv_zm3
     511              : 
     512              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_isendrecv_i, mp_isendrecv_iv, &
     513              :          mp_isendrecv_l, mp_isendrecv_lv, mp_isendrecv_r, mp_isendrecv_rv, &
     514              :          mp_isendrecv_d, mp_isendrecv_dv, mp_isendrecv_c, mp_isendrecv_cv, &
     515              :          mp_isendrecv_z, mp_isendrecv_zv
     516              :       GENERIC, PUBLIC :: isendrecv => mp_isendrecv_i, mp_isendrecv_iv, &
     517              :          mp_isendrecv_l, mp_isendrecv_lv, mp_isendrecv_r, mp_isendrecv_rv, &
     518              :          mp_isendrecv_d, mp_isendrecv_dv, mp_isendrecv_c, mp_isendrecv_cv, &
     519              :          mp_isendrecv_z, mp_isendrecv_zv
     520              : 
     521              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_isend_iv, mp_isend_im2, mp_isend_im3, mp_isend_im4, &
     522              :          mp_isend_lv, mp_isend_lm2, mp_isend_lm3, mp_isend_lm4, &
     523              :          mp_isend_rv, mp_isend_rm2, mp_isend_rm3, mp_isend_rm4, &
     524              :          mp_isend_dv, mp_isend_dm2, mp_isend_dm3, mp_isend_dm4, &
     525              :          mp_isend_cv, mp_isend_cm2, mp_isend_cm3, mp_isend_cm4, &
     526              :          mp_isend_zv, mp_isend_zm2, mp_isend_zm3, mp_isend_zm4, &
     527              :          mp_isend_bv, mp_isend_bm3, mp_isend_custom
     528              :       GENERIC, PUBLIC :: isend => mp_isend_iv, mp_isend_im2, mp_isend_im3, mp_isend_im4, &
     529              :          mp_isend_lv, mp_isend_lm2, mp_isend_lm3, mp_isend_lm4, &
     530              :          mp_isend_rv, mp_isend_rm2, mp_isend_rm3, mp_isend_rm4, &
     531              :          mp_isend_dv, mp_isend_dm2, mp_isend_dm3, mp_isend_dm4, &
     532              :          mp_isend_cv, mp_isend_cm2, mp_isend_cm3, mp_isend_cm4, &
     533              :          mp_isend_zv, mp_isend_zm2, mp_isend_zm3, mp_isend_zm4, &
     534              :          mp_isend_bv, mp_isend_bm3, mp_isend_custom
     535              : 
     536              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_irecv_iv, mp_irecv_im2, mp_irecv_im3, mp_irecv_im4, &
     537              :          mp_irecv_lv, mp_irecv_lm2, mp_irecv_lm3, mp_irecv_lm4, &
     538              :          mp_irecv_rv, mp_irecv_rm2, mp_irecv_rm3, mp_irecv_rm4, &
     539              :          mp_irecv_dv, mp_irecv_dm2, mp_irecv_dm3, mp_irecv_dm4, &
     540              :          mp_irecv_cv, mp_irecv_cm2, mp_irecv_cm3, mp_irecv_cm4, &
     541              :          mp_irecv_zv, mp_irecv_zm2, mp_irecv_zm3, mp_irecv_zm4, &
     542              :          mp_irecv_bv, mp_irecv_bm3, mp_irecv_custom
     543              :       GENERIC, PUBLIC :: irecv => mp_irecv_iv, mp_irecv_im2, mp_irecv_im3, mp_irecv_im4, &
     544              :          mp_irecv_lv, mp_irecv_lm2, mp_irecv_lm3, mp_irecv_lm4, &
     545              :          mp_irecv_rv, mp_irecv_rm2, mp_irecv_rm3, mp_irecv_rm4, &
     546              :          mp_irecv_dv, mp_irecv_dm2, mp_irecv_dm3, mp_irecv_dm4, &
     547              :          mp_irecv_cv, mp_irecv_cm2, mp_irecv_cm3, mp_irecv_cm4, &
     548              :          mp_irecv_zv, mp_irecv_zm2, mp_irecv_zm3, mp_irecv_zm4, &
     549              :          mp_irecv_bv, mp_irecv_bm3, mp_irecv_custom
     550              : 
     551              :       PROCEDURE, PUBLIC, PASS(comm), NON_OVERRIDABLE :: probe => mp_probe
     552              : 
     553              :       PROCEDURE, PUBLIC, PASS(comm), NON_OVERRIDABLE :: sync => mp_sync
     554              :       PROCEDURE, PUBLIC, PASS(comm), NON_OVERRIDABLE :: isync => mp_isync
     555              : 
     556              :       PROCEDURE, PUBLIC, PASS(comm1), NON_OVERRIDABLE :: compare => mp_comm_compare
     557              :       PROCEDURE, PUBLIC, PASS(comm1), NON_OVERRIDABLE :: rank_compare => mp_rank_compare
     558              : 
     559              :       PROCEDURE, PUBLIC, PASS(comm2), NON_OVERRIDABLE :: from_dup => mp_comm_dup
     560              :       PROCEDURE, PUBLIC, PASS(comm), NON_OVERRIDABLE :: mp_comm_free
     561              :       GENERIC, PUBLIC :: free => mp_comm_free
     562              : 
     563              :       PROCEDURE, PUBLIC, PASS(comm), NON_OVERRIDABLE :: mp_comm_init
     564              :       GENERIC, PUBLIC :: init => mp_comm_init
     565              : 
     566              :       PROCEDURE, PUBLIC, PASS(comm), NON_OVERRIDABLE :: get_size => mp_comm_size
     567              :       PROCEDURE, PUBLIC, PASS(comm), NON_OVERRIDABLE :: get_rank => mp_comm_rank
     568              :       PROCEDURE, PUBLIC, PASS(comm), NON_OVERRIDABLE :: get_ndims => mp_comm_get_ndims
     569              :       PROCEDURE, PUBLIC, PASS(comm), NON_OVERRIDABLE :: is_source => mp_comm_is_source
     570              : 
     571              :       ! Creation routines
     572              :       PROCEDURE, PRIVATE, PASS(sub_comm), NON_OVERRIDABLE :: mp_comm_split, mp_comm_split_direct
     573              :       GENERIC, PUBLIC :: from_split => mp_comm_split, mp_comm_split_direct
     574              :       PROCEDURE, PUBLIC, PASS(mp_new_comm), NON_OVERRIDABLE :: from_reordering => mp_reordering
     575              :       PROCEDURE, PUBLIC, PASS(comm_new), NON_OVERRIDABLE :: mp_comm_assign
     576              :       GENERIC, PUBLIC :: ASSIGNMENT(=) => mp_comm_assign
     577              : 
     578              :       ! Other Getters
     579              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_comm_get_tag_ub
     580              :       GENERIC, PUBLIC :: get_tag_ub => mp_comm_get_tag_ub
     581              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_comm_get_host_rank
     582              :       GENERIC, PUBLIC :: get_host_rank => mp_comm_get_host_rank
     583              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_comm_get_io_rank
     584              :       GENERIC, PUBLIC :: get_io_rank => mp_comm_get_io_rank
     585              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: mp_comm_get_wtime_is_global
     586              :       GENERIC, PUBLIC :: get_wtime_is_global => mp_comm_get_wtime_is_global
     587              :    END TYPE
     588              : 
     589              :    TYPE mp_request_type
     590              :       PRIVATE
     591              :       MPI_REQUEST_TYPE :: handle = mp_request_null_handle
     592              :    CONTAINS
     593              :       PROCEDURE, PUBLIC, NON_OVERRIDABLE :: set_handle => mp_request_type_set_handle
     594              :       PROCEDURE, PUBLIC, NON_OVERRIDABLE :: get_handle => mp_request_type_get_handle
     595              :       PROCEDURE, PRIVATE, NON_OVERRIDABLE :: mp_request_op_eq
     596              :       PROCEDURE, PRIVATE, NON_OVERRIDABLE :: mp_request_op_neq
     597              :       GENERIC, PUBLIC :: OPERATOR(==) => mp_request_op_eq
     598              :       GENERIC, PUBLIC :: OPERATOR(/=) => mp_request_op_neq
     599              : 
     600              :       PROCEDURE, PUBLIC, PASS(request), NON_OVERRIDABLE :: test => mp_test_1
     601              : 
     602              :       PROCEDURE, PUBLIC, PASS(request), NON_OVERRIDABLE :: wait => mp_wait
     603              :    END TYPE
     604              : 
     605              :    TYPE mp_win_type
     606              :       PRIVATE
     607              :       MPI_WIN_TYPE :: handle = mp_win_null_handle
     608              :    CONTAINS
     609              :       PROCEDURE, PUBLIC, NON_OVERRIDABLE :: set_handle => mp_win_type_set_handle
     610              :       PROCEDURE, PUBLIC, NON_OVERRIDABLE :: get_handle => mp_win_type_get_handle
     611              :       PROCEDURE, PRIVATE, NON_OVERRIDABLE :: mp_win_op_eq
     612              :       PROCEDURE, PRIVATE, NON_OVERRIDABLE :: mp_win_op_neq
     613              :       GENERIC, PUBLIC :: OPERATOR(==) => mp_win_op_eq
     614              :       GENERIC, PUBLIC :: OPERATOR(/=) => mp_win_op_neq
     615              : 
     616              :       PROCEDURE, PRIVATE, PASS(win), NON_OVERRIDABLE :: mp_win_create_iv, mp_win_create_lv, &
     617              :          mp_win_create_rv, mp_win_create_dv, mp_win_create_cv, mp_win_create_zv
     618              :       GENERIC, PUBLIC :: create => mp_win_create_iv, mp_win_create_lv, &
     619              :          mp_win_create_rv, mp_win_create_dv, mp_win_create_cv, mp_win_create_zv
     620              : 
     621              :       PROCEDURE, PRIVATE, PASS(win), NON_OVERRIDABLE :: mp_rget_iv, mp_rget_lv, &
     622              :          mp_rget_rv, mp_rget_dv, mp_rget_cv, mp_rget_zv
     623              :       GENERIC, PUBLIC :: rget => mp_rget_iv, mp_rget_lv, &
     624              :          mp_rget_rv, mp_rget_dv, mp_rget_cv, mp_rget_zv
     625              : 
     626              :       PROCEDURE, PUBLIC, PASS(win), NON_OVERRIDABLE :: free => mp_win_free
     627              :       PROCEDURE, PUBLIC, PASS(win_new), NON_OVERRIDABLE :: mp_win_assign
     628              :       GENERIC, PUBLIC :: ASSIGNMENT(=) => mp_win_assign
     629              : 
     630              :       PROCEDURE, PUBLIC, PASS(win), NON_OVERRIDABLE :: lock_all => mp_win_lock_all
     631              :       PROCEDURE, PUBLIC, PASS(win), NON_OVERRIDABLE :: unlock_all => mp_win_unlock_all
     632              :       PROCEDURE, PUBLIC, PASS(win), NON_OVERRIDABLE :: flush_all => mp_win_flush_all
     633              :    END TYPE
     634              : 
     635              :    TYPE mp_file_type
     636              :       PRIVATE
     637              :       MPI_FILE_TYPE :: handle = mp_file_null_handle
     638              :    CONTAINS
     639              :       PROCEDURE, PUBLIC, NON_OVERRIDABLE :: set_handle => mp_file_type_set_handle
     640              :       PROCEDURE, PUBLIC, NON_OVERRIDABLE :: get_handle => mp_file_type_get_handle
     641              :       PROCEDURE, PRIVATE, NON_OVERRIDABLE :: mp_file_op_eq
     642              :       PROCEDURE, PRIVATE, NON_OVERRIDABLE :: mp_file_op_neq
     643              :       GENERIC, PUBLIC :: OPERATOR(==) => mp_file_op_eq
     644              :       GENERIC, PUBLIC :: OPERATOR(/=) => mp_file_op_neq
     645              : 
     646              :       PROCEDURE, PRIVATE, PASS(fh), NON_OVERRIDABLE :: mp_file_write_at_ch, mp_file_write_at_chv, &
     647              :          mp_file_write_at_i, mp_file_write_at_iv, mp_file_write_at_r, mp_file_write_at_rv, &
     648              :          mp_file_write_at_d, mp_file_write_at_dv, mp_file_write_at_c, mp_file_write_at_cv, &
     649              :          mp_file_write_at_z, mp_file_write_at_zv, mp_file_write_at_l, mp_file_write_at_lv
     650              :       GENERIC, PUBLIC :: write_at => mp_file_write_at_ch, mp_file_write_at_chv, &
     651              :          mp_file_write_at_i, mp_file_write_at_iv, mp_file_write_at_r, mp_file_write_at_rv, &
     652              :          mp_file_write_at_d, mp_file_write_at_dv, mp_file_write_at_c, mp_file_write_at_cv, &
     653              :          mp_file_write_at_z, mp_file_write_at_zv, mp_file_write_at_l, mp_file_write_at_lv
     654              : 
     655              :       PROCEDURE, PRIVATE, PASS(fh), NON_OVERRIDABLE :: mp_file_write_at_all_ch, mp_file_write_at_all_chv, &
     656              :          mp_file_write_at_all_i, mp_file_write_at_all_iv, mp_file_write_at_all_l, mp_file_write_at_all_lv, &
     657              :          mp_file_write_at_all_r, mp_file_write_at_all_rv, mp_file_write_at_all_d, mp_file_write_at_all_dv, &
     658              :          mp_file_write_at_all_c, mp_file_write_at_all_cv, mp_file_write_at_all_z, mp_file_write_at_all_zv
     659              :       GENERIC, PUBLIC :: write_at_all => mp_file_write_at_all_ch, mp_file_write_at_all_chv, &
     660              :          mp_file_write_at_all_i, mp_file_write_at_all_iv, mp_file_write_at_all_l, mp_file_write_at_all_lv, &
     661              :          mp_file_write_at_all_r, mp_file_write_at_all_rv, mp_file_write_at_all_d, mp_file_write_at_all_dv, &
     662              :          mp_file_write_at_all_c, mp_file_write_at_all_cv, mp_file_write_at_all_z, mp_file_write_at_all_zv
     663              : 
     664              :       PROCEDURE, PRIVATE, PASS(fh), NON_OVERRIDABLE :: mp_file_read_at_ch, mp_file_read_at_chv, &
     665              :          mp_file_read_at_i, mp_file_read_at_iv, mp_file_read_at_r, mp_file_read_at_rv, &
     666              :          mp_file_read_at_d, mp_file_read_at_dv, mp_file_read_at_c, mp_file_read_at_cv, &
     667              :          mp_file_read_at_z, mp_file_read_at_zv, mp_file_read_at_l, mp_file_read_at_lv
     668              :       GENERIC, PUBLIC :: read_at => mp_file_read_at_ch, mp_file_read_at_chv, &
     669              :          mp_file_read_at_i, mp_file_read_at_iv, mp_file_read_at_r, mp_file_read_at_rv, &
     670              :          mp_file_read_at_d, mp_file_read_at_dv, mp_file_read_at_c, mp_file_read_at_cv, &
     671              :          mp_file_read_at_z, mp_file_read_at_zv, mp_file_read_at_l, mp_file_read_at_lv
     672              : 
     673              :       PROCEDURE, PRIVATE, PASS(fh), NON_OVERRIDABLE :: mp_file_read_at_all_ch, mp_file_read_at_all_chv, &
     674              :          mp_file_read_at_all_i, mp_file_read_at_all_iv, mp_file_read_at_all_l, mp_file_read_at_all_lv, &
     675              :          mp_file_read_at_all_r, mp_file_read_at_all_rv, mp_file_read_at_all_d, mp_file_read_at_all_dv, &
     676              :          mp_file_read_at_all_c, mp_file_read_at_all_cv, mp_file_read_at_all_z, mp_file_read_at_all_zv
     677              :       GENERIC, PUBLIC :: read_at_all => mp_file_read_at_all_ch, mp_file_read_at_all_chv, &
     678              :          mp_file_read_at_all_i, mp_file_read_at_all_iv, mp_file_read_at_all_l, mp_file_read_at_all_lv, &
     679              :          mp_file_read_at_all_r, mp_file_read_at_all_rv, mp_file_read_at_all_d, mp_file_read_at_all_dv, &
     680              :          mp_file_read_at_all_c, mp_file_read_at_all_cv, mp_file_read_at_all_z, mp_file_read_at_all_zv
     681              : 
     682              :       PROCEDURE, PUBLIC, PASS(fh), NON_OVERRIDABLE :: open => mp_file_open
     683              :       PROCEDURE, PUBLIC, PASS(fh), NON_OVERRIDABLE :: close => mp_file_close
     684              :       PROCEDURE, PRIVATE, PASS(fh_new), NON_OVERRIDABLE :: mp_file_assign
     685              :       GENERIC, PUBLIC :: ASSIGNMENT(=) => mp_file_assign
     686              : 
     687              :       PROCEDURE, PUBLIC, PASS(fh), NON_OVERRIDABLE :: get_size => mp_file_get_size
     688              :       PROCEDURE, PUBLIC, PASS(fh), NON_OVERRIDABLE :: get_position => mp_file_get_position
     689              : 
     690              :       PROCEDURE, PUBLIC, PASS(fh), NON_OVERRIDABLE :: read_all => mp_file_read_all_chv
     691              :       PROCEDURE, PUBLIC, PASS(fh), NON_OVERRIDABLE :: write_all => mp_file_write_all_chv
     692              :    END TYPE
     693              : 
     694              :    TYPE mp_info_type
     695              :       PRIVATE
     696              :       MPI_INFO_TYPE :: handle = mp_info_null_handle
     697              :    CONTAINS
     698              :       PROCEDURE, NON_OVERRIDABLE :: set_handle => mp_info_type_set_handle
     699              :       PROCEDURE, NON_OVERRIDABLE :: get_handle => mp_info_type_get_handle
     700              :       PROCEDURE, PRIVATE, NON_OVERRIDABLE :: mp_info_op_eq
     701              :       PROCEDURE, PRIVATE, NON_OVERRIDABLE :: mp_info_op_neq
     702              :       GENERIC, PUBLIC :: OPERATOR(==) => mp_info_op_eq
     703              :       GENERIC, PUBLIC :: OPERATOR(/=) => mp_info_op_neq
     704              :    END TYPE
     705              : 
     706              :    TYPE, EXTENDS(mp_comm_type) :: mp_cart_type
     707              :       INTEGER, DIMENSION(:), ALLOCATABLE, PUBLIC :: mepos_cart, num_pe_cart
     708              :       LOGICAL, DIMENSION(:), ALLOCATABLE, PUBLIC :: periodic
     709              :    CONTAINS
     710              :       PROCEDURE, PUBLIC, PASS(comm_cart), NON_OVERRIDABLE :: create => mp_cart_create
     711              :       PROCEDURE, PUBLIC, PASS(sub_comm), NON_OVERRIDABLE :: from_sub => mp_cart_sub
     712              : 
     713              :       PROCEDURE, PRIVATE, PASS(comm), NON_OVERRIDABLE :: get_info_cart => mp_cart_get
     714              : 
     715              :       PROCEDURE, PUBLIC, PASS(comm), NON_OVERRIDABLE :: coords => mp_cart_coords
     716              :       PROCEDURE, PUBLIC, PASS(comm), NON_OVERRIDABLE :: rank_cart => mp_cart_rank
     717              :    END TYPE
     718              : 
     719              : ! **************************************************************************************************
     720              : !> \brief stores all the informations relevant to an mpi environment
     721              : !> \param owns_group if it owns the group (and thus should free it when
     722              : !>        this object is deallocated)
     723              : !> \param ref_count the reference count, when it is zero this object gets
     724              : !>        deallocated
     725              : !> \par History
     726              : !>      08.2002 created [fawzi]
     727              : !> \author Fawzi Mohamed
     728              : ! **************************************************************************************************
     729              :    TYPE, EXTENDS(mp_comm_type) :: mp_para_env_type
     730              :       PRIVATE
     731              :       ! We set it to true to have less initialization steps in case we create a new communicator
     732              :       LOGICAL :: owns_group = .TRUE.
     733              :       INTEGER :: ref_count = -1
     734              :    CONTAINS
     735              :       PROCEDURE, PUBLIC, PASS(para_env), NON_OVERRIDABLE :: retain => mp_para_env_retain
     736              :       PROCEDURE, PUBLIC, PASS(para_env), NON_OVERRIDABLE :: is_valid => mp_para_env_is_valid
     737              :    END TYPE mp_para_env_type
     738              : 
     739              : ! **************************************************************************************************
     740              : !> \brief represent a pointer to a para env (to build arrays)
     741              : !> \param para_env the pointer to the para_env
     742              : !> \par History
     743              : !>      07.2003 created [fawzi]
     744              : !> \author Fawzi Mohamed
     745              : ! **************************************************************************************************
     746              :    TYPE mp_para_env_p_type
     747              :       TYPE(mp_para_env_type), POINTER :: para_env => NULL()
     748              :    END TYPE mp_para_env_p_type
     749              : 
     750              : ! **************************************************************************************************
     751              : !> \brief represent a multidimensional parallel environment
     752              : !> \param mepos_cart the position of the actual processor
     753              : !> \param num_pe_cart number of processors in the group in each dimension
     754              : !> \param source_cart id of a special processor (for example the one for i-o,
     755              : !>        or the master
     756              : !> \param owns_group if it owns the group (and thus should free it when
     757              : !>        this object is deallocated)
     758              : !> \param ref_count the reference count, when it is zero this object gets
     759              : !>        deallocated
     760              : !> \note
     761              : !>      not yet implemented for mpi
     762              : !> \par History
     763              : !>      08.2002 created [fawzi]
     764              : !> \author Fawzi Mohamed
     765              : ! **************************************************************************************************
     766              :    TYPE, EXTENDS(mp_cart_type) :: mp_para_cart_type
     767              :       PRIVATE
     768              :       ! We set it to true to have less initialization steps in case we create a new communicator
     769              :       LOGICAL :: owns_group = .TRUE.
     770              :       INTEGER :: ref_count = -1
     771              :    CONTAINS
     772              :       PROCEDURE, PUBLIC, PASS(cart), NON_OVERRIDABLE :: retain => mp_para_cart_retain
     773              :       PROCEDURE, PUBLIC, PASS(cart), NON_OVERRIDABLE :: is_valid => mp_para_cart_is_valid
     774              :    END TYPE mp_para_cart_type
     775              : 
     776              :    ! Create the constants from the corresponding handles
     777              :    TYPE(mp_comm_type), PARAMETER, PUBLIC :: mp_comm_null = mp_comm_type(mp_comm_null_handle)
     778              :    TYPE(mp_comm_type), PARAMETER, PUBLIC :: mp_comm_self = mp_comm_type(mp_comm_self_handle)
     779              :    TYPE(mp_comm_type), PARAMETER, PUBLIC :: mp_comm_world = mp_comm_type(mp_comm_world_handle)
     780              :    TYPE(mp_request_type), PARAMETER, PUBLIC :: mp_request_null = mp_request_type(mp_request_null_handle)
     781              :    TYPE(mp_win_type), PARAMETER, PUBLIC :: mp_win_null = mp_win_type(mp_win_null_handle)
     782              :    TYPE(mp_file_type), PARAMETER, PUBLIC :: mp_file_null = mp_file_type(mp_file_null_handle)
     783              :    TYPE(mp_info_type), PARAMETER, PUBLIC :: mp_info_null = mp_info_type(mp_info_null_handle)
     784              : 
     785              : #if !defined(__parallel)
     786              :    ! This communicator is to be used in serial mode to emulate a valid communicator which is not a compiler constant
     787              :    INTEGER, PARAMETER, PRIVATE :: mp_comm_default_handle = 1
     788              :    TYPE(mp_comm_type), PARAMETER, PRIVATE :: mp_comm_default = mp_comm_type(mp_comm_default_handle)
     789              : #endif
     790              : 
     791              :    ! Constants to compare communicators
     792              :    INTEGER, PARAMETER, PUBLIC :: mp_comm_ident = 0
     793              :    INTEGER, PARAMETER, PUBLIC :: mp_comm_congruent = 1
     794              :    INTEGER, PARAMETER, PUBLIC :: mp_comm_similar = 2
     795              :    INTEGER, PARAMETER, PUBLIC :: mp_comm_unequal = 3
     796              :    INTEGER, PARAMETER, PUBLIC :: mp_comm_compare_default = -1
     797              : 
     798              :    ! init and error
     799              :    PUBLIC :: mp_world_init, mp_world_finalize
     800              :    PUBLIC :: mp_abort
     801              : 
     802              :    ! informational / generation of sub comms
     803              :    PUBLIC :: mp_dims_create
     804              :    PUBLIC :: cp2k_is_parallel
     805              : 
     806              :    ! message passing
     807              :    PUBLIC :: mp_waitall, mp_waitany
     808              :    PUBLIC :: mp_testall, mp_testany
     809              : 
     810              :    ! Memory management
     811              :    PUBLIC :: mp_allocate, mp_deallocate
     812              : 
     813              :    ! I/O
     814              :    PUBLIC :: mp_file_delete
     815              :    PUBLIC :: mp_file_get_amode
     816              : 
     817              :    ! some 'advanced types' currently only used for dbcsr
     818              :    PUBLIC :: mp_type_descriptor_type
     819              :    PUBLIC :: mp_type_make
     820              :    PUBLIC :: mp_type_size
     821              : 
     822              :    ! vector types
     823              :    PUBLIC :: mp_type_indexed_make_r, mp_type_indexed_make_d, &
     824              :              mp_type_indexed_make_c, mp_type_indexed_make_z
     825              : 
     826              :    ! More I/O types and routines: variable spaced data using bytes for spacings
     827              :    PUBLIC :: mp_file_descriptor_type
     828              :    PUBLIC :: mp_file_type_free
     829              :    PUBLIC :: mp_file_type_hindexed_make_chv
     830              :    PUBLIC :: mp_file_type_set_view_chv
     831              : 
     832              :    PUBLIC :: mp_get_library_version
     833              : 
     834              :    ! assumed to be private
     835              : 
     836              :    INTERFACE mp_waitall
     837              :       MODULE PROCEDURE mp_waitall_1, mp_waitall_2
     838              :    END INTERFACE
     839              : 
     840              :    INTERFACE mp_testall
     841              :       MODULE PROCEDURE mp_testall_tv
     842              :    END INTERFACE
     843              : 
     844              :    INTERFACE mp_testany
     845              :       MODULE PROCEDURE mp_testany_1, mp_testany_2
     846              :    END INTERFACE
     847              : 
     848              :    INTERFACE mp_type_free
     849              :       MODULE PROCEDURE mp_type_free_m, mp_type_free_v
     850              :    END INTERFACE
     851              : 
     852              :    !
     853              :    ! interfaces to deal easily with scalars / vectors / matrices / ...
     854              :    ! of the different types (integers, doubles, logicals, characters)
     855              :    !
     856              :    INTERFACE mp_allocate
     857              :       MODULE PROCEDURE mp_allocate_i, &
     858              :          mp_allocate_l, &
     859              :          mp_allocate_r, &
     860              :          mp_allocate_d, &
     861              :          mp_allocate_c, &
     862              :          mp_allocate_z
     863              :    END INTERFACE
     864              : 
     865              :    INTERFACE mp_deallocate
     866              :       MODULE PROCEDURE mp_deallocate_i, &
     867              :          mp_deallocate_l, &
     868              :          mp_deallocate_r, &
     869              :          mp_deallocate_d, &
     870              :          mp_deallocate_c, &
     871              :          mp_deallocate_z
     872              :    END INTERFACE
     873              : 
     874              :    INTERFACE mp_type_make
     875              :       MODULE PROCEDURE mp_type_make_struct
     876              :       MODULE PROCEDURE mp_type_make_i, mp_type_make_l, &
     877              :          mp_type_make_r, mp_type_make_d, &
     878              :          mp_type_make_c, mp_type_make_z
     879              :    END INTERFACE
     880              : 
     881              :    INTERFACE mp_alloc_mem
     882              :       MODULE PROCEDURE mp_alloc_mem_i, mp_alloc_mem_l, &
     883              :          mp_alloc_mem_d, mp_alloc_mem_z, &
     884              :          mp_alloc_mem_r, mp_alloc_mem_c
     885              :    END INTERFACE
     886              : 
     887              :    INTERFACE mp_free_mem
     888              :       MODULE PROCEDURE mp_free_mem_i, mp_free_mem_l, &
     889              :          mp_free_mem_d, mp_free_mem_z, &
     890              :          mp_free_mem_r, mp_free_mem_c
     891              :    END INTERFACE
     892              : 
     893              : ! Type declarations
     894              :    TYPE mp_indexing_meta_type
     895              :       INTEGER, DIMENSION(:), POINTER :: index => NULL(), chunks => NULL()
     896              :    END TYPE mp_indexing_meta_type
     897              : 
     898              :    TYPE mp_type_descriptor_type
     899              :       MPI_DATA_TYPE :: type_handle = mp_datatype_null_handle
     900              :       INTEGER :: length = -1
     901              : #if defined(__parallel)
     902              :       INTEGER(kind=mpi_address_kind) :: base = -1
     903              : #endif
     904              :       INTEGER(kind=int_4), DIMENSION(:), POINTER :: data_i => NULL()
     905              :       INTEGER(kind=int_8), DIMENSION(:), POINTER :: data_l => NULL()
     906              :       REAL(kind=real_4), DIMENSION(:), POINTER :: data_r => NULL()
     907              :       REAL(kind=real_8), DIMENSION(:), POINTER :: data_d => NULL()
     908              :       COMPLEX(kind=real_4), DIMENSION(:), POINTER :: data_c => NULL()
     909              :       COMPLEX(kind=real_8), DIMENSION(:), POINTER :: data_z => NULL()
     910              :       TYPE(mp_type_descriptor_type), DIMENSION(:), POINTER :: subtype => NULL()
     911              :       INTEGER :: vector_descriptor(2) = -1
     912              :       LOGICAL :: has_indexing = .FALSE.
     913              :       TYPE(mp_indexing_meta_type) :: index_descriptor = mp_indexing_meta_type()
     914              :    END TYPE mp_type_descriptor_type
     915              : 
     916              :    TYPE mp_file_indexing_meta_type
     917              :       INTEGER, DIMENSION(:), POINTER   :: index => NULL()
     918              :       INTEGER(kind=file_offset), &
     919              :          DIMENSION(:), POINTER         :: chunks => NULL()
     920              :    END TYPE mp_file_indexing_meta_type
     921              : 
     922              :    TYPE mp_file_descriptor_type
     923              :       MPI_DATA_TYPE :: type_handle = mp_datatype_null_handle
     924              :       INTEGER                          :: length = -1
     925              :       LOGICAL                          :: has_indexing = .FALSE.
     926              :       TYPE(mp_file_indexing_meta_type) :: index_descriptor = mp_file_indexing_meta_type()
     927              :    END TYPE
     928              : 
     929              :    ! we make some assumptions on the length of INTEGERS, REALS and LOGICALS
     930              :    INTEGER, PARAMETER :: intlen = BIT_SIZE(0)/8
     931              :    INTEGER, PARAMETER :: reallen = 8
     932              :    INTEGER, PARAMETER :: loglen = BIT_SIZE(0)/8
     933              :    INTEGER, PARAMETER :: charlen = 1
     934              : 
     935              :    LOGICAL, PUBLIC, SAVE :: mp_collect_timings = .FALSE.
     936              : 
     937              : CONTAINS
     938              : 
     939              :    #:mute
     940              :       #:set types = ["comm", "request", "win", "file", "info"]
     941              :    #:endmute
     942              :    #:for type in types
     943      2794143 :       LOGICAL FUNCTION mp_${type}$_op_eq(${type}$1, ${type}$2)
     944              :          CLASS(mp_${type}$_type), INTENT(IN) :: ${type}$1, ${type}$2
     945              : #if defined(__parallel) && defined(__MPI_F08)
     946      2794143 :          mp_${type}$_op_eq = (${type}$1%handle%mpi_val == ${type}$2%handle%mpi_val)
     947              : #else
     948              :          mp_${type}$_op_eq = (${type}$1%handle == ${type}$2%handle)
     949              : #endif
     950      2794143 :       END FUNCTION mp_${type}$_op_eq
     951              : 
     952      2998395 :       LOGICAL FUNCTION mp_${type}$_op_neq(${type}$1, ${type}$2)
     953              :          CLASS(mp_${type}$_type), INTENT(IN) :: ${type}$1, ${type}$2
     954              : #if defined(__parallel) && defined(__MPI_F08)
     955      2998395 :          mp_${type}$_op_neq = (${type}$1%handle%mpi_val /= ${type}$2%handle%mpi_val)
     956              : #else
     957              :          mp_${type}$_op_neq = (${type}$1%handle /= ${type}$2%handle)
     958              : #endif
     959      2998395 :       END FUNCTION mp_${type}$_op_neq
     960              : 
     961      5471549 :       ELEMENTAL #{if type=="comm"}#IMPURE #{endif}#SUBROUTINE mp_${type}$_type_set_handle(this, handle #{if type=="comm"}#, ndims#{endif}#)
     962              :       CLASS(mp_${type}$_type), INTENT(INOUT) :: this
     963              :       INTEGER, INTENT(IN) :: handle
     964              :       #:if type=="comm"
     965              :          INTEGER, INTENT(IN), OPTIONAL :: ndims
     966              :       #:endif
     967              : 
     968              : #if defined(__parallel) && defined(__MPI_F08)
     969      5471549 :       this%handle%mpi_val = handle
     970              : #else
     971              :       this%handle = handle
     972              : #endif
     973              : 
     974              :       #:if type=="comm"
     975              :          SELECT TYPE (this)
     976              :          CLASS IS (mp_cart_type)
     977            0 :             IF (.NOT. PRESENT(ndims)) &
     978              :                CALL cp_abort(__LOCATION__, &
     979            0 :                              "Setup of a cartesian communicator requires information on the number of dimensions!")
     980              :          END SELECT
     981      5467833 :          IF (PRESENT(ndims)) this%ndims = ndims
     982      5467833 :          CALL this%init()
     983              :       #:endif
     984              : 
     985      5471549 :       END SUBROUTINE mp_${type}$_type_set_handle
     986              : 
     987      2230252 :       ELEMENTAL FUNCTION mp_${type}$_type_get_handle(this) RESULT(handle)
     988              :          CLASS(mp_${type}$_type), INTENT(IN) :: this
     989              :          INTEGER :: handle
     990              : 
     991              : #if defined(__parallel) && defined(__MPI_F08)
     992      2230252 :          handle = this%handle%mpi_val
     993              : #else
     994              :          handle = this%handle
     995              : #endif
     996      2230252 :       END FUNCTION mp_${type}$_type_get_handle
     997              :       #:endfor
     998              : 
     999        24304 :       FUNCTION mp_comm_get_tag_ub(comm) RESULT(tag_ub)
    1000              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    1001              :          INTEGER :: tag_ub
    1002              : 
    1003              : #if defined(__parallel)
    1004              :          INTEGER :: ierr
    1005              :          LOGICAL :: flag
    1006              :          INTEGER(KIND=MPI_ADDRESS_KIND) :: attrval
    1007              : 
    1008        24304 :          CALL MPI_COMM_GET_ATTR(comm%handle, MPI_TAG_UB, attrval, flag, ierr)
    1009        24304 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_get_attr @ mp_comm_get_tag_ub")
    1010        24304 :          IF (.NOT. flag) CPABORT("Upper bound of tags not available!")
    1011        24304 :          tag_ub = INT(attrval, KIND=KIND(tag_ub))
    1012              : #else
    1013              :          MARK_USED(comm)
    1014              :          tag_ub = HUGE(1)
    1015              : #endif
    1016        24304 :       END FUNCTION mp_comm_get_tag_ub
    1017              : 
    1018            0 :       FUNCTION mp_comm_get_host_rank(comm) RESULT(host_rank)
    1019              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    1020              :          INTEGER :: host_rank
    1021              : 
    1022              : #if defined(__parallel)
    1023              :          INTEGER :: ierr
    1024              :          LOGICAL :: flag
    1025              :          INTEGER(KIND=MPI_ADDRESS_KIND) :: attrval
    1026              : 
    1027            0 :          CALL MPI_COMM_GET_ATTR(comm%handle, MPI_HOST, attrval, flag, ierr)
    1028            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_get_attr @ mp_comm_get_host_rank")
    1029            0 :          IF (.NOT. flag) CPABORT("Host process rank not available!")
    1030            0 :          host_rank = INT(attrval, KIND=KIND(host_rank))
    1031              : #else
    1032              :          MARK_USED(comm)
    1033              :          host_rank = 0
    1034              : #endif
    1035            0 :       END FUNCTION mp_comm_get_host_rank
    1036              : 
    1037            0 :       FUNCTION mp_comm_get_io_rank(comm) RESULT(io_rank)
    1038              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    1039              :          INTEGER :: io_rank
    1040              : 
    1041              : #if defined(__parallel)
    1042              :          INTEGER :: ierr
    1043              :          LOGICAL :: flag
    1044              :          INTEGER(KIND=MPI_ADDRESS_KIND) :: attrval
    1045              : 
    1046            0 :          CALL MPI_COMM_GET_ATTR(comm%handle, MPI_IO, attrval, flag, ierr)
    1047            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_get_attr @ mp_comm_get_io_rank")
    1048            0 :          IF (.NOT. flag) CPABORT("IO rank not available!")
    1049            0 :          io_rank = INT(attrval, KIND=KIND(io_rank))
    1050              : #else
    1051              :          MARK_USED(comm)
    1052              :          io_rank = 0
    1053              : #endif
    1054            0 :       END FUNCTION mp_comm_get_io_rank
    1055              : 
    1056            0 :       FUNCTION mp_comm_get_wtime_is_global(comm) RESULT(wtime_is_global)
    1057              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    1058              :          LOGICAL :: wtime_is_global
    1059              : 
    1060              : #if defined(__parallel)
    1061              :          INTEGER :: ierr
    1062              :          LOGICAL :: flag
    1063              :          INTEGER(KIND=MPI_ADDRESS_KIND) :: attrval
    1064              : 
    1065            0 :          CALL MPI_COMM_GET_ATTR(comm%handle, MPI_TAG_UB, attrval, flag, ierr)
    1066            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_get_attr @ mp_comm_get_wtime_is_global")
    1067            0 :          IF (.NOT. flag) CPABORT("Synchronization state of WTIME not available!")
    1068            0 :          wtime_is_global = (attrval == 1_MPI_ADDRESS_KIND)
    1069              : #else
    1070              :          MARK_USED(comm)
    1071              :          wtime_is_global = .TRUE.
    1072              : #endif
    1073            0 :       END FUNCTION mp_comm_get_wtime_is_global
    1074              : 
    1075              : ! **************************************************************************************************
    1076              : !> \brief initializes the system default communicator
    1077              : !> \param mp_comm [output] : handle of the default communicator
    1078              : !> \par History
    1079              : !>      2.2004 created [Joost VandeVondele ]
    1080              : !> \note
    1081              : !>      should only be called once
    1082              : ! **************************************************************************************************
    1083         9302 :       SUBROUTINE mp_world_init(mp_comm)
    1084              :          CLASS(mp_comm_type), INTENT(OUT)                     :: mp_comm
    1085              : #if defined(__parallel)
    1086              :          INTEGER                                  :: ierr, provided_tsl
    1087              : #if defined(__MIMIC)
    1088              :          INTEGER                                  :: mimic_handle
    1089              : #endif
    1090              : 
    1091         9302 : !$OMP MASTER
    1092              : #if defined(__DLAF)
    1093              :          ! DLA-Future requires that the MPI library supports THREAD_MULTIPLE mode
    1094              :          CALL mpi_init_thread(MPI_THREAD_MULTIPLE, provided_tsl, ierr)
    1095              :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_init_thread @ mp_world_init")
    1096              :          IF (provided_tsl < MPI_THREAD_MULTIPLE) THEN
    1097              :             CALL mp_stop(0, "MPI library does not support the requested level of threading (MPI_THREAD_MULTIPLE), "// &
    1098              :                          "required by DLA-Future. Build CP2K without DLA-Future.")
    1099              :          END IF
    1100              : #else
    1101         9302 :          CALL mpi_init_thread(MPI_THREAD_SERIALIZED, provided_tsl, ierr)
    1102         9302 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_init_thread @ mp_world_init")
    1103         9302 :          IF (provided_tsl < MPI_THREAD_SERIALIZED) THEN
    1104            0 :             CALL mp_stop(0, "MPI library does not support the requested level of threading (MPI_THREAD_SERIALIZED).")
    1105              :          END IF
    1106              : #endif
    1107              : !$OMP END MASTER
    1108         9302 :          CALL mpi_comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN, ierr)
    1109         9302 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_set_errhandler @ mp_world_init")
    1110              : #endif
    1111         9302 :          debug_comm_count = 1
    1112         9302 :          mp_comm = mp_comm_world
    1113              : #if defined(__MIMIC)
    1114         9302 :          mimic_handle = mp_comm%get_handle()
    1115         9302 :          CALL mcl_initialize(mimic_handle)
    1116         9302 :          CALL mp_comm%set_handle(mimic_handle)
    1117              : #if defined(__MPI_F08)
    1118         9302 :          mimic_comm_world%mpi_val = mimic_handle
    1119              : #else
    1120              :          mimic_comm_world = mimic_handle
    1121              : #endif
    1122              : #endif
    1123         9302 :          CALL mp_comm%init()
    1124         9302 :          CALL add_mp_perf_env()
    1125         9302 :       END SUBROUTINE mp_world_init
    1126              : 
    1127              : ! **************************************************************************************************
    1128              : !> \brief re-create the system default communicator with a different MPI
    1129              : !>        rank order
    1130              : !> \param mp_comm [output] : handle of the default communicator
    1131              : !> \param mp_new_comm ...
    1132              : !> \param ranks_order ...
    1133              : !> \par History
    1134              : !>      1.2012 created [ Christiane Pousa ]
    1135              : !> \note
    1136              : !>      should only be called once, at very beginning of CP2K run
    1137              : ! **************************************************************************************************
    1138          744 :       SUBROUTINE mp_reordering(mp_comm, mp_new_comm, ranks_order)
    1139              :          CLASS(mp_comm_type), INTENT(IN)                      :: mp_comm
    1140              :          CLASS(mp_comm_type), INTENT(out)                     :: mp_new_comm
    1141              :          INTEGER, DIMENSION(:), CONTIGUOUS, INTENT(IN)                    :: ranks_order
    1142              : 
    1143              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_reordering'
    1144              : 
    1145              :          INTEGER                                  :: handle, ierr
    1146              : #if defined(__parallel)
    1147              :          MPI_GROUP_TYPE                                  :: newgroup, oldgroup
    1148              : #endif
    1149              : 
    1150          744 :          CALL mp_timeset(routineN, handle)
    1151              :          ierr = 0
    1152              : #if defined(__parallel)
    1153              : 
    1154          744 :          CALL mpi_comm_group(mp_comm%handle, oldgroup, ierr)
    1155          744 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_group @ mp_reordering")
    1156          744 :          CALL mpi_group_incl(oldgroup, SIZE(ranks_order), ranks_order, newgroup, ierr)
    1157          744 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_group_incl @ mp_reordering")
    1158              : 
    1159          744 :          CALL mpi_comm_create(mp_comm%handle, newgroup, mp_new_comm%handle, ierr)
    1160          744 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_create @ mp_reordering")
    1161              : 
    1162          744 :          CALL mpi_group_free(oldgroup, ierr)
    1163          744 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_group_free @ mp_reordering")
    1164          744 :          CALL mpi_group_free(newgroup, ierr)
    1165          744 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_group_free @ mp_reordering")
    1166              : 
    1167          744 :          CALL add_perf(perf_id=1, count=1)
    1168              : #else
    1169              :          MARK_USED(mp_comm)
    1170              :          MARK_USED(ranks_order)
    1171              :          mp_new_comm%handle = mp_comm_default_handle
    1172              : #endif
    1173          744 :          debug_comm_count = debug_comm_count + 1
    1174          744 :          CALL mp_new_comm%init()
    1175          744 :          CALL mp_timestop(handle)
    1176          744 :       END SUBROUTINE mp_reordering
    1177              : 
    1178              : ! **************************************************************************************************
    1179              : !> \brief finalizes the system default communicator
    1180              : !> \par History
    1181              : !>      2.2004 created [Joost VandeVondele]
    1182              : ! **************************************************************************************************
    1183        18604 :       SUBROUTINE mp_world_finalize()
    1184              : 
    1185              :          CHARACTER(LEN=default_string_length) :: debug_comm_count_char
    1186              : #if defined(__parallel)
    1187              :          INTEGER                              :: ierr
    1188              : #if defined(__MIMIC)
    1189         9302 :          CALL mpi_barrier(mimic_comm_world, ierr)
    1190              : #else
    1191              :          CALL mpi_barrier(MPI_COMM_WORLD, ierr) ! call mpi directly to avoid 0 stack pointer
    1192              : #endif
    1193              : #endif
    1194         9302 :          CALL rm_mp_perf_env()
    1195              : 
    1196         9302 :          debug_comm_count = debug_comm_count - 1
    1197              : #if defined(__parallel)
    1198         9302 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_barrier @ mp_world_finalize")
    1199              : #endif
    1200         9302 :          IF (debug_comm_count /= 0) THEN
    1201              :             ! A bug, we're leaking or double-freeing communicators. Needs to be fixed where the leak happens.
    1202              :             ! Memory leak checking might be helpful to locate the culprit
    1203            0 :             WRITE (unit=debug_comm_count_char, FMT='(I2)') debug_comm_count
    1204              :             CALL cp_abort(__LOCATION__, "mp_world_finalize: assert failed:"// &
    1205            0 :                           " leaking communicators "//ADJUSTL(TRIM(debug_comm_count_char)))
    1206              :          END IF
    1207              : #if defined(__parallel)
    1208         9302 :          CALL mpi_finalize(ierr)
    1209         9302 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_finalize @ mp_world_finalize")
    1210              : #endif
    1211              : 
    1212         9302 :       END SUBROUTINE mp_world_finalize
    1213              : 
    1214              : ! all the following routines should work for a given communicator, not MPI_WORLD
    1215              : 
    1216              : ! **************************************************************************************************
    1217              : !> \brief globally stops all tasks
    1218              : !>       this is intended to be low level, most of CP2K should call cp_abort()
    1219              : ! **************************************************************************************************
    1220            0 :       SUBROUTINE mp_abort()
    1221              :          INTEGER                                            :: ierr
    1222              : #if defined(__MIMIC)
    1223              :          LOGICAL                                            :: mcl_initialized
    1224              : #endif
    1225              : 
    1226            0 :          ierr = 0
    1227              : 
    1228              : #if !defined(__NO_ABORT)
    1229              : #if defined(__parallel)
    1230              : #if defined(__MIMIC)
    1231              :          CALL mcl_is_initialized(mcl_initialized)
    1232              :          IF (mcl_initialized) CALL mcl_abort(1, ierr)
    1233              : #endif
    1234              :          CALL mpi_abort(MPI_COMM_WORLD, 1, ierr)
    1235              : #else
    1236              :          CALL m_abort()
    1237              : #endif
    1238              : #endif
    1239              :          ! this routine never returns and levels with non-zero exit code
    1240            0 :          STOP 1
    1241              :       END SUBROUTINE mp_abort
    1242              : 
    1243              : ! **************************************************************************************************
    1244              : !> \brief stops *after an mpi error* translating the error code
    1245              : !> \param ierr an error code * returned by an mpi call *
    1246              : !> \param prg_code ...
    1247              : !> \note
    1248              : !>       this function is private to message_passing.F
    1249              : ! **************************************************************************************************
    1250            0 :       SUBROUTINE mp_stop(ierr, prg_code)
    1251              :          INTEGER, INTENT(IN)                        :: ierr
    1252              :          CHARACTER(LEN=*), INTENT(IN)               :: prg_code
    1253              : 
    1254              : #if defined(__parallel)
    1255              :          INTEGER                                    :: istat, len
    1256              :          CHARACTER(LEN=MPI_MAX_ERROR_STRING)        :: error_string
    1257              :          CHARACTER(LEN=MPI_MAX_ERROR_STRING + 512)  :: full_error
    1258              : #else
    1259              :          CHARACTER(LEN=512)                         :: full_error
    1260              : #endif
    1261              : 
    1262              : #if defined(__parallel)
    1263            0 :          CALL mpi_error_string(ierr, error_string, len, istat)
    1264            0 :          WRITE (full_error, '(A,I0,A)') ' MPI error ', ierr, ' in '//TRIM(prg_code)//' : '//error_string(1:len)
    1265              : #else
    1266              :          WRITE (full_error, '(A,I0,A)') ' MPI error (!?) ', ierr, ' in '//TRIM(prg_code)
    1267              : #endif
    1268              : 
    1269            0 :          CPABORT(full_error)
    1270              : 
    1271            0 :       END SUBROUTINE mp_stop
    1272              : 
    1273              : ! **************************************************************************************************
    1274              : !> \brief synchronizes with a barrier a given group of mpi tasks
    1275              : !> \param group mpi communicator
    1276              : ! **************************************************************************************************
    1277      6631788 :       SUBROUTINE mp_sync(comm)
    1278              :          CLASS(mp_comm_type), INTENT(IN)                                :: comm
    1279              : 
    1280              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_sync'
    1281              : 
    1282              :          INTEGER                                            :: handle, ierr
    1283              : 
    1284              :          ierr = 0
    1285      3315894 :          CALL mp_timeset(routineN, handle)
    1286              : 
    1287              : #if defined(__parallel)
    1288      3315894 :          CALL mpi_barrier(comm%handle, ierr)
    1289      3315894 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_barrier @ mp_sync")
    1290      3315894 :          CALL add_perf(perf_id=5, count=1)
    1291              : #else
    1292              :          MARK_USED(comm)
    1293              : #endif
    1294      3315894 :          CALL mp_timestop(handle)
    1295              : 
    1296      3315894 :       END SUBROUTINE mp_sync
    1297              : 
    1298              : ! **************************************************************************************************
    1299              : !> \brief synchronizes with a barrier a given group of mpi tasks
    1300              : !> \param comm mpi communicator
    1301              : !> \param request ...
    1302              : ! **************************************************************************************************
    1303            0 :       SUBROUTINE mp_isync(comm, request)
    1304              :          CLASS(mp_comm_type), INTENT(IN)                    :: comm
    1305              :          TYPE(mp_request_type), INTENT(OUT)                 :: request
    1306              : 
    1307              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_isync'
    1308              : 
    1309              :          INTEGER                                            :: handle, ierr
    1310              : 
    1311              :          ierr = 0
    1312            0 :          CALL mp_timeset(routineN, handle)
    1313              : 
    1314              : #if defined(__parallel)
    1315            0 :          CALL mpi_ibarrier(comm%handle, request%handle, ierr)
    1316            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_ibarrier @ mp_isync")
    1317            0 :          CALL add_perf(perf_id=26, count=1)
    1318              : #else
    1319              :          MARK_USED(comm)
    1320              :          request = mp_request_null
    1321              : #endif
    1322            0 :          CALL mp_timestop(handle)
    1323              : 
    1324            0 :       END SUBROUTINE mp_isync
    1325              : 
    1326              : ! **************************************************************************************************
    1327              : !> \brief returns task id for a given mpi communicator
    1328              : !> \param taskid The ID of the communicator
    1329              : !> \param comm mpi communicator
    1330              : ! **************************************************************************************************
    1331     34752650 :       SUBROUTINE mp_comm_rank(taskid, comm)
    1332              : 
    1333              :          INTEGER, INTENT(OUT)                               :: taskid
    1334              :          CLASS(mp_comm_type), INTENT(IN)                    :: comm
    1335              : 
    1336              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_comm_rank'
    1337              : 
    1338              :          INTEGER                                            :: handle
    1339              : #if defined(__parallel)
    1340              :          INTEGER :: ierr
    1341              : #endif
    1342              : 
    1343     17376325 :          CALL mp_timeset(routineN, handle)
    1344              : 
    1345              : #if defined(__parallel)
    1346     17376325 :          CALL mpi_comm_rank(comm%handle, taskid, ierr)
    1347     17376325 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_rank @ mp_comm_rank")
    1348              : #else
    1349              :          MARK_USED(comm)
    1350              :          taskid = 0
    1351              : #endif
    1352     17376325 :          CALL mp_timestop(handle)
    1353              : 
    1354     17376325 :       END SUBROUTINE mp_comm_rank
    1355              : 
    1356              : ! **************************************************************************************************
    1357              : !> \brief returns number of tasks for a given mpi communicator
    1358              : !> \param numtask ...
    1359              : !> \param comm mpi communicator
    1360              : ! **************************************************************************************************
    1361     34752650 :       SUBROUTINE mp_comm_size(numtask, comm)
    1362              : 
    1363              :          INTEGER, INTENT(OUT)                               :: numtask
    1364              :          CLASS(mp_comm_type), INTENT(IN)                    :: comm
    1365              : 
    1366              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_comm_size'
    1367              : 
    1368              :          INTEGER                                            :: handle
    1369              : #if defined(__parallel)
    1370              :          INTEGER :: ierr
    1371              : #endif
    1372              : 
    1373     17376325 :          CALL mp_timeset(routineN, handle)
    1374              : 
    1375              : #if defined(__parallel)
    1376     17376325 :          CALL mpi_comm_size(comm%handle, numtask, ierr)
    1377     17376325 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_rank @ mp_comm_size")
    1378              : #else
    1379              :          MARK_USED(comm)
    1380              :          numtask = 1
    1381              : #endif
    1382     17376325 :          CALL mp_timestop(handle)
    1383              : 
    1384     17376325 :       END SUBROUTINE mp_comm_size
    1385              : 
    1386              : ! **************************************************************************************************
    1387              : !> \brief returns info for a given Cartesian MPI communicator
    1388              : !> \param comm ...
    1389              : !> \param ndims ...
    1390              : !> \param dims ...
    1391              : !> \param task_coor ...
    1392              : !> \param periods ...
    1393              : ! **************************************************************************************************
    1394      8727843 :       SUBROUTINE mp_cart_get(comm, dims, task_coor, periods)
    1395              : 
    1396              :          CLASS(mp_cart_type), INTENT(IN)                    :: comm
    1397              :          INTEGER, INTENT(OUT), OPTIONAL                     :: dims(comm%ndims), task_coor(comm%ndims)
    1398              :          LOGICAL, INTENT(out), OPTIONAL                     :: periods(comm%ndims)
    1399              : 
    1400              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_cart_get'
    1401              : 
    1402              :          INTEGER                                            :: handle
    1403              : #if defined(__parallel)
    1404              :          INTEGER :: ierr
    1405     17455686 :          INTEGER                               :: my_dims(comm%ndims), my_task_coor(comm%ndims)
    1406     17455686 :          LOGICAL                               :: my_periods(comm%ndims)
    1407              : #endif
    1408              : 
    1409      8727843 :          CALL mp_timeset(routineN, handle)
    1410              : 
    1411              : #if defined(__parallel)
    1412      8727843 :          CALL mpi_cart_get(comm%handle, comm%ndims, my_dims, my_periods, my_task_coor, ierr)
    1413      8727843 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_cart_get @ mp_cart_get")
    1414     34912198 :          IF (PRESENT(dims)) dims = my_dims
    1415     34912198 :          IF (PRESENT(task_coor)) task_coor = my_task_coor
    1416     34912198 :          IF (PRESENT(periods)) periods = my_periods
    1417              : #else
    1418              :          MARK_USED(comm)
    1419              :          IF (PRESENT(task_coor)) task_coor = 0
    1420              :          IF (PRESENT(dims)) dims = 1
    1421              :          IF (PRESENT(periods)) periods = .FALSE.
    1422              : #endif
    1423      8727843 :          CALL mp_timestop(handle)
    1424              : 
    1425      8727843 :       END SUBROUTINE mp_cart_get
    1426              : 
    1427            0 :       INTEGER ELEMENTAL FUNCTION mp_comm_get_ndims(comm)
    1428              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    1429              : 
    1430            0 :          mp_comm_get_ndims = comm%ndims
    1431              : 
    1432            0 :       END FUNCTION
    1433              : 
    1434              : ! **************************************************************************************************
    1435              : !> \brief creates a cartesian communicator from any communicator
    1436              : !> \param comm_old ...
    1437              : !> \param ndims ...
    1438              : !> \param dims ...
    1439              : !> \param pos ...
    1440              : !> \param comm_cart ...
    1441              : ! **************************************************************************************************
    1442      1639256 :       SUBROUTINE mp_cart_create(comm_old, ndims, dims, comm_cart)
    1443              : 
    1444              :          CLASS(mp_comm_type), INTENT(IN) :: comm_old
    1445              :          INTEGER, INTENT(IN)                      :: ndims
    1446              :          INTEGER, INTENT(INOUT)                   :: dims(ndims)
    1447              :          CLASS(mp_cart_type), INTENT(OUT) :: comm_cart
    1448              : 
    1449              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_cart_create'
    1450              : 
    1451              :          INTEGER                                  :: handle, ierr
    1452              : #if defined(__parallel)
    1453      1639256 :          LOGICAL, DIMENSION(1:ndims)              :: period
    1454              :          LOGICAL                                  :: reorder
    1455              : #endif
    1456              : 
    1457      1639256 :          ierr = 0
    1458      1639256 :          CALL mp_timeset(routineN, handle)
    1459              : 
    1460      1639256 :          comm_cart%handle = comm_old%handle
    1461              : #if defined(__parallel)
    1462              : 
    1463      4491760 :          IF (ANY(dims == 0)) CALL mpi_dims_create(comm_old%num_pe, ndims, dims, ierr)
    1464      1639256 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_dims_create @ mp_cart_create")
    1465              : 
    1466              :          ! FIX ME.  Quick hack to avoid problems with realspace grids for compilers
    1467              :          ! like IBM that actually reorder the processors when creating the new
    1468              :          ! communicator
    1469      1639256 :          reorder = .FALSE.
    1470      4918594 :          period = .TRUE.
    1471              :          CALL mpi_cart_create(comm_old%handle, ndims, dims, period, reorder, comm_cart%handle, &
    1472      1639256 :                               ierr)
    1473      1639256 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_cart_create @ mp_cart_create")
    1474      1639256 :          CALL add_perf(perf_id=1, count=1)
    1475              : #else
    1476              :          dims = 1
    1477              :          comm_cart%handle = mp_comm_default_handle
    1478              : #endif
    1479      1639256 :          comm_cart%ndims = ndims
    1480      1639256 :          debug_comm_count = debug_comm_count + 1
    1481      1639256 :          CALL comm_cart%init()
    1482      1639256 :          CALL mp_timestop(handle)
    1483              : 
    1484      1639256 :       END SUBROUTINE mp_cart_create
    1485              : 
    1486              : ! **************************************************************************************************
    1487              : !> \brief wrapper to MPI_Cart_coords
    1488              : !> \param comm ...
    1489              : !> \param rank ...
    1490              : !> \param coords ...
    1491              : ! **************************************************************************************************
    1492        58784 :       SUBROUTINE mp_cart_coords(comm, rank, coords)
    1493              : 
    1494              :          CLASS(mp_cart_type), INTENT(IN) :: comm
    1495              :          INTEGER, INTENT(IN)                                :: rank
    1496              :          INTEGER, DIMENSION(:), INTENT(OUT)                 :: coords
    1497              : 
    1498              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_cart_coords'
    1499              : 
    1500              :          INTEGER                                            :: handle, ierr, m
    1501              : 
    1502        58784 :          ierr = 0
    1503        58784 :          CALL mp_timeset(routineN, handle)
    1504              : 
    1505        58784 :          m = SIZE(coords)
    1506              : #if defined(__parallel)
    1507        58784 :          CALL mpi_cart_coords(comm%handle, rank, m, coords, ierr)
    1508        58784 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_cart_coords @ mp_cart_coords")
    1509              : #else
    1510              :          coords = 0
    1511              :          MARK_USED(rank)
    1512              :          MARK_USED(comm)
    1513              : #endif
    1514        58784 :          CALL mp_timestop(handle)
    1515              : 
    1516        58784 :       END SUBROUTINE mp_cart_coords
    1517              : 
    1518              : ! **************************************************************************************************
    1519              : !> \brief wrapper to MPI_Comm_compare
    1520              : !> \param comm1 ...
    1521              : !> \param comm2 ...
    1522              : !> \param res ...
    1523              : ! **************************************************************************************************
    1524         4520 :       FUNCTION mp_comm_compare(comm1, comm2) RESULT(res)
    1525              : 
    1526              :          CLASS(mp_comm_type), INTENT(IN)                    :: comm1, comm2
    1527              :          INTEGER                                            :: res
    1528              : 
    1529              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_comm_compare'
    1530              : 
    1531              :          INTEGER                                            :: handle
    1532              : #if defined(__parallel)
    1533              :          INTEGER :: ierr, iout
    1534              : #endif
    1535              : 
    1536         2260 :          CALL mp_timeset(routineN, handle)
    1537              : 
    1538         2260 :          res = 0
    1539              : #if defined(__parallel)
    1540         2260 :          CALL mpi_comm_compare(comm1%handle, comm2%handle, iout, ierr)
    1541         2260 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_compare @ mp_comm_compare")
    1542              :          SELECT CASE (iout)
    1543              :          CASE (MPI_IDENT)
    1544         2260 :             res = mp_comm_ident
    1545              :          CASE (MPI_CONGRUENT)
    1546         2260 :             res = mp_comm_congruent
    1547              :          CASE (MPI_SIMILAR)
    1548            0 :             res = mp_comm_similar
    1549              :          CASE (MPI_UNEQUAL)
    1550            0 :             res = mp_comm_unequal
    1551              :          CASE default
    1552         2260 :             CPABORT("Unknown comparison state of the communicators!")
    1553              :          END SELECT
    1554              : #else
    1555              :          MARK_USED(comm1)
    1556              :          MARK_USED(comm2)
    1557              : #endif
    1558         2260 :          CALL mp_timestop(handle)
    1559              : 
    1560         2260 :       END FUNCTION mp_comm_compare
    1561              : 
    1562              : ! **************************************************************************************************
    1563              : !> \brief wrapper to MPI_Cart_sub
    1564              : !> \param comm ...
    1565              : !> \param rdim ...
    1566              : !> \param sub_comm ...
    1567              : ! **************************************************************************************************
    1568         1652 :       SUBROUTINE mp_cart_sub(comm, rdim, sub_comm)
    1569              : 
    1570              :          CLASS(mp_cart_type), INTENT(IN)                                :: comm
    1571              :          LOGICAL, DIMENSION(:), CONTIGUOUS, INTENT(IN)                  :: rdim
    1572              :          CLASS(mp_cart_type), INTENT(OUT)                               :: sub_comm
    1573              : 
    1574              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_cart_sub'
    1575              : 
    1576              :          INTEGER                                            :: handle
    1577              : #if defined(__parallel)
    1578              :          INTEGER :: ierr
    1579              : #endif
    1580              : 
    1581         1652 :          CALL mp_timeset(routineN, handle)
    1582              : 
    1583              : #if defined(__parallel)
    1584         1652 :          CALL mpi_cart_sub(comm%handle, rdim, sub_comm%handle, ierr)
    1585         1652 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_cart_sub @ mp_cart_sub")
    1586              : #else
    1587              :          MARK_USED(comm)
    1588              :          MARK_USED(rdim)
    1589              :          sub_comm%handle = mp_comm_default_handle
    1590              : #endif
    1591         6608 :          sub_comm%ndims = COUNT(rdim)
    1592         1652 :          debug_comm_count = debug_comm_count + 1
    1593         1652 :          CALL sub_comm%init()
    1594         1652 :          CALL mp_timestop(handle)
    1595              : 
    1596         1652 :       END SUBROUTINE mp_cart_sub
    1597              : 
    1598              : ! **************************************************************************************************
    1599              : !> \brief wrapper to MPI_Comm_free
    1600              : !> \param comm ...
    1601              : ! **************************************************************************************************
    1602      3874331 :       SUBROUTINE mp_comm_free(comm)
    1603              : 
    1604              :          CLASS(mp_comm_type), INTENT(INOUT)                 :: comm
    1605              : 
    1606              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_comm_free'
    1607              : 
    1608              :          INTEGER                                            :: handle
    1609              :          LOGICAL :: free_comm
    1610              : #if defined(__parallel)
    1611              :          INTEGER :: ierr
    1612              : #endif
    1613              : 
    1614      3874331 :          free_comm = .TRUE.
    1615              :          SELECT TYPE (comm)
    1616              :          CLASS IS (mp_para_env_type)
    1617       945144 :             free_comm = .FALSE.
    1618       945144 :             IF (comm%ref_count <= 0) &
    1619            0 :                CPABORT("para_env%ref_count <= 0")
    1620       945144 :             comm%ref_count = comm%ref_count - 1
    1621       945144 :             IF (comm%ref_count <= 0) THEN
    1622       193920 :                free_comm = comm%owns_group
    1623              :             END IF
    1624              :          CLASS IS (mp_para_cart_type)
    1625          144 :             free_comm = .FALSE.
    1626          144 :             IF (comm%ref_count <= 0) &
    1627            0 :                CPABORT("para_cart%ref_count <= 0")
    1628          144 :             comm%ref_count = comm%ref_count - 1
    1629          144 :             IF (comm%ref_count <= 0) THEN
    1630          144 :                free_comm = comm%owns_group
    1631              :             END IF
    1632              :          END SELECT
    1633              : 
    1634      3874331 :          CALL mp_timeset(routineN, handle)
    1635              : 
    1636      3874331 :          IF (free_comm) THEN
    1637              : #if defined(__parallel)
    1638      3092962 :             CALL mpi_comm_free(comm%handle, ierr)
    1639      3092962 :             IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_free @ mp_comm_free")
    1640              : #else
    1641              :             comm%handle = mp_comm_null_handle
    1642              : #endif
    1643      3092962 :             debug_comm_count = debug_comm_count - 1
    1644              :          END IF
    1645              : 
    1646              :          SELECT TYPE (comm)
    1647              :          CLASS IS (mp_cart_type)
    1648      2189906 :             DEALLOCATE (comm%periodic, comm%mepos_cart, comm%num_pe_cart)
    1649              :          END SELECT
    1650              : 
    1651      3874331 :          CALL mp_timestop(handle)
    1652              : 
    1653      3874331 :       END SUBROUTINE mp_comm_free
    1654              : 
    1655              : ! **************************************************************************************************
    1656              : !> \brief check whether the environment exists
    1657              : !> \param para_env ...
    1658              : !> \return ...
    1659              : ! **************************************************************************************************
    1660       805728 :       ELEMENTAL LOGICAL FUNCTION mp_para_env_is_valid(para_env)
    1661              :          CLASS(mp_para_env_type), INTENT(IN) :: para_env
    1662              : 
    1663       805728 :          mp_para_env_is_valid = para_env%ref_count > 0
    1664              : 
    1665       805728 :       END FUNCTION mp_para_env_is_valid
    1666              : 
    1667              : ! **************************************************************************************************
    1668              : !> \brief increase the reference counter but ensure that you free it later
    1669              : !> \param para_env ...
    1670              : ! **************************************************************************************************
    1671       751224 :       ELEMENTAL SUBROUTINE mp_para_env_retain(para_env)
    1672              :          CLASS(mp_para_env_type), INTENT(INOUT) :: para_env
    1673              : 
    1674       751224 :          para_env%ref_count = para_env%ref_count + 1
    1675              : 
    1676       751224 :       END SUBROUTINE mp_para_env_retain
    1677              : 
    1678              : ! **************************************************************************************************
    1679              : !> \brief check whether the given environment is valid, i.e. existent
    1680              : !> \param cart ...
    1681              : !> \return ...
    1682              : ! **************************************************************************************************
    1683          144 :       ELEMENTAL LOGICAL FUNCTION mp_para_cart_is_valid(cart)
    1684              :          CLASS(mp_para_cart_type), INTENT(IN) :: cart
    1685              : 
    1686          144 :          mp_para_cart_is_valid = cart%ref_count > 0
    1687              : 
    1688          144 :       END FUNCTION mp_para_cart_is_valid
    1689              : 
    1690              : ! **************************************************************************************************
    1691              : !> \brief increase the reference counter, don't forget to free it later
    1692              : !> \param cart ...
    1693              : ! **************************************************************************************************
    1694            0 :       ELEMENTAL SUBROUTINE mp_para_cart_retain(cart)
    1695              :          CLASS(mp_para_cart_type), INTENT(INOUT) :: cart
    1696              : 
    1697            0 :          cart%ref_count = cart%ref_count + 1
    1698              : 
    1699            0 :       END SUBROUTINE mp_para_cart_retain
    1700              : 
    1701              : ! **************************************************************************************************
    1702              : !> \brief wrapper to MPI_Comm_dup
    1703              : !> \param comm1 ...
    1704              : !> \param comm2 ...
    1705              : ! **************************************************************************************************
    1706       579660 :       SUBROUTINE mp_comm_dup(comm1, comm2)
    1707              : 
    1708              :          CLASS(mp_comm_type), INTENT(IN)                    :: comm1
    1709              :          CLASS(mp_comm_type), INTENT(OUT)                   :: comm2
    1710              : 
    1711              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_comm_dup'
    1712              : 
    1713              :          INTEGER                                            :: handle
    1714              : #if defined(__parallel)
    1715              :          INTEGER :: ierr
    1716              : #endif
    1717              : 
    1718       579660 :          CALL mp_timeset(routineN, handle)
    1719              : 
    1720              : #if defined(__parallel)
    1721       579660 :          CALL mpi_comm_dup(comm1%handle, comm2%handle, ierr)
    1722       579660 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_dup @ mp_comm_dup")
    1723              : #else
    1724              :          MARK_USED(comm1)
    1725              :          comm2%handle = mp_comm_default_handle
    1726              : #endif
    1727       579660 :          comm2%ndims = comm1%ndims
    1728       579660 :          debug_comm_count = debug_comm_count + 1
    1729       579660 :          CALL comm2%init()
    1730       579660 :          CALL mp_timestop(handle)
    1731              : 
    1732       579660 :       END SUBROUTINE mp_comm_dup
    1733              : 
    1734              : ! **************************************************************************************************
    1735              : !> \brief Implements a simple assignment function to overload the assignment operator
    1736              : !> \param comm_new communicator on the r.h.s. of the assignment operator
    1737              : !> \param comm_old communicator on the l.h.s. of the assignment operator
    1738              : ! **************************************************************************************************
    1739      8824210 :       ELEMENTAL IMPURE SUBROUTINE mp_comm_assign(comm_new, comm_old)
    1740              :          CLASS(mp_comm_type), INTENT(IN) :: comm_old
    1741              :          CLASS(mp_comm_type), INTENT(OUT) :: comm_new
    1742              : 
    1743      8824210 :          comm_new%handle = comm_old%handle
    1744      8824210 :          comm_new%ndims = comm_old%ndims
    1745      8824210 :          CALL comm_new%init(.FALSE.)
    1746      8824210 :       END SUBROUTINE
    1747              : 
    1748              : ! **************************************************************************************************
    1749              : !> \brief check whether the local process is the source process
    1750              : !> \param para_env ...
    1751              : !> \return ...
    1752              : ! **************************************************************************************************
    1753     14451356 :       ELEMENTAL LOGICAL FUNCTION mp_comm_is_source(comm)
    1754              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    1755              : 
    1756     14451356 :          mp_comm_is_source = comm%source == comm%mepos
    1757              : 
    1758     14451356 :       END FUNCTION mp_comm_is_source
    1759              : 
    1760              : ! **************************************************************************************************
    1761              : !> \brief Initializes the communicator (mostly relevant for its derived classes)
    1762              : !> \param comm ...
    1763              : ! **************************************************************************************************
    1764     17394307 :       ELEMENTAL IMPURE SUBROUTINE mp_comm_init(comm, owns_group)
    1765              :          CLASS(mp_comm_type), INTENT(INOUT) :: comm
    1766              :          LOGICAL, INTENT(IN), OPTIONAL :: owns_group
    1767              : 
    1768     17394307 :          IF (comm%handle MPI_GET_COMP /= mp_comm_null_handle MPI_GET_COMP) THEN
    1769     17215823 :             comm%source = 0
    1770     17215823 :             CALL comm%get_size(comm%num_pe)
    1771     17215823 :             CALL comm%get_rank(comm%mepos)
    1772              :          END IF
    1773              : 
    1774              :          SELECT TYPE (comm)
    1775              :          CLASS IS (mp_cart_type)
    1776      8727843 :             IF (ALLOCATED(comm%periodic)) DEALLOCATE (comm%periodic)
    1777      8727843 :             IF (ALLOCATED(comm%mepos_cart)) DEALLOCATE (comm%mepos_cart)
    1778      8727843 :             IF (ALLOCATED(comm%num_pe_cart)) DEALLOCATE (comm%num_pe_cart)
    1779              : 
    1780              :             ASSOCIATE (ndims => comm%ndims)
    1781              : 
    1782            0 :                ALLOCATE (comm%periodic(ndims), comm%mepos_cart(ndims), &
    1783     61094901 :                          comm%num_pe_cart(ndims))
    1784              :             END ASSOCIATE
    1785              : 
    1786     26184355 :             comm%mepos_cart = 0
    1787     26184355 :             comm%periodic = .FALSE.
    1788      8727843 :             IF (comm%handle MPI_GET_COMP /= mp_comm_null_handle MPI_GET_COMP) THEN
    1789              :                CALL comm%get_info_cart(comm%num_pe_cart, comm%mepos_cart, &
    1790      8727843 :                                        comm%periodic)
    1791              :             END IF
    1792              :          END SELECT
    1793              : 
    1794              :          SELECT TYPE (comm)
    1795              :          CLASS IS (mp_para_env_type)
    1796       212512 :             IF (PRESENT(owns_group)) comm%owns_group = owns_group
    1797       212512 :             comm%ref_count = 1
    1798              :          CLASS IS (mp_para_cart_type)
    1799          144 :             IF (PRESENT(owns_group)) comm%owns_group = owns_group
    1800          144 :             comm%ref_count = 1
    1801              :          END SELECT
    1802              : 
    1803     17394307 :       END SUBROUTINE
    1804              : 
    1805              : ! **************************************************************************************************
    1806              : !> \brief creates a new para environment
    1807              : !> \param para_env the new parallel environment
    1808              : !> \param group the id of the actual mpi_group
    1809              : !> \par History
    1810              : !>      08.2002 created [fawzi]
    1811              : !> \author Fawzi Mohamed
    1812              : ! **************************************************************************************************
    1813            0 :       SUBROUTINE mp_para_env_create(para_env, group)
    1814              :          TYPE(mp_para_env_type), POINTER        :: para_env
    1815              :          CLASS(mp_comm_type), INTENT(in)        :: group
    1816              : 
    1817            0 :          IF (ASSOCIATED(para_env)) &
    1818            0 :             CPABORT("The passed para_env must not be associated!")
    1819            0 :          ALLOCATE (para_env)
    1820            0 :          para_env%mp_comm_type = group
    1821            0 :          CALL para_env%init()
    1822            0 :       END SUBROUTINE mp_para_env_create
    1823              : 
    1824              : ! **************************************************************************************************
    1825              : !> \brief releases the para object (to be called when you don't want anymore
    1826              : !>      the shared copy of this object)
    1827              : !> \param para_env the new group
    1828              : !> \par History
    1829              : !>      08.2002 created [fawzi]
    1830              : !> \author Fawzi Mohamed
    1831              : !> \note
    1832              : !>      to avoid circular dependencies cp_log_handling has a private copy
    1833              : !>      of this method (see cp_log_handling:my_mp_para_env_release)!
    1834              : ! **************************************************************************************************
    1835       814471 :       SUBROUTINE mp_para_env_release(para_env)
    1836              :          TYPE(mp_para_env_type), POINTER                    :: para_env
    1837              : 
    1838       814471 :          IF (ASSOCIATED(para_env)) THEN
    1839       784427 :             CALL para_env%free()
    1840       784427 :             IF (.NOT. para_env%is_valid()) DEALLOCATE (para_env)
    1841              :          END IF
    1842       814471 :          NULLIFY (para_env)
    1843       814471 :       END SUBROUTINE mp_para_env_release
    1844              : 
    1845              : ! **************************************************************************************************
    1846              : !> \brief creates a cart (multidimensional parallel environment)
    1847              : !> \param cart the cart environment to create
    1848              : !> \param group the mpi communicator
    1849              : !> \author fawzi
    1850              : ! **************************************************************************************************
    1851            0 :       SUBROUTINE mp_para_cart_create(cart, group)
    1852              :          TYPE(mp_para_cart_type), POINTER, INTENT(OUT)      :: cart
    1853              :          CLASS(mp_comm_type), INTENT(in)                    :: group
    1854              : 
    1855            0 :          IF (ASSOCIATED(cart)) &
    1856            0 :             CPABORT("The passed para_cart must not be associated!")
    1857            0 :          ALLOCATE (cart)
    1858            0 :          cart%mp_cart_type = group
    1859            0 :          CALL cart%init()
    1860              : 
    1861            0 :       END SUBROUTINE mp_para_cart_create
    1862              : 
    1863              : ! **************************************************************************************************
    1864              : !> \brief releases the given cart
    1865              : !> \param cart the cart to release
    1866              : !> \author fawzi
    1867              : ! **************************************************************************************************
    1868          144 :       SUBROUTINE mp_para_cart_release(cart)
    1869              :          TYPE(mp_para_cart_type), POINTER                   :: cart
    1870              : 
    1871          144 :          IF (ASSOCIATED(cart)) THEN
    1872          144 :             CALL cart%free()
    1873          144 :             IF (.NOT. cart%is_valid()) DEALLOCATE (cart)
    1874              :          END IF
    1875          144 :          NULLIFY (cart)
    1876          144 :       END SUBROUTINE mp_para_cart_release
    1877              : 
    1878              : ! **************************************************************************************************
    1879              : !> \brief wrapper to MPI_Group_translate_ranks
    1880              : !> \param comm1 ...
    1881              : !> \param comm2 ...
    1882              : !> \param rank ...
    1883              : ! **************************************************************************************************
    1884      2821210 :       SUBROUTINE mp_rank_compare(comm1, comm2, rank)
    1885              : 
    1886              :          CLASS(mp_comm_type), INTENT(IN)                      :: comm1, comm2
    1887              :          INTEGER, DIMENSION(:), CONTIGUOUS, INTENT(OUT)       :: rank
    1888              : 
    1889              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_rank_compare'
    1890              : 
    1891              :          INTEGER                                  :: handle
    1892              : #if defined(__parallel)
    1893              :          INTEGER                                  :: i, ierr, n, n1, n2
    1894      2821210 :          INTEGER, ALLOCATABLE, DIMENSION(:)       :: rin
    1895              :          MPI_GROUP_TYPE :: g1, g2
    1896              : #endif
    1897              : 
    1898      2821210 :          CALL mp_timeset(routineN, handle)
    1899              : 
    1900      8463630 :          rank = 0
    1901              : #if defined(__parallel)
    1902      2821210 :          CALL mpi_comm_size(comm1%handle, n1, ierr)
    1903      2821210 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_size @ mp_rank_compare")
    1904      2821210 :          CALL mpi_comm_size(comm2%handle, n2, ierr)
    1905      2821210 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_size @ mp_rank_compare")
    1906      2821210 :          n = MAX(n1, n2)
    1907      2821210 :          CALL mpi_comm_group(comm1%handle, g1, ierr)
    1908      2821210 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_group @ mp_rank_compare")
    1909      2821210 :          CALL mpi_comm_group(comm2%handle, g2, ierr)
    1910      2821210 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_comm_group @ mp_rank_compare")
    1911      8463630 :          ALLOCATE (rin(0:n - 1), STAT=ierr)
    1912      2821210 :          IF (ierr /= 0) &
    1913            0 :             CPABORT("allocate @ mp_rank_compare")
    1914      8463630 :          DO i = 0, n - 1
    1915      8463630 :             rin(i) = i
    1916              :          END DO
    1917      2821210 :          CALL mpi_group_translate_ranks(g1, n, rin, g2, rank, ierr)
    1918      2821210 :          IF (ierr /= 0) CALL mp_stop(ierr, &
    1919            0 :                                      "mpi_group_translate_rank @ mp_rank_compare")
    1920      2821210 :          CALL mpi_group_free(g1, ierr)
    1921      2821210 :          IF (ierr /= 0) &
    1922            0 :             CPABORT("group_free @ mp_rank_compare")
    1923      2821210 :          CALL mpi_group_free(g2, ierr)
    1924      2821210 :          IF (ierr /= 0) &
    1925            0 :             CPABORT("group_free @ mp_rank_compare")
    1926      2821210 :          DEALLOCATE (rin)
    1927              : #else
    1928              :          MARK_USED(comm1)
    1929              :          MARK_USED(comm2)
    1930              : #endif
    1931      2821210 :          CALL mp_timestop(handle)
    1932              : 
    1933     19748470 :       END SUBROUTINE mp_rank_compare
    1934              : 
    1935              : ! **************************************************************************************************
    1936              : !> \brief wrapper to MPI_Dims_create
    1937              : !> \param nodes ...
    1938              : !> \param dims ...
    1939              : ! **************************************************************************************************
    1940       784452 :       SUBROUTINE mp_dims_create(nodes, dims)
    1941              : 
    1942              :          INTEGER, INTENT(IN)                                :: nodes
    1943              :          INTEGER, DIMENSION(:), INTENT(INOUT)               :: dims
    1944              : 
    1945              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_dims_create'
    1946              : 
    1947              :          INTEGER                                            :: handle, ndim
    1948              : #if defined(__parallel)
    1949              :          INTEGER :: ierr
    1950              : #endif
    1951              : 
    1952       784452 :          CALL mp_timeset(routineN, handle)
    1953              : 
    1954       784452 :          ndim = SIZE(dims)
    1955              : #if defined(__parallel)
    1956       784452 :          IF (ANY(dims == 0)) CALL mpi_dims_create(nodes, ndim, dims, ierr)
    1957       784452 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_dims_create @ mp_dims_create")
    1958              : #else
    1959              :          dims = 1
    1960              :          MARK_USED(nodes)
    1961              : #endif
    1962       784452 :          CALL mp_timestop(handle)
    1963              : 
    1964       784452 :       END SUBROUTINE mp_dims_create
    1965              : 
    1966              : ! **************************************************************************************************
    1967              : !> \brief wrapper to MPI_Cart_rank
    1968              : !> \param comm ...
    1969              : !> \param pos ...
    1970              : !> \param rank ...
    1971              : ! **************************************************************************************************
    1972      4363890 :       SUBROUTINE mp_cart_rank(comm, pos, rank)
    1973              :          CLASS(mp_cart_type), INTENT(IN)                    :: comm
    1974              :          INTEGER, DIMENSION(:), INTENT(IN)                  :: pos
    1975              :          INTEGER, INTENT(OUT)                               :: rank
    1976              : 
    1977              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_cart_rank'
    1978              : 
    1979              :          INTEGER                                            :: handle
    1980              : #if defined(__parallel)
    1981              :          INTEGER :: ierr
    1982              : #endif
    1983              : 
    1984      4363890 :          CALL mp_timeset(routineN, handle)
    1985              : 
    1986              : #if defined(__parallel)
    1987      4363890 :          CALL mpi_cart_rank(comm%handle, pos, rank, ierr)
    1988      4363890 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_cart_rank @ mp_cart_rank")
    1989              : #else
    1990              :          rank = 0
    1991              :          MARK_USED(comm)
    1992              :          MARK_USED(pos)
    1993              : #endif
    1994      4363890 :          CALL mp_timestop(handle)
    1995              : 
    1996      4363890 :       END SUBROUTINE mp_cart_rank
    1997              : 
    1998              : ! **************************************************************************************************
    1999              : !> \brief waits for completion of the given request
    2000              : !> \param request ...
    2001              : !> \par History
    2002              : !>      08.2003 created [f&j]
    2003              : !> \author joost & fawzi
    2004              : !> \note
    2005              : !>      see isendrecv
    2006              : ! **************************************************************************************************
    2007        16596 :       SUBROUTINE mp_wait(request)
    2008              :          CLASS(mp_request_type), INTENT(inout)              :: request
    2009              : 
    2010              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_wait'
    2011              : 
    2012              :          INTEGER                                            :: handle
    2013              : #if defined(__parallel)
    2014              :          INTEGER :: ierr
    2015              : #endif
    2016              : 
    2017         8298 :          CALL mp_timeset(routineN, handle)
    2018              : 
    2019              : #if defined(__parallel)
    2020              : 
    2021         8298 :          CALL mpi_wait(request%handle, MPI_STATUS_IGNORE, ierr)
    2022         8298 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_wait @ mp_wait")
    2023              : 
    2024         8298 :          CALL add_perf(perf_id=9, count=1)
    2025              : #else
    2026              :          request%handle = mp_request_null_handle
    2027              : #endif
    2028         8298 :          CALL mp_timestop(handle)
    2029         8298 :       END SUBROUTINE mp_wait
    2030              : 
    2031              : ! **************************************************************************************************
    2032              : !> \brief waits for completion of the given requests
    2033              : !> \param requests ...
    2034              : !> \par History
    2035              : !>      08.2003 created [f&j]
    2036              : !> \author joost & fawzi
    2037              : !> \note
    2038              : !>      see isendrecv
    2039              : ! **************************************************************************************************
    2040      1738926 :       SUBROUTINE mp_waitall_1(requests)
    2041              :          TYPE(mp_request_type), DIMENSION(:), INTENT(inout)     :: requests
    2042              : 
    2043              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_waitall_1'
    2044              : 
    2045              :          INTEGER                                  :: handle
    2046              : #if defined(__parallel)
    2047              :          INTEGER                                  :: count, ierr
    2048              : #endif
    2049              : 
    2050      1738926 :          CALL mp_timeset(routineN, handle)
    2051              : #if defined(__parallel)
    2052      1738926 :          count = SIZE(requests)
    2053      1738926 :          CALL mpi_waitall_internal(count, requests, ierr)
    2054      1738926 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_waitall @ mp_waitall_1")
    2055      1738926 :          CALL add_perf(perf_id=9, count=1)
    2056              : #else
    2057              :          requests = mp_request_null
    2058              : #endif
    2059      1738926 :          CALL mp_timestop(handle)
    2060      1738926 :       END SUBROUTINE mp_waitall_1
    2061              : 
    2062              : ! **************************************************************************************************
    2063              : !> \brief waits for completion of the given requests
    2064              : !> \param requests ...
    2065              : !> \par History
    2066              : !>      08.2003 created [f&j]
    2067              : !> \author joost & fawzi
    2068              : ! **************************************************************************************************
    2069       755811 :       SUBROUTINE mp_waitall_2(requests)
    2070              :          TYPE(mp_request_type), DIMENSION(:, :), INTENT(inout)  :: requests
    2071              : 
    2072              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_waitall_2'
    2073              : 
    2074              :          INTEGER                                  :: handle
    2075              : #if defined(__parallel)
    2076              :          INTEGER                                  :: count, ierr
    2077              : #endif
    2078              : 
    2079       755811 :          CALL mp_timeset(routineN, handle)
    2080              : #if defined(__parallel)
    2081      2267433 :          count = SIZE(requests)
    2082      4224679 :          CALL mpi_waitall_internal(count, requests, ierr)
    2083       755811 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_waitall @ mp_waitall_2")
    2084       755811 :          CALL add_perf(perf_id=9, count=1)
    2085              : #else
    2086              :          requests = mp_request_null
    2087              : #endif
    2088       755811 :          CALL mp_timestop(handle)
    2089       755811 :       END SUBROUTINE mp_waitall_2
    2090              : 
    2091              : ! **************************************************************************************************
    2092              : !> \brief wrapper needed to deal with interfaces as present in openmpi 1.8.1
    2093              : !>        the issue is with the rank or requests
    2094              : !> \param count ...
    2095              : !> \param array_of_requests ...
    2096              : !> \param ierr ...
    2097              : !> \author Joost VandeVondele
    2098              : ! **************************************************************************************************
    2099              : #if defined(__parallel)
    2100      2494737 :       SUBROUTINE mpi_waitall_internal(count, array_of_requests, ierr)
    2101              :          INTEGER, INTENT(in)                                      :: count
    2102              :          TYPE(mp_request_type), DIMENSION(count), INTENT(inout)   :: array_of_requests
    2103              :          INTEGER, INTENT(out)                                     :: ierr
    2104              : 
    2105      2494737 :          MPI_REQUEST_TYPE, ALLOCATABLE, DIMENSION(:), TARGET      :: request_handles
    2106              : 
    2107     20340076 :          ALLOCATE (request_handles(count), SOURCE=array_of_requests(1:count)%handle)
    2108      2494737 :          CALL mpi_waitall(count, request_handles, MPI_STATUSES_IGNORE, ierr)
    2109      8941135 :          array_of_requests(1:count)%handle = request_handles(:)
    2110      2494737 :          DEALLOCATE (request_handles)
    2111              : 
    2112      2494737 :       END SUBROUTINE mpi_waitall_internal
    2113              : #endif
    2114              : 
    2115              : ! **************************************************************************************************
    2116              : !> \brief waits for completion of any of the given requests
    2117              : !> \param requests ...
    2118              : !> \param completed ...
    2119              : !> \par History
    2120              : !>      09.2008 created
    2121              : !> \author Iain Bethune (c) The Numerical Algorithms Group (NAG) Ltd, 2008 on behalf of the HECToR project
    2122              : ! **************************************************************************************************
    2123        12536 :       SUBROUTINE mp_waitany(requests, completed)
    2124              :          TYPE(mp_request_type), DIMENSION(:), INTENT(inout)     :: requests
    2125              :          INTEGER, INTENT(out)                                   :: completed
    2126              : 
    2127              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_waitany'
    2128              : 
    2129              :          INTEGER                                      :: handle
    2130              : #if defined(__parallel)
    2131              :          INTEGER                                      :: count, ierr
    2132        12536 :          MPI_REQUEST_TYPE, ALLOCATABLE, DIMENSION(:)  :: request_handles
    2133              : #endif
    2134              : 
    2135        12536 :          CALL mp_timeset(routineN, handle)
    2136              : 
    2137              : #if defined(__parallel)
    2138        12536 :          count = SIZE(requests)
    2139              :          ! Convert CP2K's request_handles to the plain handle for the library
    2140        87752 :          ALLOCATE (request_handles(count), SOURCE=requests(1:count)%handle)
    2141              : 
    2142        12536 :          CALL mpi_waitany(count, request_handles, completed, MPI_STATUS_IGNORE, ierr)
    2143        12536 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_waitany @ mp_waitany")
    2144              : 
    2145              :          ! Convert the plain handles to CP2K handles
    2146        37608 :          requests(1:count)%handle = request_handles(:)
    2147        12536 :          DEALLOCATE (request_handles)
    2148        12536 :          CALL add_perf(perf_id=9, count=1)
    2149              : #else
    2150              :          requests = mp_request_null
    2151              :          completed = 1
    2152              : #endif
    2153        12536 :          CALL mp_timestop(handle)
    2154        25072 :       END SUBROUTINE mp_waitany
    2155              : 
    2156              : ! **************************************************************************************************
    2157              : !> \brief Tests for completion of the given requests.
    2158              : !> \brief We use mpi_test so that we can use a single status.
    2159              : !> \param requests the list of requests to test
    2160              : !> \return logical which determines if requests are complete
    2161              : !> \par History
    2162              : !>      3.2016 adapted to any shape [Nico Holmberg]
    2163              : !> \author Alfio Lazzaro
    2164              : ! **************************************************************************************************
    2165         6400 :       FUNCTION mp_testall_tv(requests) RESULT(flag)
    2166              :          TYPE(mp_request_type), DIMENSION(:), INTENT(INOUT) :: requests
    2167              :          LOGICAL                               :: flag
    2168              : 
    2169              : #if defined(__parallel)
    2170              :          INTEGER                               :: i, ierr
    2171              :          LOGICAL, DIMENSION(:), POINTER        :: flags
    2172              : #endif
    2173              : 
    2174         6400 :          flag = .TRUE.
    2175              : 
    2176              : #if defined(__parallel)
    2177        19200 :          ALLOCATE (flags(SIZE(requests)))
    2178        25600 :          DO i = 1, SIZE(requests)
    2179        19200 :             CALL mpi_test(requests(i)%handle, flags(i), MPI_STATUS_IGNORE, ierr)
    2180        19200 :             IF (ierr /= 0) CALL mp_stop(ierr, "mpi_testall @ mp_testall_tv")
    2181        45259 :             flag = flag .AND. flags(i)
    2182              :          END DO
    2183         6400 :          DEALLOCATE (flags)
    2184              : #else
    2185              :          requests = mp_request_null
    2186              : #endif
    2187         6400 :       END FUNCTION mp_testall_tv
    2188              : 
    2189              : ! **************************************************************************************************
    2190              : !> \brief Tests for completion of the given request.
    2191              : !> \param request the request
    2192              : !> \param flag logical which determines if the request is completed
    2193              : !> \par History
    2194              : !>      3.2016 created
    2195              : !> \author Nico Holmberg
    2196              : ! **************************************************************************************************
    2197          138 :       FUNCTION mp_test_1(request) RESULT(flag)
    2198              :          CLASS(mp_request_type), INTENT(inout)              :: request
    2199              :          LOGICAL                                            :: flag
    2200              : 
    2201              : #if defined(__parallel)
    2202              :          INTEGER                                            :: ierr
    2203              : 
    2204          138 :          CALL mpi_test(request%handle, flag, MPI_STATUS_IGNORE, ierr)
    2205          138 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_test @ mp_test_1")
    2206              : #else
    2207              :          MARK_USED(request)
    2208              :          flag = .TRUE.
    2209              : #endif
    2210          138 :       END FUNCTION mp_test_1
    2211              : 
    2212              : ! **************************************************************************************************
    2213              : !> \brief tests for completion of the given requests
    2214              : !> \param requests ...
    2215              : !> \param completed ...
    2216              : !> \param flag ...
    2217              : !> \par History
    2218              : !>      08.2011 created
    2219              : !> \author Iain Bethune
    2220              : ! **************************************************************************************************
    2221            0 :       SUBROUTINE mp_testany_1(requests, completed, flag)
    2222              :          TYPE(mp_request_type), DIMENSION(:), INTENT(inout)  :: requests
    2223              :          INTEGER, INTENT(out), OPTIONAL           :: completed
    2224              :          LOGICAL, INTENT(out), OPTIONAL           :: flag
    2225              : 
    2226              : #if defined(__parallel)
    2227              :          INTEGER                                  :: completed_l, count, ierr
    2228              :          LOGICAL                                  :: flag_l
    2229              : 
    2230            0 :          count = SIZE(requests)
    2231              : 
    2232            0 :          CALL mpi_testany_internal(count, requests, completed_l, flag_l, MPI_STATUS_IGNORE, ierr)
    2233            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_testany_1 @ mp_testany")
    2234              : 
    2235            0 :          IF (PRESENT(completed)) completed = completed_l
    2236            0 :          IF (PRESENT(flag)) flag = flag_l
    2237              : #else
    2238              :          MARK_USED(requests)
    2239              :          IF (PRESENT(completed)) completed = 1
    2240              :          IF (PRESENT(flag)) flag = .TRUE.
    2241              : #endif
    2242            0 :       END SUBROUTINE mp_testany_1
    2243              : 
    2244              : ! **************************************************************************************************
    2245              : !> \brief tests for completion of the given requests
    2246              : !> \param requests ...
    2247              : !> \param completed ...
    2248              : !> \param flag ...
    2249              : !> \par History
    2250              : !>      08.2011 created
    2251              : !> \author Iain Bethune
    2252              : ! **************************************************************************************************
    2253            0 :       SUBROUTINE mp_testany_2(requests, completed, flag)
    2254              :          TYPE(mp_request_type), DIMENSION(:, :), INTENT(inout)   :: requests
    2255              :          INTEGER, INTENT(out), OPTIONAL           :: completed
    2256              :          LOGICAL, INTENT(out), OPTIONAL           :: flag
    2257              : 
    2258              : #if defined(__parallel)
    2259              :          INTEGER                                  :: completed_l, count, ierr
    2260              :          LOGICAL                                  :: flag_l
    2261              : 
    2262            0 :          count = SIZE(requests)
    2263              : 
    2264            0 :          CALL mpi_testany_internal(count, requests, completed_l, flag_l, MPI_STATUS_IGNORE, ierr)
    2265            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_testany_2 @ mp_testany")
    2266              : 
    2267            0 :          IF (PRESENT(completed)) completed = completed_l
    2268            0 :          IF (PRESENT(flag)) flag = flag_l
    2269              : #else
    2270              :          MARK_USED(requests)
    2271              :          IF (PRESENT(completed)) completed = 1
    2272              :          IF (PRESENT(flag)) flag = .TRUE.
    2273              : #endif
    2274            0 :       END SUBROUTINE mp_testany_2
    2275              : 
    2276              : ! **************************************************************************************************
    2277              : !> \brief wrapper needed to deal with interfaces as present in openmpi 1.8.1
    2278              : !>        the issue is with the rank or requests
    2279              : !> \param count ...
    2280              : !> \param array_of_requests ...
    2281              : !> \param index ...
    2282              : !> \param flag ...
    2283              : !> \param status ...
    2284              : !> \param ierr ...
    2285              : !> \author Joost VandeVondele
    2286              : ! **************************************************************************************************
    2287              : #if defined(__parallel)
    2288            0 :       SUBROUTINE mpi_testany_internal(count, array_of_requests, index, flag, status, ierr)
    2289              :          INTEGER, INTENT(in)                                    :: count
    2290              :          TYPE(mp_request_type), DIMENSION(count), INTENT(inout) :: array_of_requests
    2291              :          INTEGER, INTENT(out)                                   :: index
    2292              :          LOGICAL, INTENT(out)                                   :: flag
    2293              :          MPI_STATUS_TYPE, INTENT(out)                           :: status
    2294              :          INTEGER, INTENT(out)                                   :: ierr
    2295              : 
    2296            0 :          MPI_REQUEST_TYPE, ALLOCATABLE, DIMENSION(:) :: request_handles
    2297              : 
    2298            0 :          ALLOCATE (request_handles(count), SOURCE=array_of_requests(1:count)%handle)
    2299            0 :          CALL mpi_testany(count, request_handles, index, flag, status, ierr)
    2300            0 :          array_of_requests(1:count)%handle = request_handles(:)
    2301            0 :          DEALLOCATE (request_handles)
    2302              : 
    2303            0 :       END SUBROUTINE mpi_testany_internal
    2304              : #endif
    2305              : 
    2306              : ! **************************************************************************************************
    2307              : !> \brief the direct way to split a communicator each color is a sub_comm,
    2308              : !>        the rank order is according to the order in the orig comm
    2309              : !> \param comm ...
    2310              : !> \param sub_comm ...
    2311              : !> \param color ...
    2312              : !> \param key ...
    2313              : !> \author Joost VandeVondele
    2314              : ! **************************************************************************************************
    2315       711148 :       SUBROUTINE mp_comm_split_direct(comm, sub_comm, color, key)
    2316              :          CLASS(mp_comm_type), INTENT(in)                    :: comm
    2317              :          CLASS(mp_comm_type), INTENT(OUT)                   :: sub_comm
    2318              :          INTEGER, INTENT(in)                                :: color
    2319              :          INTEGER, INTENT(in), OPTIONAL                      :: key
    2320              : 
    2321              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_comm_split_direct'
    2322              : 
    2323              :          INTEGER                                            :: handle
    2324              : #if defined(__parallel)
    2325              :          INTEGER :: ierr, my_key
    2326              : #endif
    2327              : 
    2328       711148 :          CALL mp_timeset(routineN, handle)
    2329              : 
    2330              : #if defined(__parallel)
    2331       711148 :          my_key = 0
    2332       711148 :          IF (PRESENT(key)) my_key = key
    2333       711148 :          CALL mpi_comm_split(comm%handle, color, my_key, sub_comm%handle, ierr)
    2334       711148 :          IF (ierr /= mpi_success) CALL mp_stop(ierr, routineN)
    2335       711148 :          CALL add_perf(perf_id=10, count=1)
    2336              : #else
    2337              :          sub_comm%handle = mp_comm_default_handle
    2338              :          MARK_USED(comm)
    2339              :          MARK_USED(color)
    2340              :          MARK_USED(key)
    2341              : #endif
    2342       711148 :          debug_comm_count = debug_comm_count + 1
    2343       711148 :          CALL sub_comm%init()
    2344       711148 :          CALL mp_timestop(handle)
    2345              : 
    2346       711148 :       END SUBROUTINE mp_comm_split_direct
    2347              : ! **************************************************************************************************
    2348              : !> \brief splits the given communicator in group in subgroups trying to organize
    2349              : !>      them in a way that the communication within each subgroup is
    2350              : !>      efficient (but not necessarily the communication between subgroups)
    2351              : !> \param comm the mpi communicator that you want to split
    2352              : !> \param sub_comm the communicator for the subgroup (created, needs to be freed later)
    2353              : !> \param ngroups actual number of groups
    2354              : !> \param group_distribution input  : allocated with array with the nprocs entries (0 .. nprocs-1)
    2355              : !> \param subgroup_min_size the minimum size of the subgroup
    2356              : !> \param n_subgroups the number of subgroups wanted
    2357              : !> \param group_partition n_subgroups sized array containing the number of cpus wanted per group.
    2358              : !>                         should match the total number of cpus (only used if present and associated) (0..ngroups-1)
    2359              : !> \param stride create groups using a stride (default=1) through the ranks of the comm to be split.
    2360              : !> \par History
    2361              : !>      10.2003 created [fawzi]
    2362              : !>      02.2004 modified [Joost VandeVondele]
    2363              : !> \author Fawzi Mohamed
    2364              : !> \note
    2365              : !>      at least one of subgroup_min_size and n_subgroups is needed,
    2366              : !>      the other default to the value needed to use most processors.
    2367              : !>      if less cpus are present than needed for subgroup min size, n_subgroups,
    2368              : !>      just one comm is created that contains all cpus
    2369              : ! **************************************************************************************************
    2370       160502 :       SUBROUTINE mp_comm_split(comm, sub_comm, ngroups, group_distribution, &
    2371       160502 :                                subgroup_min_size, n_subgroups, group_partition, stride)
    2372              :          CLASS(mp_comm_type), INTENT(in)                      :: comm
    2373              :          CLASS(mp_comm_type), INTENT(out)                     :: sub_comm
    2374              :          INTEGER, INTENT(out)                                 :: ngroups
    2375              :          INTEGER, DIMENSION(0:), INTENT(INOUT)                :: group_distribution
    2376              :          INTEGER, INTENT(in), OPTIONAL                        :: subgroup_min_size, &
    2377              :                                                                  n_subgroups
    2378              :          INTEGER, DIMENSION(0:), INTENT(IN), OPTIONAL         :: group_partition
    2379              :          INTEGER, OPTIONAL, INTENT(IN)                        :: stride
    2380              : 
    2381              :          CHARACTER(LEN=*), PARAMETER :: routineN = 'mp_comm_split', &
    2382              :                                         routineP = moduleN//':'//routineN
    2383              : 
    2384              :          INTEGER                                  :: handle, mepos, nnodes
    2385              : #if defined(__parallel)
    2386              :          INTEGER                                  :: color, i, ierr, j, k, &
    2387              :                                                      my_subgroup_min_size, &
    2388              :                                                      istride, local_stride, irank
    2389       160502 :          INTEGER, DIMENSION(:), ALLOCATABLE       :: rank_permutation
    2390              : #endif
    2391              : 
    2392       160502 :          CALL mp_timeset(routineN, handle)
    2393              : 
    2394              :          ! actual number of groups
    2395              : 
    2396       160502 :          IF (.NOT. PRESENT(subgroup_min_size) .AND. .NOT. PRESENT(n_subgroups)) THEN
    2397            0 :             CPABORT(routineP//" missing arguments")
    2398              :          END IF
    2399       160502 :          IF (PRESENT(subgroup_min_size) .AND. PRESENT(n_subgroups)) THEN
    2400            0 :             CPABORT(routineP//" too many arguments")
    2401              :          END IF
    2402              : 
    2403       160502 :          CALL comm%get_size(nnodes)
    2404       160502 :          CALL comm%get_rank(mepos)
    2405              : 
    2406       160502 :          IF (UBOUND(group_distribution, 1) /= nnodes - 1) THEN
    2407            0 :             CPABORT(routineP//" group_distribution wrong bounds")
    2408              :          END IF
    2409              : 
    2410              : #if defined(__parallel)
    2411       160502 :          IF (PRESENT(subgroup_min_size)) THEN
    2412          144 :             IF (subgroup_min_size < 0 .OR. subgroup_min_size > nnodes) THEN
    2413            0 :                CPABORT(routineP//" subgroup_min_size too small or too large")
    2414              :             END IF
    2415          144 :             ngroups = nnodes/subgroup_min_size
    2416          144 :             my_subgroup_min_size = subgroup_min_size
    2417              :          ELSE ! n_subgroups
    2418       160358 :             IF (n_subgroups <= 0) THEN
    2419            0 :                CPABORT(routineP//" n_subgroups too small")
    2420              :             END IF
    2421       160358 :             IF (nnodes/n_subgroups > 0) THEN ! we have a least one cpu per group
    2422       156735 :                ngroups = n_subgroups
    2423              :             ELSE ! well, only one group then
    2424         3623 :                ngroups = 1
    2425              :             END IF
    2426       160358 :             my_subgroup_min_size = nnodes/ngroups
    2427              :          END IF
    2428              : 
    2429              :          ! rank_permutation: is a permutation of ranks, so that groups are not necessarily continuous in rank of the master group
    2430              :          ! while the order is not critical (we only color ranks), it can e.g. be used to make groups that have just 1 rank per node
    2431              :          ! (by setting stride equal to the number of mpi ranks per node), or by sharing  a node between two groups (stride 2).
    2432       481506 :          ALLOCATE (rank_permutation(0:nnodes - 1))
    2433       160502 :          local_stride = 1
    2434       160502 :          IF (PRESENT(stride)) local_stride = stride
    2435       160502 :          k = 0
    2436       321004 :          DO istride = 1, local_stride
    2437       321004 :             DO irank = istride - 1, nnodes - 1, local_stride
    2438       317380 :                rank_permutation(k) = irank
    2439       317380 :                k = k + 1
    2440              :             END DO
    2441              :          END DO
    2442              : 
    2443       477882 :          DO i = 0, nnodes - 1
    2444       477882 :             group_distribution(rank_permutation(i)) = MIN(i/my_subgroup_min_size, ngroups - 1)
    2445              :          END DO
    2446              :          ! even the user gave a partition, see if we can use it to overwrite this choice
    2447       160502 :          IF (PRESENT(group_partition)) THEN
    2448       684193 :             IF (ALL(group_partition > 0) .AND. (SUM(group_partition) == nnodes) .AND. (ngroups == SIZE(group_partition))) THEN
    2449           90 :                k = 0
    2450           90 :                DO i = 0, SIZE(group_partition) - 1
    2451          150 :                   DO j = 1, group_partition(i)
    2452           60 :                      group_distribution(rank_permutation(k)) = i
    2453          120 :                      k = k + 1
    2454              :                   END DO
    2455              :                END DO
    2456              :             ELSE
    2457              :                ! just ignore silently as we have reasonable defaults. Probably a warning would not be to bad
    2458              :             END IF
    2459              :          END IF
    2460       160502 :          DEALLOCATE (rank_permutation)
    2461       160502 :          color = group_distribution(mepos)
    2462       160502 :          CALL mpi_comm_split(comm%handle, color, 0, sub_comm%handle, ierr)
    2463       160502 :          IF (ierr /= mpi_success) CALL mp_stop(ierr, "in "//routineP//" split")
    2464              : 
    2465       160502 :          CALL add_perf(perf_id=10, count=1)
    2466              : #else
    2467              :          sub_comm%handle = mp_comm_default_handle
    2468              :          group_distribution(0) = 0
    2469              :          ngroups = 1
    2470              :          MARK_USED(comm)
    2471              :          MARK_USED(stride)
    2472              :          MARK_USED(group_partition)
    2473              : #endif
    2474       160502 :          debug_comm_count = debug_comm_count + 1
    2475       160502 :          CALL sub_comm%init()
    2476       160502 :          CALL mp_timestop(handle)
    2477              : 
    2478       321004 :       END SUBROUTINE mp_comm_split
    2479              : 
    2480              : ! **************************************************************************************************
    2481              : !> \brief probes for an incoming message with any tag
    2482              : !> \param[inout] source the source of the possible incoming message,
    2483              : !>        if MP_ANY_SOURCE it is a blocking one and return value is the source
    2484              : !>        of the next incoming message
    2485              : !>        if source is a different value it is a non-blocking probe returning
    2486              : !>        MP_ANY_SOURCE if there is no incoming message
    2487              : !> \param[in] comm the communicator
    2488              : !> \param[out] tag the tag of the incoming message
    2489              : !> \author Mandes
    2490              : ! **************************************************************************************************
    2491      1548940 :       SUBROUTINE mp_probe(source, comm, tag)
    2492              :          INTEGER, INTENT(INOUT)                   :: source
    2493              :          CLASS(mp_comm_type), INTENT(IN)          :: comm
    2494              :          INTEGER, INTENT(OUT)                     :: tag
    2495              : 
    2496              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_probe'
    2497              : 
    2498              :          INTEGER                                  :: handle
    2499              : #if defined(__parallel)
    2500              :          INTEGER :: ierr
    2501              :          MPI_STATUS_TYPE     :: status_single
    2502              :          LOGICAL                                  :: flag
    2503              : #endif
    2504              : 
    2505              : !   ---------------------------------------------------------------------------
    2506              : 
    2507      1548940 :          CALL mp_timeset(routineN, handle)
    2508              : 
    2509              : #if defined(__parallel)
    2510      1548940 :          IF (source == mp_any_source) THEN
    2511           14 :             CALL mpi_probe(mp_any_source, mp_any_tag, comm%handle, status_single, ierr)
    2512           14 :             IF (ierr /= 0) CALL mp_stop(ierr, "mpi_probe @ mp_probe")
    2513           14 :             source = status_single MPI_STATUS_EXTRACT(MPI_SOURCE)
    2514           14 :             tag = status_single MPI_STATUS_EXTRACT(MPI_TAG)
    2515              :          ELSE
    2516              :             flag = .FALSE.
    2517      1548926 :             CALL mpi_iprobe(source, mp_any_tag, comm%handle, flag, status_single, ierr)
    2518      1548926 :             IF (ierr /= 0) CALL mp_stop(ierr, "mpi_iprobe @ mp_probe")
    2519      1548926 :             IF (flag .EQV. .FALSE.) THEN
    2520      1539708 :                source = mp_any_source
    2521      1539708 :                tag = -1 !status_single(MPI_TAG) ! in case of flag==false status is undefined
    2522              :             ELSE
    2523         9218 :                tag = status_single MPI_STATUS_EXTRACT(MPI_TAG)
    2524              :             END IF
    2525              :          END IF
    2526              : #else
    2527              :          tag = -1
    2528              :          MARK_USED(comm)
    2529              :          MARK_USED(source)
    2530              : #endif
    2531      1548940 :          CALL mp_timestop(handle)
    2532      1548940 :       END SUBROUTINE mp_probe
    2533              : 
    2534              : ! **************************************************************************************************
    2535              : ! Here come the data routines with none of the standard data types.
    2536              : ! **************************************************************************************************
    2537              : 
    2538              : ! **************************************************************************************************
    2539              : !> \brief ...
    2540              : !> \param msg ...
    2541              : !> \param source ...
    2542              : !> \param comm ...
    2543              : ! **************************************************************************************************
    2544       719086 :       SUBROUTINE mp_bcast_b(msg, source, comm)
    2545              :          LOGICAL, INTENT(INOUT)                             :: msg
    2546              :          INTEGER, INTENT(IN)                                :: source
    2547              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    2548              : 
    2549              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_bcast_b'
    2550              : 
    2551              :          INTEGER                                            :: handle
    2552              : #if defined(__parallel)
    2553              :          INTEGER :: ierr, msglen
    2554              : #endif
    2555              : 
    2556       719086 :          CALL mp_timeset(routineN, handle)
    2557              : 
    2558              : #if defined(__parallel)
    2559       719086 :          msglen = 1
    2560       719086 :          CALL mpi_bcast(msg, msglen, MPI_LOGICAL, source, comm%handle, ierr)
    2561       719086 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_bcast @ "//routineN)
    2562       719086 :          CALL add_perf(perf_id=2, count=1, msg_size=msglen*loglen)
    2563              : #else
    2564              :          MARK_USED(msg)
    2565              :          MARK_USED(source)
    2566              :          MARK_USED(comm)
    2567              : #endif
    2568       719086 :          CALL mp_timestop(handle)
    2569       719086 :       END SUBROUTINE mp_bcast_b
    2570              : 
    2571              : ! **************************************************************************************************
    2572              : !> \brief ...
    2573              : !> \param msg ...
    2574              : !> \param source ...
    2575              : !> \param comm ...
    2576              : ! **************************************************************************************************
    2577       673611 :       SUBROUTINE mp_bcast_b_src(msg, comm)
    2578              :          LOGICAL, INTENT(INOUT)                             :: msg
    2579              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    2580              : 
    2581              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_bcast_b_src'
    2582              : 
    2583              :          INTEGER                                            :: handle
    2584              : #if defined(__parallel)
    2585              :          INTEGER :: ierr, msglen
    2586              : #endif
    2587              : 
    2588       673611 :          CALL mp_timeset(routineN, handle)
    2589              : 
    2590              : #if defined(__parallel)
    2591       673611 :          msglen = 1
    2592       673611 :          CALL mpi_bcast(msg, msglen, MPI_LOGICAL, comm%source, comm%handle, ierr)
    2593       673611 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_bcast @ "//routineN)
    2594       673611 :          CALL add_perf(perf_id=2, count=1, msg_size=msglen*loglen)
    2595              : #else
    2596              :          MARK_USED(msg)
    2597              :          MARK_USED(comm)
    2598              : #endif
    2599       673611 :          CALL mp_timestop(handle)
    2600       673611 :       END SUBROUTINE mp_bcast_b_src
    2601              : 
    2602              : ! **************************************************************************************************
    2603              : !> \brief ...
    2604              : !> \param msg ...
    2605              : !> \param source ...
    2606              : !> \param comm ...
    2607              : ! **************************************************************************************************
    2608            0 :       SUBROUTINE mp_bcast_bv(msg, source, comm)
    2609              :          LOGICAL, CONTIGUOUS, INTENT(INOUT)                 :: msg(:)
    2610              :          INTEGER, INTENT(IN)                                :: source
    2611              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    2612              : 
    2613              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_bcast_bv'
    2614              : 
    2615              :          INTEGER                                            :: handle
    2616              : #if defined(__parallel)
    2617              :          INTEGER :: ierr, msglen
    2618              : #endif
    2619              : 
    2620            0 :          CALL mp_timeset(routineN, handle)
    2621              : 
    2622              : #if defined(__parallel)
    2623            0 :          msglen = SIZE(msg)
    2624            0 :          CALL mpi_bcast(msg, msglen, MPI_LOGICAL, source, comm%handle, ierr)
    2625            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_bcast @ "//routineN)
    2626            0 :          CALL add_perf(perf_id=2, count=1, msg_size=msglen*loglen)
    2627              : #else
    2628              :          MARK_USED(msg)
    2629              :          MARK_USED(source)
    2630              :          MARK_USED(comm)
    2631              : #endif
    2632            0 :          CALL mp_timestop(handle)
    2633            0 :       END SUBROUTINE mp_bcast_bv
    2634              : 
    2635              : ! **************************************************************************************************
    2636              : !> \brief ...
    2637              : !> \param msg ...
    2638              : !> \param comm ...
    2639              : ! **************************************************************************************************
    2640            0 :       SUBROUTINE mp_bcast_bv_src(msg, comm)
    2641              :          LOGICAL, CONTIGUOUS, INTENT(INOUT)                 :: msg(:)
    2642              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    2643              : 
    2644              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_bcast_bv_src'
    2645              : 
    2646              :          INTEGER                                            :: handle
    2647              : #if defined(__parallel)
    2648              :          INTEGER :: ierr, msglen
    2649              : #endif
    2650              : 
    2651            0 :          CALL mp_timeset(routineN, handle)
    2652              : 
    2653              : #if defined(__parallel)
    2654            0 :          msglen = SIZE(msg)
    2655            0 :          CALL mpi_bcast(msg, msglen, MPI_LOGICAL, comm%source, comm%handle, ierr)
    2656            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_bcast @ "//routineN)
    2657            0 :          CALL add_perf(perf_id=2, count=1, msg_size=msglen*loglen)
    2658              : #else
    2659              :          MARK_USED(msg)
    2660              :          MARK_USED(comm)
    2661              : #endif
    2662            0 :          CALL mp_timestop(handle)
    2663            0 :       END SUBROUTINE mp_bcast_bv_src
    2664              : 
    2665              : ! **************************************************************************************************
    2666              : !> \brief Non-blocking send of logical vector data
    2667              : !> \param msgin the input message
    2668              : !> \param dest the destination processor
    2669              : !> \param comm  the communicator object
    2670              : !> \param request communication request index
    2671              : !> \param tag message tag
    2672              : !> \par History
    2673              : !>      3.2016 added _bv subroutine [Nico Holmberg]
    2674              : !> \author fawzi
    2675              : !> \note see mp_irecv_iv
    2676              : !> \note
    2677              : !>      arrays can be pointers or assumed shape, but they must be contiguous!
    2678              : ! **************************************************************************************************
    2679           16 :       SUBROUTINE mp_isend_bv(msgin, dest, comm, request, tag)
    2680              :          LOGICAL, DIMENSION(:), INTENT(IN)        :: msgin
    2681              :          INTEGER, INTENT(IN)                      :: dest
    2682              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    2683              :          TYPE(mp_request_type), INTENT(out)       :: request
    2684              :          INTEGER, INTENT(in), OPTIONAL            :: tag
    2685              : 
    2686              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_isend_bv'
    2687              : 
    2688              :          INTEGER                                  :: handle
    2689              : #if defined(__parallel)
    2690              :          INTEGER                                  :: ierr, msglen, my_tag
    2691              :          LOGICAL                                  :: foo(1)
    2692              : #endif
    2693              : 
    2694           16 :          CALL mp_timeset(routineN, handle)
    2695              : 
    2696              : #if defined(__parallel)
    2697              : #if !defined(__GNUC__) || __GNUC__ >= 9
    2698           16 :          CPASSERT(IS_CONTIGUOUS(msgin))
    2699              : #endif
    2700              : 
    2701           16 :          my_tag = 0
    2702           16 :          IF (PRESENT(tag)) my_tag = tag
    2703              : 
    2704           16 :          msglen = SIZE(msgin, 1)
    2705           16 :          IF (msglen > 0) THEN
    2706              :             CALL mpi_isend(msgin(1), msglen, MPI_LOGICAL, dest, my_tag, &
    2707           16 :                            comm%handle, request%handle, ierr)
    2708              :          ELSE
    2709              :             CALL mpi_isend(foo, msglen, MPI_LOGICAL, dest, my_tag, &
    2710            0 :                            comm%handle, request%handle, ierr)
    2711              :          END IF
    2712           16 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_isend @ "//routineN)
    2713              : 
    2714           16 :          CALL add_perf(perf_id=11, count=1, msg_size=msglen*loglen)
    2715              : #else
    2716              :          CPABORT("mp_isend called in non parallel case")
    2717              :          MARK_USED(msgin)
    2718              :          MARK_USED(dest)
    2719              :          MARK_USED(comm)
    2720              :          MARK_USED(tag)
    2721              :          request = mp_request_null
    2722              : #endif
    2723           16 :          CALL mp_timestop(handle)
    2724           16 :       END SUBROUTINE mp_isend_bv
    2725              : 
    2726              : ! **************************************************************************************************
    2727              : !> \brief Non-blocking receive of logical vector data
    2728              : !> \param msgout the received message
    2729              : !> \param source the source processor
    2730              : !> \param comm  the communicator object
    2731              : !> \param request communication request index
    2732              : !> \param tag message tag
    2733              : !> \par History
    2734              : !>      3.2016 added _bv subroutine [Nico Holmberg]
    2735              : !> \author fawzi
    2736              : !> \note see mp_irecv_iv
    2737              : !> \note
    2738              : !>      arrays can be pointers or assumed shape, but they must be contiguous!
    2739              : ! **************************************************************************************************
    2740           16 :       SUBROUTINE mp_irecv_bv(msgout, source, comm, request, tag)
    2741              :          LOGICAL, DIMENSION(:), INTENT(INOUT)     :: msgout
    2742              :          INTEGER, INTENT(IN)                      :: source
    2743              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    2744              :          TYPE(mp_request_type), INTENT(out)       :: request
    2745              :          INTEGER, INTENT(in), OPTIONAL            :: tag
    2746              : 
    2747              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_irecv_bv'
    2748              : 
    2749              :          INTEGER                                  :: handle
    2750              : #if defined(__parallel)
    2751              :          INTEGER                                  :: ierr, msglen, my_tag
    2752              :          LOGICAL                                  :: foo(1)
    2753              : #endif
    2754              : 
    2755           16 :          CALL mp_timeset(routineN, handle)
    2756              : 
    2757              : #if defined(__parallel)
    2758              : #if !defined(__GNUC__) || __GNUC__ >= 9
    2759           16 :          CPASSERT(IS_CONTIGUOUS(msgout))
    2760              : #endif
    2761              : 
    2762           16 :          my_tag = 0
    2763           16 :          IF (PRESENT(tag)) my_tag = tag
    2764              : 
    2765           16 :          msglen = SIZE(msgout, 1)
    2766           16 :          IF (msglen > 0) THEN
    2767              :             CALL mpi_irecv(msgout(1), msglen, MPI_LOGICAL, source, my_tag, &
    2768           16 :                            comm%handle, request%handle, ierr)
    2769              :          ELSE
    2770              :             CALL mpi_irecv(foo, msglen, MPI_LOGICAL, source, my_tag, &
    2771            0 :                            comm%handle, request%handle, ierr)
    2772              :          END IF
    2773           16 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_ircv @ "//routineN)
    2774              : 
    2775           16 :          CALL add_perf(perf_id=12, count=1, msg_size=msglen*loglen)
    2776              : #else
    2777              :          CPABORT("mp_irecv called in non parallel case")
    2778              :          MARK_USED(msgout)
    2779              :          MARK_USED(source)
    2780              :          MARK_USED(comm)
    2781              :          MARK_USED(tag)
    2782              :          request = mp_request_null
    2783              : #endif
    2784           16 :          CALL mp_timestop(handle)
    2785           16 :       END SUBROUTINE mp_irecv_bv
    2786              : 
    2787              : ! **************************************************************************************************
    2788              : !> \brief Non-blocking send of rank-3 logical data
    2789              : !> \param msgin the input message
    2790              : !> \param dest the destination processor
    2791              : !> \param comm  the communicator object
    2792              : !> \param request communication request index
    2793              : !> \param tag message tag
    2794              : !> \par History
    2795              : !>      2.2016 added _bm3 subroutine [Nico Holmberg]
    2796              : !> \author fawzi
    2797              : !> \note see mp_irecv_iv
    2798              : !> \note
    2799              : !>      arrays can be pointers or assumed shape, but they must be contiguous!
    2800              : ! **************************************************************************************************
    2801            0 :       SUBROUTINE mp_isend_bm3(msgin, dest, comm, request, tag)
    2802              :          LOGICAL, DIMENSION(:, :, :), INTENT(INOUT) :: msgin
    2803              :          INTEGER, INTENT(IN)                        :: dest
    2804              :          CLASS(mp_comm_type), INTENT(IN)            :: comm
    2805              :          TYPE(mp_request_type), INTENT(out)         :: request
    2806              :          INTEGER, INTENT(in), OPTIONAL              :: tag
    2807              : 
    2808              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_isend_bm3'
    2809              : 
    2810              :          INTEGER                                    :: handle
    2811              : #if defined(__parallel)
    2812              :          INTEGER                                    :: ierr, msglen, my_tag
    2813              :          LOGICAL                                    :: foo(1)
    2814              : #endif
    2815              : 
    2816            0 :          CALL mp_timeset(routineN, handle)
    2817              : 
    2818              : #if defined(__parallel)
    2819              : #if !defined(__GNUC__) || __GNUC__ >= 9
    2820            0 :          CPASSERT(IS_CONTIGUOUS(msgin))
    2821              : #endif
    2822              : 
    2823            0 :          my_tag = 0
    2824            0 :          IF (PRESENT(tag)) my_tag = tag
    2825              : 
    2826            0 :          msglen = SIZE(msgin, 1)*SIZE(msgin, 2)*SIZE(msgin, 3)
    2827            0 :          IF (msglen > 0) THEN
    2828              :             CALL mpi_isend(msgin(1, 1, 1), msglen, MPI_LOGICAL, dest, my_tag, &
    2829            0 :                            comm%handle, request%handle, ierr)
    2830              :          ELSE
    2831              :             CALL mpi_isend(foo, msglen, MPI_LOGICAL, dest, my_tag, &
    2832            0 :                            comm%handle, request%handle, ierr)
    2833              :          END IF
    2834            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_isend @ "//routineN)
    2835              : 
    2836            0 :          CALL add_perf(perf_id=11, count=1, msg_size=msglen*loglen)
    2837              : #else
    2838              :          CPABORT("mp_isend called in non parallel case")
    2839              :          MARK_USED(msgin)
    2840              :          MARK_USED(dest)
    2841              :          MARK_USED(comm)
    2842              :          MARK_USED(tag)
    2843              :          request = mp_request_null
    2844              : #endif
    2845            0 :          CALL mp_timestop(handle)
    2846            0 :       END SUBROUTINE mp_isend_bm3
    2847              : 
    2848              : ! **************************************************************************************************
    2849              : !> \brief Non-blocking receive of rank-3 logical data
    2850              : !> \param msgout the received message
    2851              : !> \param source the source processor
    2852              : !> \param comm  the communicator object
    2853              : !> \param request communication request index
    2854              : !> \param tag message tag
    2855              : !> \par History
    2856              : !>      2.2016 added _bm3 subroutine [Nico Holmberg]
    2857              : !> \author fawzi
    2858              : !> \note see mp_irecv_iv
    2859              : !> \note
    2860              : !>      arrays can be pointers or assumed shape, but they must be contiguous!
    2861              : ! **************************************************************************************************
    2862            0 :       SUBROUTINE mp_irecv_bm3(msgout, source, comm, request, tag)
    2863              :          LOGICAL, DIMENSION(:, :, :), INTENT(INOUT) :: msgout
    2864              :          INTEGER, INTENT(IN)                        :: source
    2865              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    2866              :          TYPE(mp_request_type), INTENT(out)         :: request
    2867              :          INTEGER, INTENT(in), OPTIONAL              :: tag
    2868              : 
    2869              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_irecv_bm3'
    2870              : 
    2871              :          INTEGER                                    :: handle
    2872              : #if defined(__parallel)
    2873              :          INTEGER                                    :: ierr, msglen, my_tag
    2874              :          LOGICAL                                    :: foo(1)
    2875              : #endif
    2876              : 
    2877            0 :          CALL mp_timeset(routineN, handle)
    2878              : 
    2879              : #if defined(__parallel)
    2880              : #if !defined(__GNUC__) || __GNUC__ >= 9
    2881            0 :          CPASSERT(IS_CONTIGUOUS(msgout))
    2882              : #endif
    2883              : 
    2884            0 :          my_tag = 0
    2885            0 :          IF (PRESENT(tag)) my_tag = tag
    2886              : 
    2887            0 :          msglen = SIZE(msgout, 1)*SIZE(msgout, 2)*SIZE(msgout, 3)
    2888            0 :          IF (msglen > 0) THEN
    2889              :             CALL mpi_irecv(msgout(1, 1, 1), msglen, MPI_LOGICAL, source, my_tag, &
    2890            0 :                            comm%handle, request%handle, ierr)
    2891              :          ELSE
    2892              :             CALL mpi_irecv(foo, msglen, MPI_LOGICAL, source, my_tag, &
    2893            0 :                            comm%handle, request%handle, ierr)
    2894              :          END IF
    2895            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_ircv @ "//routineN)
    2896              : 
    2897            0 :          CALL add_perf(perf_id=12, count=1, msg_size=msglen*loglen)
    2898              : #else
    2899              :          CPABORT("mp_irecv called in non parallel case")
    2900              :          MARK_USED(msgout)
    2901              :          MARK_USED(source)
    2902              :          MARK_USED(comm)
    2903              :          MARK_USED(request)
    2904              :          MARK_USED(tag)
    2905              :          request = mp_request_null
    2906              : #endif
    2907            0 :          CALL mp_timestop(handle)
    2908            0 :       END SUBROUTINE mp_irecv_bm3
    2909              : 
    2910              : ! **************************************************************************************************
    2911              : !> \brief Broadcasts a string.
    2912              : !> \param msg ...
    2913              : !> \param source ...
    2914              : !> \param comm ...
    2915              : ! **************************************************************************************************
    2916      3986284 :       SUBROUTINE mp_bcast_av(msg, source, comm)
    2917              :          CHARACTER(LEN=*), INTENT(INOUT)          :: msg
    2918              :          INTEGER, INTENT(IN)                      :: source
    2919              :          CLASS(mp_comm_type), INTENT(IN)          :: comm
    2920              : 
    2921              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_bcast_av'
    2922              : 
    2923              :          INTEGER                                  :: handle
    2924              : #if defined(__parallel)
    2925              :          INTEGER                                  :: ierr, msglen
    2926              : #endif
    2927              : 
    2928      3986284 :          CALL mp_timeset(routineN, handle)
    2929              : 
    2930              : #if defined(__parallel)
    2931      3986284 :          msglen = LEN(msg)*charlen
    2932      3986284 :          IF (comm%mepos /= source) msg = "" ! need to clear msg
    2933      3986284 :          CALL mpi_bcast(msg, msglen, MPI_CHARACTER, source, comm%handle, ierr)
    2934      3986284 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_bcast @ "//routineN)
    2935      3986284 :          CALL add_perf(perf_id=2, count=1, msg_size=msglen)
    2936              : #else
    2937              :          MARK_USED(msg)
    2938              :          MARK_USED(source)
    2939              :          MARK_USED(comm)
    2940              : #endif
    2941      3986284 :          CALL mp_timestop(handle)
    2942      3986284 :       END SUBROUTINE mp_bcast_av
    2943              : 
    2944              : ! **************************************************************************************************
    2945              : !> \brief Broadcasts a string.
    2946              : !> \param msg ...
    2947              : !> \param comm ...
    2948              : ! **************************************************************************************************
    2949          746 :       SUBROUTINE mp_bcast_av_src(msg, comm)
    2950              :          CHARACTER(LEN=*), INTENT(INOUT)          :: msg
    2951              :          CLASS(mp_comm_type), INTENT(IN)          :: comm
    2952              : 
    2953              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_bcast_av_src'
    2954              : 
    2955              :          INTEGER                                  :: handle
    2956              : #if defined(__parallel)
    2957              :          INTEGER                                  :: ierr, msglen
    2958              : #endif
    2959              : 
    2960          746 :          CALL mp_timeset(routineN, handle)
    2961              : 
    2962              : #if defined(__parallel)
    2963          746 :          msglen = LEN(msg)*charlen
    2964          746 :          IF (.NOT. comm%is_source()) msg = "" ! need to clear msg
    2965          746 :          CALL mpi_bcast(msg, msglen, MPI_CHARACTER, comm%source, comm%handle, ierr)
    2966          746 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_bcast @ "//routineN)
    2967          746 :          CALL add_perf(perf_id=2, count=1, msg_size=msglen)
    2968              : #else
    2969              :          MARK_USED(msg)
    2970              :          MARK_USED(comm)
    2971              : #endif
    2972          746 :          CALL mp_timestop(handle)
    2973          746 :       END SUBROUTINE mp_bcast_av_src
    2974              : 
    2975              : ! **************************************************************************************************
    2976              : !> \brief ...
    2977              : !> \param msg ...
    2978              : !> \param source ...
    2979              : !> \param comm ...
    2980              : ! **************************************************************************************************
    2981           28 :       SUBROUTINE mp_bcast_am(msg, source, comm)
    2982              :          CHARACTER(LEN=*), CONTIGUOUS, INTENT(INOUT)  :: msg(:)
    2983              :          INTEGER, INTENT(IN)                          :: source
    2984              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    2985              : 
    2986              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_bcast_am'
    2987              : 
    2988              :          INTEGER                                  :: handle
    2989              : #if defined(__parallel)
    2990              :          INTEGER                                  :: ierr, msglen
    2991              : #endif
    2992              : 
    2993           28 :          CALL mp_timeset(routineN, handle)
    2994              : 
    2995              : #if defined(__parallel)
    2996           28 :          msglen = SIZE(msg)*LEN(msg(1))*charlen
    2997         1922 :          IF (comm%mepos /= source) msg = "" ! need to clear msg
    2998           28 :          CALL mpi_bcast(msg, msglen, MPI_CHARACTER, source, comm%handle, ierr)
    2999           28 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_bcast @ "//routineN)
    3000           28 :          CALL add_perf(perf_id=2, count=1, msg_size=msglen)
    3001              : #else
    3002              :          MARK_USED(msg)
    3003              :          MARK_USED(source)
    3004              :          MARK_USED(comm)
    3005              : #endif
    3006           28 :          CALL mp_timestop(handle)
    3007           28 :       END SUBROUTINE mp_bcast_am
    3008              : 
    3009        80800 :       SUBROUTINE mp_bcast_am_src(msg, comm)
    3010              :          CHARACTER(LEN=*), CONTIGUOUS, INTENT(INOUT)  :: msg(:)
    3011              :          CLASS(mp_comm_type), INTENT(IN)              :: comm
    3012              : 
    3013              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_bcast_am_src'
    3014              : 
    3015              :          INTEGER                                  :: handle
    3016              : #if defined(__parallel)
    3017              :          INTEGER                                  :: ierr, msglen
    3018              : #endif
    3019              : 
    3020        80800 :          CALL mp_timeset(routineN, handle)
    3021              : 
    3022              : #if defined(__parallel)
    3023        80800 :          msglen = SIZE(msg)*LEN(msg(1))*charlen
    3024     40480800 :          IF (.NOT. comm%is_source()) msg = "" ! need to clear msg
    3025        80800 :          CALL mpi_bcast(msg, msglen, MPI_CHARACTER, comm%source, comm%handle, ierr)
    3026        80800 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_bcast @ "//routineN)
    3027        80800 :          CALL add_perf(perf_id=2, count=1, msg_size=msglen)
    3028              : #else
    3029              :          MARK_USED(msg)
    3030              :          MARK_USED(comm)
    3031              : #endif
    3032        80800 :          CALL mp_timestop(handle)
    3033        80800 :       END SUBROUTINE mp_bcast_am_src
    3034              : 
    3035              : ! **************************************************************************************************
    3036              : !> \brief Finds the location of the minimal element in a vector.
    3037              : !> \param[in,out] msg         Find location of minimum element among these
    3038              : !>                            data (input).
    3039              : !> \param[in] comm            Message passing environment identifier
    3040              : !> \par MPI mapping
    3041              : !>      mpi_allreduce with the MPI_MINLOC reduction function identifier
    3042              : !> \par Invalid data types
    3043              : !>      This routine is invalid for (int_8) data!
    3044              : ! **************************************************************************************************
    3045          310 :       SUBROUTINE mp_minloc_dv(msg, comm)
    3046              :          REAL(kind=real_8), CONTIGUOUS, INTENT(INOUT)         :: msg(:)
    3047              :          CLASS(mp_comm_type), INTENT(IN)                      :: comm
    3048              : 
    3049              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_minloc_dv'
    3050              : 
    3051              :          INTEGER                                  :: handle
    3052              : #if defined(__parallel)
    3053              :          INTEGER                                  :: ierr, msglen
    3054          310 :          REAL(kind=real_8), ALLOCATABLE           :: res(:)
    3055              : #endif
    3056              : 
    3057              :          IF ("d" == "l" .AND. real_8 == int_8) THEN
    3058              :             CPABORT("Minimal location not available with long integers @ "//routineN)
    3059              :          END IF
    3060          310 :          CALL mp_timeset(routineN, handle)
    3061              : 
    3062              : #if defined(__parallel)
    3063          310 :          msglen = SIZE(msg)
    3064          930 :          ALLOCATE (res(1:msglen), STAT=ierr)
    3065          310 :          IF (ierr /= 0) &
    3066            0 :             CPABORT("allocate @ "//routineN)
    3067          310 :          CALL mpi_allreduce(msg, res, msglen/2, MPI_2DOUBLE_PRECISION, MPI_MINLOC, comm%handle, ierr)
    3068          310 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_allreduce @ "//routineN)
    3069          930 :          msg = res
    3070          310 :          DEALLOCATE (res)
    3071          310 :          CALL add_perf(perf_id=3, count=1, msg_size=msglen*real_8_size)
    3072              : #else
    3073              :          MARK_USED(msg)
    3074              :          MARK_USED(comm)
    3075              : #endif
    3076          310 :          CALL mp_timestop(handle)
    3077          310 :       END SUBROUTINE mp_minloc_dv
    3078              : 
    3079              : ! **************************************************************************************************
    3080              : !> \brief Finds the location of the minimal element in a vector.
    3081              : !> \param[in,out] msg         Find location of minimum element among these
    3082              : !>                            data (input).
    3083              : !> \param[in] comm            Message passing environment identifier
    3084              : !> \par MPI mapping
    3085              : !>      mpi_allreduce with the MPI_MINLOC reduction function identifier
    3086              : !> \par Invalid data types
    3087              : !>      This routine is invalid for (int_8) data!
    3088              : ! **************************************************************************************************
    3089            0 :       SUBROUTINE mp_minloc_iv(msg, comm)
    3090              :          INTEGER(KIND=int_4), CONTIGUOUS, INTENT(INOUT)       :: msg(:)
    3091              :          CLASS(mp_comm_type), INTENT(IN)                      :: comm
    3092              : 
    3093              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_minloc_iv'
    3094              : 
    3095              :          INTEGER                                  :: handle
    3096              : #if defined(__parallel)
    3097              :          INTEGER                                  :: ierr, msglen
    3098            0 :          INTEGER(KIND=int_4), ALLOCATABLE         :: res(:)
    3099              : #endif
    3100              : 
    3101              :          IF ("i" == "l" .AND. int_4 == int_8) THEN
    3102              :             CPABORT("Minimal location not available with long integers @ "//routineN)
    3103              :          END IF
    3104            0 :          CALL mp_timeset(routineN, handle)
    3105              : 
    3106              : #if defined(__parallel)
    3107            0 :          msglen = SIZE(msg)
    3108            0 :          ALLOCATE (res(1:msglen))
    3109            0 :          CALL mpi_allreduce(msg, res, msglen/2, MPI_2INTEGER, MPI_MINLOC, comm%handle, ierr)
    3110            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_allreduce @ "//routineN)
    3111            0 :          msg = res
    3112            0 :          DEALLOCATE (res)
    3113            0 :          CALL add_perf(perf_id=3, count=1, msg_size=msglen*int_4_size)
    3114              : #else
    3115              :          MARK_USED(msg)
    3116              :          MARK_USED(comm)
    3117              : #endif
    3118            0 :          CALL mp_timestop(handle)
    3119            0 :       END SUBROUTINE mp_minloc_iv
    3120              : 
    3121              : ! **************************************************************************************************
    3122              : !> \brief Finds the location of the minimal element in a vector.
    3123              : !> \param[in,out] msg         Find location of minimum element among these
    3124              : !>                            data (input).
    3125              : !> \param[in] comm            Message passing environment identifier
    3126              : !> \par MPI mapping
    3127              : !>      mpi_allreduce with the MPI_MINLOC reduction function identifier
    3128              : !> \par Invalid data types
    3129              : !>      This routine is invalid for (int_8) data!
    3130              : ! **************************************************************************************************
    3131            0 :       SUBROUTINE mp_minloc_lv(msg, comm)
    3132              :          INTEGER(KIND=int_8), CONTIGUOUS, INTENT(INOUT)       :: msg(:)
    3133              :          CLASS(mp_comm_type), INTENT(IN)                      :: comm
    3134              : 
    3135              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_minloc_lv'
    3136              : 
    3137              :          INTEGER                                  :: handle
    3138              : #if defined(__parallel)
    3139              :          INTEGER                                  :: ierr, msglen
    3140            0 :          INTEGER(KIND=int_8), ALLOCATABLE         :: res(:)
    3141              : #endif
    3142              : 
    3143              :          IF ("l" == "l" .AND. int_8 == int_8) THEN
    3144            0 :             CPABORT("Minimal location not available with long integers @ "//routineN)
    3145              :          END IF
    3146            0 :          CALL mp_timeset(routineN, handle)
    3147              : 
    3148              : #if defined(__parallel)
    3149            0 :          msglen = SIZE(msg)
    3150            0 :          ALLOCATE (res(1:msglen))
    3151            0 :          CALL mpi_allreduce(msg, res, msglen/2, MPI_INTEGER8, MPI_MINLOC, comm%handle, ierr)
    3152            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_allreduce @ "//routineN)
    3153            0 :          msg = res
    3154            0 :          DEALLOCATE (res)
    3155            0 :          CALL add_perf(perf_id=3, count=1, msg_size=msglen*int_8_size)
    3156              : #else
    3157              :          MARK_USED(msg)
    3158              :          MARK_USED(comm)
    3159              : #endif
    3160            0 :          CALL mp_timestop(handle)
    3161            0 :       END SUBROUTINE mp_minloc_lv
    3162              : 
    3163              : ! **************************************************************************************************
    3164              : !> \brief Finds the location of the minimal element in a vector.
    3165              : !> \param[in,out] msg         Find location of minimum element among these
    3166              : !>                            data (input).
    3167              : !> \param[in] comm            Message passing environment identifier
    3168              : !> \par MPI mapping
    3169              : !>      mpi_allreduce with the MPI_MINLOC reduction function identifier
    3170              : !> \par Invalid data types
    3171              : !>      This routine is invalid for (int_8) data!
    3172              : ! **************************************************************************************************
    3173            0 :       SUBROUTINE mp_minloc_rv(msg, comm)
    3174              :          REAL(kind=real_4), CONTIGUOUS, INTENT(INOUT)         :: msg(:)
    3175              :          CLASS(mp_comm_type), INTENT(IN)                      :: comm
    3176              : 
    3177              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_minloc_rv'
    3178              : 
    3179              :          INTEGER                                  :: handle
    3180              : #if defined(__parallel)
    3181              :          INTEGER                                  :: ierr, msglen
    3182            0 :          REAL(kind=real_4), ALLOCATABLE           :: res(:)
    3183              : #endif
    3184              : 
    3185              :          IF ("r" == "l" .AND. real_4 == int_8) THEN
    3186              :             CPABORT("Minimal location not available with long integers @ "//routineN)
    3187              :          END IF
    3188            0 :          CALL mp_timeset(routineN, handle)
    3189              : 
    3190              : #if defined(__parallel)
    3191            0 :          msglen = SIZE(msg)
    3192            0 :          ALLOCATE (res(1:msglen))
    3193            0 :          CALL mpi_allreduce(msg, res, msglen/2, MPI_2REAL, MPI_MINLOC, comm%handle, ierr)
    3194            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_allreduce @ "//routineN)
    3195            0 :          msg = res
    3196            0 :          DEALLOCATE (res)
    3197            0 :          CALL add_perf(perf_id=3, count=1, msg_size=msglen*real_4_size)
    3198              : #else
    3199              :          MARK_USED(msg)
    3200              :          MARK_USED(comm)
    3201              : #endif
    3202            0 :          CALL mp_timestop(handle)
    3203            0 :       END SUBROUTINE mp_minloc_rv
    3204              : 
    3205              : ! **************************************************************************************************
    3206              : !> \brief Finds the location of the maximal element in a vector.
    3207              : !> \param[in,out] msg         Find location of maximum element among these
    3208              : !>                            data (input).
    3209              : !> \param[in] comm            Message passing environment identifier
    3210              : !> \par MPI mapping
    3211              : !>      mpi_allreduce with the MPI_MAXLOC reduction function identifier
    3212              : !> \par Invalid data types
    3213              : !>      This routine is invalid for (int_8) data!
    3214              : ! **************************************************************************************************
    3215      7959711 :       SUBROUTINE mp_maxloc_dv(msg, comm)
    3216              :          REAL(kind=real_8), CONTIGUOUS, INTENT(INOUT)         :: msg(:)
    3217              :          CLASS(mp_comm_type), INTENT(IN)                      :: comm
    3218              : 
    3219              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_maxloc_dv'
    3220              : 
    3221              :          INTEGER                                  :: handle
    3222              : #if defined(__parallel)
    3223              :          INTEGER                                  :: ierr, msglen
    3224      7959711 :          REAL(kind=real_8), ALLOCATABLE           :: res(:)
    3225              : #endif
    3226              : 
    3227              :          IF ("d" == "l" .AND. real_8 == int_8) THEN
    3228              :             CPABORT("Maximal location not available with long integers @ "//routineN)
    3229              :          END IF
    3230      7959711 :          CALL mp_timeset(routineN, handle)
    3231              : 
    3232              : #if defined(__parallel)
    3233      7959711 :          msglen = SIZE(msg)
    3234     23879133 :          ALLOCATE (res(1:msglen))
    3235      7959711 :          CALL mpi_allreduce(msg, res, msglen/2, MPI_2DOUBLE_PRECISION, MPI_MAXLOC, comm%handle, ierr)
    3236      7959711 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_allreduce @ "//routineN)
    3237     23879133 :          msg = res
    3238      7959711 :          DEALLOCATE (res)
    3239      7959711 :          CALL add_perf(perf_id=3, count=1, msg_size=msglen*real_8_size)
    3240              : #else
    3241              :          MARK_USED(msg)
    3242              :          MARK_USED(comm)
    3243              : #endif
    3244      7959711 :          CALL mp_timestop(handle)
    3245      7959711 :       END SUBROUTINE mp_maxloc_dv
    3246              : 
    3247              : ! **************************************************************************************************
    3248              : !> \brief Finds the location of the maximal element in a vector.
    3249              : !> \param[in,out] msg         Find location of maximum element among these
    3250              : !>                            data (input).
    3251              : !> \param[in] comm            Message passing environment identifier
    3252              : !> \par MPI mapping
    3253              : !>      mpi_allreduce with the MPI_MAXLOC reduction function identifier
    3254              : !> \par Invalid data types
    3255              : !>      This routine is invalid for (int_8) data!
    3256              : ! **************************************************************************************************
    3257          138 :       SUBROUTINE mp_maxloc_iv(msg, comm)
    3258              :          INTEGER(KIND=int_4), CONTIGUOUS, INTENT(INOUT)       :: msg(:)
    3259              :          CLASS(mp_comm_type), INTENT(IN)                      :: comm
    3260              : 
    3261              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_maxloc_iv'
    3262              : 
    3263              :          INTEGER                                  :: handle
    3264              : #if defined(__parallel)
    3265              :          INTEGER                                  :: ierr, msglen
    3266          138 :          INTEGER(KIND=int_4), ALLOCATABLE         :: res(:)
    3267              : #endif
    3268              : 
    3269              :          IF ("i" == "l" .AND. int_4 == int_8) THEN
    3270              :             CPABORT("Maximal location not available with long integers @ "//routineN)
    3271              :          END IF
    3272          138 :          CALL mp_timeset(routineN, handle)
    3273              : 
    3274              : #if defined(__parallel)
    3275          138 :          msglen = SIZE(msg)
    3276          414 :          ALLOCATE (res(1:msglen))
    3277          138 :          CALL mpi_allreduce(msg, res, msglen/2, MPI_2INTEGER, MPI_MAXLOC, comm%handle, ierr)
    3278          138 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_allreduce @ "//routineN)
    3279          414 :          msg = res
    3280          138 :          DEALLOCATE (res)
    3281          138 :          CALL add_perf(perf_id=3, count=1, msg_size=msglen*int_4_size)
    3282              : #else
    3283              :          MARK_USED(msg)
    3284              :          MARK_USED(comm)
    3285              : #endif
    3286          138 :          CALL mp_timestop(handle)
    3287          138 :       END SUBROUTINE mp_maxloc_iv
    3288              : 
    3289              : ! **************************************************************************************************
    3290              : !> \brief Finds the location of the maximal element in a vector.
    3291              : !> \param[in,out] msg         Find location of maximum element among these
    3292              : !>                            data (input).
    3293              : !> \param[in] comm            Message passing environment identifier
    3294              : !> \par MPI mapping
    3295              : !>      mpi_allreduce with the MPI_MAXLOC reduction function identifier
    3296              : !> \par Invalid data types
    3297              : !>      This routine is invalid for (int_8) data!
    3298              : ! **************************************************************************************************
    3299            0 :       SUBROUTINE mp_maxloc_lv(msg, comm)
    3300              :          INTEGER(KIND=int_8), CONTIGUOUS, INTENT(INOUT)       :: msg(:)
    3301              :          CLASS(mp_comm_type), INTENT(IN)                      :: comm
    3302              : 
    3303              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_maxloc_lv'
    3304              : 
    3305              :          INTEGER                                  :: handle
    3306              : #if defined(__parallel)
    3307              :          INTEGER                                  :: ierr, msglen
    3308            0 :          INTEGER(KIND=int_8), ALLOCATABLE         :: res(:)
    3309              : #endif
    3310              : 
    3311              :          IF ("l" == "l" .AND. int_8 == int_8) THEN
    3312            0 :             CPABORT("Maximal location not available with long integers @ "//routineN)
    3313              :          END IF
    3314            0 :          CALL mp_timeset(routineN, handle)
    3315              : 
    3316              : #if defined(__parallel)
    3317            0 :          msglen = SIZE(msg)
    3318            0 :          ALLOCATE (res(1:msglen))
    3319            0 :          CALL mpi_allreduce(msg, res, msglen/2, MPI_INTEGER8, MPI_MAXLOC, comm%handle, ierr)
    3320            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_allreduce @ "//routineN)
    3321            0 :          msg = res
    3322            0 :          DEALLOCATE (res)
    3323            0 :          CALL add_perf(perf_id=3, count=1, msg_size=msglen*int_8_size)
    3324              : #else
    3325              :          MARK_USED(msg)
    3326              :          MARK_USED(comm)
    3327              : #endif
    3328            0 :          CALL mp_timestop(handle)
    3329            0 :       END SUBROUTINE mp_maxloc_lv
    3330              : 
    3331              : ! **************************************************************************************************
    3332              : !> \brief Finds the location of the maximal element in a vector.
    3333              : !> \param[in,out] msg         Find location of maximum element among these
    3334              : !>                            data (input).
    3335              : !> \param[in] comm            Message passing environment identifier
    3336              : !> \par MPI mapping
    3337              : !>      mpi_allreduce with the MPI_MAXLOC reduction function identifier
    3338              : !> \par Invalid data types
    3339              : !>      This routine is invalid for (int_8) data!
    3340              : ! **************************************************************************************************
    3341            0 :       SUBROUTINE mp_maxloc_rv(msg, comm)
    3342              :          REAL(kind=real_4), CONTIGUOUS, INTENT(INOUT)         :: msg(:)
    3343              :          CLASS(mp_comm_type), INTENT(IN)                      :: comm
    3344              : 
    3345              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_maxloc_rv'
    3346              : 
    3347              :          INTEGER                                  :: handle
    3348              : #if defined(__parallel)
    3349              :          INTEGER                                  :: ierr, msglen
    3350            0 :          REAL(kind=real_4), ALLOCATABLE           :: res(:)
    3351              : #endif
    3352              : 
    3353              :          IF ("r" == "l" .AND. real_4 == int_8) THEN
    3354              :             CPABORT("Maximal location not available with long integers @ "//routineN)
    3355              :          END IF
    3356            0 :          CALL mp_timeset(routineN, handle)
    3357              : 
    3358              : #if defined(__parallel)
    3359            0 :          msglen = SIZE(msg)
    3360            0 :          ALLOCATE (res(1:msglen))
    3361            0 :          CALL mpi_allreduce(msg, res, msglen/2, MPI_2REAL, MPI_MAXLOC, comm%handle, ierr)
    3362            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_allreduce @ "//routineN)
    3363            0 :          msg = res
    3364            0 :          DEALLOCATE (res)
    3365            0 :          CALL add_perf(perf_id=3, count=1, msg_size=msglen*real_4_size)
    3366              : #else
    3367              :          MARK_USED(msg)
    3368              :          MARK_USED(comm)
    3369              : #endif
    3370            0 :          CALL mp_timestop(handle)
    3371            0 :       END SUBROUTINE mp_maxloc_rv
    3372              : 
    3373              : ! **************************************************************************************************
    3374              : !> \brief Logical OR reduction
    3375              : !> \param[in,out] msg         Datum to perform inclusive disjunction (input)
    3376              : !>                            and resultant inclusive disjunction (output)
    3377              : !> \param[in] comm            Message passing environment identifier
    3378              : !> \par MPI mapping
    3379              : !>      mpi_allreduce
    3380              : ! **************************************************************************************************
    3381        58746 :       SUBROUTINE mp_sum_b(msg, comm)
    3382              :          LOGICAL, INTENT(INOUT)                             :: msg
    3383              :          CLASS(mp_comm_type), INTENT(IN)                                :: comm
    3384              : 
    3385              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_sum_b'
    3386              : 
    3387              :          INTEGER                                            :: handle
    3388              : #if defined(__parallel)
    3389              :          INTEGER :: ierr, msglen
    3390              : #endif
    3391              : 
    3392        58746 :          CALL mp_timeset(routineN, handle)
    3393              : #if defined(__parallel)
    3394        58746 :          msglen = 1
    3395        58746 :          CALL mpi_allreduce(MPI_IN_PLACE, msg, msglen, MPI_LOGICAL, MPI_LOR, comm%handle, ierr)
    3396        58746 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_allreduce @ "//routineN)
    3397              : #else
    3398              :          MARK_USED(msg)
    3399              :          MARK_USED(comm)
    3400              : #endif
    3401        58746 :          CALL mp_timestop(handle)
    3402        58746 :       END SUBROUTINE mp_sum_b
    3403              : 
    3404              : ! **************************************************************************************************
    3405              : !> \brief Logical OR reduction
    3406              : !> \param[in,out] msg         Datum to perform inclusive disjunction (input)
    3407              : !>                            and resultant inclusive disjunction (output)
    3408              : !> \param[in] comm             Message passing environment identifier
    3409              : !> \par MPI mapping
    3410              : !>      mpi_allreduce
    3411              : ! **************************************************************************************************
    3412            0 :       SUBROUTINE mp_sum_bv(msg, comm)
    3413              :          LOGICAL, DIMENSION(:), CONTIGUOUS, INTENT(INOUT)               :: msg
    3414              :          CLASS(mp_comm_type), INTENT(IN)                                :: comm
    3415              : 
    3416              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_sum_bv'
    3417              : 
    3418              :          INTEGER                                            :: handle
    3419              : #if defined(__parallel)
    3420              :          INTEGER :: ierr, msglen
    3421              : #endif
    3422              : 
    3423            0 :          CALL mp_timeset(routineN, handle)
    3424              : #if defined(__parallel)
    3425            0 :          msglen = SIZE(msg)
    3426            0 :          IF (msglen > 0) THEN
    3427            0 :             CALL mpi_allreduce(MPI_IN_PLACE, msg, msglen, MPI_LOGICAL, MPI_LOR, comm%handle, ierr)
    3428            0 :             IF (ierr /= 0) CALL mp_stop(ierr, "mpi_allreduce @ "//routineN)
    3429              :          END IF
    3430              : #else
    3431              :          MARK_USED(msg)
    3432              :          MARK_USED(comm)
    3433              : #endif
    3434            0 :          CALL mp_timestop(handle)
    3435            0 :       END SUBROUTINE mp_sum_bv
    3436              : 
    3437              : ! **************************************************************************************************
    3438              : !> \brief Logical OR reduction
    3439              : !> \param[in,out] msg         Datum to perform inclusive disjunction (input)
    3440              : !>                            and resultant inclusive disjunction (output)
    3441              : !> \param[in] comm             Message passing environment identifier
    3442              : !> \param request ...
    3443              : !> \par MPI mapping
    3444              : !>      mpi_allreduce
    3445              : ! **************************************************************************************************
    3446            0 :       SUBROUTINE mp_isum_bv(msg, comm, request)
    3447              :          LOGICAL, DIMENSION(:), INTENT(INOUT)               :: msg
    3448              :          CLASS(mp_comm_type), INTENT(IN)                                :: comm
    3449              :          TYPE(mp_request_type), INTENT(INOUT)                             :: request
    3450              : 
    3451              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_isum_bv'
    3452              : 
    3453              :          INTEGER                                            :: handle
    3454              : #if defined(__parallel)
    3455              :          INTEGER :: ierr, msglen
    3456              : #endif
    3457              : 
    3458            0 :          CALL mp_timeset(routineN, handle)
    3459              : #if defined(__parallel)
    3460            0 :          msglen = SIZE(msg)
    3461              : #if !defined(__GNUC__) || __GNUC__ >= 9
    3462            0 :          CPASSERT(IS_CONTIGUOUS(msg))
    3463              : #endif
    3464              : 
    3465            0 :          IF (msglen > 0) THEN
    3466            0 :             CALL mpi_iallreduce(MPI_IN_PLACE, msg, msglen, MPI_LOGICAL, MPI_LOR, comm%handle, request%handle, ierr)
    3467            0 :             IF (ierr /= 0) CALL mp_stop(ierr, "mpi_allreduce @ "//routineN)
    3468              :          ELSE
    3469            0 :             request = mp_request_null
    3470              :          END IF
    3471              : #else
    3472              :          MARK_USED(msg)
    3473              :          MARK_USED(comm)
    3474              :          request = mp_request_null
    3475              : #endif
    3476            0 :          CALL mp_timestop(handle)
    3477            0 :       END SUBROUTINE mp_isum_bv
    3478              : 
    3479              : ! **************************************************************************************************
    3480              : !> \brief Get Version of the MPI Library (MPI 3)
    3481              : !> \param[out] version        Version of the library,
    3482              : !>                            declared as CHARACTER(LEN=mp_max_library_version_string)
    3483              : !> \param[out] resultlen      Length (in printable characters) of
    3484              : !>                            the result returned in version (integer)
    3485              : ! **************************************************************************************************
    3486            0 :       SUBROUTINE mp_get_library_version(version, resultlen)
    3487              :          CHARACTER(len=*), INTENT(OUT)                      :: version
    3488              :          INTEGER, INTENT(OUT)                               :: resultlen
    3489              : 
    3490              : #if defined(__parallel)
    3491              :          INTEGER                                            :: ierr
    3492              : #endif
    3493              : 
    3494            0 :          version = ''
    3495              : 
    3496              : #if defined(__parallel)
    3497              :          ierr = 0
    3498            0 :          CALL mpi_get_library_version(version, resultlen, ierr)
    3499            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_get_library_version @ mp_get_library_version")
    3500              : #else
    3501              :          resultlen = 0
    3502              : #endif
    3503            0 :       END SUBROUTINE mp_get_library_version
    3504              : 
    3505              : ! **************************************************************************************************
    3506              : !> \brief Opens a file
    3507              : !> \param[in] groupid    message passing environment identifier
    3508              : !> \param[out] fh        file handle (file storage unit)
    3509              : !> \param[in] filepath   path to the file
    3510              : !> \param amode_status   access mode
    3511              : !> \param info ...
    3512              : !> \par MPI-I/O mapping  mpi_file_open
    3513              : !> \par STREAM-I/O mapping  OPEN
    3514              : !>
    3515              : !> \param[in](optional) info   info object
    3516              : !> \par History
    3517              : !>      11.2012 created [Hossein Bani-Hashemian]
    3518              : ! **************************************************************************************************
    3519         1896 :       SUBROUTINE mp_file_open(groupid, fh, filepath, amode_status, info)
    3520              :          CLASS(mp_comm_type), INTENT(IN)                      :: groupid
    3521              :          CLASS(mp_file_type), INTENT(OUT)                     :: fh
    3522              :          CHARACTER(len=*), INTENT(IN)                         :: filepath
    3523              :          INTEGER, INTENT(IN)                                  :: amode_status
    3524              :          TYPE(mp_info_type), INTENT(IN), OPTIONAL             :: info
    3525              : 
    3526              : #if defined(__parallel)
    3527              :          INTEGER                                  :: ierr
    3528              :          MPI_INFO_TYPE                            :: my_info
    3529              : #else
    3530              :          CHARACTER(LEN=10)                        :: fstatus, fposition
    3531              :          INTEGER                                  :: amode, handle, istat
    3532              :          LOGICAL                                  :: exists, is_open
    3533              : #endif
    3534              : 
    3535              : #if defined(__parallel)
    3536              :          ierr = 0
    3537         1896 :          my_info = mpi_info_null
    3538         1896 :          IF (PRESENT(info)) my_info = info%handle
    3539         1896 :          CALL mpi_file_open(groupid%handle, filepath, amode_status, my_info, fh%handle, ierr)
    3540         1896 :          CALL mpi_file_set_errhandler(fh%handle, MPI_ERRORS_RETURN, ierr)
    3541         1896 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_file_set_errhandler @ mp_file_open")
    3542              : #else
    3543              :          MARK_USED(groupid)
    3544              :          MARK_USED(info)
    3545              :          amode = amode_status
    3546              :          IF (amode > file_amode_append) THEN
    3547              :             fposition = "APPEND"
    3548              :             amode = amode - file_amode_append
    3549              :          ELSE
    3550              :             fposition = "REWIND"
    3551              :          END IF
    3552              :          IF ((amode == file_amode_create) .OR. &
    3553              :              (amode == file_amode_create + file_amode_wronly) .OR. &
    3554              :              (amode == file_amode_create + file_amode_wronly + file_amode_excl)) THEN
    3555              :             fstatus = "UNKNOWN"
    3556              :          ELSE
    3557              :             fstatus = "OLD"
    3558              :          END IF
    3559              :          ! Get a new unit number
    3560              :          DO handle = 1, 999
    3561              :             INQUIRE (UNIT=handle, EXIST=exists, OPENED=is_open, IOSTAT=istat)
    3562              :             IF (exists .AND. (.NOT. is_open) .AND. (istat == 0)) EXIT
    3563              :          END DO
    3564              :          OPEN (UNIT=handle, FILE=filepath, STATUS=fstatus, ACCESS="STREAM", POSITION=fposition)
    3565              :          fh%handle = handle
    3566              : #endif
    3567         1896 :       END SUBROUTINE mp_file_open
    3568              : 
    3569              : ! **************************************************************************************************
    3570              : !> \brief Deletes a file. Auxiliary routine to emulate 'replace' action for mp_file_open.
    3571              : !>        Only the master processor should call this routine.
    3572              : !> \param[in] filepath   path to the file
    3573              : !> \param[in](optional) info   info object
    3574              : !> \par History
    3575              : !>      11.2017 created [Nico Holmberg]
    3576              : ! **************************************************************************************************
    3577          162 :       SUBROUTINE mp_file_delete(filepath, info)
    3578              :          CHARACTER(len=*), INTENT(IN)             :: filepath
    3579              :          TYPE(mp_info_type), INTENT(IN), OPTIONAL :: info
    3580              : 
    3581              : #if defined(__parallel)
    3582              :          INTEGER                                  :: ierr
    3583              :          MPI_INFO_TYPE                            :: my_info
    3584              :          LOGICAL                                  :: exists
    3585              : 
    3586          162 :          ierr = 0
    3587          162 :          my_info = mpi_info_null
    3588          162 :          IF (PRESENT(info)) my_info = info%handle
    3589          162 :          INQUIRE (FILE=filepath, EXIST=exists)
    3590          162 :          IF (exists) CALL mpi_file_delete(filepath, my_info, ierr)
    3591          162 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_file_set_errhandler @ mp_file_delete")
    3592              : #else
    3593              :          MARK_USED(filepath)
    3594              :          MARK_USED(info)
    3595              :          ! Explicit file delete not necessary, handled by subsequent call to open_file with action 'replace'
    3596              : #endif
    3597              : 
    3598          162 :       END SUBROUTINE mp_file_delete
    3599              : 
    3600              : ! **************************************************************************************************
    3601              : !> \brief Closes a file
    3602              : !> \param[in] fh   file handle (file storage unit)
    3603              : !> \par MPI-I/O mapping   mpi_file_close
    3604              : !> \par STREAM-I/O mapping   CLOSE
    3605              : !>
    3606              : !> \par History
    3607              : !>      11.2012 created [Hossein Bani-Hashemian]
    3608              : ! **************************************************************************************************
    3609         3792 :       SUBROUTINE mp_file_close(fh)
    3610              :          CLASS(mp_file_type), INTENT(INOUT)                             :: fh
    3611              : 
    3612              : #if defined(__parallel)
    3613              :          INTEGER                                            :: ierr
    3614              : 
    3615              :          ierr = 0
    3616         1896 :          CALL mpi_file_set_errhandler(fh%handle, MPI_ERRORS_RETURN, ierr)
    3617         1896 :          CALL mpi_file_close(fh%handle, ierr)
    3618         1896 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_file_set_errhandler @ mp_file_close")
    3619              : #else
    3620              :          CLOSE (fh%handle)
    3621              :          fh%handle = mp_file_null_handle
    3622              : #endif
    3623         1896 :       END SUBROUTINE mp_file_close
    3624              : 
    3625            0 :       SUBROUTINE mp_file_assign(fh_new, fh_old)
    3626              :          CLASS(mp_file_type), INTENT(OUT) :: fh_new
    3627              :          CLASS(mp_file_type), INTENT(IN) :: fh_old
    3628              : 
    3629            0 :          fh_new%handle = fh_old%handle
    3630              : 
    3631            0 :       END SUBROUTINE
    3632              : 
    3633              : ! **************************************************************************************************
    3634              : !> \brief Returns the file size
    3635              : !> \param[in] fh file handle (file storage unit)
    3636              : !> \param[out] file_size  the file size
    3637              : !> \par MPI-I/O mapping   mpi_file_get_size
    3638              : !> \par STREAM-I/O mapping   INQUIRE
    3639              : !>
    3640              : !> \par History
    3641              : !>      12.2012 created [Hossein Bani-Hashemian]
    3642              : ! **************************************************************************************************
    3643            0 :       SUBROUTINE mp_file_get_size(fh, file_size)
    3644              :          CLASS(mp_file_type), INTENT(IN)                                :: fh
    3645              :          INTEGER(kind=file_offset), INTENT(OUT)             :: file_size
    3646              : 
    3647              : #if defined(__parallel)
    3648              :          INTEGER                                            :: ierr
    3649              : #endif
    3650              : 
    3651              : #if defined(__parallel)
    3652              :          ierr = 0
    3653            0 :          CALL mpi_file_set_errhandler(fh%handle, MPI_ERRORS_RETURN, ierr)
    3654            0 :          CALL mpi_file_get_size(fh%handle, file_size, ierr)
    3655            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_file_set_errhandler @ mp_file_get_size")
    3656              : #else
    3657              :          INQUIRE (UNIT=fh%handle, SIZE=file_size)
    3658              : #endif
    3659            0 :       END SUBROUTINE mp_file_get_size
    3660              : 
    3661              : ! **************************************************************************************************
    3662              : !> \brief Returns the file position
    3663              : !> \param[in] fh file handle (file storage unit)
    3664              : !> \param[out] file_size  the file position
    3665              : !> \par MPI-I/O mapping   mpi_file_get_position
    3666              : !> \par STREAM-I/O mapping   INQUIRE
    3667              : !>
    3668              : !> \par History
    3669              : !>      11.2017 created [Nico Holmberg]
    3670              : ! **************************************************************************************************
    3671         3716 :       SUBROUTINE mp_file_get_position(fh, pos)
    3672              :          CLASS(mp_file_type), INTENT(IN)                                :: fh
    3673              :          INTEGER(kind=file_offset), INTENT(OUT)             :: pos
    3674              : 
    3675              : #if defined(__parallel)
    3676              :          INTEGER                                            :: ierr
    3677              : #endif
    3678              : 
    3679              : #if defined(__parallel)
    3680              :          ierr = 0
    3681         1858 :          CALL mpi_file_set_errhandler(fh%handle, MPI_ERRORS_RETURN, ierr)
    3682         1858 :          CALL mpi_file_get_position(fh%handle, pos, ierr)
    3683         1858 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_file_set_errhandler @ mp_file_get_position")
    3684              : #else
    3685              :          INQUIRE (UNIT=fh%handle, POS=pos)
    3686              : #endif
    3687         1858 :       END SUBROUTINE mp_file_get_position
    3688              : 
    3689              : ! **************************************************************************************************
    3690              : !> \brief (parallel) Blocking individual file write using explicit offsets
    3691              : !>        (serial) Unformatted stream write
    3692              : !> \param[in] fh     file handle (file storage unit)
    3693              : !> \param[in] offset file offset (position)
    3694              : !> \param[in] msg    data to be written to the file
    3695              : !> \param msglen ...
    3696              : !> \par MPI-I/O mapping   mpi_file_write_at
    3697              : !> \par STREAM-I/O mapping   WRITE
    3698              : !> \param[in](optional) msglen number of the elements of data
    3699              : ! **************************************************************************************************
    3700            0 :       SUBROUTINE mp_file_write_at_chv(fh, offset, msg, msglen)
    3701              :          CHARACTER, CONTIGUOUS, INTENT(IN)                      :: msg(:)
    3702              :          CLASS(mp_file_type), INTENT(IN)                        :: fh
    3703              :          INTEGER, INTENT(IN), OPTIONAL              :: msglen
    3704              :          INTEGER(kind=file_offset), INTENT(IN)      :: offset
    3705              : 
    3706              : #if defined(__parallel)
    3707              :          INTEGER                                    :: ierr, msg_len
    3708              : #endif
    3709              : 
    3710              : #if defined(__parallel)
    3711            0 :          msg_len = SIZE(msg)
    3712            0 :          IF (PRESENT(msglen)) msg_len = msglen
    3713            0 :          CALL MPI_FILE_WRITE_AT(fh%handle, offset, msg, msg_len, MPI_CHARACTER, MPI_STATUS_IGNORE, ierr)
    3714            0 :          IF (ierr /= 0) &
    3715            0 :             CPABORT("mpi_file_write_at_chv @ mp_file_write_at_chv")
    3716              : #else
    3717              :          MARK_USED(msglen)
    3718              :          WRITE (UNIT=fh%handle, POS=offset + 1) msg
    3719              : #endif
    3720            0 :       END SUBROUTINE mp_file_write_at_chv
    3721              : 
    3722              : ! **************************************************************************************************
    3723              : !> \brief ...
    3724              : !> \param fh ...
    3725              : !> \param offset ...
    3726              : !> \param msg ...
    3727              : ! **************************************************************************************************
    3728         8748 :       SUBROUTINE mp_file_write_at_ch(fh, offset, msg)
    3729              :          CHARACTER(LEN=*), INTENT(IN)               :: msg
    3730              :          CLASS(mp_file_type), INTENT(IN)            :: fh
    3731              :          INTEGER(kind=file_offset), INTENT(IN)      :: offset
    3732              : 
    3733              : #if defined(__parallel)
    3734              :          INTEGER                                    :: ierr
    3735              : #endif
    3736              : 
    3737              : #if defined(__parallel)
    3738         8748 :          CALL MPI_FILE_WRITE_AT(fh%handle, offset, msg, LEN(msg), MPI_CHARACTER, MPI_STATUS_IGNORE, ierr)
    3739         8748 :          IF (ierr /= 0) &
    3740            0 :             CPABORT("mpi_file_write_at_ch @ mp_file_write_at_ch")
    3741              : #else
    3742              :          WRITE (UNIT=fh%handle, POS=offset + 1) msg
    3743              : #endif
    3744         8748 :       END SUBROUTINE mp_file_write_at_ch
    3745              : 
    3746              : ! **************************************************************************************************
    3747              : !> \brief (parallel) Blocking collective file write using explicit offsets
    3748              : !>        (serial) Unformatted stream write
    3749              : !> \param fh ...
    3750              : !> \param offset ...
    3751              : !> \param msg ...
    3752              : !> \param msglen ...
    3753              : !> \par MPI-I/O mapping   mpi_file_write_at_all
    3754              : !> \par STREAM-I/O mapping   WRITE
    3755              : ! **************************************************************************************************
    3756            0 :       SUBROUTINE mp_file_write_at_all_chv(fh, offset, msg, msglen)
    3757              :          CHARACTER, CONTIGUOUS, INTENT(IN)                      :: msg(:)
    3758              :          CLASS(mp_file_type), INTENT(IN)                        :: fh
    3759              :          INTEGER, INTENT(IN), OPTIONAL              :: msglen
    3760              :          INTEGER(kind=file_offset), INTENT(IN)      :: offset
    3761              : 
    3762              : #if defined(__parallel)
    3763              :          INTEGER                                    :: ierr, msg_len
    3764              : #endif
    3765              : 
    3766              : #if defined(__parallel)
    3767            0 :          msg_len = SIZE(msg)
    3768            0 :          IF (PRESENT(msglen)) msg_len = msglen
    3769            0 :          CALL MPI_FILE_WRITE_AT_ALL(fh%handle, offset, msg, msg_len, MPI_CHARACTER, MPI_STATUS_IGNORE, ierr)
    3770            0 :          IF (ierr /= 0) &
    3771            0 :             CPABORT("mpi_file_write_at_all_chv @ mp_file_write_at_all_chv")
    3772              : #else
    3773              :          MARK_USED(msglen)
    3774              :          WRITE (UNIT=fh%handle, POS=offset + 1) msg
    3775              : #endif
    3776            0 :       END SUBROUTINE mp_file_write_at_all_chv
    3777              : 
    3778              : ! **************************************************************************************************
    3779              : !> \brief wrapper to MPI_File_write_at_all
    3780              : !> \param fh ...
    3781              : !> \param offset ...
    3782              : !> \param msg ...
    3783              : ! **************************************************************************************************
    3784            0 :       SUBROUTINE mp_file_write_at_all_ch(fh, offset, msg)
    3785              :          CHARACTER(LEN=*), INTENT(IN)               :: msg
    3786              :          CLASS(mp_file_type), INTENT(IN)            :: fh
    3787              :          INTEGER(kind=file_offset), INTENT(IN)      :: offset
    3788              : 
    3789              : #if defined(__parallel)
    3790              :          INTEGER                                    :: ierr
    3791              : #endif
    3792              : 
    3793              : #if defined(__parallel)
    3794            0 :          CALL MPI_FILE_WRITE_AT_ALL(fh%handle, offset, msg, LEN(msg), MPI_CHARACTER, MPI_STATUS_IGNORE, ierr)
    3795            0 :          IF (ierr /= 0) &
    3796            0 :             CPABORT("mpi_file_write_at_all_ch @ mp_file_write_at_all_ch")
    3797              : #else
    3798              :          WRITE (UNIT=fh%handle, POS=offset + 1) msg
    3799              : #endif
    3800            0 :       END SUBROUTINE mp_file_write_at_all_ch
    3801              : 
    3802              : ! **************************************************************************************************
    3803              : !> \brief (parallel) Blocking individual file read using explicit offsets
    3804              : !>        (serial) Unformatted stream read
    3805              : !> \param[in] fh     file handle (file storage unit)
    3806              : !> \param[in] offset file offset (position)
    3807              : !> \param[out] msg   data to be read from the file
    3808              : !> \param msglen ...
    3809              : !> \par MPI-I/O mapping   mpi_file_read_at
    3810              : !> \par STREAM-I/O mapping   READ
    3811              : !> \param[in](optional) msglen  number of elements of data
    3812              : ! **************************************************************************************************
    3813            0 :       SUBROUTINE mp_file_read_at_chv(fh, offset, msg, msglen)
    3814              :          CHARACTER, CONTIGUOUS, INTENT(OUT)                     :: msg(:)
    3815              :          CLASS(mp_file_type), INTENT(IN)                        :: fh
    3816              :          INTEGER, INTENT(IN), OPTIONAL              :: msglen
    3817              :          INTEGER(kind=file_offset), INTENT(IN)      :: offset
    3818              : 
    3819              : #if defined(__parallel)
    3820              :          INTEGER                                    :: ierr, msg_len
    3821              : #endif
    3822              : 
    3823              : #if defined(__parallel)
    3824            0 :          msg_len = SIZE(msg)
    3825            0 :          IF (PRESENT(msglen)) msg_len = msglen
    3826            0 :          CALL MPI_FILE_READ_AT(fh%handle, offset, msg, msg_len, MPI_CHARACTER, MPI_STATUS_IGNORE, ierr)
    3827            0 :          IF (ierr /= 0) &
    3828            0 :             CPABORT("mpi_file_read_at_chv @ mp_file_read_at_chv")
    3829              : #else
    3830              :          MARK_USED(msglen)
    3831              :          READ (UNIT=fh%handle, POS=offset + 1) msg
    3832              : #endif
    3833            0 :       END SUBROUTINE mp_file_read_at_chv
    3834              : 
    3835              : ! **************************************************************************************************
    3836              : !> \brief wrapper to MPI_File_read_at
    3837              : !> \param fh ...
    3838              : !> \param offset ...
    3839              : !> \param msg ...
    3840              : ! **************************************************************************************************
    3841            0 :       SUBROUTINE mp_file_read_at_ch(fh, offset, msg)
    3842              :          CHARACTER(LEN=*), INTENT(OUT)              :: msg
    3843              :          CLASS(mp_file_type), INTENT(IN)            :: fh
    3844              :          INTEGER(kind=file_offset), INTENT(IN)      :: offset
    3845              : 
    3846              : #if defined(__parallel)
    3847              :          INTEGER                                    :: ierr
    3848              : #endif
    3849              : 
    3850              : #if defined(__parallel)
    3851            0 :          CALL MPI_FILE_READ_AT(fh%handle, offset, msg, LEN(msg), MPI_CHARACTER, MPI_STATUS_IGNORE, ierr)
    3852            0 :          IF (ierr /= 0) &
    3853            0 :             CPABORT("mpi_file_read_at_ch @ mp_file_read_at_ch")
    3854              : #else
    3855              :          READ (UNIT=fh%handle, POS=offset + 1) msg
    3856              : #endif
    3857            0 :       END SUBROUTINE mp_file_read_at_ch
    3858              : 
    3859              : ! **************************************************************************************************
    3860              : !> \brief (parallel) Blocking collective file read using explicit offsets
    3861              : !>        (serial) Unformatted stream read
    3862              : !> \param fh ...
    3863              : !> \param offset ...
    3864              : !> \param msg ...
    3865              : !> \param msglen ...
    3866              : !> \par MPI-I/O mapping    mpi_file_read_at_all
    3867              : !> \par STREAM-I/O mapping   READ
    3868              : ! **************************************************************************************************
    3869            0 :       SUBROUTINE mp_file_read_at_all_chv(fh, offset, msg, msglen)
    3870              :          CHARACTER, INTENT(OUT)                     :: msg(:)
    3871              :          CLASS(mp_file_type), INTENT(IN)                        :: fh
    3872              :          INTEGER, INTENT(IN), OPTIONAL              :: msglen
    3873              :          INTEGER(kind=file_offset), INTENT(IN)      :: offset
    3874              : 
    3875              : #if defined(__parallel)
    3876              :          INTEGER                                    :: ierr, msg_len
    3877              : #endif
    3878              : 
    3879              : #if defined(__parallel)
    3880            0 :          msg_len = SIZE(msg)
    3881            0 :          IF (PRESENT(msglen)) msg_len = msglen
    3882            0 :          CALL MPI_FILE_READ_AT_ALL(fh%handle, offset, msg, msg_len, MPI_CHARACTER, MPI_STATUS_IGNORE, ierr)
    3883            0 :          IF (ierr /= 0) &
    3884            0 :             CPABORT("mpi_file_read_at_all_chv @ mp_file_read_at_all_chv")
    3885              : #else
    3886              :          MARK_USED(msglen)
    3887              :          READ (UNIT=fh%handle, POS=offset + 1) msg
    3888              : #endif
    3889            0 :       END SUBROUTINE mp_file_read_at_all_chv
    3890              : 
    3891              : ! **************************************************************************************************
    3892              : !> \brief wrapper to MPI_File_read_at_all
    3893              : !> \param fh ...
    3894              : !> \param offset ...
    3895              : !> \param msg ...
    3896              : ! **************************************************************************************************
    3897            0 :       SUBROUTINE mp_file_read_at_all_ch(fh, offset, msg)
    3898              :          CHARACTER(LEN=*), INTENT(OUT)              :: msg
    3899              :          CLASS(mp_file_type), INTENT(IN)            :: fh
    3900              :          INTEGER(kind=file_offset), INTENT(IN)      :: offset
    3901              : 
    3902              : #if defined(__parallel)
    3903              :          INTEGER                                    :: ierr
    3904              : #endif
    3905              : 
    3906              : #if defined(__parallel)
    3907            0 :          CALL MPI_FILE_READ_AT_ALL(fh%handle, offset, msg, LEN(msg), MPI_CHARACTER, MPI_STATUS_IGNORE, ierr)
    3908            0 :          IF (ierr /= 0) &
    3909            0 :             CPABORT("mpi_file_read_at_all_ch @ mp_file_read_at_all_ch")
    3910              : #else
    3911              :          READ (UNIT=fh%handle, POS=offset + 1) msg
    3912              : #endif
    3913            0 :       END SUBROUTINE mp_file_read_at_all_ch
    3914              : 
    3915              : ! **************************************************************************************************
    3916              : !> \brief Returns the size of a data type in bytes
    3917              : !> \param[in] type_descriptor  data type
    3918              : !> \param[out] type_size       size of the data type
    3919              : !> \par MPI mapping
    3920              : !>      mpi_type_size
    3921              : !>
    3922              : ! **************************************************************************************************
    3923            0 :       SUBROUTINE mp_type_size(type_descriptor, type_size)
    3924              :          TYPE(mp_type_descriptor_type), INTENT(IN)          :: type_descriptor
    3925              :          INTEGER, INTENT(OUT)                               :: type_size
    3926              : 
    3927              : #if defined(__parallel)
    3928              :          INTEGER                                            :: ierr
    3929              : 
    3930              :          ierr = 0
    3931            0 :          CALL MPI_TYPE_SIZE(type_descriptor%type_handle, type_size, ierr)
    3932            0 :          IF (ierr /= 0) &
    3933            0 :             CPABORT("mpi_type_size failed @ mp_type_size")
    3934              : #else
    3935              :          SELECT CASE (type_descriptor%type_handle)
    3936              :          CASE (1)
    3937              :             type_size = real_4_size
    3938              :          CASE (3)
    3939              :             type_size = real_8_size
    3940              :          CASE (5)
    3941              :             type_size = 2*real_4_size
    3942              :          CASE (7)
    3943              :             type_size = 2*real_8_size
    3944              :          END SELECT
    3945              : #endif
    3946            0 :       END SUBROUTINE mp_type_size
    3947              : 
    3948              : ! **************************************************************************************************
    3949              : !> \brief wrapper to MPI_Type_create_struct
    3950              : !> \param subtypes ...
    3951              : !> \param vector_descriptor ...
    3952              : !> \param index_descriptor ...
    3953              : !> \return ...
    3954              : ! **************************************************************************************************
    3955            0 :       FUNCTION mp_type_make_struct(subtypes, &
    3956              :                                    vector_descriptor, index_descriptor) &
    3957              :          RESULT(type_descriptor)
    3958              :          TYPE(mp_type_descriptor_type), &
    3959              :             DIMENSION(:), INTENT(IN)                :: subtypes
    3960              :          INTEGER, DIMENSION(2), INTENT(IN), &
    3961              :             OPTIONAL                                :: vector_descriptor
    3962              :          TYPE(mp_indexing_meta_type), &
    3963              :             INTENT(IN), OPTIONAL                    :: index_descriptor
    3964              :          TYPE(mp_type_descriptor_type)              :: type_descriptor
    3965              : 
    3966              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_type_make_struct'
    3967              : 
    3968              :          INTEGER                                    :: i, n
    3969            0 :          INTEGER, ALLOCATABLE, DIMENSION(:)         :: lengths
    3970              : #if defined(__parallel)
    3971              :          INTEGER :: ierr
    3972              :          INTEGER(kind=mpi_address_kind), &
    3973            0 :             ALLOCATABLE, DIMENSION(:)               :: displacements
    3974              : #if defined(__MPI_F08)
    3975              :          ! Even OpenMPI 5.x misses mpi_get_address in the F08 interface
    3976              :          EXTERNAL                                   :: mpi_get_address
    3977              : #endif
    3978              : #endif
    3979            0 :          MPI_DATA_TYPE, ALLOCATABLE, DIMENSION(:) :: old_types
    3980              : 
    3981            0 :          n = SIZE(subtypes)
    3982            0 :          type_descriptor%length = 1
    3983              : #if defined(__parallel)
    3984            0 :          ierr = 0
    3985            0 :          CALL mpi_get_address(MPI_BOTTOM, type_descriptor%base, ierr)
    3986            0 :          IF (ierr /= 0) &
    3987            0 :             CPABORT("MPI_get_address @ "//routineN)
    3988            0 :          ALLOCATE (displacements(n))
    3989              : #endif
    3990            0 :          type_descriptor%vector_descriptor(1:2) = 1
    3991            0 :          type_descriptor%has_indexing = .FALSE.
    3992            0 :          ALLOCATE (type_descriptor%subtype(n))
    3993            0 :          type_descriptor%subtype(:) = subtypes(:)
    3994            0 :          ALLOCATE (lengths(n), old_types(n))
    3995            0 :          DO i = 1, SIZE(subtypes)
    3996              : #if defined(__parallel)
    3997            0 :             displacements(i) = subtypes(i)%base
    3998              : #endif
    3999            0 :             old_types(i) = subtypes(i)%type_handle
    4000            0 :             lengths(i) = subtypes(i)%length
    4001              :          END DO
    4002              : #if defined(__parallel)
    4003              :          CALL MPI_Type_create_struct(n, &
    4004              :                                      lengths, displacements, old_types, &
    4005            0 :                                      type_descriptor%type_handle, ierr)
    4006            0 :          IF (ierr /= 0) &
    4007            0 :             CPABORT("MPI_Type_create_struct @ "//routineN)
    4008            0 :          CALL MPI_Type_commit(type_descriptor%type_handle, ierr)
    4009            0 :          IF (ierr /= 0) &
    4010            0 :             CPABORT("MPI_Type_commit @ "//routineN)
    4011              : #endif
    4012            0 :          IF (PRESENT(vector_descriptor) .OR. PRESENT(index_descriptor)) THEN
    4013            0 :             CPABORT(routineN//" Vectors and indices NYI")
    4014              :          END IF
    4015            0 :       END FUNCTION mp_type_make_struct
    4016              : 
    4017              : ! **************************************************************************************************
    4018              : !> \brief wrapper to MPI_Type_free
    4019              : !> \param type_descriptor ...
    4020              : ! **************************************************************************************************
    4021            0 :       RECURSIVE SUBROUTINE mp_type_free_m(type_descriptor)
    4022              :          TYPE(mp_type_descriptor_type), INTENT(inout)       :: type_descriptor
    4023              : 
    4024              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_type_free_m'
    4025              : 
    4026              :          INTEGER                                            :: handle, i
    4027              : #if defined(__parallel)
    4028              :          INTEGER :: ierr
    4029              : #endif
    4030              : 
    4031            0 :          CALL mp_timeset(routineN, handle)
    4032              : 
    4033              :          ! If the subtype is associated, then it's a user-defined data type.
    4034              : 
    4035            0 :          IF (ASSOCIATED(type_descriptor%subtype)) THEN
    4036            0 :             DO i = 1, SIZE(type_descriptor%subtype)
    4037            0 :                CALL mp_type_free_m(type_descriptor%subtype(i))
    4038              :             END DO
    4039            0 :             DEALLOCATE (type_descriptor%subtype)
    4040              :          END IF
    4041              : #if defined(__parallel)
    4042              :          ierr = 0
    4043            0 :          CALL MPI_Type_free(type_descriptor%type_handle, ierr)
    4044            0 :          IF (ierr /= 0) &
    4045            0 :             CPABORT("MPI_Type_free @ "//routineN)
    4046              : #endif
    4047              : 
    4048            0 :          CALL mp_timestop(handle)
    4049              : 
    4050            0 :       END SUBROUTINE mp_type_free_m
    4051              : 
    4052              : ! **************************************************************************************************
    4053              : !> \brief ...
    4054              : !> \param type_descriptors ...
    4055              : ! **************************************************************************************************
    4056            0 :       SUBROUTINE mp_type_free_v(type_descriptors)
    4057              :          TYPE(mp_type_descriptor_type), DIMENSION(:), &
    4058              :             INTENT(inout)                                   :: type_descriptors
    4059              : 
    4060              :          INTEGER                                            :: i
    4061              : 
    4062            0 :          DO i = 1, SIZE(type_descriptors)
    4063            0 :             CALL mp_type_free(type_descriptors(i))
    4064              :          END DO
    4065              : 
    4066            0 :       END SUBROUTINE mp_type_free_v
    4067              : 
    4068              : ! **************************************************************************************************
    4069              : !> \brief Creates an indexed MPI type for arrays of strings using bytes for spacing (hindexed type)
    4070              : !> \param count   number of array blocks to read
    4071              : !> \param lengths lengths of each array block
    4072              : !> \param displs  byte offsets for array blocks
    4073              : !> \return container holding the created type
    4074              : !> \author Nico Holmberg [05.2017]
    4075              : ! **************************************************************************************************
    4076         3792 :       FUNCTION mp_file_type_hindexed_make_chv(count, lengths, displs) &
    4077              :          RESULT(type_descriptor)
    4078              :          INTEGER, INTENT(IN)                       :: count
    4079              :          INTEGER, DIMENSION(1:count), &
    4080              :             INTENT(IN), TARGET                     :: lengths
    4081              :          INTEGER(kind=file_offset), &
    4082              :             DIMENSION(1:count), INTENT(in), TARGET :: displs
    4083              :          TYPE(mp_file_descriptor_type)             :: type_descriptor
    4084              : 
    4085              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_file_hindexed_make_chv'
    4086              : 
    4087              :          INTEGER :: ierr, handle
    4088              : 
    4089              :          ierr = 0
    4090         1896 :          CALL mp_timeset(routineN, handle)
    4091              : 
    4092              : #if defined(__parallel)
    4093              :          CALL MPI_Type_create_hindexed(count, lengths, INT(displs, KIND=address_kind), MPI_CHARACTER, &
    4094       406226 :                                        type_descriptor%type_handle, ierr)
    4095         1896 :          IF (ierr /= 0) &
    4096            0 :             CPABORT("MPI_Type_create_hindexed @ "//routineN)
    4097         1896 :          CALL MPI_Type_commit(type_descriptor%type_handle, ierr)
    4098         1896 :          IF (ierr /= 0) &
    4099            0 :             CPABORT("MPI_Type_commit @ "//routineN)
    4100              : #else
    4101              :          type_descriptor%type_handle = 68
    4102              : #endif
    4103         1896 :          type_descriptor%length = count
    4104         1896 :          type_descriptor%has_indexing = .TRUE.
    4105         1896 :          type_descriptor%index_descriptor%index => lengths
    4106         1896 :          type_descriptor%index_descriptor%chunks => displs
    4107              : 
    4108         1896 :          CALL mp_timestop(handle)
    4109              : 
    4110         1896 :       END FUNCTION mp_file_type_hindexed_make_chv
    4111              : 
    4112              : ! **************************************************************************************************
    4113              : !> \brief Uses a previously created indexed MPI character type to tell the MPI processes
    4114              : !>        how to partition (set_view) an opened file
    4115              : !> \param fh      the file handle associated with the input file
    4116              : !> \param offset  global offset determining where the relevant data begins
    4117              : !> \param type_descriptor container for the MPI type
    4118              : !> \author Nico Holmberg [05.2017]
    4119              : ! **************************************************************************************************
    4120         1896 :       SUBROUTINE mp_file_type_set_view_chv(fh, offset, type_descriptor)
    4121              :          TYPE(mp_file_type), INTENT(IN)                      :: fh
    4122              :          INTEGER(kind=file_offset), INTENT(IN)    :: offset
    4123              :          TYPE(mp_file_descriptor_type)            :: type_descriptor
    4124              : 
    4125              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_file_set_view_chv'
    4126              : 
    4127              :          INTEGER                                   :: handle
    4128              : #if defined(__parallel)
    4129              :          INTEGER :: ierr
    4130              : #endif
    4131              : 
    4132         1896 :          CALL mp_timeset(routineN, handle)
    4133              : 
    4134              : #if defined(__parallel)
    4135              :          ierr = 0
    4136         1896 :          CALL mpi_file_set_errhandler(fh%handle, MPI_ERRORS_RETURN, ierr)
    4137              :          CALL MPI_File_set_view(fh%handle, offset, MPI_CHARACTER, &
    4138         1896 :                                 type_descriptor%type_handle, "native", MPI_INFO_NULL, ierr)
    4139         1896 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_file_set_errhandler @ MPI_File_set_view")
    4140              : #else
    4141              :          ! Uses absolute offsets stored in mp_file_descriptor_type
    4142              :          MARK_USED(fh)
    4143              :          MARK_USED(offset)
    4144              :          MARK_USED(type_descriptor)
    4145              : #endif
    4146              : 
    4147         1896 :          CALL mp_timestop(handle)
    4148              : 
    4149         1896 :       END SUBROUTINE mp_file_type_set_view_chv
    4150              : 
    4151              : ! **************************************************************************************************
    4152              : !> \brief (parallel) Collective, blocking read of a character array from a file. File access pattern
    4153              : !                    determined by a previously set file view.
    4154              : !>        (serial)   Unformatted stream read using explicit offsets
    4155              : !> \param fh     the file handle associated with the input file
    4156              : !> \param msglen the message length of an individual vector component
    4157              : !> \param ndims  the number of vector components
    4158              : !> \param buffer the buffer where the data is placed
    4159              : !> \param type_descriptor container for the MPI type
    4160              : !> \author Nico Holmberg [05.2017]
    4161              : ! **************************************************************************************************
    4162           38 :       SUBROUTINE mp_file_read_all_chv(fh, msglen, ndims, buffer, type_descriptor)
    4163              :          CLASS(mp_file_type), INTENT(IN)                       :: fh
    4164              :          INTEGER, INTENT(IN)                       :: msglen
    4165              :          INTEGER, INTENT(IN)                       :: ndims
    4166              :          CHARACTER(LEN=msglen), DIMENSION(ndims), INTENT(INOUT)   :: buffer
    4167              :          TYPE(mp_file_descriptor_type), &
    4168              :             INTENT(IN), OPTIONAL                   :: type_descriptor
    4169              : 
    4170              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_file_read_all_chv'
    4171              : 
    4172              :          INTEGER                                   :: handle
    4173              : #if defined(__parallel)
    4174              :          INTEGER:: ierr
    4175              : #else
    4176              :          INTEGER :: i
    4177              : #endif
    4178              : 
    4179           38 :          CALL mp_timeset(routineN, handle)
    4180              : 
    4181              : #if defined(__parallel)
    4182              :          ierr = 0
    4183              :          MARK_USED(type_descriptor)
    4184           38 :          CALL MPI_File_read_all(fh%handle, buffer, ndims*msglen, MPI_CHARACTER, MPI_STATUS_IGNORE, ierr)
    4185           38 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_file_set_errhandler @ MPI_File_read_all")
    4186           38 :          CALL add_perf(perf_id=28, count=1, msg_size=ndims*msglen)
    4187              : #else
    4188              :          MARK_USED(msglen)
    4189              :          MARK_USED(ndims)
    4190              :          IF (.NOT. PRESENT(type_descriptor)) &
    4191              :             CALL cp_abort(__LOCATION__, &
    4192              :                           "Container for mp_file_descriptor_type must be present in serial call.")
    4193              :          IF (.NOT. type_descriptor%has_indexing) &
    4194              :             CALL cp_abort(__LOCATION__, &
    4195              :                           "File view has not been set in mp_file_descriptor_type.")
    4196              :          ! Use explicit offsets
    4197              :          DO i = 1, ndims
    4198              :             READ (fh%handle, POS=type_descriptor%index_descriptor%chunks(i)) buffer(i)
    4199              :          END DO
    4200              : #endif
    4201              : 
    4202           38 :          CALL mp_timestop(handle)
    4203              : 
    4204           38 :       END SUBROUTINE mp_file_read_all_chv
    4205              : 
    4206              : ! **************************************************************************************************
    4207              : !> \brief (parallel) Collective, blocking write of a character array to a file. File access pattern
    4208              : !                    determined by a previously set file view.
    4209              : !>        (serial)   Unformatted stream write using explicit offsets
    4210              : !> \param fh     the file handle associated with the output file
    4211              : !> \param msglen the message length of an individual vector component
    4212              : !> \param ndims  the number of vector components
    4213              : !> \param buffer the buffer where the data is placed
    4214              : !> \param type_descriptor container for the MPI type
    4215              : !> \author Nico Holmberg [05.2017]
    4216              : ! **************************************************************************************************
    4217         1858 :       SUBROUTINE mp_file_write_all_chv(fh, msglen, ndims, buffer, type_descriptor)
    4218              :          CLASS(mp_file_type), INTENT(IN)                      :: fh
    4219              :          INTEGER, INTENT(IN)                                  :: msglen
    4220              :          INTEGER, INTENT(IN)                                  :: ndims
    4221              :          CHARACTER(LEN=msglen), DIMENSION(ndims), INTENT(IN)  :: buffer
    4222              :          TYPE(mp_file_descriptor_type), &
    4223              :             INTENT(IN), OPTIONAL                              :: type_descriptor
    4224              : 
    4225              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_file_write_all_chv'
    4226              : 
    4227              :          INTEGER :: handle
    4228              : #if defined(__parallel)
    4229              :          INTEGER :: ierr
    4230              : #else
    4231              :          INTEGER :: i
    4232              : #endif
    4233              : 
    4234         1858 :          CALL mp_timeset(routineN, handle)
    4235              : 
    4236              : #if defined(__parallel)
    4237              :          MARK_USED(type_descriptor)
    4238         1858 :          CALL mpi_file_set_errhandler(fh%handle, MPI_ERRORS_RETURN, ierr)
    4239         1858 :          CALL MPI_File_write_all(fh%handle, buffer, ndims*msglen, MPI_CHARACTER, MPI_STATUS_IGNORE, ierr)
    4240         1858 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_file_set_errhandler @ MPI_File_write_all")
    4241         1858 :          CALL add_perf(perf_id=28, count=1, msg_size=ndims*msglen)
    4242              : #else
    4243              :          MARK_USED(msglen)
    4244              :          MARK_USED(ndims)
    4245              :          IF (.NOT. PRESENT(type_descriptor)) &
    4246              :             CALL cp_abort(__LOCATION__, &
    4247              :                           "Container for mp_file_descriptor_type must be present in serial call.")
    4248              :          IF (.NOT. type_descriptor%has_indexing) &
    4249              :             CALL cp_abort(__LOCATION__, &
    4250              :                           "File view has not been set in mp_file_descriptor_type.")
    4251              :          ! Use explicit offsets
    4252              :          DO i = 1, ndims
    4253              :             WRITE (fh%handle, POS=type_descriptor%index_descriptor%chunks(i)) buffer(i)
    4254              :          END DO
    4255              : #endif
    4256              : 
    4257         1858 :          CALL mp_timestop(handle)
    4258              : 
    4259         1858 :       END SUBROUTINE mp_file_write_all_chv
    4260              : 
    4261              : ! **************************************************************************************************
    4262              : !> \brief Releases the type used for MPI I/O
    4263              : !> \param type_descriptor the container for the MPI type
    4264              : !> \author Nico Holmberg [05.2017]
    4265              : ! **************************************************************************************************
    4266         3792 :       SUBROUTINE mp_file_type_free(type_descriptor)
    4267              :          TYPE(mp_file_descriptor_type)             :: type_descriptor
    4268              : 
    4269              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_file_type_free'
    4270              : 
    4271              :          INTEGER                                   :: handle
    4272              : #if defined(__parallel)
    4273              :          INTEGER :: ierr
    4274              : #endif
    4275              : 
    4276         1896 :          CALL mp_timeset(routineN, handle)
    4277              : 
    4278              : #if defined(__parallel)
    4279         1896 :          CALL MPI_Type_free(type_descriptor%type_handle, ierr)
    4280         1896 :          IF (ierr /= 0) &
    4281            0 :             CPABORT("MPI_Type_free @ "//routineN)
    4282              : #endif
    4283              : #if defined(__parallel) && defined(__MPI_F08)
    4284         1896 :          type_descriptor%type_handle%mpi_val = -1
    4285              : #else
    4286              :          type_descriptor%type_handle = -1
    4287              : #endif
    4288         1896 :          type_descriptor%length = -1
    4289         1896 :          IF (type_descriptor%has_indexing) THEN
    4290         1896 :             NULLIFY (type_descriptor%index_descriptor%index)
    4291         1896 :             NULLIFY (type_descriptor%index_descriptor%chunks)
    4292         1896 :             type_descriptor%has_indexing = .FALSE.
    4293              :          END IF
    4294              : 
    4295         1896 :          CALL mp_timestop(handle)
    4296              : 
    4297         1896 :       END SUBROUTINE mp_file_type_free
    4298              : 
    4299              : ! **************************************************************************************************
    4300              : !> \brief (parallel) Utility routine to determine MPI file access mode based on variables
    4301              : !                    that in the serial case would get passed to the intrinsic OPEN
    4302              : !>        (serial)   No action
    4303              : !> \param mpi_io     flag that determines if MPI I/O will actually be used
    4304              : !> \param replace    flag that indicates whether file needs to be deleted prior to opening it
    4305              : !> \param amode      the MPI I/O access mode
    4306              : !> \param form       formatted or unformatted data?
    4307              : !> \param action     the variable that determines what to do with file
    4308              : !> \param status     the status flag:
    4309              : !> \param position   should the file be appended or rewound
    4310              : !> \author Nico Holmberg [11.2017]
    4311              : ! **************************************************************************************************
    4312         1858 :       SUBROUTINE mp_file_get_amode(mpi_io, replace, amode, form, action, status, position)
    4313              :          LOGICAL, INTENT(INOUT)                             :: mpi_io, replace
    4314              :          INTEGER, INTENT(OUT)                               :: amode
    4315              :          CHARACTER(len=*), INTENT(IN)                       :: form, action, status, position
    4316              : 
    4317         1858 :          amode = -1
    4318              : #if defined(__parallel)
    4319              :          ! Disable mpi io for unformatted access
    4320            0 :          SELECT CASE (form)
    4321              :          CASE ("FORMATTED")
    4322              :             ! Do nothing
    4323              :          CASE ("UNFORMATTED")
    4324            0 :             mpi_io = .FALSE.
    4325              :          CASE DEFAULT
    4326         1858 :             CPABORT("Unknown MPI file form requested.")
    4327              :          END SELECT
    4328              :          ! Determine file access mode (limited set of allowed choices)
    4329         1858 :          SELECT CASE (action)
    4330              :          CASE ("WRITE")
    4331         1858 :             amode = file_amode_wronly
    4332            0 :             SELECT CASE (status)
    4333              :             CASE ("NEW")
    4334              :                ! Try to open new file for writing, crash if file already exists
    4335            0 :                amode = amode + file_amode_create + file_amode_excl
    4336              :             CASE ("UNKNOWN")
    4337              :                ! Open file for writing and create it if file does not exist
    4338         1534 :                amode = amode + file_amode_create
    4339           76 :                SELECT CASE (position)
    4340              :                CASE ("APPEND")
    4341              :                   ! Append existing file
    4342           76 :                   amode = amode + file_amode_append
    4343              :                CASE ("REWIND", "ASIS")
    4344              :                   ! Do nothing
    4345              :                CASE DEFAULT
    4346         1534 :                   CPABORT("Unknown MPI file position requested.")
    4347              :                END SELECT
    4348              :             CASE ("OLD")
    4349          324 :                SELECT CASE (position)
    4350              :                CASE ("APPEND")
    4351              :                   ! Append existing file
    4352            0 :                   amode = amode + file_amode_append
    4353              :                CASE ("REWIND", "ASIS")
    4354              :                   ! Do nothing
    4355              :                CASE DEFAULT
    4356            0 :                   CPABORT("Unknown MPI file position requested.")
    4357              :                END SELECT
    4358              :             CASE ("REPLACE")
    4359              :                ! Overwrite existing file. Must delete existing file first
    4360          324 :                amode = amode + file_amode_create
    4361          324 :                replace = .TRUE.
    4362              :             CASE ("SCRATCH")
    4363              :                ! Disable
    4364            0 :                mpi_io = .FALSE.
    4365              :             CASE DEFAULT
    4366         1858 :                CPABORT("Unknown MPI file status requested.")
    4367              :             END SELECT
    4368              :          CASE ("READ")
    4369            0 :             amode = file_amode_rdonly
    4370            0 :             SELECT CASE (status)
    4371              :             CASE ("NEW")
    4372            0 :                CPABORT("Cannot read from 'NEW' file.")
    4373              :             CASE ("REPLACE")
    4374            0 :                CPABORT("Illegal status 'REPLACE' for read.")
    4375              :             CASE ("UNKNOWN", "OLD")
    4376              :                ! Do nothing
    4377              :             CASE ("SCRATCH")
    4378              :                ! Disable
    4379            0 :                mpi_io = .FALSE.
    4380              :             CASE DEFAULT
    4381            0 :                CPABORT("Unknown MPI file status requested.")
    4382              :             END SELECT
    4383              :          CASE ("READWRITE")
    4384            0 :             amode = file_amode_rdwr
    4385            0 :             SELECT CASE (status)
    4386              :             CASE ("NEW")
    4387              :                ! Try to open new file, crash if file already exists
    4388            0 :                amode = amode + file_amode_create + file_amode_excl
    4389              :             CASE ("UNKNOWN")
    4390              :                ! Open file and create it if file does not exist
    4391            0 :                amode = amode + file_amode_create
    4392            0 :                SELECT CASE (position)
    4393              :                CASE ("APPEND")
    4394              :                   ! Append existing file
    4395            0 :                   amode = amode + file_amode_append
    4396              :                CASE ("REWIND", "ASIS")
    4397              :                   ! Do nothing
    4398              :                CASE DEFAULT
    4399            0 :                   CPABORT("Unknown MPI file position requested.")
    4400              :                END SELECT
    4401              :             CASE ("OLD")
    4402            0 :                SELECT CASE (position)
    4403              :                CASE ("APPEND")
    4404              :                   ! Append existing file
    4405            0 :                   amode = amode + file_amode_append
    4406              :                CASE ("REWIND", "ASIS")
    4407              :                   ! Do nothing
    4408              :                CASE DEFAULT
    4409            0 :                   CPABORT("Unknown MPI file position requested.")
    4410              :                END SELECT
    4411              :             CASE ("REPLACE")
    4412              :                ! Overwrite existing file. Must delete existing file first
    4413            0 :                amode = amode + file_amode_create
    4414            0 :                replace = .TRUE.
    4415              :             CASE ("SCRATCH")
    4416              :                ! Disable
    4417            0 :                mpi_io = .FALSE.
    4418              :             CASE DEFAULT
    4419            0 :                CPABORT("Unknown MPI file status requested.")
    4420              :             END SELECT
    4421              :          CASE DEFAULT
    4422         1858 :             CPABORT("Unknown MPI file action requested.")
    4423              :          END SELECT
    4424              : #else
    4425              :          MARK_USED(replace)
    4426              :          MARK_USED(form)
    4427              :          MARK_USED(position)
    4428              :          MARK_USED(status)
    4429              :          MARK_USED(action)
    4430              :          mpi_io = .FALSE.
    4431              : #endif
    4432              : 
    4433         1858 :       END SUBROUTINE mp_file_get_amode
    4434              : 
    4435              : ! **************************************************************************************************
    4436              : !> \brief Non-blocking send of custom type
    4437              : !> \param msgin ...
    4438              : !> \param dest ...
    4439              : !> \param comm ...
    4440              : !> \param request ...
    4441              : !> \param tag ...
    4442              : ! **************************************************************************************************
    4443            0 :       SUBROUTINE mp_isend_custom(msgin, dest, comm, request, tag)
    4444              :          TYPE(mp_type_descriptor_type), INTENT(IN)          :: msgin
    4445              :          INTEGER, INTENT(IN)                                :: dest
    4446              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    4447              :          TYPE(mp_request_type), INTENT(out)                               :: request
    4448              :          INTEGER, INTENT(in), OPTIONAL                      :: tag
    4449              : 
    4450              :          INTEGER                                            :: ierr, my_tag
    4451              : 
    4452              :          ierr = 0
    4453            0 :          my_tag = 0
    4454              : 
    4455              : #if defined(__parallel)
    4456            0 :          IF (PRESENT(tag)) my_tag = tag
    4457              : 
    4458              :          CALL mpi_isend(MPI_BOTTOM, 1, msgin%type_handle, dest, my_tag, &
    4459            0 :                         comm%handle, request%handle, ierr)
    4460            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_isend @ mp_isend_custom")
    4461              : #else
    4462              :          MARK_USED(msgin)
    4463              :          MARK_USED(dest)
    4464              :          MARK_USED(comm)
    4465              :          MARK_USED(tag)
    4466              :          ierr = 1
    4467              :          request = mp_request_null
    4468              :          CALL mp_stop(ierr, "mp_isend called in non parallel case")
    4469              : #endif
    4470            0 :       END SUBROUTINE mp_isend_custom
    4471              : 
    4472              : ! **************************************************************************************************
    4473              : !> \brief Non-blocking receive of vector data
    4474              : !> \param msgout ...
    4475              : !> \param source ...
    4476              : !> \param comm ...
    4477              : !> \param request ...
    4478              : !> \param tag ...
    4479              : ! **************************************************************************************************
    4480            0 :       SUBROUTINE mp_irecv_custom(msgout, source, comm, request, tag)
    4481              :          TYPE(mp_type_descriptor_type), INTENT(INOUT)       :: msgout
    4482              :          INTEGER, INTENT(IN)                                :: source
    4483              :          CLASS(mp_comm_type), INTENT(IN) :: comm
    4484              :          TYPE(mp_request_type), INTENT(out)                               :: request
    4485              :          INTEGER, INTENT(in), OPTIONAL                      :: tag
    4486              : 
    4487              :          INTEGER                                            :: ierr, my_tag
    4488              : 
    4489              :          ierr = 0
    4490            0 :          my_tag = 0
    4491              : 
    4492              : #if defined(__parallel)
    4493            0 :          IF (PRESENT(tag)) my_tag = tag
    4494              : 
    4495              :          CALL mpi_irecv(MPI_BOTTOM, 1, msgout%type_handle, source, my_tag, &
    4496            0 :                         comm%handle, request%handle, ierr)
    4497            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_irecv @ mp_irecv_custom")
    4498              : #else
    4499              :          MARK_USED(msgout)
    4500              :          MARK_USED(source)
    4501              :          MARK_USED(comm)
    4502              :          MARK_USED(tag)
    4503              :          ierr = 1
    4504              :          request = mp_request_null
    4505              :          CPABORT("mp_irecv called in non parallel case")
    4506              : #endif
    4507            0 :       END SUBROUTINE mp_irecv_custom
    4508              : 
    4509              : ! **************************************************************************************************
    4510              : !> \brief Window free
    4511              : !> \param win ...
    4512              : ! **************************************************************************************************
    4513            0 :       SUBROUTINE mp_win_free(win)
    4514              :          CLASS(mp_win_type), INTENT(INOUT)                  :: win
    4515              : 
    4516              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_win_free'
    4517              : 
    4518              :          INTEGER                                            :: handle
    4519              : #if defined(__parallel)
    4520              :          INTEGER :: ierr
    4521              : #endif
    4522              : 
    4523            0 :          CALL mp_timeset(routineN, handle)
    4524              : 
    4525              : #if defined(__parallel)
    4526              :          ierr = 0
    4527            0 :          CALL mpi_win_free(win%handle, ierr)
    4528            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_win_free @ "//routineN)
    4529              : 
    4530            0 :          CALL add_perf(perf_id=21, count=1)
    4531              : #else
    4532              :          win%handle = mp_win_null_handle
    4533              : #endif
    4534            0 :          CALL mp_timestop(handle)
    4535            0 :       END SUBROUTINE mp_win_free
    4536              : 
    4537            0 :       SUBROUTINE mp_win_assign(win_new, win_old)
    4538              :          CLASS(mp_win_type), INTENT(OUT) :: win_new
    4539              :          CLASS(mp_win_type), INTENT(IN) :: win_old
    4540              : 
    4541            0 :          win_new%handle = win_old%handle
    4542              : 
    4543            0 :       END SUBROUTINE mp_win_assign
    4544              : 
    4545              : ! **************************************************************************************************
    4546              : !> \brief Window flush
    4547              : !> \param win ...
    4548              : ! **************************************************************************************************
    4549            0 :       SUBROUTINE mp_win_flush_all(win)
    4550              :          CLASS(mp_win_type), INTENT(IN)                     :: win
    4551              : 
    4552              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_win_flush_all'
    4553              : 
    4554              :          INTEGER                                            :: handle, ierr
    4555              : 
    4556              :          ierr = 0
    4557            0 :          CALL mp_timeset(routineN, handle)
    4558              : 
    4559              : #if defined(__parallel)
    4560            0 :          CALL mpi_win_flush_all(win%handle, ierr)
    4561            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_win_flush_all @ "//routineN)
    4562              : #else
    4563              :          MARK_USED(win)
    4564              : #endif
    4565            0 :          CALL mp_timestop(handle)
    4566            0 :       END SUBROUTINE mp_win_flush_all
    4567              : 
    4568              : ! **************************************************************************************************
    4569              : !> \brief Window lock
    4570              : !> \param win ...
    4571              : ! **************************************************************************************************
    4572            0 :       SUBROUTINE mp_win_lock_all(win)
    4573              :          CLASS(mp_win_type), INTENT(IN)                     :: win
    4574              : 
    4575              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_win_lock_all'
    4576              : 
    4577              :          INTEGER                                            :: handle, ierr
    4578              : 
    4579              :          ierr = 0
    4580            0 :          CALL mp_timeset(routineN, handle)
    4581              : 
    4582              : #if defined(__parallel)
    4583              : 
    4584            0 :          CALL mpi_win_lock_all(MPI_MODE_NOCHECK, win%handle, ierr)
    4585            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_win_lock_all @ "//routineN)
    4586              : 
    4587            0 :          CALL add_perf(perf_id=19, count=1)
    4588              : #else
    4589              :          MARK_USED(win)
    4590              : #endif
    4591            0 :          CALL mp_timestop(handle)
    4592            0 :       END SUBROUTINE mp_win_lock_all
    4593              : 
    4594              : ! **************************************************************************************************
    4595              : !> \brief Window lock
    4596              : !> \param win ...
    4597              : ! **************************************************************************************************
    4598            0 :       SUBROUTINE mp_win_unlock_all(win)
    4599              :          CLASS(mp_win_type), INTENT(IN)                     :: win
    4600              : 
    4601              :          CHARACTER(len=*), PARAMETER :: routineN = 'mp_win_unlock_all'
    4602              : 
    4603              :          INTEGER                                            :: handle, ierr
    4604              : 
    4605              :          ierr = 0
    4606            0 :          CALL mp_timeset(routineN, handle)
    4607              : 
    4608              : #if defined(__parallel)
    4609              : 
    4610            0 :          CALL mpi_win_unlock_all(win%handle, ierr)
    4611            0 :          IF (ierr /= 0) CALL mp_stop(ierr, "mpi_win_unlock_all @ "//routineN)
    4612              : 
    4613            0 :          CALL add_perf(perf_id=19, count=1)
    4614              : #else
    4615              :          MARK_USED(win)
    4616              : #endif
    4617            0 :          CALL mp_timestop(handle)
    4618            0 :       END SUBROUTINE mp_win_unlock_all
    4619              : 
    4620              : ! **************************************************************************************************
    4621              : !> \brief Starts a timer region
    4622              : !> \param routineN ...
    4623              : !> \param handle ...
    4624              : ! **************************************************************************************************
    4625    139678622 :       SUBROUTINE mp_timeset(routineN, handle)
    4626              :          CHARACTER(len=*), INTENT(IN)                       :: routineN
    4627              :          INTEGER, INTENT(OUT)                               :: handle
    4628              : 
    4629    139678622 :          IF (mp_collect_timings) &
    4630    139468544 :             CALL timeset(routineN, handle)
    4631    139678622 :       END SUBROUTINE mp_timeset
    4632              : 
    4633              : ! **************************************************************************************************
    4634              : !> \brief Ends a timer region
    4635              : !> \param handle ...
    4636              : ! **************************************************************************************************
    4637    139678622 :       SUBROUTINE mp_timestop(handle)
    4638              :          INTEGER, INTENT(IN)                                :: handle
    4639              : 
    4640    139678622 :          IF (mp_collect_timings) &
    4641    139468544 :             CALL timestop(handle)
    4642    139678622 :       END SUBROUTINE mp_timestop
    4643              : 
    4644              :       #:include 'message_passing.fypp'
    4645              : 
    4646     65522174 :    END MODULE message_passing
        

Generated by: LCOV version 2.0-1