-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] out-of-bounds write in SUNMatScaleAddI_Sparse #581
Comments
Hi @dweindl, thanks for raising the issue and the nice example to reproduce it. It seems the issue is the sparse matrix addition algorithm is assuming the row indices for a column are sorted which is not the case for your matrix. For example, the column 0 row indices are {0, 1, 3, 2, 4, 10, 7, 8}. I'm not sure if this is a documentation issue or a bug in the algorithm (probably the latter), but I'll discuss with the team tomorrow to plan out a fix. Either way, I see a related out of bounds bug here when N>M:
As a temporary fix, you can reorder the row indices to be ascending:
This ran cleanly through valgrind. |
Thanks for looking into that, @Steven-Roberts. I can confirm that ordering the indexvals fixes the problem. |
About 18 months ago, another user submitted PR #257 to adjust how this function was implemented. Essentially, our original implementation (that was in sundials 5.8.0) required I see three options:
|
Fixes #581 The new implementation eliminates all temporary storage/mallocs and only traverses the matrix entries once when diagonal elements don't need to be added. The sparse matrix example shows about a 1.5x speedup on 50000x50000 matrices.
Fixed in #584. |
We've been lagging behind SUNDIALS development. This updates the SUNDIALS library from v5.8.0 to [v7.1.1](https://sundials.readthedocs.io/en/latest/Changelog_link.html#changes-to-sundials-in-release-7-1-1). Note: * This includes the post-7.1.1 changes to `cmake/tpl/FindKLU.cmake` from LLNL/sundials#582 * This includes the post-7.1.1 changes to [`sundials/src/sunmatrix/sparse/sunmatrix_sparse.c:SUNMatScaleAddI_Sparse`](https://github.com/LLNL/sundials/blob/736369d543cb80956b1ba87377ffc0c8cf6b342b/src/sunmatrix/sparse/sunmatrix_sparse.c#L625C1-L694C2) from LLNL/sundials#584, fixing LLNL/sundials#581 The majority of changes inside amici are related to the introduction of [SUNContext](https://sundials.readthedocs.io/en/latest/sundials/SUNContext_link.html#the-suncontext-type), which is required for the construction of all SUNDIALS objects. Other trivial changes are related to renamed types and macros. Furthermore, the error handling strategy has changed. As a consequence, simulation error messages will look slightly different. Closes #1565
Current Behavior:
For the example below, I encounter out-of-bounds writes in
SUNMatScaleAddI_Sparse
atsundials/src/sunmatrix/sparse/sunmatrix_sparse.c
Line 753 in c28eaa3
Expected Behavior:
No out-of-bounds writes.
Steps To Reproduce:
Download test_SUNMatScaleAddI_Sparse.tar.gz
Unpack:
tar -xzf test_SUNMatScaleAddI_Sparse.tar.gz && cd test_SUNMatScaleAddI_Sparse
Configure & build:
cmake -S. -Bbuild && cmake --build build
(this might need some adaptation to find the sundials configuration)valgrind build/sparsetest
:Environment:
Anything else:
Running the same example with
SUNMatScaleAddI_Sparse
from sundials 6.6.2 works as expected.It seems the problem was introduced in #257.
The text was updated successfully, but these errors were encountered: