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