Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to retrieve the MPI communicator from LAMMPS instance via library/python interface #2357

Merged
merged 2 commits into from
Sep 11, 2020

Conversation

akohlmey
Copy link
Member

@akohlmey akohlmey commented Sep 10, 2020

Summary

This enables retrieving the communicator used by a LAMMPS instance in either the C-library interface or the python interface.

Author(s)

Axel Kohlmeyer, Temple U

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).

Backward Compatibility

N/A

Implementation Notes

For increased portability between programming languages and MPI implementations, the new library function returns the Fortran representation of the communicator, which is always an integer. It can be converted back using MPI_Comm_f2c().

This is compatible with mpi4py and thus allows doing MPI calls from within Python functions that are launched via python invoke or similar. A minimal example for using it is:

region box block 0 2 0 2 0 2
create_box 1 box

python pymod input 1 SELF format p here """

def pymod(lmpptr):
    from lammps import lammps
    lmp = lammps(ptr=lmpptr)

    comm = lmp.get_mpi_comm()
    size = comm.Get_size()
    rank = comm.Get_rank()
    print("This is rank %d of %d" % (rank,size))
"""

python pymod invoke

Which produces the following output when run with mpirun -np 2 ./lmp -in in.mpi-in-python:

LAMMPS (24 Aug 2020)
  using 1 OpenMP thread(s) per MPI task
Created orthogonal box = (0.0000000 0.0000000 0.0000000) to (2.0000000 2.0000000 2.0000000)
  1 by 1 by 2 MPI processor grid
This is rank 0 of 2
This is rank 1 of 2
Total wall time: 0:00:00

And, more importantly, when run with mpirun -np 4 ./lmp -p 2x2 -in in.mpi-in-python:

LAMMPS (24 Aug 2020)
Running on 2 partitions of processors
This is rank 0 of 2
This is rank 1 of 2
This is rank 0 of 2
This is rank 1 of 2

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.

@akohlmey akohlmey merged commit 101d391 into lammps:master Sep 11, 2020
@akohlmey akohlmey deleted the lib-get-mpi-comm branch September 11, 2020 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants