Loading [MathJax]/extensions/tex2jax.js
Neko 0.9.99
A portable framework for high-order spectral element flow simulations
All Classes Namespaces Files Functions Variables Typedefs Enumerator Macros Pages
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!
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
46 type, public, abstract :: gs_comm_t
48 type(stack_i4_t), allocatable :: send_dof(:)
51 type(stack_i4_t), allocatable :: recv_dof(:)
55 integer, allocatable :: send_pe(:)
57 integer, allocatable :: recv_pe(:)
58 contains
59 procedure(gs_comm_init), pass(this), deferred :: init
60 procedure(gs_comm_free), pass(this), deferred :: free
61 procedure(gs_nbsend), pass(this), deferred :: nbsend
62 procedure(gs_nbrecv), pass(this), deferred :: nbrecv
63 procedure(gs_nbwait), pass(this), deferred :: nbwait
64 procedure, pass(this) :: init_dofs
65 procedure, pass(this) :: free_dofs
66 procedure, pass(this) :: init_order
67 procedure, pass(this) :: free_order
68 end type gs_comm_t
69
73 abstract interface
74 subroutine gs_comm_init(this, send_pe, recv_pe)
75 import gs_comm_t
76 import stack_i4_t
77 class(gs_comm_t), intent(inout) :: this
78 type(stack_i4_t), intent(inout) :: send_pe
79 type(stack_i4_t), intent(inout) :: recv_pe
80 end subroutine gs_comm_init
81 end interface
82
84 abstract interface
85 subroutine gs_comm_free(this)
86 import gs_comm_t
87 class(gs_comm_t), intent(inout) :: this
88 end subroutine gs_comm_free
89 end interface
90
97 abstract interface
98 subroutine gs_nbsend(this, u, n, deps, strm)
99 import gs_comm_t
100 import stack_i4_t
101 import c_ptr
102 import rp
103 class(gs_comm_t), intent(inout) :: this
104 integer, intent(in) :: n
105 real(kind=rp), dimension(n), intent(inout) :: u
106 type(c_ptr), intent(inout) :: deps
107 type(c_ptr), intent(inout) :: strm
108 end subroutine gs_nbsend
109 end interface
110
111
114 abstract interface
115 subroutine gs_nbrecv(this)
116 import gs_comm_t
117 class(gs_comm_t), intent(inout) :: this
118 end subroutine gs_nbrecv
119 end interface
120
129 abstract interface
130 subroutine gs_nbwait(this, u, n, op, strm)
131 import gs_comm_t
132 import stack_i4_t
133 import c_ptr
134 import rp
135 class(gs_comm_t), intent(inout) :: this
136 integer, intent(in) :: n
137 real(kind=rp), dimension(n), intent(inout) :: u
138 integer :: op
139 type(c_ptr), intent(inout) :: strm
140 end subroutine gs_nbwait
141 end interface
142
144contains
145 !Initalize stacks for each rank of dof indices to send/recv
146 subroutine init_dofs(this)
147 class(gs_comm_t), intent(inout) :: this
148 integer :: i
149
150 call this%free_dofs()
151
152 allocate(this%send_dof(0:pe_size-1))
153 allocate(this%recv_dof(0:pe_size-1))
154
155 do i = 0, pe_size -1
156 call this%send_dof(i)%init()
157 call this%recv_dof(i)%init()
158 end do
159
160 end subroutine init_dofs
161
162 subroutine free_dofs(this)
163 class(gs_comm_t), intent(inout) :: this
164 integer :: i
165
166 if (allocated(this%send_dof)) then
167 do i = 0, pe_size - 1
168 call this%send_dof(i)%free()
169 end do
170 deallocate(this%send_dof)
171 end if
172
173 if (allocated(this%recv_dof)) then
174 do i = 0, pe_size - 1
175 call this%recv_dof(i)%free()
176 end do
177 deallocate(this%recv_dof)
178 end if
179
180 end subroutine free_dofs
181
185 subroutine init_order(this, send_pe, recv_pe)
186 class(gs_comm_t), intent(inout) :: this
187 type(stack_i4_t), intent(inout) :: send_pe
188 type(stack_i4_t), intent(inout) :: recv_pe
189 integer, pointer :: sp(:)
190 integer :: i
191
192 allocate(this%send_pe(send_pe%size()))
193
194 sp => send_pe%array()
195 do i = 1, send_pe%size()
196 this%send_pe(i) = sp(i)
197 end do
198
199 allocate(this%recv_pe(recv_pe%size()))
200
201 sp => recv_pe%array()
202 do i = 1, recv_pe%size()
203 this%recv_pe(i) = sp(i)
204 end do
205
206 end subroutine init_order
207
208 subroutine free_order(this)
209 class(gs_comm_t), intent(inout) :: this
210
211 if (allocated(this%send_pe)) then
212 deallocate(this%send_pe)
213 end if
214
215 if (allocated(this%recv_pe)) then
216 deallocate(this%recv_pe)
217 end if
218
219 end subroutine free_order
220
221end module gs_comm
Abstract interface for deallocating a Gather-scatter communication method.
Definition gs_comm.f90:85
Abstract interface for initializing a Gather-scatter communication method.
Definition gs_comm.f90:74
Abstract interface for initiating non-blocking recieve operations Posts non-blocking recieve of value...
Definition gs_comm.f90:115
Abstract interface for initiating non-blocking send operations Sends the values in u(send_dof(send_pe...
Definition gs_comm.f90:98
Abstract interface for waiting on non-blocking operations Waits and checks that data is in buffers an...
Definition gs_comm.f90:130
Definition comm.F90:1
integer pe_size
MPI size of communicator.
Definition comm.F90:53
Defines a gather-scatter communication method.
Definition gs_comm.f90:34
subroutine init_dofs(this)
Definition gs_comm.f90:147
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:186
integer, parameter, public gs_comm_nvshmem
Definition gs_comm.f90:42
subroutine free_dofs(this)
Definition gs_comm.f90:163
integer, parameter, public gs_comm_nccl
Definition gs_comm.f90:42
subroutine free_order(this)
Definition gs_comm.f90:209
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:46
Integer based stack.
Definition stack.f90:63