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
krylov_fctry.f90
Go to the documentation of this file.
1! Copyright (c) 2021-2024, 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
38 use cacg, only : cacg_t
39 use pipecg, only : pipecg_t
40 use pipecg_sx, only : sx_pipecg_t
44 use bicgstab, only : bicgstab_t
45 use gmres, only : gmres_t
46 use cheby, only : cheby_t
48 use gmres_sx, only : sx_gmres_t
50 use num_types, only : rp
51 use precon, only : pc_t
52 use utils, only : neko_type_error
54 implicit none
55
56 ! List of all possible types created by the factory routine
57 character(len=20) :: KSP_KNOWN_TYPES(9) = [character(len=20) :: &
58 "cg", &
59 "pipecg", &
60 "fusedcg", &
61 "cacg", &
62 "gmres", &
63 "cheby", &
64 "bicgstab", &
65 "fusedcoupledcg", &
66 "coupledcg"]
67
68contains
69
78 module subroutine krylov_solver_factory(object, n, type_name, &
79 max_iter, abstol, m, monitor)
80 class(ksp_t), allocatable, intent(inout) :: object
81 integer, intent(in), value :: n
82 character(len=*), intent(in) :: type_name
83 integer, intent(in) :: max_iter
84 real(kind=rp), optional :: abstol
85 class(pc_t), optional, intent(in), target :: M
86 logical, optional, intent(in) :: monitor
87
88 if (allocated(object)) then
89 call object%free()
90 deallocate(object)
91 end if
92
93 select case (trim(type_name))
94 case ('cg')
95 if (neko_bcknd_sx .eq. 1) then
96 allocate(sx_cg_t::object)
97 else if (neko_bcknd_device .eq. 1) then
98 allocate(cg_device_t::object)
99 else
100 allocate(cg_t::object)
101 end if
102
103 case ('coupledcg')
104 allocate(cg_cpld_t::object)
105 if (neko_bcknd_device .eq. 1) then
106 call neko_error('Coupled CG only supported for CPU')
107 end if
108
109 case ('pipecg')
110 if (neko_bcknd_sx .eq. 1) then
111 allocate(sx_pipecg_t::object)
112 else if (neko_bcknd_device .eq. 1) then
113 if (neko_bcknd_opencl .eq. 1) then
114 call neko_error('PipeCG not supported for OpenCL')
115 end if
116 allocate(pipecg_device_t::object)
117 else
118 allocate(pipecg_t::object)
119 end if
120
121 case ('fusedcg')
122 if (neko_bcknd_device .eq. 1) then
123 if (neko_bcknd_opencl .eq. 1) then
124 call neko_error('FusedCG not supported for OpenCL')
125 end if
126 allocate(fusedcg_device_t::object)
127 else
128 call neko_error('FusedCG only supported for CUDA/HIP')
129 end if
130
131 case ('fusedcoupledcg')
132 if (neko_bcknd_device .eq. 1) then
133 if (neko_bcknd_opencl .eq. 1) then
134 call neko_error('Coupled FusedCG not supported for OpenCL')
135 end if
136 allocate(fusedcg_cpld_device_t::object)
137 else
138 call neko_error('Coupled FusedCG only supported for CUDA/HIP')
139 end if
140
141 case ('cacg')
142 allocate(cacg_t::object)
143
144 case ('gmres')
145 if (neko_bcknd_sx .eq. 1) then
146 allocate(sx_gmres_t::object)
147 else if (neko_bcknd_device .eq. 1) then
148 allocate(gmres_device_t::object)
149 else
150 allocate(gmres_t::object)
151 end if
152
153 case ('cheby')
154 if (neko_bcknd_device .eq. 1) then
155 allocate(cheby_device_t::object)
156 else
157 allocate(cheby_t::object)
158 end if
159
160 case ('bicgstab')
161 allocate(bicgstab_t::object)
162
163 case default
164 call neko_type_error('Krylov solver', type_name, ksp_known_types)
165 end select
166
167 call object%init(n, max_iter, m = m, abs_tol = abstol, monitor = monitor)
168
169 end subroutine krylov_solver_factory
170
171end submodule krylov_fctry
172
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.
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:251
Standard preconditioned Bi-Conjugate Gradient Stabilized method.
Definition bicgstab.f90:50
S-step communication avoiding preconditioned conjugate gradient method.
Definition cacg.f90:51
Standard preconditioned conjugate gradient method.
Definition cg.f90:51
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:50
Standard preconditioned generalized minimal residual method.
Standard preconditioned generalized minimal residual method (SX version)
Definition gmres_sx.f90:49
Pipelined preconditioned conjugate gradient method.
Definition pipecg.f90:51
Pipelined preconditioned conjugate gradient method.
Pipelined preconditioned conjugate gradient method for SX-Aurora.
Definition pipecg_sx.f90:49
Defines a canonical Krylov preconditioner.
Definition precon.f90:40