Skip to content

Fix data race on shared molecule in batched MMFF minimizers - #237

Merged
scal444 merged 1 commit into
NVIDIA-BioNeMo:mainfrom
scal444:mmff-thread-race-fix
Jul 27, 2026
Merged

Fix data race on shared molecule in batched MMFF minimizers#237
scal444 merged 1 commit into
NVIDIA-BioNeMo:mainfrom
scal444:mmff-thread-race-fix

Conversation

@scal444

@scal444 scal444 commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Batch threads built each molecule's MMFF force field inside the OpenMP loop, and RDKit's MMFFMolProperties constructor mutates the molecule it types. Conformers of one molecule can span several batches, so threads raced on the same ROMol, producing wrong atom types and heap corruption. The trigger is thread count, not GPU count.

Build each molecule's MMFFMolProperties once under std::call_once and share it; contribs still build per batch through the non-mutating overload, so preprocessing stays interleaved with GPU work.

Fixes #236

Batch threads built each molecule's MMFF force field inside the OpenMP
loop, and RDKit's MMFFMolProperties constructor mutates the molecule it
types. Conformers of one molecule can span several batches, so threads
raced on the same ROMol, producing wrong atom types and heap corruption.
The trigger is thread count, not GPU count.

Build each molecule's MMFFMolProperties once under std::call_once and
share it; contribs still build per batch through the non-mutating
overload, so preprocessing stays interleaved with GPU work.
@scal444
scal444 requested a review from evasnow1992 July 27, 2026 16:46
@greptile-apps

greptile-apps Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes concurrent MMFF preprocessing for conformers belonging to one molecule, but the guard does not cover duplicate references to that molecule.

  • Extracts MMFFMolProperties construction into a shared helper.
  • Adds per-input-index call_once storage used by the BFGS and FIRE batch minimizers.
  • Adds a multithreaded MMFF regression test and adjusts FMCS test include paths.

Confidence Score: 3/5

This PR should not merge until MMFF property initialization is synchronized by molecule identity or duplicate molecule references are explicitly rejected.

The new call_once guard fixes conformers sharing one input index, but duplicate input entries referencing the same ROMol receive independent guards and can still concurrently invoke the mutating MMFFMolProperties constructor.

Files Needing Attention: src/minimizer/mmff_minimize.cpp, tests/test_mmff.cu

Important Files Changed

Filename Overview
src/minimizer/mmff_minimize.cpp Shares MMFF properties across batch threads, but indexing the synchronization guard by molIdx leaves aliased ROMol entries able to initialize concurrently.
rdkit_extensions/mmff_flattened_builder.cpp Extracts MMFF property construction and configuration into a shared-pointer-returning helper.
rdkit_extensions/mmff_flattened_builder.h Declares the helper and documents the mutation and synchronization requirements.
tests/test_mmff.cu Adds coverage for one molecule whose conformers span threads, but does not cover the supported duplicate-ROMol input shape.
tests/test_fmcs_primitives.cu Qualifies three FMCS test includes with their source-tree paths.

Reviews (1): Last reviewed commit: "Fix data race on shared molecule in batc..." | Re-trigger Greptile

Comment thread src/minimizer/mmff_minimize.cpp

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

Thank you for fixing this!

@scal444
scal444 merged commit d74cf42 into NVIDIA-BioNeMo:main Jul 27, 2026
9 of 10 checks passed
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.

Rare MMFF setup race

2 participants