Julia interface to hypre linear solvers (https://github.com/hypre-space/hypre)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

47 lines
12 KiB

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Solvers and preconditioners · HYPRE.jl</title><meta name="title" content="Solvers and preconditioners · HYPRE.jl"/><meta property="og:title" content="Solvers and preconditioners · HYPRE.jl"/><meta property="twitter:title" content="Solvers and preconditioners · HYPRE.jl"/><meta name="description" content="Documentation for HYPRE.jl."/><meta property="og:description" content="Documentation for HYPRE.jl."/><meta property="twitter:description" content="Documentation for HYPRE.jl."/><meta property="og:url" content="https://fredrikekre.github.io/HYPRE.jl/stable/solvers-preconditioners/"/><meta property="twitter:url" content="https://fredrikekre.github.io/HYPRE.jl/stable/solvers-preconditioners/"/><link rel="canonical" href="https://fredrikekre.github.io/HYPRE.jl/stable/solvers-preconditioners/"/><script data-outdated-warner src="../assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.050/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.8/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../assets/documenter.js"></script><script src="../search_index.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/catppuccin-mocha.css" data-theme-name="catppuccin-mocha"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/catppuccin-macchiato.css" data-theme-name="catppuccin-macchiato"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/catppuccin-frappe.css" data-theme-name="catppuccin-frappe"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/catppuccin-latte.css" data-theme-name="catppuccin-latte"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><div class="docs-package-name"><span class="docs-autofit"><a href="../">HYPRE.jl</a></span></div><button class="docs-search-query input is-rounded is-small is-clickable my-2 mx-auto py-1 px-2" id="documenter-search-query">Search docs (Ctrl + /)</button><ul class="docs-menu"><li><a class="tocitem" href="../">Home</a></li><li><a class="tocitem" href="../matrix-vector/">Matrix/vector representation</a></li><li class="is-active"><a class="tocitem" href>Solvers and preconditioners</a></li><li><a class="tocitem" href="../libhypre/">LibHYPRE C API</a></li><li><a class="tocitem" href="../api/">API</a></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><a class="docs-sidebar-button docs-navbar-link fa-solid fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a><nav class="breadcrumb"><ul class="is-hidden-mobile"><li class="is-active"><a href>Solvers and preconditioners</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Solvers and preconditioners</a></li></ul></nav><div class="docs-right"><a class="docs-navbar-link" href="https://github.com/fredrikekre/HYPRE.jl" title="View the repository on GitHub"><span class="docs-icon fa-brands"></span><span class="docs-label is-hidden-touch">GitHub</span></a><a class="docs-navbar-link" href="https://github.com/fredrikekre/HYPRE.jl/blob/master/docs/src/solvers-preconditioners.md" title="Edit source on GitHub"><span class="docs-icon fa-solid"></span></a><a class="docs-settings-button docs-navbar-link fa-solid fa-gear" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-article-toggle-button fa-solid fa-chevron-up" id="documenter-article-toggle-button" href="javascript:;" title="Collapse all docstrings"></a></div></header><article class="content" id="documenter-page"><h1 id="Solvers-and-preconditioners"><a class="docs-heading-anchor" href="#Solvers-and-preconditioners">Solvers and preconditioners</a><a id="Solvers-and-preconditioners-1"></a><a class="docs-heading-anchor-permalink" href="#Solvers-and-preconditioners" title="Permalink"></a></h1><p>HYPRE.jl wraps most of HYPREs <a href="https://hypre.readthedocs.io/en/latest/api-sol-parcsr.html">ParCSR solvers and preconditioners</a>.</p><p>The synopsis for creating and using HYPRE.jl&#39;s solver wrappers is the same for all solvers:</p><ol><li>Set up the linear system (see <a href="../matrix-vector/#Matrix/vector-representation">Matrix/vector representation</a>)</li><li>(Optional) Configure a preconditioner</li><li>Configure a solver</li><li>Use <a href="../api/#HYPRE.solve"><code>HYPRE.solve</code></a> or <a href="../api/#HYPRE.solve!"><code>HYPRE.solve!</code></a> to solve the system</li></ol><p>Here is the corresponding pseudo-code:</p><pre><code class="language-julia hljs"># 1. Setup up linear system
A = HYPREMatrix(...)
b = HYPREVector(...)
# 2. Configure a preconditioner
precond = HYPRESolver(; settings...)
# 3. Configure a solver
solver = HYPRESolver(; Precond = precond, settings...)
# 4. Solve the system
x = HYPRE.solve(solver, A, b)</code></pre><p>The following solvers/preconditioners are currently available:</p><ul><li><a href="../api/#HYPRE.BiCGSTAB"><code>HYPRE.BiCGSTAB</code></a></li><li><a href="../api/#HYPRE.BoomerAMG"><code>HYPRE.BoomerAMG</code></a></li><li><a href="../api/#HYPRE.FlexGMRES"><code>HYPRE.FlexGMRES</code></a></li><li><a href="../api/#HYPRE.GMRES"><code>HYPRE.GMRES</code></a></li><li><a href="../api/#HYPRE.Hybrid"><code>HYPRE.Hybrid</code></a></li><li><a href="../api/#HYPRE.ILU"><code>HYPRE.ILU</code></a></li><li><a href="../api/#HYPRE.ParaSails"><code>HYPRE.ParaSails</code></a></li><li><a href="../api/#HYPRE.PCG"><code>HYPRE.PCG</code></a></li></ul><h3 id="Solver-configuration"><a class="docs-heading-anchor" href="#Solver-configuration">Solver configuration</a><a id="Solver-configuration-1"></a><a class="docs-heading-anchor-permalink" href="#Solver-configuration" title="Permalink"></a></h3><p>Settings are passed as keyword arguments, with the names matching directly to <code>HYPRE_SolverSet*</code> calls from the HYPRE C API (see example below). Most settings are passed directly to HYPRE, for example <code>Tol = 1e-9</code> would be passed directly to <code>HYPRE_SolverSetTol</code> for the correponding solver.</p><p>Setting a preconditioner can be done by passing a <code>HYPRESolver</code> directly with the <code>Precond</code> keyword argument, without any need to also pass the corresponding <code>HYPRE_SolverSetup</code> and <code>HYPRE_SolverSolve</code> as must be done in the C API. In addition, solvers that have required settings when used as a preconditioner will have those applied automatically.</p><p>HYPRE.jl adds finalizers to the solvers, which takes care of calling the their respective <code>HYPRE_SolverDestroy</code> function when the solver is garbage collected.</p><h4 id="Example:-Conjugate-gradient-with-algebraic-multigrid-preconditioner"><a class="docs-heading-anchor" href="#Example:-Conjugate-gradient-with-algebraic-multigrid-preconditioner">Example: Conjugate gradient with algebraic multigrid preconditioner</a><a id="Example:-Conjugate-gradient-with-algebraic-multigrid-preconditioner-1"></a><a class="docs-heading-anchor-permalink" href="#Example:-Conjugate-gradient-with-algebraic-multigrid-preconditioner" title="Permalink"></a></h4><p>Here is an example of creating a <code>PCG</code> (conjugate gradient) solver with <code>BoomerAMG</code> (algebraic multigrid) as preconditioner:</p><pre><code class="language-julia hljs"># Setup up linear system
A = HYPREMatrix(...)
b = HYPREVector(...)
# Preconditioner
precond = HYPRE.BoomerAMG(; RelaxType = 6, CoarsenType = 6)
# Solver
solver = HYPRE.PCG(; MaxIter = 1000, Tol = 1e-9, Precond = precond)
# Solve
x = HYPRE.solve(solver, A, b)</code></pre><p>Note that <code>Tol = 0.0</code> and <code>MaxIter = 1</code> are required settings when using <code>BoomerAMG</code> as a preconditioner. These settings are added automatically since it is passed as a preconditioner to the <code>PCG</code> solver.</p><div class="admonition is-category-not"><header class="admonition-header">Corresponding C code</header><div class="admonition-body"><p>For comparison between the APIs, here is the corresponding C code for setting up the solver above:</p><pre><code class="language-c hljs">/* Setup linear system */
HYPRE_IJMatrix A;
HYPRE_IJVector b, x;
/* Preconditioner */
HYPRE_Solver precond;
HYPRE_BoomerAMGCreate(&amp;precond);
HYPRE_BoomerAMGSetCoarsenType(precond, 6);
HYPRE_BoomerAMGSetRelaxType(precond, 6);
HYPRE_BoomerAMGSetTol(precond, 0.0);
HYPRE_BoomerAMGSetMaxIter(precond, 1);
/* Solver */
HYPRE_Solver solver;
HYPRE_ParCSRPCGCreate(MPI_COMM_WORLD, &amp;solver);
HYPRE_PCGSetMaxIter(solver, 1000);
/* Add preconditioner */
HYPRE_PCGSetPrecond(solver, (HYPRE_PtrToSolverFcn) HYPRE_BoomerAMGSolve,
(HYPRE_PtrToSolverFcn) HYPRE_BoomerAMGSetup, precond);
/* Solve */
HYPRE_ParCSRPCGSetup(solver, A, b, x);
HYPRE_ParCSRPCGSolve(solver, A, b, x);</code></pre></div></div></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../matrix-vector/">« Matrix/vector representation</a><a class="docs-footer-nextpage" href="../libhypre/">LibHYPRE C API »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.7.0 on <span class="colophon-date" title="Tuesday 1 October 2024 09:08">Tuesday 1 October 2024</span>. Using Julia version 1.10.5.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>