From 742eebec2d533ef113b595f656dcf6ce2073a181 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 16 Feb 2021 20:22:18 -0500 Subject: [PATCH] support checking the size of MPI communicators and fail if LAMMPS and mpi4py have a mismatch --- python/lammps/core.py | 4 ++++ src/library.cpp | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index 8639743a75..e13bf9585b 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -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: diff --git a/src/library.cpp b/src/library.cpp index 71bf205d90..2a7bbf07b3 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -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 }