Neko 1.99.1
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
53 use utils, only : neko_type_error
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 if (allocated(object)) then
90 call object%free()
91 deallocate(object)
92 end if
93
94 select case (trim(type_name))
95 case ('cg')
96 if (neko_bcknd_sx .eq. 1) then
97 allocate(sx_cg_t::object)
98 else if (neko_bcknd_device .eq. 1) then
99 allocate(cg_device_t::object)
100 else
101 allocate(cg_t::object)
102 end if
103
104 case ('coupled_cg')
105 if (neko_bcknd_device .eq. 1) then
106 allocate(cg_cpld_device_t::object)
107 else
108 allocate(cg_cpld_t::object)
109 end if
110
111 case ('pipecg')
112 if (neko_bcknd_sx .eq. 1) then
113 allocate(sx_pipecg_t::object)
114 else if (neko_bcknd_device .eq. 1) then
115 if (neko_bcknd_opencl .eq. 1) then
116 call neko_error('PipeCG not supported for OpenCL')
117 end if
118 allocate(pipecg_device_t::object)
119 else
120 allocate(pipecg_t::object)
121 end if
122
123 case ('fused_cg')
124 if (neko_bcknd_device .eq. 1) then
125 if (neko_bcknd_opencl .eq. 1) then
126 call neko_error('FusedCG not supported for OpenCL')
127 end if
128 allocate(fusedcg_device_t::object)
129 else
130 call neko_error('FusedCG only supported for CUDA/HIP')
131 end if
132
133 case ('fused_coupled_cg')
134 if (neko_bcknd_device .eq. 1) then
135 if (neko_bcknd_opencl .eq. 1) then
136 call neko_error('Coupled FusedCG not supported for OpenCL')
137 end if
138 allocate(fusedcg_cpld_device_t::object)
139 else
140 call neko_error('Coupled FusedCG only supported for CUDA/HIP')
141 end if
142
143 case ('cacg')
144 allocate(cacg_t::object)
145
146 case ('gmres')
147 if (neko_bcknd_sx .eq. 1) then
148 allocate(sx_gmres_t::object)
149 else if (neko_bcknd_device .eq. 1) then
150 allocate(gmres_device_t::object)
151 else
152 allocate(gmres_t::object)
153 end if
154
155 case ('cheby')
156 if (neko_bcknd_device .eq. 1) then
157 allocate(cheby_device_t::object)
158 else
159 allocate(cheby_t::object)
160 end if
161
162 case ('bicgstab')
163 allocate(bicgstab_t::object)
164
165 case default
166 call neko_type_error('Krylov solver', type_name, ksp_known_types)
167 end select
168
169 call object%init(n, max_iter, m = m, abs_tol = abstol, monitor = monitor)
170
171 end subroutine krylov_solver_factory
172
173end 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, 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_error(base_type, wrong_type, known_types)
Reports an error allocating a type for a particular base pointer class.
Definition utils.f90:313
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:51
Standard preconditioned conjugate gradient method (SX version)
Definition cg_sx.f90:48
Defines a Chebyshev preconditioner.
Definition cheby.f90:52
Defines a Chebyshev preconditioner.
Fused preconditioned conjugate gradient method.
Fused preconditioned conjugate gradient method.
Standard preconditioned generalized minimal residual method.
Definition gmres.f90:51
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