support checking the size of MPI communicators and fail if LAMMPS and mpi4py have a mismatch

This commit is contained in:
Axel Kohlmeyer
2021-02-16 20:22:18 -05:00
parent f929e57261
commit 742eebec2d
2 changed files with 9 additions and 3 deletions

View File

@ -325,6 +325,10 @@ class lammps(object):
else:
MPI_Comm = c_void_p
# Detect whether LAMMPS and mpi4py definitely use different MPI libs
if sizeof(MPI_Comm) != self.lib.lammps_config_has_mpi_support():
raise Exception('Inconsistent MPI library in LAMMPS and mpi4py')
narg = 0
cargs = None
if cmdargs:

View File

@ -4128,16 +4128,18 @@ void lammps_get_os_info(char *buffer, int buf_size)
/* ---------------------------------------------------------------------- */
/** This function is used to query whether LAMMPS was compiled with
* a real MPI library or in serial.
* a real MPI library or in serial. For the real MPI library it
* reports the size of the MPI communicator in bytes (4 or 8),
* which allows to check for compatibility with a hosting code.
*
* \return 0 when compiled with MPI STUBS, otherwise 1 */
* \return 0 when compiled with MPI STUBS, otherwise the MPI_Comm size in bytes */
int lammps_config_has_mpi_support()
{
#ifdef MPI_STUBS
return 0;
#else
return 1;
return sizeof(MPI_Comm);
#endif
}