Skip to content

Fix: check restart file reading and fix MPI datatype mismatch for bool flag#7660

Open
DanielZhao0432 wants to merge 7 commits into
deepmodeling:developfrom
DanielZhao0432:develop
Open

Fix: check restart file reading and fix MPI datatype mismatch for bool flag#7660
DanielZhao0432 wants to merge 7 commits into
deepmodeling:developfrom
DanielZhao0432:develop

Conversation

@DanielZhao0432

Copy link
Copy Markdown
Collaborator

Linked Issue

Fixes #7547

Description

This PR addresses two potential issues in the Molecular Dynamics (MD) restart functions of both FIRE and MSST schemes:

  1. MPI Datatype Mismatch (Memory Safety):
    In FIRE::restart and MSST::restart, the status flag ok is declared as a C++ bool (typically 1 byte). However, MPI_Bcast was broadcasting it using MPI_INT (typically 4 bytes). This mismatch can cause stack memory corruption (specifically buffer overflow on receiving processes and out-of-bounds read on the root process).
    To resolve this, we change the MPI datatype to MPI_C_BOOL to align with the rest of the ABACUS codebase and safely match the size of the boolean variable.

  2. Unchecked File Extraction:
    Previously, the file stream extraction (file >> step_rst_ >> ...) was performed without validating the success of the read operation. If the restart file was empty, truncated, or contained invalid data formats, the variables would silently remain in an uninitialized or corrupted state.
    We now check the stream state after reading and correctly set ok = false if any extraction fails.

Files Changed

  • source/source_md/fire.cpp
  • source/source_md/msst.cpp

…ot.py

Refactored input file handling to check for 'ElecStaticPot.cube' in subdirectories. Added error handling for missing input files.
Fix: resolve undefined variable and early termination in aveElecStatPot.py
@DanielZhao0432 DanielZhao0432 added the Refactor Refactor ABACUS codes label Jul 20, 2026
@DanielZhao0432
DanielZhao0432 requested a review from mohanchen July 22, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code scan] Broadcast MD restart bool flags with the correct MPI datatype

1 participant