Neko  0.9.0
A portable framework for high-order spectral element flow simulations
gs_comm.f90
Go to the documentation of this file.
1 ! Copyright (c) 2022, The Neko Authors
2 ! All rights reserved.
3 !
4 ! Redistribution and use in source and binary forms, with or without
5 ! modification, are permitted provided that the following conditions
6 ! are met:
7 !
8 ! * Redistributions of source code must retain the above copyright
9 ! notice, this list of conditions and the following disclaimer.
10 !
11 ! * Redistributions in binary form must reproduce the above
12 ! copyright notice, this list of conditions and the following
13 ! disclaimer in the documentation and/or other materials provided
14 ! with the distribution.
15 !
16 ! * Neither the name of the authors nor the names of its
17 ! contributors may be used to endorse or promote products derived
18 ! from this software without specific prior written permission.
19 !
20 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 ! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 ! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 ! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 ! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 ! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 ! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 ! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 ! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 ! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 ! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 ! POSSIBILITY OF SUCH DAMAGE.
32 !
34 module gs_comm
35  use num_types, only : rp
36  use comm, only : pe_size
37  use stack, only : stack_i4_t
38  use, intrinsic :: iso_c_binding
39  implicit none
40  private
41 
42  integer, public, parameter :: gs_comm_mpi = 1, gs_comm_mpigpu = 2
43 
45  type, public, abstract :: gs_comm_t
46  type(stack_i4_t), allocatable :: send_dof(:)
47  type(stack_i4_t), allocatable :: recv_dof(:)
48  integer, allocatable :: send_pe(:)
49  integer, allocatable :: recv_pe(:)
50  contains
51  procedure(gs_comm_init), pass(this), deferred :: init
52  procedure(gs_comm_free), pass(this), deferred :: free
53  procedure(gs_nbsend), pass(this), deferred :: nbsend
54  procedure(gs_nbrecv), pass(this), deferred :: nbrecv
55  procedure(gs_nbwait), pass(this), deferred :: nbwait
56  procedure, pass(this) :: init_dofs
57  procedure, pass(this) :: free_dofs
58  procedure, pass(this) :: init_order
59  procedure, pass(this) :: free_order
60  end type gs_comm_t
61 
63  abstract interface
64  subroutine gs_comm_init(this, send_pe, recv_pe)
65  import gs_comm_t
66  import stack_i4_t
67  class(gs_comm_t), intent(inout) :: this
68  type(stack_i4_t), intent(inout) :: send_pe
69  type(stack_i4_t), intent(inout) :: recv_pe
70  end subroutine gs_comm_init
71  end interface
72 
74  abstract interface
75  subroutine gs_comm_free(this)
76  import gs_comm_t
77  class(gs_comm_t), intent(inout) :: this
78  end subroutine gs_comm_free
79  end interface
80 
82  abstract interface
83  subroutine gs_nbsend(this, u, n, deps, strm)
84  import gs_comm_t
85  import stack_i4_t
86  import c_ptr
87  import rp
88  class(gs_comm_t), intent(inout) :: this
89  integer, intent(in) :: n
90  real(kind=rp), dimension(n), intent(inout) :: u
91  type(c_ptr), intent(inout) :: deps
92  type(c_ptr), intent(inout) :: strm
93  end subroutine gs_nbsend
94  end interface
95 
97  abstract interface
98  subroutine gs_nbrecv(this)
99  import gs_comm_t
100  class(gs_comm_t), intent(inout) :: this
101  end subroutine gs_nbrecv
102  end interface
103 
105  abstract interface
106  subroutine gs_nbwait(this, u, n, op, strm)
107  import gs_comm_t
108  import stack_i4_t
109  import c_ptr
110  import rp
111  class(gs_comm_t), intent(inout) :: this
112  integer, intent(in) :: n
113  real(kind=rp), dimension(n), intent(inout) :: u
114  integer :: op
115  type(c_ptr), intent(inout) :: strm
116  end subroutine gs_nbwait
117  end interface
118 
120 contains
121 
122  subroutine init_dofs(this)
123  class(gs_comm_t), intent(inout) :: this
124  integer :: i
125 
126  call this%free_dofs()
127 
128  allocate(this%send_dof(0:pe_size-1))
129  allocate(this%recv_dof(0:pe_size-1))
130 
131  do i = 0, pe_size -1
132  call this%send_dof(i)%init()
133  call this%recv_dof(i)%init()
134  end do
135 
136  end subroutine init_dofs
137 
138  subroutine free_dofs(this)
139  class(gs_comm_t), intent(inout) :: this
140  integer :: i
141 
142  if (allocated(this%send_dof)) then
143  do i = 0, pe_size - 1
144  call this%send_dof(i)%free()
145  end do
146  deallocate(this%send_dof)
147  end if
148 
149  if (allocated(this%recv_dof)) then
150  do i = 0, pe_size - 1
151  call this%recv_dof(i)%free()
152  end do
153  deallocate(this%recv_dof)
154  end if
155 
156  end subroutine free_dofs
157 
158  subroutine init_order(this, send_pe, recv_pe)
159  class(gs_comm_t), intent(inout) :: this
160  type(stack_i4_t), intent(inout) :: send_pe
161  type(stack_i4_t), intent(inout) :: recv_pe
162  integer, pointer :: sp(:)
163  integer :: i
164 
165  allocate(this%send_pe(send_pe%size()))
166 
167  sp => send_pe%array()
168  do i = 1, send_pe%size()
169  this%send_pe(i) = sp(i)
170  end do
171 
172  allocate(this%recv_pe(recv_pe%size()))
173 
174  sp => recv_pe%array()
175  do i = 1, recv_pe%size()
176  this%recv_pe(i) = sp(i)
177  end do
178 
179  end subroutine init_order
180 
181  subroutine free_order(this)
182  class(gs_comm_t), intent(inout) :: this
183 
184  if (allocated(this%send_pe)) then
185  deallocate(this%send_pe)
186  end if
187 
188  if (allocated(this%recv_pe)) then
189  deallocate(this%recv_pe)
190  end if
191 
192  end subroutine free_order
193 
194 end module gs_comm
Abstract interface for deallocating a Gather-scatter communication method.
Definition: gs_comm.f90:75
Abstract interface for initialising a Gather-scatter communication method.
Definition: gs_comm.f90:64
Abstract interface for initiating non-blocking receive operations.
Definition: gs_comm.f90:98
Abstract interface for initiating non-blocking send operations.
Definition: gs_comm.f90:83
Abstract interface for watining on non-blocking operations.
Definition: gs_comm.f90:106
Definition: comm.F90:1
integer pe_size
MPI size of communicator.
Definition: comm.F90:31
Defines a gather-scatter communication method.
Definition: gs_comm.f90:34
subroutine init_dofs(this)
Definition: gs_comm.f90:123
integer, parameter, public gs_comm_mpigpu
Definition: gs_comm.f90:42
integer, parameter, public gs_comm_mpi
Definition: gs_comm.f90:42
subroutine init_order(this, send_pe, recv_pe)
Definition: gs_comm.f90:159
subroutine free_dofs(this)
Definition: gs_comm.f90:139
subroutine free_order(this)
Definition: gs_comm.f90:182
integer, parameter, public rp
Global precision used in computations.
Definition: num_types.f90:12
Implements a dynamic stack ADT.
Definition: stack.f90:35
Gather-scatter communication method.
Definition: gs_comm.f90:45
Integer based stack.
Definition: stack.f90:63