Skip to content

Resolve SUNDIALS Linear Solver interface - #9

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

Resolve SUNDIALS Linear Solver interface#9
JeffZ594 wants to merge 12 commits into
resolve-developfrom
resolve/sunlinsol

Conversation

@JeffZ594

@JeffZ594 JeffZ594 commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

This PR implements SUNLinSol using Re::Solve.

  • 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 requested a review from pelesh July 7, 2026 18:02
Comment thread test/unit_tests/sunlinsol/resolve/CMakeLists.txt Outdated
…error

Co-authored-by: Nicholson Koukpaizan <72402802+nkoukpaizan@users.noreply.github.com>

@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.

Very nice work! Tests pass on HIP backend.

There are some apparent bugs in the code related to device/host memory access and I am not sure how this code works. Please take a look at comments below.

The solver setup function does not check for failures and always declares success no matter what happens.

Once these issues are addressed, please remove debugging and commented out code and update the documentation.

Comment on lines +172 to +189
if (FACTORIZED(S))
{
solver->refactorize();
}
else
{
solver->analyze();
solver->factorize();
// Perform setup only if working with GPU
if (RESOLVE_MEMSPACE(S) != ReSolve::memory::HOST)
{
solver->refactorizationSetup();
}
FACTORIZED(S) = SUNTRUE;
}

return SUN_SUCCESS;
}

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 function is returning SUN_SUCCESS even when factorization fails.

Comment on lines +212 to +213
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.

This will fail if iterative refinement is not set in the SystemSolver. Some guards are needed.

Comment on lines +225 to +226
vec_b.setData(N_VGetArrayPointer(b), RESOLVE_MEMSPACE(S));
vec_x.setData(N_VGetArrayPointer(x), RESOLVE_MEMSPACE(S));

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.

Shouldn't these be N_VGetDeviceArrayPointer calls instead of N_VGetArrayPointer?

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.

These should be N_VGetDeviceArrayPointer calls although I'm still not sure why the unit test succeeds in spite of setData being given a host pointer instead of a device one. For now I will work on modify the test to use CUDA/HIP NVectors so that the N_VGetDeviceArrayPointer calls can be made.

@pelesh pelesh added the enhancement New feature or request label Jul 10, 2026

// Its possible this step is necessary for the ReSolve interface but all other
// linear solvers do not require this SUNLinSolSetup
SUNLinSolSetup(LS, A);

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.

This additional set up being required is kind of strange. No other solver requires this step. I am not entirely sure why this is necessary since the SUNDIALS KLU solver does not require it. It might be a bug in the solver but the updated SUNLinSolSetup with checks does not return an error when this line is commented out.

@JeffZ594

Copy link
Copy Markdown
Collaborator Author

For now, I have only tested the Heat Equation example on CPU.

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.

3 participants