Fix: check restart file reading and fix MPI datatype mismatch for bool flag#7660
Open
DanielZhao0432 wants to merge 7 commits into
Open
Fix: check restart file reading and fix MPI datatype mismatch for bool flag#7660DanielZhao0432 wants to merge 7 commits into
DanielZhao0432 wants to merge 7 commits into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked Issue
Fixes #7547
Description
This PR addresses two potential issues in the Molecular Dynamics (MD) restart functions of both
FIREandMSSTschemes:MPI Datatype Mismatch (Memory Safety):
In
FIRE::restartandMSST::restart, the status flagokis declared as a C++bool(typically 1 byte). However,MPI_Bcastwas broadcasting it usingMPI_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_BOOLto align with the rest of the ABACUS codebase and safely match the size of the boolean variable.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 = falseif any extraction fails.Files Changed
source/source_md/fire.cppsource/source_md/msst.cpp