Skip to content

ReSolve SUNDIALS Linear Solver interface and unit test - #10

Open
JeffZ594 wants to merge 12 commits into
resolve-developfrom
resolve/sunlinsol-only
Open

ReSolve SUNDIALS Linear Solver interface and unit test#10
JeffZ594 wants to merge 12 commits into
resolve-developfrom
resolve/sunlinsol-only

Conversation

@JeffZ594

@JeffZ594 JeffZ594 commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

This pull request contains only the interface and the unit test for the ReSolve Linear Solver interface.

The test is located in test/unit_tests/sunlinsol/resolve. Set the cmake option SUNDIALS_TEST_ENABLE_UNIT_TESTS=ON to build SUNDIALS with the unit tests.

The test creates a random $N\times N$ $A$ matrix and $b$ vector for testing.

The tests can be run using make test, or can be run from the command line using a custom system size by providing two arguments, the size of the system to be tested and whether timing should be printed (0 for no, 1 for yes).

The test currently passes on CPU and CUDA GPU.

Following are results for the CPU and GPU tests. An NVIDIA A100 GPU was used for the tests

Backend $N$ Time
CPU 300 0.05
CPU 1000 0.11
CUDA 300 0.53
CUDA 1000 0.59
  • Please target the develop branch not main.
  • Review our Contributing Guide, and ensure that you sign your last commit (at minimum) as per the guide.
  • Provide a concise description of what your pull request does, and why it is needed/benefical.
  • Add a note about your change to the CHANGELOG.md and docs/shared/RecentChanges.rst files. Notice that the former is a markdown file and the latter is reStructuredText, so the formatting is slightly different.
  • After your PR is opened, ensure that all of the tests are passing (a SUNDIALS developer will have to allow the testing to run).

@JeffZ594 JeffZ594 self-assigned this Jul 17, 2026
@JeffZ594 JeffZ594 added the enhancement New feature or request label Jul 17, 2026
@JeffZ594
JeffZ594 requested review from nkoukpaizan and pelesh July 17, 2026 23:35

@pelesh pelesh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks good -- almost ready to merge. A few things to consider:

  • Please describe in the PR how to verify new solver. Test coverage needs some clarification.
  • Similarly, adding Sphinx documentation for the code would be helpful.
  • I am not sure why you are not using SUNLINEARSOLVER_MATRIX_ITERATIVE interface. True, the refactorizaton solver is classified as "direct" but with iterative refinement it behaves as any other iterative solver.

Comment thread include/sunlinsol/sunlinsol_resolve.hpp Outdated
Comment thread src/sunlinsol/resolve/sunlinsol_resolve.cpp Outdated

@pelesh pelesh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It looks good to me.

Please axpand a little bit on the documentation.

I'd appreciate reviews by @nkoukpaizan and @Steven-Roberts before merging.

Comment thread doc/shared/sunlinsol/SUNLinSol_ReSolve.rst
@pelesh
pelesh requested a review from Steven-Roberts August 4, 2026 02:51

@nkoukpaizan nkoukpaizan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me. Tested the CPU and CUDA backends.

@Steven-Roberts Steven-Roberts left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Overall looks good!

Comment thread src/sunlinsol/resolve/sunlinsol_resolve.cpp Outdated
}

/* Get Re::Solve solver */
auto* solver = reinterpret_cast<ReSolve::SystemSolver*>(RESOLVE_CONTENT(S)->solver);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This appears a couple times, so it might be helpful to define a macro (or a more idiomatic C++ alternative). Also, static_cast should be better here.

/* Currently, if an iterative method is set, return an error */
if (solver->getRefinementMethod() == "fgmres" || solver->getSolveMethod() == "randgmres" || solver->getSolveMethod() == "fgmres")
{
std::cout << "Iterative methods are not currently supported";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Doesn't follow normal SUNDIALS error handling conventions

Comment on lines +257 to +260
if (solver->getRefinementMethod() == "fgmres" || solver->getSolveMethod() == "randgmres" || solver->getSolveMethod() == "fgmres")
{
solver->getIterativeSolver().setTol(tol);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think it's currently possible to enter this branch due to error checking, but if this gets supported, it may be better classified as SUNLINEARSOLVER_MATRIX_ITERATIVE type. I'm a bit concerned about using the tol argument when the type if SUNLINEARSOLVER_DIRECT, but I'll need to check on this...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Right now it is impossible to enter this branch, but we plan on supporting the resolve iterative solvers and if those are used they will be classified as SUNLINEARSOLVER_MATRIX_ITERATIVE type.

Comment thread doc/shared/sunlinsol/SUNLinSol_ReSolve.rst Outdated
}


int SUNLinSolSetup_ReSolve(SUNLinearSolver S, SUNMatrix A)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The A argument is used for error checking, but I don't see it passed to the ReSolve::SystemSolver. Does that already have a reference to the matrix that it may (re)factorize in this function? Could A and that matrix get out of sync?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The ReSolve::SystemSolver does have a reference to the matrix. I believe they could get out of sync and right now it is implicitly assumed that A and that matrix are the same. I will discuss this with @pelesh.

Comment thread src/sunlinsol/resolve/CMakeLists.txt Outdated
JeffZ594 and others added 4 commits August 5, 2026 21:19
Co-authored-by: Steven Roberts <roberts115@llnl.gov>
Co-authored-by: Steven Roberts <roberts115@llnl.gov>
Co-authored-by: Steven Roberts <roberts115@llnl.gov>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants