[Code scan] Use the LAMMPS communicator instead of MPI_COMM_WORLD
bug
Found during a Codex global scan of `deepmodeling/deepmd-kit` at commit `73de44b1f94471b2e3bdb6b11f57b34d7bc791bb`.
## Problem
The LAMMPS pair base uses `MPI_COMM_WORLD` for node-rank detection and model-content broadcast instead of the communicator owned by the LAMMPS instance.
Evidence:
- `get_node_rank()` uses `MPI_COMM_WORLD` for rank/size queries, broadcasts, split, and barrier: https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/source/lmp/pair_base.cpp#L54-L99
- `get_file_content()` broadcasts model bytes over `MPI_COMM_WORLD`: https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/source/lmp/pair_base.cpp#L101-L120
## Impact
LAMMPS can run with partitions or be embedded on a subcommunicator. Using `MPI_COMM_WORLD` can cross-talk between independent simulations or deadlock ranks that are not participating in the same pair style.
## Suggested Fix
Use the pair style's LAMMPS communicator consistently, and prefer `MPI_Comm_split_type(world, MPI_COMM_TYPE_SHARED, ...)` for node-local ranks. Add an MPI regression test with two independent LAMMPS partitions/subcommunicators loading different models.
0 条评论