Skip to content

Commit c5963e3

Browse files
authored
Use FGCRODR instead of GMRES for "Newton-Krylov" adjoint (#2782)
* checkpoint * optimize product * nested parallel improvements * add test, non flexible mode for FGCRODR * fix the VkWk optimization * simplify settings * update
1 parent 83175fc commit c5963e3

11 files changed

Lines changed: 324 additions & 78 deletions

File tree

Common/include/linear_algebra/CSysSolve.hpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
#include "CSysVector.hpp"
4242
#include "../option_structure.hpp"
4343

44+
SU2_IGNORE_WARNING("-Wmaybe-uninitialized")
45+
#include "Eigen/Core"
46+
#include "Eigen/Dense"
47+
SU2_RESTORE_WARNING
48+
4449
class CConfig;
4550
class CGeometry;
4651
template <class T>
@@ -110,6 +115,7 @@ class CSysSolve {
110115
mutable unsigned long k = 0;
111116
mutable std::vector<VectorType> Z, V; /*!< \brief Large matrices used by FGMRES, v^i+1 = A * z^i. */
112117
mutable std::vector<VectorType> W, T; /*!< \brief Large matrices used by FGCRODR for deflation vectors. */
118+
mutable Eigen::Matrix<ScalarType, Eigen::Dynamic, Eigen::Dynamic> VkWk;
113119

114120
/*!< \brief Temporary used when it is necessary to interface between active and passive types. */
115121
VectorType LinSysSol_tmp;
@@ -292,8 +298,8 @@ class CSysSolve {
292298
template <class Dummy = int>
293299
unsigned long FGCRODR_LinSolverImpl(const VectorType& b, VectorType& x, const ProductType& mat_vec,
294300
const PrecondType& precond, ScalarType tol, unsigned long max_iter,
295-
ScalarType& residual, bool monitoring, const CConfig* config,
296-
FgcrodrMode mode) const;
301+
ScalarType& residual, bool monitoring, const CConfig* config, FgcrodrMode mode,
302+
unsigned long custom_m) const;
297303

298304
/*!
299305
* \brief Creates the inner solver for nested preconditioning if the settings allow it.
@@ -316,7 +322,7 @@ class CSysSolve {
316322
* \param[in] tol - tolerance with which to solve the system
317323
* \param[in] m - maximum size of the search subspace
318324
* \param[out] residual - final normalized residual
319-
* \param[in] monitoring - turn on priting residuals from solver to screen.
325+
* \param[in] monitoring - turn on priting residuals from solver to screen
320326
* \param[in] config - Definition of the particular problem.
321327
*/
322328
unsigned long CG_LinSolver(const VectorType& b, VectorType& x, const ProductType& mat_vec, const PrecondType& precond,
@@ -332,7 +338,7 @@ class CSysSolve {
332338
* \param[in] tol - tolerance with which to solve the system
333339
* \param[in] m - maximum size of the search subspace
334340
* \param[out] residual - final normalized residual
335-
* \param[in] monitoring - turn on priting residuals from solver to screen.
341+
* \param[in] monitoring - turn on priting residuals from solver to screen
336342
* \param[in] config - Definition of the particular problem.
337343
*/
338344
unsigned long FGMRES_LinSolver(const VectorType& b, VectorType& x, const ProductType& mat_vec,
@@ -355,14 +361,15 @@ class CSysSolve {
355361
* \param[in] tol - tolerance with which to solve the system
356362
* \param[in] max_iter - maximum number of iterations
357363
* \param[out] residual - final normalized residual
358-
* \param[in] monitoring - turn on priting residuals from solver to screen.
364+
* \param[in] monitoring - turn on priting residuals from solver to screen
359365
* \param[in] config - Definition of the particular problem.
360366
* \param[in] mode - See FgcrodrMode.
367+
* \param[in] custom_m - alternative maximum size of the search subspace, overrides the config value if != 0.
361368
*/
362369
unsigned long FGCRODR_LinSolver(const VectorType& b, VectorType& x, const ProductType& mat_vec,
363370
const PrecondType& precond, ScalarType tol, unsigned long max_iter,
364371
ScalarType& residual, bool monitoring, const CConfig* config,
365-
FgcrodrMode mode = FgcrodrMode::NORMAL) const;
372+
FgcrodrMode mode = FgcrodrMode::NORMAL, unsigned long custom_m = 0) const;
366373

367374
/*!
368375
* \brief Biconjugate Gradient Stabilized Method (BCGSTAB)
@@ -373,7 +380,7 @@ class CSysSolve {
373380
* \param[in] tol - tolerance with which to solve the system
374381
* \param[in] m - maximum size of the search subspace
375382
* \param[out] residual - final normalized residual
376-
* \param[in] monitoring - turn on priting residuals from solver to screen.
383+
* \param[in] monitoring - turn on priting residuals from solver to screen
377384
* \param[in] config - Definition of the particular problem.
378385
*/
379386
unsigned long BCGSTAB_LinSolver(const VectorType& b, VectorType& x, const ProductType& mat_vec,
@@ -389,7 +396,7 @@ class CSysSolve {
389396
* \param[in] tol - tolerance with which to solve the system
390397
* \param[in] m - maximum number of iterations
391398
* \param[out] residual - final normalized residual
392-
* \param[in] monitoring - turn on priting residuals from solver to screen.
399+
* \param[in] monitoring - turn on priting residuals from solver to screen
393400
* \param[in] config - Definition of the particular problem.
394401
*/
395402
unsigned long Smoother_LinSolver(const VectorType& b, VectorType& x, const ProductType& mat_vec,

Common/include/linear_algebra/CSysVector.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#pragma once
3030

3131
#include <memory>
32+
#include <vector>
3233

3334
#include "../parallelization/mpi_structure.hpp"
3435
#include "../parallelization/omp_structure.hpp"
@@ -371,6 +372,18 @@ class CSysVector : public VecExpr::CVecExpr<CSysVector<ScalarType>, ScalarType>
371372
return dot_scratch[0];
372373
}
373374

375+
/*!
376+
* \brief Computes the product of V^T W efficiencly, where V and W are tall matrices stored as vectors of CSysVector.
377+
* \param[in] V - Tall matrix.
378+
* \param[in] i0 - First column of V to consider.
379+
* \param[in] n - Number of columns to consider from V starting at i0.
380+
* \param[in] W - Tall matrix.
381+
* \param[in] m - Number of columns to consider from W.
382+
* \return n by m matrix with the result of the product.
383+
*/
384+
static const su2matrix<ScalarType>& multiDot(const std::vector<CSysVector>& V, size_t i0, size_t n,
385+
const std::vector<CSysVector>& W, size_t m);
386+
374387
/*!
375388
* \brief Squared L2 norm of the vector (via dot with self).
376389
* \return Squared L2 norm.

0 commit comments

Comments
 (0)