Neko 1.99.3
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, intrinsic :: iso_c_binding
39 implicit none
40 private
41
42 integer, public, parameter :: gs_comm_mpi = 1, gs_comm_mpigpu = 2, &
44 gs_comm_caf = 6
45
47 type, public, abstract :: gs_comm_t
49 type(stack_i4_t), allocatable :: send_dof(:)
52 type(stack_i4_t), allocatable :: recv_dof(:)
56 integer, allocatable :: send_pe(:)
58 integer, allocatable :: recv_pe(:)
59 contains
60 procedure(gs_comm_init), pass(this), deferred :: init
61 procedure(gs_comm_free), pass(this), deferred :: free
62 procedure(gs_nbsend), pass(this), deferred :: nbsend
63 procedure(gs_nbrecv), pass(this), deferred :: nbrecv
64 procedure(gs_nbwait), pass(this), deferred :: nbwait
65 procedure, pass(this) :: init_dofs
66 procedure, pass(this) :: free_dofs
67 procedure, pass(this) :: init_order
68 procedure, pass(this) :: free_order
69 end type gs_comm_t
70
74 abstract interface
75 subroutine gs_comm_init(this, send_pe, recv_pe)
76 import gs_comm_t
77 import stack_i4_t
78 class(gs_comm_t), intent(inout) :: this
79 type(stack_i4_t), intent(inout) :: send_pe
80 type(stack_i4_t), intent(inout) :: recv_pe
81 end subroutine gs_comm_init
82 end interface
83
85 abstract interface
86 subroutine gs_comm_free(this)
87 import gs_comm_t
88 class(gs_comm_t), intent(inout) :: this
89 end subroutine gs_comm_free
90 end interface
91
98 abstract interface
99 subroutine gs_nbsend(this, u, n, deps, strm)
100 import gs_comm_t
101 import stack_i4_t
102 import c_ptr
103 import rp
104 class(gs_comm_t), intent(inout) :: this
105 integer, intent(in) :: n
106 real(kind=rp), dimension(n), intent(inout) :: u
107 type(c_ptr), intent(inout) :: deps
108 type(c_ptr), intent(inout) :: strm
109 end subroutine gs_nbsend
110 end interface
111
112
115 abstract interface
116 subroutine gs_nbrecv(this)
117 import gs_comm_t
118 class(gs_comm_t), intent(inout) :: this
119 end subroutine gs_nbrecv
120 end interface
121
130 abstract interface
131 subroutine gs_nbwait(this, u, n, op, strm)
132 import gs_comm_t
133 import stack_i4_t
134 import c_ptr
135 import rp
136 class(gs_comm_t), intent(inout) :: this
137 integer, intent(in) :: n
138 real(kind=rp), dimension(n), intent(inout) :: u
139 integer :: op
140 type(c_ptr), intent(inout) :: strm
141 end subroutine gs_nbwait
142 end interface
143
145contains
146 !Initalize stacks for each rank of dof indices to send/recv
147 subroutine init_dofs(this)
148 class(gs_comm_t), intent(inout) :: this
149 integer :: i
150
151 call this%free_dofs()
152
153 allocate(this%send_dof(0:pe_size-1))
154 allocate(this%recv_dof(0:pe_size-1))
155
156 do i = 0, pe_size -1
157 call this%send_dof(i)%init()
158 call this%recv_dof(i)%init()
159 end do
160
161 end subroutine init_dofs
162
163 subroutine free_dofs(this)
164 class(gs_comm_t), intent(inout) :: this
165 integer :: i
166
167 if (allocated(this%send_dof)) then
168 do i = 0, pe_size - 1
169 call this%send_dof(i)%free()
170 end do
171 deallocate(this%send_dof)
172 end if
173
174 if (allocated(this%recv_dof)) then
175 do i = 0, pe_size - 1
176 call this%recv_dof(i)%free()
177 end do
178 deallocate(this%recv_dof)
179 end if
180
181 end subroutine free_dofs
182
186 subroutine init_order(this, send_pe, recv_pe)
187 class(gs_comm_t), intent(inout) :: this
188 type(stack_i4_t), intent(inout) :: send_pe
189 type(stack_i4_t), intent(inout) :: recv_pe
190 integer, pointer :: sp(:)
191 integer :: i
192
193 allocate(this%send_pe(send_pe%size()))
194
195 sp => send_pe%array()
196 do i = 1, send_pe%size()
197 this%send_pe(i) = sp(i)
198 end do
199
200 allocate(this%recv_pe(recv_pe%size()))
201
202 sp => recv_pe%array()
203 do i = 1, recv_pe%size()
204 this%recv_pe(i) = sp(i)
205 end do
206
207 end subroutine init_order
208
209 subroutine free_order(this)
210 class(gs_comm_t), intent(inout) :: this
211
212 if (allocated(this%send_pe)) then
213 deallocate(this%send_pe)
214 end if
215
216 if (allocated(this%recv_pe)) then
217 deallocate(this%recv_pe)
218 end if
219
220 end subroutine free_order
221
222end module gs_comm
Abstract interface for deallocating a Gather-scatter communication method.
Definition gs_comm.f90:86
Abstract interface for initializing a Gather-scatter communication method.
Definition gs_comm.f90:75
Abstract interface for initiating non-blocking recieve operations Posts non-blocking recieve of value...
Definition gs_comm.f90:116
Abstract interface for initiating non-blocking send operations Sends the values in u(send_dof(send_pe...
Definition gs_comm.f90:99
Abstract interface for waiting on non-blocking operations Waits and checks that data is in buffers an...
Definition gs_comm.f90:131
Definition comm.F90:1
integer, public pe_size
MPI size of communicator.
Definition comm.F90:60
Defines a gather-scatter communication method.
Definition gs_comm.f90:34
subroutine init_dofs(this)
Definition gs_comm.f90:148
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)
Obtains which ranks to send and receive data from.
Definition gs_comm.f90:187
integer, parameter, public gs_comm_nvshmem
Definition gs_comm.f90:42
integer, parameter, public gs_comm_openshmem
Definition gs_comm.f90:42
subroutine free_dofs(this)
Definition gs_comm.f90:164
integer, parameter, public gs_comm_nccl
Definition gs_comm.f90:42
subroutine free_order(this)
Definition gs_comm.f90:210
integer, parameter, public gs_comm_caf
Definition gs_comm.f90:42
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Implements a dynamic stack ADT.
Definition stack.f90:49
Gather-scatter communication method.
Definition gs_comm.f90:47
Integer based stack.
Definition stack.f90:77