5.13.2-dev0
mHM
The mesoscale Hydrological Model
Loading...
Searching...
No Matches
mo_common_MPI_tools.F90
Go to the documentation of this file.
1!> \file mo_common_mpi_tools.f90
2!> \brief \copybrief mo_common_mpi_tools
3!> \details \copydetails mo_common_mpi_tools
4
5!> \brief tools for MPI communication that are mHM or mRM specific
6!> \author Maren Kaluza
7!> \author Sebastian Mueller
8!> \date 2019-2021
9!> \details This module contains sending and receiving subroutines for
10!! data that are specific for mHM or mRM
11!> \copyright Copyright 2005-\today, the mHM Developers, Luis Samaniego, Sabine Attinger: All rights reserved.
12!! mHM is released under the LGPLv3+ license \license_note
13!> \ingroup f_common
15
16#ifdef MPI
17 use mo_kind, only : i4, dp
18 use mo_message, only : message
19 use mo_string_utils, only : num2str
20 use mo_common_variables, only: comm
21 use mpi_f08
22#endif
23
24 IMPLICIT NONE
25
26 PRIVATE
27
28#ifdef MPI
29 PUBLIC :: distribute_parameterset, get_parameterset
30#endif
31 public :: mpi_tools_init
32 public :: mpi_tools_finalize
33
34 ! ------------------------------------------------------------------
35
36contains
37#ifdef MPI
38 !> \brief Distrubute parameter set with MPI.
39 subroutine distribute_parameterset(parameterset)
41 real(dp), dimension(:), intent(in) :: parameterset
42
43 integer(i4) :: nproc, iproc, dimen
44 integer(i4) :: ierror
45
46 call mpi_comm_size(domainmeta%comMaster, nproc, ierror)
47 dimen = size(parameterset(:))
48 do iproc = 1, nproc-1
49 call mpi_send(dimen, 1, &
50 mpi_integer,iproc,0,domainmeta%comMaster,ierror)
51 call mpi_send(parameterset(:),dimen, &
52 mpi_double_precision,iproc,0,domainmeta%comMaster,ierror)
53 end do
54 end subroutine distribute_parameterset
55
56 !> \brief Get distrubuted parameter set with MPI.
57 subroutine get_parameterset(parameterset)
58 use mpi_f08
60 real(dp), dimension(:), allocatable, intent(inout) :: parameterset
61
62 integer(i4) :: dimen
63 integer(i4) :: ierror
64 type(MPI_Status) :: status
65
66 call mpi_recv(dimen, 1, mpi_integer, 0, 0, domainmeta%comMaster, status, ierror)
67 allocate(parameterset(dimen))
68 call mpi_recv(parameterset, dimen, mpi_double_precision, 0, 0, domainmeta%comMaster, status, ierror)
69 end subroutine get_parameterset
70#endif
71
72 !> \brief Finalize the MPI run of mHM.
73 subroutine mpi_tools_init()
74
75 implicit none
76
77#ifdef MPI
78 integer :: ierror
79 integer(i4) :: nproc, rank
80
81 ! Initialize MPI
82 call mpi_init(ierror)
83 call mpi_comm_dup(mpi_comm_world, comm, ierror)
84 ! find number of processes nproc
85 call mpi_comm_size(comm, nproc, ierror)
86 ! find the number the process is referred to, called rank
87 call mpi_comm_rank(comm, rank, ierror)
88 call message('MPI!, comm ', num2str(rank), num2str(nproc))
89#endif
90
91 end subroutine mpi_tools_init
92
93 !> \brief Finalize the MPI run of mHM.
94 subroutine mpi_tools_finalize()
95
96 implicit none
97
98#ifdef MPI
99 integer :: ierror
100 integer(i4) :: nproc, rank
101
102 ! find number of processes nproc
103 call mpi_comm_size(comm, nproc, ierror)
104 call mpi_comm_rank(comm, rank, ierror)
105 call message('MPI finished ', num2str(rank), num2str(nproc))
106 call mpi_finalize(ierror)
107#endif
108
109 end subroutine mpi_tools_finalize
110
111END MODULE mo_common_mpi_tools
tools for MPI communication that are mHM or mRM specific
subroutine, public mpi_tools_finalize()
Finalize the MPI run of mHM.
subroutine, public mpi_tools_init()
Finalize the MPI run of mHM.
Provides structures needed by mHM, mRM and/or mpr.
type(domain_meta), public domainmeta