Skip to content

Fix memory handling in KLU examples#449

Open
tamar-dewilde wants to merge 3 commits into
developfrom
tamar/issue448-klu-host-allocation
Open

Fix memory handling in KLU examples#449
tamar-dewilde wants to merge 3 commits into
developfrom
tamar/issue448-klu-host-allocation

Conversation

@tamar-dewilde

@tamar-dewilde tamar-dewilde commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Description

Fixes the missing host allocation in the KLU examples reported in #448.

Both kluFactor.cpp and kluRefactor.cpp create the solution vector but do not allocate its host storage before calling the KLU solve. This causes the solve to report:

[ERROR] Trying to copy from external vector, but destination (host) is not allocated!
KLU solve status: 1

and kluRefactor.exe then terminates with a segmentation fault.

I also checked the remaining examples and found similar memory handling issues in four experimental KLU examples. These changes allocate host and device storage once, synchronize updated data before device use, and clean up the allocated objects.

The FGMRES example stored a pointer to a local preconditioner that was destroyed at the end of the iteration. The preconditioner now remains valid until cleanup.

Closes #448

@shakedregev

Proposed changes

  • Allocate the solution vector in host memory after it is created in kluFactor.cpp.
  • Allocate the solution vector in host memory after it is created in kluRefactor.cpp.
  • Fix repeated and missing allocations in four experimental KLU examples.
  • Synchronize updated RHS and solution data before device use.
  • Fix the preconditioner lifetime in the FGMRES example.
  • Update the cleanup blocks to delete vec_rhs, the solver objects, and the handlers in the correct order.

Checklist

  • All tests pass (make test and make test_install per testing instructions). Code tested on
    • CPU backend
    • CUDA backend
    • HIP backend
  • I have manually run the affected KLU examples and verified that the fixed paths complete without allocation errors. Code tested on:
    • CPU backend
    • CUDA backend
    • HIP backend
  • Code compiles cleanly with flags -Wall -Wpedantic -Wconversion -Wextra.
  • The new code follows Re::Solve style guidelines.
  • N/A: The existing KLU examples reproduce the bug.
  • N/A: This fix does not add a new feature or public API that needs documentation.
  • The feature branch is rebased with respect to the target branch.
  • N/A: This is a small follow-up fix to the explicit memory management change already listed in CHANGELOG.md.

Further comments

On the current develop branch, kluRefactor.exe later reaches a separate allocation failure in ExampleHelper::printSummary(). That issue is addressed in #447. With the pending #447 fix temporarily applied, the 20-system ACTIVSg10k run completes with exit code 0.

The experimental CUDA RF examples complete their initial KLU solves but still fail in the later RF path because of the separate factor transfer issue tracked in #451.

The experimental GLU example no longer reports allocation errors and its initial solve succeeds, but the later updated systems still produce inaccurate residuals. That issue is separate from the memory handling changes in this PR.

@tamar-dewilde tamar-dewilde self-assigned this Jul 14, 2026
@tamar-dewilde tamar-dewilde added the bug Something isn't working label Jul 14, 2026

@shakedregev shakedregev 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, but I unfortunately can't test yet. Can you double check all the examples and add them to this PR if they need similar fixes?

@tamar-dewilde tamar-dewilde changed the title Allocate host solution vectors in KLU examples Fix memory handling in KLU examples Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: kluRefactor does not allocate host memory for the solution vector

2 participants