Skip to content

Add portable applyMMat fallback for OpenBLAS and other BLAS vendors - #15

Merged
sobolevnrm merged 1 commit into
masterfrom
fix-pbsam-generic-blas
Oct 25, 2026
Merged

sobolevnrm merged 1 commit into
masterfrom
fix-pbsam-generic-blas

Conversation

@sobolevnrm

Copy link
Copy Markdown
Member

Summary

Makes PBSAM work with OpenBLAS (and any BLAS vendor other than ACML, MKL, or Apple) by adding a portable fallback to applyMMat.

Problem

applyMMat in pbsam/src/Solvmat.cpp computes Y = alpha*A*X + beta*Y only inside #ifdef __ACML, #ifdef __MKL, or #if defined(__MACOS) || defined(__XCODE).
cmake/Dependencies.cmake defines none of those for OpenBLAS, the default vendor, but always defines __LAU.
So on OpenBLAS builds, applyMMat does nothing, and callers in Solvmat.cpp and Gradsolvmat.cpp read uninitialized new double[] buffers.

Effects:

Fix

  • Add a column-major fallback loop used when no vendor-specific branch applies.
    It does not read Y when beta is zero, because callers pass uninitialized output buffers.
  • Add SolverUTest.ApplyMMat, which fails without the fix on OpenBLAS.

Testing

On macOS with both -DBLA_VENDOR=Apple and -DBLA_VENDOR=OpenBLAS (Homebrew):

  • pbsamtest (103 tests, including the new one) and pbamtest (160 tests) pass.
  • Standalone pbsam on the APBS gly pair gives identical energies and forces with both vendors (0.00494129 and 0.00496847 kT) and similar runtime (about 1 s).
  • Without the fix, the new test fails on OpenBLAS.

applyMMat only performed the multiplication for ACML, MKL, and Apple
BLAS. With OpenBLAS (the default, and what Linux CI uses), the function
did nothing while __LAU was still defined, so callers read uninitialized
output buffers and PBSAM produced NaN or ~1e306 energies. Add a
column-major fallback used when no vendor-specific branch applies, and
a unit test that fails without it.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 3eaf20ea-3ac0-4701-958f-28527bf641fc
@sobolevnrm
sobolevnrm merged commit 8d254e5 into master Oct 25, 2026
7 checks passed
@sobolevnrm
sobolevnrm deleted the fix-pbsam-generic-blas branch October 25, 2026 23:56
sobolevnrm pushed a commit to Electrostatics/apbs that referenced this pull request Oct 25, 2026
pb_solvers 8d254e5 makes PBSAM's matrix multiply work with OpenBLAS
(Electrostatics/pb_solvers#15), which fixes the Linux PBSAM results.

Refs #321

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 3eaf20ea-3ac0-4701-958f-28527bf641fc
sobolevnrm added a commit to Electrostatics/apbs that referenced this pull request Oct 26, 2026
* Fix PBAM/PBSAM regression tests and test them in CI

Restore the salt concentrations that were commented out in 2021, replace
the obsolete pbsam-auto keyword with pbsam, and update the PBSAM reference
energies for the solvent-dielectric scaling that pb_solvers 5671943 (2017)
applied to energies to match forces. Add a PR-triggered Linux job that
builds with PBAM/PBSAM enabled and runs their regression tests.

Refs #321

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 3eaf20ea-3ac0-4701-958f-28527bf641fc

* Fix out-of-bounds read in PBAM/PBSAM write parsing

NOsh_parsePBAM and NOsh_parsePBSAM read writefmt[numwrite - 1] and
writestem[numwrite - 1] even when the input had no write statement,
indexing element -1. Only check the write format when a write exists.

Refs #321

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 3eaf20ea-3ac0-4701-958f-28527bf641fc

* Pin pb_solvers with the BaseSystem type-count fix

pb_solvers cef00d7 fixes a heap-buffer-overflow in BaseSystem that made
PBSAM results platform dependent (Electrostatics/pb_solvers#14).

Refs #321

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 3eaf20ea-3ac0-4701-958f-28527bf641fc

* Pin pb_solvers with the OpenBLAS applyMMat fix

pb_solvers 8d254e5 makes PBSAM's matrix multiply work with OpenBLAS
(Electrostatics/pb_solvers#15), which fixes the Linux PBSAM results.

Refs #321

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 3eaf20ea-3ac0-4701-958f-28527bf641fc

---------

Co-authored-by: Nathan Baker <[email protected]>
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 3eaf20ea-3ac0-4701-958f-28527bf641fc
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