Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
krylov_fctry.f90
Go to the documentation of this file.
1! Copyright (c) 2021-2025, 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!
33submodule(krylov) krylov_fctry
34 use cg, only : cg_t
35 use cg_sx, only : sx_cg_t
36 use cg_cpld, only : cg_cpld_t
37 use cg_device, only : cg_device_t
39 use cacg, only : cacg_t
40 use pipecg, only : pipecg_t
41 use pipecg_sx, only : sx_pipecg_t
45 use bicgstab, only : bicgstab_t
48 use gmres, only : gmres_t
49 use cheby, only : cheby_t
51 use gmres_sx, only : sx_gmres_t
53 use num_types, only : rp
54 use precon, only : pc_t
57 implicit none
58
59 ! List of all possible types created by the factory routine
60 character(len=20) :: KSP_KNOWN_TYPES(10) = [character(len=20) :: &
61 "cg", &
62 "pipecg", &
63 "fused_cg", &
64 "cacg", &
65 "gmres", &
66 "cheby", &
67 "bicgstab", &
68 "coupled_bicgstab", &
69 "fused_coupled_cg", &
70 "coupled_cg"]
71
72contains
73
82 module subroutine krylov_solver_factory(object, n, type_name, &
83 max_iter, abstol, m, monitor)
84 class(ksp_t), allocatable, intent(inout) :: object
85 integer, intent(in), value :: n
86 character(len=*), intent(in) :: type_name
87 integer, intent(in) :: max_iter
88 real(kind=rp), optional :: abstol
89 class(pc_t), optional, intent(in), target :: M
90 logical, optional, intent(in) :: monitor
91
92 call krylov_solver_allocator(object, type_name)
93
94 call object%init(n, max_iter, m = m, abs_tol = abstol, monitor = monitor)
95
96 end subroutine krylov_solver_factory
97
101 module subroutine krylov_solver_allocator(object, type_name)
102 class(ksp_t), allocatable, intent(inout) :: object
103 character(len=*), intent(in) :: type_name
104 integer :: i
105
106 if (allocated(object)) then
107 call object%free()
108 deallocate(object)
109 end if
110
111 select case (trim(type_name))
112 case ('cg')
113 if (neko_bcknd_sx .eq. 1) then
114 allocate(sx_cg_t::object)
115 else if (neko_bcknd_device .eq. 1) then
116 allocate(cg_device_t::object)
117 else
118 allocate(cg_t::object)
119 end if
120
121 case ('coupled_cg')
122 if (neko_bcknd_device .eq. 1) then
123 allocate(cg_cpld_device_t::object)
124 else
125 allocate(cg_cpld_t::object)
126 end if
127
128 case ('pipecg')
129 if (neko_bcknd_sx .eq. 1) then
130 allocate(sx_pipecg_t::object)
131 else if (neko_bcknd_device .eq. 1) then
132 if (neko_bcknd_opencl .eq. 1 .or. neko_bcknd_metal .eq. 1) then
133 call neko_error('PipeCG not supported for OpenCL/Metal')
134 end if
135 allocate(pipecg_device_t::object)
136 else
137 allocate(pipecg_t::object)
138 end if
139
140 case ('fused_cg')
141 if (neko_bcknd_device .eq. 1) then
142 if (neko_bcknd_opencl .eq. 1 .or. neko_bcknd_metal .eq. 1) then
143 call neko_error('FusedCG not supported for OpenCL/Metal')
144 end if
145 allocate(fusedcg_device_t::object)
146 else
147 call neko_error('FusedCG only supported for CUDA/HIP')
148 end if
149
150 case ('fused_coupled_cg')
151 if (neko_bcknd_device .eq. 1) then
152 if (neko_bcknd_opencl .eq. 1 .or. neko_bcknd_metal .eq. 1) then
153 call neko_error('Coupled FusedCG not supported for OpenCL/Metal')
154 end if
155 allocate(fusedcg_cpld_device_t::object)
156 else
157 call neko_error('Coupled FusedCG only supported for CUDA/HIP')
158 end if
159
160 case ('cacg')
161 allocate(cacg_t::object)
162
163 case ('gmres')
164 if (neko_bcknd_sx .eq. 1) then
165 allocate(sx_gmres_t::object)
166 else if (neko_bcknd_device .eq. 1) then
167 allocate(gmres_device_t::object)
168 else
169 allocate(gmres_t::object)
170 end if
171
172 case ('cheby')
173 if (neko_bcknd_device .eq. 1) then
174 allocate(cheby_device_t::object)
175 else
176 allocate(cheby_t::object)
177 end if
178
179 case ('bicgstab')
180 if (neko_bcknd_device .eq. 1) then
181 allocate(bicgstab_device_t::object)
182 else
183 allocate(bicgstab_t::object)
184 end if
185
186 case ('coupled_bicgstab')
187 if (neko_bcknd_device .eq. 1) then
188 call neko_error('Coupled BiCGStab is not supported on devices')
189 else
190 allocate(bicgstab_cpld_t::object)
191 end if
192
193 case default
194 do i = 1, krylov_registry_size
195 if (trim(type_name) .eq. trim(krylov_registry(i)%type_name)) then
196 call krylov_registry(i)%allocator(object)
197 return
198 end if
199 end do
200
201 call neko_type_error('Krylov solver', type_name, ksp_known_types)
202 end select
203
204 end subroutine krylov_solver_allocator
205
211 module subroutine register_krylov(type_name, allocator)
212 character(len=*), intent(in) :: type_name
213 procedure(krylov_allocate), pointer, intent(in) :: allocator
214 type(krylov_allocator_entry), allocatable :: temp(:)
215 integer :: i
216
217 do i = 1, size(ksp_known_types)
218 if (trim(type_name) .eq. trim(ksp_known_types(i))) then
219 call neko_type_registration_error("Krylov solver", type_name, &
220 .true.)
221 end if
222 end do
223
224 do i = 1, krylov_registry_size
225 if (trim(type_name) .eq. trim(krylov_registry(i)%type_name)) then
226 call neko_type_registration_error("Krylov solver", type_name, &
227 .false.)
228 end if
229 end do
230
231 if (krylov_registry_size .eq. 0) then
232 allocate(krylov_registry(1))
233 else
234 allocate(temp(krylov_registry_size + 1))
235 temp(1:krylov_registry_size) = krylov_registry
236 call move_alloc(temp, krylov_registry)
237 end if
238
239 krylov_registry_size = krylov_registry_size + 1
240 krylov_registry(krylov_registry_size)%type_name = type_name
241 krylov_registry(krylov_registry_size)%allocator => allocator
242 end subroutine register_krylov
243
244end submodule krylov_fctry
Provides a coupled CPU implementation of the BiCGStab method.
Provides a device implementation of the BiCGStab method.
Provides a CPU implementation of the BiCGStab method.
Definition bicgstab.f90:34
Defines a communication avoiding Conjugate Gradient method.
Definition cacg.f90:34
Defines a coupled Conjugate Gradient methods for accelerators.
Defines a coupled Conjugate Gradient methods.
Defines various Conjugate Gradient methods for accelerators.
Definition cg_device.f90:34
Defines various Conjugate Gradient methods.
Definition cg_sx.f90:34
Defines various Conjugate Gradient methods.
Definition cg.f90:34
Chebyshev preconditioner.
Chebyshev preconditioner.
Definition cheby.f90:34
Defines a fused Conjugate Gradient method for accelerators.
Defines a fused Conjugate Gradient method for accelerators.
Defines various GMRES methods.
Defines various GMRES methods.
Definition gmres_sx.f90:34
Defines various GMRES methods.
Definition gmres.f90:34
Implements the base abstract type for Krylov solvers plus helper types.
Definition krylov.f90:34
Build configurations.
integer, parameter neko_bcknd_sx
integer, parameter neko_bcknd_device
integer, parameter neko_bcknd_opencl
integer, parameter neko_bcknd_metal
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Defines a pipelined Conjugate Gradient methods.
Defines a pipelined Conjugate Gradient methods SX-Aurora backend.
Definition pipecg_sx.f90:34
Defines a pipelined Conjugate Gradient methods.
Definition pipecg.f90:34
Krylov preconditioner.
Definition precon.f90:34
Utilities.
Definition utils.f90:35
subroutine, public neko_type_registration_error(base_type, wrong_type, known)
Definition utils.f90:393
subroutine, public neko_type_error(base_type, wrong_type, known_types)
Reports an error allocating a type for a particular base pointer class.
Definition utils.f90:376
CPU implementation of the right-preconditioned BiCGStab method.
Definition bicgstab.f90:60
Coupled right-preconditioned CPU BiCGStab method.
Device implementation of the right-preconditioned BiCGStab method.
S-step communication avoiding preconditioned conjugate gradient method.
Definition cacg.f90:55
Standard preconditioned conjugate gradient method.
Definition cg.f90:55
Coupled preconditioned conjugate gradient method.
Device based coupled preconditioned conjugate gradient method.
Device based preconditioned conjugate gradient method.
Definition cg_device.f90:55
Standard preconditioned conjugate gradient method (SX version)
Definition cg_sx.f90:50
Defines a Chebyshev preconditioner.
Definition cheby.f90:55
Defines a Chebyshev preconditioner.
Fused preconditioned conjugate gradient method.
Fused preconditioned conjugate gradient method.
Standard preconditioned generalized minimal residual method.
Definition gmres.f90:54
Standard preconditioned generalized minimal residual method.
Standard preconditioned generalized minimal residual method (SX version)
Definition gmres_sx.f90:52
Pipelined preconditioned conjugate gradient method.
Definition pipecg.f90:56
Pipelined preconditioned conjugate gradient method.
Pipelined preconditioned conjugate gradient method for SX-Aurora.
Definition pipecg_sx.f90:53
Defines a canonical Krylov preconditioner.
Definition precon.f90:40