Skip to content

Conversation

greole
Copy link
Collaborator

@greole greole commented Sep 15, 2025

This PR refactors the preconditioner implementation by placing the generation into separate files. Additionally, a central coarse solver generation routine is added.

@greole greole changed the base branch from dev to stack/ogl_0.6 September 15, 2025 09:43
@greole greole changed the base branch from stack/ogl_0.6 to enh/repart_comm September 15, 2025 09:43
@greole greole changed the title Refact/precond Refactor preconditioner implementation Sep 17, 2025
@greole greole requested a review from Copilot September 17, 2025 09:00
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the preconditioner implementation by extracting the generation logic from a monolithic class into separate, focused header files. The main changes involve moving preconditioner-specific code into dedicated classes while introducing a centralized coarse solver generation routine for better code organization and maintainability.

  • Extracted preconditioner implementations into dedicated header files (Jacobi, LU, Cholesky, ISAI, Multigrid)
  • Added a centralized coarse solver generation function in CoarseSolver.cpp
  • Introduced utility functions for Schwarz wrapping operations

Reviewed Changes

Copilot reviewed 12 out of 14 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/Preconditioner/CoarseSolver.cpp New implementation for centralized coarse solver generation
include/OGL/StoppingCriterion.hpp Minor formatting improvement to debug message
include/OGL/Preconditioner/Schwarz.hpp New utility functions for wrapping preconditioners with Schwarz methods
include/OGL/Preconditioner/PreconditionerWrapper.hpp New base wrapper class definition
include/OGL/Preconditioner/Multigrid.hpp New dedicated Multigrid preconditioner class
include/OGL/Preconditioner/LU.hpp New LU factorization preconditioner class
include/OGL/Preconditioner/Jacobi.hpp New Block Jacobi preconditioner class
include/OGL/Preconditioner/ISAI.hpp New ISAI preconditioner class
include/OGL/Preconditioner/CoarseSolver.hpp Header declaration for coarse solver generation function
include/OGL/Preconditioner/Cholesky.hpp New Cholesky factorization preconditioner class
include/OGL/Preconditioner.hpp Refactored main class to use new dedicated preconditioner classes
CMakeLists.txt Added new source file to build configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +43 to +69
if (solver == "CG") {
coarsest_solver = gko::share(cg::build()
.with_preconditioner(bjfac)
.with_criteria(solve_it, solve_red)
.on(exec));
}
if (solver == "BiCGStab") {
coarsest_solver = gko::share(bicgstab::build()
.with_preconditioner(bjfac)
.with_criteria(solve_it, solve_red)
.on(exec));
}
if (solver == "GMRES") {
coarsest_solver = gko::share(gmres::build()
.with_preconditioner(bjfac)
.with_criteria(solve_it, solve_red)
.on(exec));
}
if (solver == "Jacobi") {
scalar relaxFac{
solverDict.lookupOrDefault("relaxationFactor", scalar(0.9))};
coarsest_solver = gko::share(ir::build()
.with_solver(bjfac)
.with_relaxation_factor(relaxFac)
.with_criteria(solve_it, solve_red)
.on(exec));
}
Copy link
Preview

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.

This chain of if statements should use else-if to avoid unnecessary condition checks once a match is found. The current implementation continues checking all conditions even after finding a match.

Copilot uses AI. Check for mistakes.

auto coarsening = d.lookupOrDefault<word>("coarsening", word("PGM"));
auto coarseWeight = d.lookupOrDefault("coarseWeight", scalar(0.1));

if (coarsening == "fixed") {
Copy link
Preview

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.

This function has multiple return paths and incomplete logic. The function can return from either the 'fixed' or 'PGM' coarsening branches, but there's no return statement at the end for unhandled cases, which could lead to undefined behavior.

Copilot uses AI. Check for mistakes.

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

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.

Comment on lines 63 to 73
virtual std::shared_ptr<gko::LinOp> create()
{
if (type_ == "SPD") {
return dispatch_schwarz(mtx_, exec_, generate_precond_factory_spd(),
d_, verbose_);
}
if (type_ == "General") {
return dispatch_schwarz(
mtx_, exec_, generate_precond_factory_general(), d_, verbose_);
}
}
Copy link
Preview

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 has multiple return paths but no return statement at the end, which could lead to undefined behavior if none of the type conditions are met.

Copilot uses AI. Check for mistakes.

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

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.

greole and others added 2 commits September 17, 2025 11:05
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant