Check that hdf5 has MPI if performing depletion with MPI

Check added in openmc/depletion/__init__.py.
Without this check, the exporting of the Results to hdf5 will
hang, as the second process attempts to write to a file
that has already been opened on another process.
This error is only raised after a full transport calculation
has been run.
The check raises a more helpful error directly at the import
from openmc.deplete, prior to transport calculations.
This commit is contained in:
Andrew Johnson 2019-06-20 14:43:33 -05:00
parent 812c667c81
commit 6370b362c7
No known key found for this signature in database
GPG key ID: 253418E91B7F6FEB

View file

@ -6,10 +6,24 @@ A depletion front-end tool.
"""
from .dummy_comm import DummyCommunicator
try:
from mpi4py import MPI
comm = MPI.COMM_WORLD
have_mpi = True
# check if running with MPI and if hdf5 is MPI-enabled
from h5py import get_config
if not get_config().mpi and comm.size > 1:
# Raise exception only on process 0
if comm.rank:
from sys import exit
exit()
raise RuntimeError(
"Need MPI-enabled HDF5 install to perform depletion with MPI"
)
except ImportError:
comm = DummyCommunicator()
have_mpi = False