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
47 use gmres, only : gmres_t
48 use cheby, only : cheby_t
50 use gmres_sx, only : sx_gmres_t
52 use num_types, only : rp
53 use precon, only : pc_t
56 implicit none
57
58 ! List of all possible types created by the factory routine
59 character(len=20) :: KSP_KNOWN_TYPES(9) = [character(len=20) :: &
60 "cg", &
61 "pipecg", &
62 "fused_cg", &
63 "cacg", &
64 "gmres", &
65 "cheby", &
66 "bicgstab", &
67 "fused_coupled_cg", &
68 "coupled_cg"]
69
70contains
71
80 module subroutine krylov_solver_factory(object, n, type_name, &
81 max_iter, abstol, m, monitor)
82 class(ksp_t), allocatable, intent(inout) :: object
83 integer, intent(in), value :: n
84 character(len=*), intent(in) :: type_name
85 integer, intent(in) :: max_iter
86 real(kind=rp), optional :: abstol
87 class(pc_t), optional, intent(in), target :: M
88 logical, optional, intent(in) :: monitor
89
90 call krylov_solver_allocator(object, type_name)
91
92 call object%init(n, max_iter, m = m, abs_tol = abstol, monitor = monitor)
93
94 end subroutine krylov_solver_factory
95
99 module subroutine krylov_solver_allocator(object, type_name)
100 class(ksp_t), allocatable, intent(inout) :: object
101 character(len=*), intent(in) :: type_name
102 integer :: i
103
104 if (allocated(object)) then
105 call object%free()
106 deallocate(object)
107 end if
108
109 select case (trim(type_name))
110 case ('cg')
111 if (neko_bcknd_sx .eq. 1) then
112 allocate(sx_cg_t::object)
113 else if (neko_bcknd_device .eq. 1) then
114 allocate(cg_device_t::object)
115 else
116 allocate(cg_t::object)
117 end if
118
119 case ('coupled_cg')
120 if (neko_bcknd_device .eq. 1) then
121 allocate(cg_cpld_device_t::object)
122 else
123 allocate(cg_cpld_t::object)
124 end if
125
126 case ('pipecg')
127 if (neko_bcknd_sx .eq. 1) then
128 allocate(sx_pipecg_t::object)
129 else if (neko_bcknd_device .eq. 1) then
130 if (neko_bcknd_opencl .eq. 1 .or. neko_bcknd_metal .eq. 1) then
131 call neko_error('PipeCG not supported for OpenCL/Metal')
132 end if
133 allocate(pipecg_device_t::object)
134 else
135 allocate(pipecg_t::object)
136 end if
137
138 case ('fused_cg')
139 if (neko_bcknd_device .eq. 1) then
140 if (neko_bcknd_opencl .eq. 1 .or. neko_bcknd_metal .eq. 1) then
141 call neko_error('FusedCG not supported for OpenCL/Metal')
142 end if
143 allocate(fusedcg_device_t::object)
144 else
145 call neko_error('FusedCG only supported for CUDA/HIP')
146 end if
147
148 case ('fused_coupled_cg')
149 if (neko_bcknd_device .eq. 1) then
150 if (neko_bcknd_opencl .eq. 1 .or. neko_bcknd_metal .eq. 1) then
151 call neko_error('Coupled FusedCG not supported for OpenCL/Metal')
152 end if
153 allocate(fusedcg_cpld_device_t::object)
154 else
155 call neko_error('Coupled FusedCG only supported for CUDA/HIP')
156 end if
157
158 case ('cacg')
159 allocate(cacg_t::object)
160
161 case ('gmres')
162 if (neko_bcknd_sx .eq. 1) then
163 allocate(sx_gmres_t::object)
164 else if (neko_bcknd_device .eq. 1) then
165 allocate(gmres_device_t::object)
166 else
167 allocate(gmres_t::object)
168 end if
169
170 case ('cheby')
171 if (neko_bcknd_device .eq. 1) then
172 allocate(cheby_device_t::object)
173 else
174 allocate(cheby_t::object)
175 end if
176
177 case ('bicgstab')
178 if (neko_bcknd_device .eq. 1) then
179 allocate(bicgstab_device_t::object)
180 else
181 allocate(bicgstab_t::object)
182 end if
183
184 case default
185 do i = 1, krylov_registry_size
186 if (trim(type_name) .eq. trim(krylov_registry(i)%type_name)) then
187 call krylov_registry(i)%allocator(object)
188 return
189 end if
190 end do
191
192 call neko_type_error('Krylov solver', type_name, ksp_known_types)
193 end select
194
195 end subroutine krylov_solver_allocator
196
202 module subroutine register_krylov(type_name, allocator)
203 character(len=*), intent(in) :: type_name
204 procedure(krylov_allocate), pointer, intent(in) :: allocator
205 type(krylov_allocator_entry), allocatable :: temp(:)
206 integer :: i
207
208 do i = 1, size(ksp_known_types)
209 if (trim(type_name) .eq. trim(ksp_known_types(i))) then
210 call neko_type_registration_error("Krylov solver", type_name, &
211 .true.)
212 end if
213 end do
214
215 do i = 1, krylov_registry_size
216 if (trim(type_name) .eq. trim(krylov_registry(i)%type_name)) then
217 call neko_type_registration_error("Krylov solver", type_name, &
218 .false.)
219 end if
220 end do
221
222 if (krylov_registry_size .eq. 0) then
223 allocate(krylov_registry(1))
224 else
225 allocate(temp(krylov_registry_size + 1))
226 temp(1:krylov_registry_size) = krylov_registry
227 call move_alloc(temp, krylov_registry)
228 end if
229
230 krylov_registry_size = krylov_registry_size + 1
231 krylov_registry(krylov_registry_size)%type_name = type_name
232 krylov_registry(krylov_registry_size)%allocator => allocator
233 end subroutine register_krylov
234
235end submodule krylov_fctry
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:380
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:365
CPU implementation of the right-preconditioned BiCGStab method.
Definition bicgstab.f90:58
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