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, tag, 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 integer, intent(in) :: tag
108 type(c_ptr), intent(inout) :: deps
109 type(c_ptr), intent(inout) :: strm
110 end subroutine gs_nbsend
111 end interface
112
113
116 abstract interface
117 subroutine gs_nbrecv(this, tag)
118 import gs_comm_t
119 class(gs_comm_t), intent(inout) :: this
120 integer, intent(in) :: tag
121 end subroutine gs_nbrecv
122 end interface
123
132 abstract interface
133 subroutine gs_nbwait(this, u, n, op, strm)
134 import gs_comm_t
135 import stack_i4_t
136 import c_ptr
137 import rp
138 class(gs_comm_t), intent(inout) :: this
139 integer, intent(in) :: n
140 real(kind=rp), dimension(n), intent(inout) :: u
141 integer :: op
142 type(c_ptr), intent(inout) :: strm
143 end subroutine gs_nbwait
144 end interface
145
147contains
148 !Initalize stacks for each rank of dof indices to send/recv
149 subroutine init_dofs(this)
150 class(gs_comm_t), intent(inout) :: this
151 integer :: i
152
153 call this%free_dofs()
154
155 allocate(this%send_dof(0:pe_size-1))
156 allocate(this%recv_dof(0:pe_size-1))
157
158 do i = 0, pe_size -1
159 call this%send_dof(i)%init()
160 call this%recv_dof(i)%init()
161 end do
162
163 end subroutine init_dofs
164
165 subroutine free_dofs(this)
166 class(gs_comm_t), intent(inout) :: this
167 integer :: i
168
169 if (allocated(this%send_dof)) then
170 do i = 0, pe_size - 1
171 call this%send_dof(i)%free()
172 end do
173 deallocate(this%send_dof)
174 end if
175
176 if (allocated(this%recv_dof)) then
177 do i = 0, pe_size - 1
178 call this%recv_dof(i)%free()
179 end do
180 deallocate(this%recv_dof)
181 end if
182
183 end subroutine free_dofs
184
188 subroutine init_order(this, send_pe, recv_pe)
189 class(gs_comm_t), intent(inout) :: this
190 type(stack_i4_t), intent(inout) :: send_pe
191 type(stack_i4_t), intent(inout) :: recv_pe
192 integer, pointer :: sp(:)
193 integer :: i
194
195 allocate(this%send_pe(send_pe%size()))
196
197 sp => send_pe%array()
198 do i = 1, send_pe%size()
199 this%send_pe(i) = sp(i)
200 end do
201
202 allocate(this%recv_pe(recv_pe%size()))
203
204 sp => recv_pe%array()
205 do i = 1, recv_pe%size()
206 this%recv_pe(i) = sp(i)
207 end do
208
209 end subroutine init_order
210
211 subroutine free_order(this)
212 class(gs_comm_t), intent(inout) :: this
213
214 if (allocated(this%send_pe)) then
215 deallocate(this%send_pe)
216 end if
217
218 if (allocated(this%recv_pe)) then
219 deallocate(this%recv_pe)
220 end if
221
222 end subroutine free_order
223
224end 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:117
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:133
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 init_dofs(this)
Definition gs_comm.f90:150
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:189
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:166
integer, parameter, public gs_comm_nccl
Definition gs_comm.f90:42
subroutine free_order(this)
Definition gs_comm.f90:212
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