Neko 1.99.5
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
gs_comm.f90
Go to the documentation of this file.
1! Copyright (c) 2022-2026, 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!
34module gs_comm
35 use num_types, only : rp
36 use comm, only : pe_size
37 use stack, only : stack_i4_t
38 use utils, only : neko_error
39 use, intrinsic :: iso_c_binding
40 implicit none
41 private
42
43 integer, public, parameter :: gs_comm_mpi = 1, gs_comm_mpigpu = 2, &
46
49 integer, public, parameter :: gs_vec_nc = 3
50
52 type, public, abstract :: gs_comm_t
54 type(stack_i4_t), allocatable :: send_dof(:)
57 type(stack_i4_t), allocatable :: recv_dof(:)
61 integer, allocatable :: send_pe(:)
63 integer, allocatable :: recv_pe(:)
67 logical :: vec_supported = .false.
68 contains
69 procedure(gs_comm_init), pass(this), deferred :: init
70 procedure(gs_comm_free), pass(this), deferred :: free
71 procedure(gs_nbsend), pass(this), deferred :: nbsend
72 procedure(gs_nbrecv), pass(this), deferred :: nbrecv
73 procedure(gs_nbwait), pass(this), deferred :: nbwait
74 procedure, pass(this) :: init_dofs
75 procedure, pass(this) :: free_dofs
76 procedure, pass(this) :: init_order
77 procedure, pass(this) :: free_order
80 procedure, pass(this) :: nbsend_vec => gs_nbsend_vec
81 procedure, pass(this) :: nbrecv_vec => gs_nbrecv_vec
82 procedure, pass(this) :: nbwait_vec => gs_nbwait_vec
83 end type gs_comm_t
84
88 abstract interface
89 subroutine gs_comm_init(this, send_pe, recv_pe)
90 import gs_comm_t
91 import stack_i4_t
92 class(gs_comm_t), intent(inout) :: this
93 type(stack_i4_t), intent(inout) :: send_pe
94 type(stack_i4_t), intent(inout) :: recv_pe
95 end subroutine gs_comm_init
96 end interface
97
99 abstract interface
100 subroutine gs_comm_free(this)
101 import gs_comm_t
102 class(gs_comm_t), intent(inout) :: this
103 end subroutine gs_comm_free
104 end interface
105
112 abstract interface
113 subroutine gs_nbsend(this, u, n, tag, deps, strm)
114 import gs_comm_t
115 import stack_i4_t
116 import c_ptr
117 import rp
118 class(gs_comm_t), intent(inout) :: this
119 integer, intent(in) :: n
120 real(kind=rp), dimension(n), intent(inout) :: u
121 integer, intent(in) :: tag
122 type(c_ptr), intent(inout) :: deps
123 type(c_ptr), intent(inout) :: strm
124 end subroutine gs_nbsend
125 end interface
126
127
130 abstract interface
131 subroutine gs_nbrecv(this, tag)
132 import gs_comm_t
133 class(gs_comm_t), intent(inout) :: this
134 integer, intent(in) :: tag
135 end subroutine gs_nbrecv
136 end interface
137
146 abstract interface
147 subroutine gs_nbwait(this, u, n, op, strm)
148 import gs_comm_t
149 import stack_i4_t
150 import c_ptr
151 import rp
152 class(gs_comm_t), intent(inout) :: this
153 integer, intent(in) :: n
154 real(kind=rp), dimension(n), intent(inout) :: u
155 integer :: op
156 type(c_ptr), intent(inout) :: strm
157 end subroutine gs_nbwait
158 end interface
159
161contains
162 !Initalize stacks for each rank of dof indices to send/recv
163 subroutine init_dofs(this)
164 class(gs_comm_t), intent(inout) :: this
165 integer :: i
166
167 call this%free_dofs()
168
169 allocate(this%send_dof(0:pe_size-1))
170 allocate(this%recv_dof(0:pe_size-1))
171
172 do i = 0, pe_size -1
173 call this%send_dof(i)%init()
174 call this%recv_dof(i)%init()
175 end do
176
177 end subroutine init_dofs
178
179 subroutine free_dofs(this)
180 class(gs_comm_t), intent(inout) :: this
181 integer :: i
182
183 if (allocated(this%send_dof)) then
184 do i = 0, pe_size - 1
185 call this%send_dof(i)%free()
186 end do
187 deallocate(this%send_dof)
188 end if
189
190 if (allocated(this%recv_dof)) then
191 do i = 0, pe_size - 1
192 call this%recv_dof(i)%free()
193 end do
194 deallocate(this%recv_dof)
195 end if
196
197 end subroutine free_dofs
198
202 subroutine init_order(this, send_pe, recv_pe)
203 class(gs_comm_t), intent(inout) :: this
204 type(stack_i4_t), intent(inout) :: send_pe
205 type(stack_i4_t), intent(inout) :: recv_pe
206 integer, pointer :: sp(:)
207 integer :: i
208
209 allocate(this%send_pe(send_pe%size()))
210
211 sp => send_pe%array()
212 do i = 1, send_pe%size()
213 this%send_pe(i) = sp(i)
214 end do
215
216 allocate(this%recv_pe(recv_pe%size()))
217
218 sp => recv_pe%array()
219 do i = 1, recv_pe%size()
220 this%recv_pe(i) = sp(i)
221 end do
222
223 end subroutine init_order
224
225 subroutine free_order(this)
226 class(gs_comm_t), intent(inout) :: this
227
228 if (allocated(this%send_pe)) then
229 deallocate(this%send_pe)
230 end if
231
232 if (allocated(this%recv_pe)) then
233 deallocate(this%recv_pe)
234 end if
235
236 end subroutine free_order
237
242 subroutine gs_nbsend_vec(this, u, n, nc, tag, deps, strm)
243 class(gs_comm_t), intent(inout) :: this
244 integer, intent(in) :: n, nc
245 real(kind=rp), dimension(nc*n), intent(inout) :: u
246 integer, intent(in) :: tag
247 type(c_ptr), intent(inout) :: deps
248 type(c_ptr), intent(inout) :: strm
249 call neko_error('Vector gather-scatter not supported by this comm backend')
250 end subroutine gs_nbsend_vec
251
253 subroutine gs_nbrecv_vec(this, tag, nc)
254 class(gs_comm_t), intent(inout) :: this
255 integer, intent(in) :: tag, nc
256 call neko_error('Vector gather-scatter not supported by this comm backend')
257 end subroutine gs_nbrecv_vec
258
260 subroutine gs_nbwait_vec(this, u, n, nc, op, strm)
261 class(gs_comm_t), intent(inout) :: this
262 integer, intent(in) :: n, nc
263 real(kind=rp), dimension(nc*n), intent(inout) :: u
264 integer :: op
265 type(c_ptr), intent(inout) :: strm
266 call neko_error('Vector gather-scatter not supported by this comm backend')
267 end subroutine gs_nbwait_vec
268
269end module gs_comm
Abstract interface for deallocating a Gather-scatter communication method.
Definition gs_comm.f90:100
Abstract interface for initializing a Gather-scatter communication method.
Definition gs_comm.f90:89
Abstract interface for initiating non-blocking recieve operations Posts non-blocking recieve of value...
Definition gs_comm.f90:131
Abstract interface for initiating non-blocking send operations Sends the values in u(send_dof(send_pe...
Definition gs_comm.f90:113
Abstract interface for waiting on non-blocking operations Waits and checks that data is in buffers an...
Definition gs_comm.f90:147
Definition comm.F90:1
integer, public pe_size
MPI size of communicator.
Definition comm.F90:61
Defines a gather-scatter communication method.
Definition gs_comm.f90:34
subroutine gs_nbsend_vec(this, u, n, nc, tag, deps, strm)
Default fused vector send. Abort unless a backend overrides it.
Definition gs_comm.f90:243
subroutine init_dofs(this)
Definition gs_comm.f90:164
subroutine gs_nbrecv_vec(this, tag, nc)
Default fused vector receive. Abort unless a backend overrides it.
Definition gs_comm.f90:254
integer, parameter, public gs_vec_nc
Maximum number of components handled by the fused vector (multi-component) halo exchange used by gs_o...
Definition gs_comm.f90:49
integer, parameter, public gs_comm_mpigpu
Definition gs_comm.f90:43
integer, parameter, public gs_comm_neighbour
Definition gs_comm.f90:43
integer, parameter, public gs_comm_mpi
Definition gs_comm.f90:43
subroutine init_order(this, send_pe, recv_pe)
Obtains which ranks to send and receive data from.
Definition gs_comm.f90:203
subroutine gs_nbwait_vec(this, u, n, nc, op, strm)
Default fused vector wait/reduce. Abort unless a backend overrides it.
Definition gs_comm.f90:261
integer, parameter, public gs_comm_nvshmem
Definition gs_comm.f90:43
integer, parameter, public gs_comm_openshmem
Definition gs_comm.f90:43
integer, parameter, public gs_comm_utofu
Definition gs_comm.f90:43
subroutine free_dofs(this)
Definition gs_comm.f90:180
integer, parameter, public gs_comm_nccl
Definition gs_comm.f90:43
subroutine free_order(this)
Definition gs_comm.f90:226
integer, parameter, public gs_comm_caf
Definition gs_comm.f90:43
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Implements a dynamic stack ADT.
Definition stack.f90:49
Utilities.
Definition utils.f90:35
Gather-scatter communication method.
Definition gs_comm.f90:52
Integer based stack.
Definition stack.f90:77