avoid loading mpi4py if the LAMMPS executable has been built without MPI
This commit is contained in:
@ -286,9 +286,10 @@ class lammps(object):
|
|||||||
self.lib.lammps_fix_external_set_energy_global = [c_void_p, c_char_p, c_double]
|
self.lib.lammps_fix_external_set_energy_global = [c_void_p, c_char_p, c_double]
|
||||||
self.lib.lammps_fix_external_set_virial_global = [c_void_p, c_char_p, POINTER(c_double)]
|
self.lib.lammps_fix_external_set_virial_global = [c_void_p, c_char_p, POINTER(c_double)]
|
||||||
|
|
||||||
# detect if Python is using version of mpi4py that can pass a communicator
|
# detect if Python is using a version of mpi4py that can pass communicators
|
||||||
|
# only needed if LAMMPS has been compiled with MPI support.
|
||||||
self.has_mpi4py = False
|
self.has_mpi4py = False
|
||||||
|
if self.has_mpi_support:
|
||||||
try:
|
try:
|
||||||
from mpi4py import __version__ as mpi4py_version
|
from mpi4py import __version__ as mpi4py_version
|
||||||
# tested to work with mpi4py versions 2 and 3
|
# tested to work with mpi4py versions 2 and 3
|
||||||
@ -307,18 +308,18 @@ class lammps(object):
|
|||||||
|
|
||||||
if not ptr:
|
if not ptr:
|
||||||
|
|
||||||
# with mpi4py v2, can pass MPI communicator to LAMMPS
|
# with mpi4py v2+, we can pass MPI communicators to LAMMPS
|
||||||
# need to adjust for type of MPI communicator object
|
# need to adjust for type of MPI communicator object
|
||||||
# allow for int (like MPICH) or void* (like OpenMPI)
|
# allow for int (like MPICH) or void* (like OpenMPI)
|
||||||
if self.has_mpi4py and self.has_mpi_support:
|
if self.has_mpi_support and self.has_mpi4py:
|
||||||
from mpi4py import MPI
|
from mpi4py import MPI
|
||||||
self.MPI = MPI
|
self.MPI = MPI
|
||||||
|
|
||||||
if comm:
|
if comm:
|
||||||
if not self.has_mpi4py:
|
|
||||||
raise Exception('Python mpi4py version is not 2 or 3')
|
|
||||||
if not self.has_mpi_support:
|
if not self.has_mpi_support:
|
||||||
raise Exception('LAMMPS not compiled with real MPI library')
|
raise Exception('LAMMPS not compiled with real MPI library')
|
||||||
|
if not self.has_mpi4py:
|
||||||
|
raise Exception('Python mpi4py version is not 2 or 3')
|
||||||
if self.MPI._sizeof(self.MPI.Comm) == sizeof(c_int):
|
if self.MPI._sizeof(self.MPI.Comm) == sizeof(c_int):
|
||||||
MPI_Comm = c_int
|
MPI_Comm = c_int
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user