Skip to content

Commit

Permalink
Fix memory leaks in Simulation.get_eigenmode and enable building with…
Browse files Browse the repository at this point in the history
…out MPB (#558)

* Fix memory leaks in Simulation.get_eigenmode

* Enable building without MPB

* Wrong macro name in meep.i

* Build without MPB in travis

* Fix .travis syntax

* Include config.h

* Typo

* Stub out _get_eigenmode and pass preprocessor directives through SWIG

* Make config.h available to SWIG preprocessor

* Run make clean before building without MPB
  • Loading branch information
ChristopherHogan authored and stevengj committed Oct 18, 2018
1 parent 1b6d1c5 commit 031a33b
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 83 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ matrix:
- MKCHECKFLAGS="-j 2"
- CPPFLAGS="${HDF5_SERIAL_CPPFLAGS} ${CPPFLAGS}"
- LDFLAGS="${HDF5_SERIAL_LDFLAGS} ${LDFLAGS}"
- BUILD_WITHOUT_MPB="1"
addons:
apt:
packages:
Expand Down Expand Up @@ -164,6 +165,12 @@ script:
make ${MKCHECKFLAGS} check &&
popd;
fi
- >
if [[ "${BUILD_WITHOUT_MPB}" == "1" ]]; then
../configure --enable-maintainer-mode --prefix=$HOME/local --with-libctl=$HOME/local/share/libctl ${MPICONF} ac_cv_header_mpb_h=no &&
make clean &&
make;
fi
# Kill background sleep loop
- kill %1

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ else
have_python=no],[#include <Python.h>])

AC_MSG_CHECKING([for coverage module])
$PYTHON -c 'import coverage'
$PYTHON -c 'import coverage' 2>/dev/null
if test $? = 0; then
AC_MSG_RESULT([yes])
have_coverage=yes
Expand Down
76 changes: 56 additions & 20 deletions python/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ HPPFILES= \
$(top_srcdir)/libmeepgeom/meepgeom.hpp \
$(top_srcdir)/libmeepgeom/material_data.hpp

BUILT_SOURCES = meep-python.cpp mpb-python.cpp __init__.py mpb.py
EXTRA_DIST = $(BUILT_SOURCES) typemap_utils.cpp solver.py mpb_data.py materials.py examples tests
BUILT_SOURCES = meep-python.cpp __init__.py
EXTRA_DIST = $(BUILT_SOURCES) typemap_utils.cpp materials.py examples tests

CLEANFILES = $(BUILT_SOURCES) meep.py .coverage

if WITH_MPB
PYMPBINCLUDE=-I$(top_srcdir)/libpympb
LIBPYMPB=$(top_builddir)/libpympb/libpympb.la
BUILT_SOURCES += mpb-python.cpp mpb.py
EXTRA_DIST += solver.py mpb_data.py
endif

LIBMEEPGEOM = $(top_builddir)/libmeepgeom/libmeepgeom.la
Expand All @@ -30,27 +32,49 @@ _meep_la_LIBADD = $(LIBMEEP) $(LIBMEEPGEOM) $(PYTHON_LIBS) @LIBCTLGEOM_LIBS@
_meep_la_LDFLAGS = -module -version-info @SHARED_VERSION_INFO@
_meep_la_CPPFLAGS = $(PYTHON_INCLUDES) $(AM_CPPFLAGS)

if WITH_MPB
_mpb_la_SOURCES = mpb-python.cpp
_mpb_la_LIBADD = $(LIBMEEPGEOM) $(PYTHON_LIBS) $(LIBPYMPB) @LIBCTLGEOM_LIBS@
_mpb_la_LDFLAGS = -module -version-info @SHARED_VERSION_INFO@
_mpb_la_CPPFLAGS = $(PYTHON_INCLUDES) $(AM_CPPFLAGS)
MPB_LA = _mpb.la
endif # WITH_MPB

TEST_DIR = tests

# material_dispersion.py test must be excluded from test suite for MPI build
if WITH_MPI
MDPYTEST=
MPBPYTEST=
else
MDPYTEST=$(TEST_DIR)/material_dispersion.py
if WITH_MPB
MPBPYTEST=$(TEST_DIR)/mpb.py
else
MPBPYTEST=
endif # WITH_MPB
endif # WITH_MPI

if WITH_MPB
BINARY_GRATING_TEST = $(TEST_DIR)/binary_grating.py
KDOM_TEST = $(TEST_DIR)/kdom.py
MODE_COEFFS_TEST = $(TEST_DIR)/mode_coeffs.py
MODE_DECOMPOSITION_TEST = $(TEST_DIR)/mode_decomposition.py
WVG_SRC_TEST = $(TEST_DIR)/wvg_src.py
else
BINARY_GRATING_TEST =
KDOM_TEST =
MODE_COEFFS_TEST =
MODE_DECOMPOSITION_TEST =
WVG_SRC_TEST =
endif

TEST_DIR = tests
TESTS = \
$(TEST_DIR)/3rd_harm_1d.py \
$(TEST_DIR)/absorber_1d.py \
$(TEST_DIR)/antenna_radiation.py \
$(TEST_DIR)/bend_flux.py \
$(TEST_DIR)/binary_grating.py \
$(BINARY_GRATING_TEST) \
$(TEST_DIR)/cavity_arrayslice.py \
$(TEST_DIR)/chunks.py \
$(TEST_DIR)/cyl_ellipsoid.py \
Expand All @@ -61,12 +85,12 @@ TESTS = \
$(TEST_DIR)/geom.py \
$(TEST_DIR)/holey_wvg_bands.py \
$(TEST_DIR)/holey_wvg_cavity.py \
$(TEST_DIR)/kdom.py \
$(KDOM_TEST) \
$(TEST_DIR)/ldos.py \
$(MDPYTEST) \
$(MPBPYTEST) \
$(TEST_DIR)/mode_coeffs.py \
$(TEST_DIR)/mode_decomposition.py \
$(MODE_COEFFS_TEST) \
$(MODE_DECOMPOSITION_TEST) \
$(TEST_DIR)/multilevel_atom.py \
$(TEST_DIR)/physical.py \
$(TEST_DIR)/pw_source.py \
Expand All @@ -76,7 +100,7 @@ TESTS = \
$(TEST_DIR)/simulation.py \
$(TEST_DIR)/source.py \
$(TEST_DIR)/user_defined_material.py \
$(TEST_DIR)/wvg_src.py
$(WVG_SRC_TEST)

if WITH_COVERAGE
PY_LOG_COMPILER = coverage run -a --omit=$(top_srcdir)/python/tests/*,${HOME}/virtualenv/*,$(top_srcdir)/python/examples/*
Expand All @@ -88,18 +112,22 @@ TEST_EXTENSIONS = .py
TESTS_ENVIRONMENT = export PYTHONPATH=$(abs_top_builddir)/python:$$PYTHONPATH;

if WITH_PYTHON
pympbdir = $(pkgpythondir)/mpb
pkgpython_PYTHON = geom.py __init__.py source.py simulation.py materials.py
pkgpyexec_LTLIBRARIES = _meep.la
if WITH_MPB
pympbdir = $(pkgpythondir)/mpb
pympb_DATA = mpb.py solver.py mpb_data.py
pympb_LTLIBRARIES = _mpb.la
endif
endif # WITH_MPB
endif # WITH_PYTHON

if WITH_MPB
install-data-hook:
mv $(DESTDIR)$(pkgpythondir)/mpb/mpb.py $(DESTDIR)$(pkgpythondir)/mpb/__init__.py

uninstall-hook:
rm -f $(DESTDIR)$(pkgpythondir)/mpb/__init__.py
endif

if MAINTAINER_MODE

Expand All @@ -110,32 +138,37 @@ MEEP_SWIG_SRC = meep.i numpy.i vec.i
meep-python.cpp: $(MEEP_SWIG_SRC) $(HPPFILES)
$(SWIG) -Wextra $(AM_CPPFLAGS) -outdir $(builddir) -c++ -python -o $@ $(srcdir)/meep.i

if WITH_MPB
MPB_SWIG_SRC = mpb.i

mpb-python.cpp: $(MPB_SWIG_SRC) $(top_srcdir)/libpympb/pympb.hpp
$(SWIG) -Wextra $(AM_CPPFLAGS) $(PYMPBINCLUDE) -outdir $(builddir) -c++ -python -o $@ $(srcdir)/mpb.i

meep.py: meep-python.cpp

mpb.py: mpb-python.cpp
MPB_PY = mpb.py
endif # WITH_MPB

meep.py: meep-python.cpp

__init__.py: meep.py mpb.py
__init__.py: meep.py $(MPB_PY)
cp $< $@
echo "__version__ = '$(shell git describe --tags | sed 's/^v//')'" >> $@
if [[ "${SWIG_VERSION}" = 3.0.12 ]]; then \
sed -i.bak '/^if _swig_python_version_info >= (2, 7, 0):/,/^else:/d' $@; \
sed -i.bak 's/ import _meep/from . import _meep/' $@; \
fi
if WITH_MPB
if [[ "${SWIG_VERSION}" == 3.0.12 ]]; then \
sed -i.bak '/^if _swig_python_version_info >= (2, 7, 0):/,/^else:/d' mpb.py; \
sed -i.bak 's/ import _mpb/from . import _mpb/' mpb.py; \
fi

endif

INIT_PY = __init__.py
MPB_PY = $(builddir)/mpb.py
MPB_PY_PATH = $(builddir)/mpb.py
else

INIT_PY = $(srcdir)/__init__.py
MPB_PY = $(srcdir)/mpb.py
MPB_PY_PATH = $(srcdir)/mpb.py

endif # MAINTAINER_MODE

Expand All @@ -150,12 +183,15 @@ PY_PKG_FILES = \
$(HL_IFACE) \
.libs/_meep.so

meep: _meep.la _mpb.la __init__.py $(HL_IFACE)
mkdir -p meep/mpb
meep: _meep.la $(MPB_LA) __init__.py $(HL_IFACE)
mkdir -p meep
cp $(PY_PKG_FILES) meep
if WITH_MPB
mkdir -p meep/mpb
cp .libs/_mpb.so meep/mpb
cp $(MPB_PY) meep/mpb/__init__.py
cp $(MPB_PY_PATH) meep/mpb/__init__.py
cp $(srcdir)/solver.py $(srcdir)/mpb_data.py meep/mpb
endif

all-local: meep

Expand Down
Loading

0 comments on commit 031a33b

Please sign in to comment.