Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ to turn off this check")
endif()

set(GINKGO_CHECKOUT_VERSION
"ogl_0600_gko190"
"ogl_0600_gko190"
CACHE STRING "Use specific version of ginkgo")

if(OGL_DEVEL_TOOLS)
Expand Down Expand Up @@ -216,13 +216,14 @@ target_sources(
src/MatrixWrapper/SparsityPattern.cpp
src/MatrixWrapper/Distributed.cpp
src/MatrixWrapper/Combination.cpp
src/Preconditioner/CoarseSolver.cpp
src/Repartitioner.cpp
src/Solver/CG.cpp
src/Solver/PipeCG.cpp
src/Solver/BiCGStab.cpp
src/Solver/GMRES.cpp
src/Solver/Multigrid.cpp
# src/Solver/IR.cpp
src/Solver/PipeCG.cpp
src/Solver/BiCGStab.cpp
src/Solver/GMRES.cpp
src/Solver/Multigrid.cpp
# src/Solver/IR.cpp
)

enable_sanitizers(
Expand Down
1 change: 1 addition & 0 deletions include/OGL/DevicePersistent/Vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class PersistentVector
tmp.set_executor(ref_exec);

MPI_Request copy_back_req;

MPI_Iscatterv(tmp.get_data(), repartAllToAll.send_counts.data(),
repartAllToAll.send_offsets.data(), MPI_DOUBLE,
const_cast<T *>(memory_), repartAllToAll.recv_counts[0],
Expand Down
483 changes: 18 additions & 465 deletions include/OGL/Preconditioner.hpp

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions include/OGL/Preconditioner/Cholesky.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// SPDX-FileCopyrightText: 2025 OGL authors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once

#include "OGL/Preconditioner/Schwarz.hpp"

class Cholesky // : public PreconditionerWrapper
{
using dic = gko::preconditioner::Jacobi<double, label>;
using fic = gko::preconditioner::Jacobi<float, label>;

std::shared_ptr<gko::Executor> exec_;
std::shared_ptr<const gko::LinOp> mtx_;
const dictionary &d_;
const label verbose_;
bool skip_sorting_;
bool multi_level_schwarz_;
word precision_;
word factorization_;


public:
Cholesky(std::shared_ptr<gko::Executor> exec,
std::shared_ptr<const gko::LinOp> mtx, const dictionary &d,
label verbose)
: exec_(exec),
mtx_(mtx),
d_(d),
verbose_(verbose),
skip_sorting_(d.lookupOrDefault<Switch>("skipSorting", true)),
multi_level_schwarz_(
d.lookupOrDefault<Switch>("multiLevelSchwarz", false)),
precision_(d.lookupOrDefault("precision", word("double"))),
factorization_(d.lookupOrDefault("factorization", word("IC")))
{
word msg = "Generate " + factorization_ +
" preconditioner:\n\tprecision: " + precision_;
MLOG_0(verbose_, msg)
}


std::shared_ptr<gko::LinOp> generate_factorization() const
{
if (factorization_ == "IC") {
Comment on lines +43 to +45
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function generate_factorization() has multiple return paths through if statements but no return statement at the end, which could lead to undefined behavior if none of the conditions are met.

Copilot uses AI. Check for mistakes.
auto factorization_factory =
gko::factorization::Ic<scalar, label>::build()
.with_skip_sorting(skip_sorting_)
.on(exec_);

auto gkodistmatrix =
gko::as<RepartDistMatrix>(mtx_)->get_dist_matrix();
return factorization_factory->generate(
gko::as<gko::experimental::distributed::Matrix<scalar, label,
label>>(
gkodistmatrix)
->get_local_matrix());
}
if (factorization_ == "ParIC") {
label iterations = d_.lookupOrDefault("iterations", label(5));
auto factorization_factory =
gko::factorization::ParIct<scalar, label>::build()
.with_skip_sorting(skip_sorting_)
.with_iterations(iterations)
.on(exec_);

auto gkodistmatrix =
gko::as<RepartDistMatrix>(mtx_)->get_dist_matrix();
return factorization_factory->generate(
gko::as<gko::experimental::distributed::Matrix<scalar, label,
label>>(
gkodistmatrix)
->get_local_matrix());
}
if (factorization_ == "ParICT") {
label iterations = d_.lookupOrDefault("iterations", label(5));
label fillInLimit = d_.lookupOrDefault("fillInLimit", label(2));
auto factorization_factory =
gko::factorization::ParIct<scalar, label>::build()
.with_skip_sorting(skip_sorting_)
.with_fill_in_limit(fillInLimit)
.with_iterations(iterations)
.on(exec_);

auto gkodistmatrix =
gko::as<RepartDistMatrix>(mtx_)->get_dist_matrix();
return factorization_factory->generate(
gko::as<gko::experimental::distributed::Matrix<scalar, label,
label>>(
gkodistmatrix)
->get_local_matrix());
}
}

virtual std::shared_ptr<gko::LinOp> create()
{
auto precond_factory = gko::preconditioner::Ic<>::build().on(exec_);
return dispatch_schwarz(
mtx_, exec_,
gko::share(precond_factory->generate(generate_factorization())), d_,
verbose_);
}
};
11 changes: 11 additions & 0 deletions include/OGL/Preconditioner/CoarseSolver.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: 2024 OGL authors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once

#include <ginkgo/ginkgo.hpp>

#include "fvCFD.H"

std::shared_ptr<const gko::LinOpFactory> generate_coarse_solver(
std::shared_ptr<gko::Executor> exec, const dictionary &d, label verbose);
81 changes: 81 additions & 0 deletions include/OGL/Preconditioner/ISAI.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// SPDX-FileCopyrightText: 2025 OGL authors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once

#include "OGL/Preconditioner/Schwarz.hpp"

class ISAI // : public PreconditionerWrapper
{
using dic = gko::preconditioner::Jacobi<double, label>;
using fic = gko::preconditioner::Jacobi<float, label>;

std::shared_ptr<gko::Executor> exec_;
std::shared_ptr<const gko::LinOp> mtx_;
const dictionary &d_;
const label verbose_;
bool skip_sorting_;
bool multi_level_schwarz_;
word type_;
label sparsityPower_;


public:
ISAI(std::shared_ptr<gko::Executor> exec,
std::shared_ptr<const gko::LinOp> mtx, const dictionary &d,
label verbose)
: exec_(exec),
mtx_(mtx),
d_(d),
verbose_(verbose),
skip_sorting_(d.lookupOrDefault<Switch>("skipSorting", true)),
multi_level_schwarz_(
d.lookupOrDefault<Switch>("multiLevelSchwarz", false)),
type_(d.lookupOrDefault("type", word("general"))),
sparsityPower_(d.lookupOrDefault("sparsityPower", label(1)))
{
word msg = "Generate " + type_ + "ISAI" +
" preconditioner:\n\tsparsityPower: " +
std::to_string(sparsityPower_);
MLOG_0(verbose_, msg)
}

auto generate_precond_factory_spd()
{
return gko::preconditioner::Isai<gko::preconditioner::isai_type::spd,
scalar, label>::build()
.with_skip_sorting(skip_sorting_)
.with_sparsity_power(sparsityPower_)
.on(exec_);
}

auto generate_precond_factory_general()
{
return gko::preconditioner::Isai<
gko::preconditioner::isai_type::general, scalar,
label>::build()
.with_skip_sorting(skip_sorting_)
.with_sparsity_power(sparsityPower_)
.on(exec_);
}

virtual std::shared_ptr<gko::LinOp> create()
{
if (type_ == "SPD") {
auto b = generate_precond_factory_spd();
return dispatch_schwarz(
mtx_, exec_,
gko::share(
b->generate(gko::as<RepartDistMatrix>(mtx_)->get_local())),
d_, verbose_);
}
if (type_ == "General") {
auto b = generate_precond_factory_general();
return dispatch_schwarz(
mtx_, exec_,
gko::share(
b->generate(gko::as<RepartDistMatrix>(mtx_)->get_local())),
d_, verbose_);
}
}
};
70 changes: 70 additions & 0 deletions include/OGL/Preconditioner/Jacobi.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// SPDX-FileCopyrightText: 2025 OGL authors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once

#include "OGL/Preconditioner/Schwarz.hpp"

class BlockJacobi // : public PreconditionerWrapper
{
using dbj = gko::preconditioner::Jacobi<double, label>;
using fbj = gko::preconditioner::Jacobi<float, label>;

std::shared_ptr<gko::Executor> exec_;
std::shared_ptr<const gko::LinOp> mtx_;
const dictionary &d_;
const label verbose_;
bool skip_sorting_;
bool multi_level_schwarz_;
label max_block_size_;
word precision_;


public:
BlockJacobi(std::shared_ptr<gko::Executor> exec,
std::shared_ptr<const gko::LinOp> mtx, const dictionary &d,
label verbose)
: exec_(exec),
mtx_(mtx),
d_(d),
verbose_(verbose),
skip_sorting_(d.lookupOrDefault<Switch>("skipSorting", true)),
multi_level_schwarz_(
d.lookupOrDefault<Switch>("multiLevelSchwarz", false)),
max_block_size_(d.lookupOrDefault("maxBlockSize", label(1))),
precision_(d.lookupOrDefault("precision", word("double")))
{
word msg = "Generate (Block)-Jacobi preconditioner:\n\tprecision: " +
precision_ + "\n\tmaxBlockSize " +
std::to_string(max_block_size_);
MLOG_0(verbose_, msg)
}

virtual std::shared_ptr<gko::LinOp> create()
{
auto builder = [this](auto b) {
return b.with_skip_sorting(skip_sorting_)
.with_max_block_size(static_cast<gko::uint32>(max_block_size_))
.on(exec_);
};

if (precision_ == "double") {
auto b = builder(dbj::build());
return dispatch_schwarz(
mtx_, exec_,
gko::share(
b->generate(gko::as<RepartDistMatrix>(mtx_)->get_local())),
d_, verbose_);
}
if (precision_ == "float") {
auto b = builder(fbj::build());
return dispatch_schwarz(
mtx_, exec_,
gko::share(
b->generate(gko::as<RepartDistMatrix>(mtx_)->get_local())),
d_, verbose_);
}

return {};
}
};
Loading
Loading