Skip to content

maint(kokkosNL): nicer failure modes for large cutoffs in dense systems#45

Open
HaoZeke wants to merge 2 commits intometatomicfrom
fix/kokkos-nl-overflow
Open

maint(kokkosNL): nicer failure modes for large cutoffs in dense systems#45
HaoZeke wants to merge 2 commits intometatomicfrom
fix/kokkos-nl-overflow

Conversation

@HaoZeke
Copy link
Member

@HaoZeke HaoZeke commented Mar 8, 2026

Summary

  • Detect when estimated neighbor count for a metatomic model cutoff exceeds neigh_modify one and error with a message specifying the exact neigh_modify line to add
  • Add defensive guards in npair_kokkos and nbin_kokkos to produce clear error messages instead of SIGFPE when bin parameters are degenerate
  • Generalize the fix_metatomic binsize hack to apply whenever the user has not explicitly set binsize (not just when pair_style none)

Details

Dense systems with large cutoffs (e.g. PET-MAD with ~5.5 A interaction range) crash with SIGFPE in NPairKokkosBuildFunctorGhost. Root causes:

  1. Default one=2000 (max neighbors per atom) is too small for dense systems with large cutoffs
  2. pair_metatomic did not set binsize, and fix_metatomic only set it when pair_style none
  3. The Kokkos NL builder has no guard against degenerate bin parameters

Changes:

  • pair_metatomic::init_style: estimate neighbors from (4/3)*pi*(cutoff+skin)^3 * density with 2x safety margin; error if this exceeds neigh_modify one, with a message specifying the exact fix
  • fix_metatomic::init: generalize binsize hack to apply whenever binsizeflag is unset; add the same density-based neighbor check with clear error
  • npair_kokkos.cpp: guard atoms_per_bin <= 0 before the build while-loop
  • nbin_kokkos.cpp: guard mbins <= 0 in bin_atoms_setup

Example error message:

The metatomic model cutoff (5.5000) with current system density requires
approximately 4200 neighbors per atom, but neigh_modify one is only 2000.
Add 'neigh_modify one 4200 page 42000 binsize 2.7500' to your input script.

Changes:

  • pair_metatomic::init_style: auto-set binsize = 0.5 * max_cutoff when user has not set binsizeflag; estimate neighbors from (4/3)*pi*(cutoff+skin)^3 * density with 2x safety margin; auto-increase one/page with warning
  • fix_metatomic::init: generalize binsize hack to apply whenever binsizeflag is unset (not just pair_style none); add same density-based one/page auto-increase
  • npair_kokkos.cpp: guard atoms_per_bin <= 0 before the build while-loop
  • nbin_kokkos.cpp: guard mbins <= 0 in bin_atoms_setup

User workaround (still works as override): neigh_modify one 100000 page 1000000 binsize 5.5

cc @PicoCentauri

Related Issue(s)

Internal comments.

Author(s)

Licensing

By submitting this pull request, I agree, that my contribution will be included in LAMMPS and redistributed under either the GNU General Public License version 2 (GPL v2) or the GNU Lesser General Public License version 2.1 (LGPL v2.1).

Artificial Intelligence (AI) Tools Usage

By submitting this pull request, I confirm that I did NOT use any AI tools to generate
all or parts of the code and modifications in this pull request.

Backward Compatibility

Implementation Notes

Post Submission Checklist

  • The feature or features in this pull request is complete
  • Licensing information is complete
  • Corresponding author information is complete
  • The source code follows the LAMMPS formatting guidelines
  • Suitable new documentation files and/or updates to the existing docs are included
  • The added/updated documentation is integrated and tested with the documentation build system
  • The feature has been verified to work with the conventional build system
  • The feature has been verified to work with the CMake based build system
  • Suitable tests have been added to the unittest tree.
  • A package specific README file has been included or updated
  • One or more example input decks are included

Further Information, Files, and Links

Detect when the estimated neighbor count for the model cutoff and system
density exceeds neigh_modify one, and error with a clear message telling
the user exactly what neigh_modify line to add. Also add guards in the
Kokkos NL builder (npair_kokkos, nbin_kokkos) to produce clear errors
instead of SIGFPE when atoms_per_bin or mbins is zero.
Per review: auto-set one/page when estimated neighbor count exceeds
defaults, with an info message showing the adjustment. Users can still
override manually.

Also improve nbin_kokkos error message with explicit neigh_modify
suggestion per PicoCentauri review.
@HaoZeke HaoZeke requested a review from PicoCentauri March 11, 2026 12:51
Copy link

@PicoCentauri PicoCentauri left a comment

Choose a reason for hiding this comment

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

LGTM

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.

3 participants