From 425633ca702dc6c439f0b7f9ab32a0b31277120c Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Tue, 28 Jan 2020 20:44:50 +0100 Subject: [PATCH 1/7] improve mpi4py error message and update centos7 installer --- contrib/build-meep.sh | 97 +++++++++++++++++++++++++++++++++++-------- python/meep.i | 4 +- 2 files changed, 82 insertions(+), 19 deletions(-) diff --git a/contrib/build-meep.sh b/contrib/build-meep.sh index 65829a0ec..15c7a6077 100755 --- a/contrib/build-meep.sh +++ b/contrib/build-meep.sh @@ -18,6 +18,7 @@ EOF [ -z "$1" ] && echo "(use -h for help)" +test=false installdeps=true while [ ! -z "$1" ]; do @@ -35,6 +36,13 @@ while [ ! -z "$1" ]; do -n) # do not check for distribution dependencies installdeps=false ;; + -S) # source directory (default: /src) + SRCDIR="$2" + shift + ;; + -t) # basic test + test=true + ;; *) echo "'$1' ?" help "$0" @@ -45,16 +53,17 @@ done # detect wether DESTDIR is ending with src/ -[ -z ${DESTDIR} ] && DESTDIR=$(pwd) -[ ${DESTDIR##*/} = src ] && DESTDIR=$(cd $(pwd)/..; pwd) -SRCDIR=${DESTDIR}/src +[ -z "${DESTDIR}" ] && DESTDIR=$(pwd) +[ "${DESTDIR##*/}" = src ] && DESTDIR=$(cd $(pwd)/..; pwd) +[ -z "$SRCDIR" ] && SRCDIR=${DESTDIR}/src cat << EOF This sript will download or update sources, compile and install MEEP. -Please ensure the following final paths fit your needs: +Please ensure the following final paths fit your needs +Or use help '$0 -h' to change them: '${DESTDIR}/bin/meep' - '${DESTDIR}/lib/...' + '${DESTDIR}/lib(64)/...' '${DESTDIR}/share/...' '${DESTDIR}/...' '${SRCDIR}/' @@ -63,6 +72,28 @@ Press return to continue EOF read junk +if $ubuntu; then + RPATH_FLAGS="-Wl,-rpath,${DESTDIR}/lib:/usr/lib/x86_64-linux-gnu/hdf5/openmpi" + LDFLAGS="-L${DESTDIR}/lib -L/usr/lib/x86_64-linux-gnu/hdf5/openmpi ${RPATH_FLAGS}" + CFLAGS="-I${DESTDIR}/include -I/usr/include/hdf5/openmpi" +fi + +if $centos; then + export CC=/usr/lib64/openmpi/bin/mpicc + export CXX=/usr/lib64/openmpi/bin/mpicxx + export PATH=${PATH}:/usr/lib64/openmpi/bin + RPATH_FLAGS="-Wl,-rpath,${DESTDIR}/lib64:/usr/lib64/openmpi/lib" + LDFLAGS="-L${DESTDIR}/lib64 -L/usr/lib64/openmpi/lib ${RPATH_FLAGS}" + CFLAGS="-I${DESTDIR}/include -I/usr/include/openmpi-x86_64/" + export PYTHONPATH=${DESTDIR}/lib/python3.6/site-packages + export PYTHONPATH=${PYTHONPATH}:/usr/local/lib64/python3.6/site-packages + export PYTHONPATH=${PYTHONPATH}:/usr/local/lib64/python3.6/site-packages/mpi4py + export LD_LIBRARY_PATH=${DESTDIR}/lib64:/usr/lib64/openmpi/lib:/usr/local/lib64/python3.6/site-packages/mpi4py/lib-pmpi:/usr/local/lib64/python3.6/site-packages/mpi4py + export LD_PRELOAD=/usr/lib64/openmpi/lib/libmpi.so +fi + +if ! $test; then + if ! lsb_release; then echo "Minimum requirements:" echo " Ubuntu:" @@ -116,8 +147,11 @@ gitclone () autogensh () { - sh autogen.sh PKG_CONFIG_PATH="${PKG_CONFIG_PATH}" RPATH_FLAGS="${RPATH_FLAGS}" LDFLAGS="${LDFLAGS}" CFLAGS="${CFLAGS}" CPPFLAGS="${CPPFLAGS}" \ - --disable-static --enable-shared --prefix="${DESTDIR}" \ + LIB64="${DESTDIR}/lib" + $centos && LIB64="${DESTDIR}/lib64" + LLP="${LD_LIBRARY_PATH}:${LIB64}" + sh autogen.sh PKG_CONFIG_PATH="${PKG_CONFIG_PATH}" RPATH_FLAGS="${RPATH_FLAGS}" LDFLAGS="${LDFLAGS}" CFLAGS="${CFLAGS}" CPPFLAGS="${CPPFLAGS}" LD_LIBRARY_PATH=${LLP} \ + --disable-static --enable-shared --prefix="${DESTDIR}" --libdir=${LIB64} \ --with-libctl=${DESTDIR}/share/libctl \ "$@" } @@ -152,12 +186,7 @@ if $installdeps && $ubuntu; then sudo -H pip3 install --no-cache-dir mpi4py export HDF5_MPI="ON" sudo -H pip3 install --no-binary=h5py h5py - sudo -H pip3 install matplotlib>3.0.0 - - RPATH_FLAGS="-Wl,-rpath,${DESTDIR}/lib:/usr/lib/x86_64-linux-gnu/hdf5/openmpi" - LDFLAGS="-L${DESTDIR}/lib -L/usr/lib/x86_64-linux-gnu/hdf5/openmpi ${RPATH_FLAGS}" - CFLAGS="-I${DESTDIR}/include -I/usr/include/hdf5/openmpi" - + sudo -H pip3 install matplotlib\>3.0.0 fi if $installdeps && $centos; then @@ -190,6 +219,12 @@ if $installdeps && $centos; then systemtap \ wget + sudo yum -y install \ + python3 \ + python3-devel \ + python36-numpy \ + python36-scipy + sudo yum -y install \ openblas-devel \ fftw3-devel \ @@ -213,10 +248,7 @@ if $installdeps && $centos; then guile-devel \ swig - export PATH=${PATH}:/usr/lib64/openmpi/bin - RPATH_FLAGS="-Wl,-rpath,${DESTDIR}/lib:/usr/lib64/openmpi/lib" - LDFLAGS="-L${DESTDIR}/lib -L/usr/lib64/openmpi/lib ${RPATH_FLAGS}" - CFLAGS="-I${DESTDIR}/include -I/usr/include/openmpi-x86_64/" + sudo -E pip3 install mpi4py fi CPPFLAGS=${CFLAGS} @@ -263,3 +295,34 @@ autogensh --with-mpi --with-openmp PYTHON=python3 make -j && $SUDO make install # all done + +if $centos; then + cd ${DESTDIR}/lib/python3.6/site-packages/meep/ + for i in ../../../../lib64/python3.6/site-packages/meep/*meep*; do + ln -sf $i + done +fi + +fi # ! $test + +######## +# test + +test=/tmp/test-meep.py + +echo "export PYTHONPATH=${PYTHONPATH}" +echo "export PATH=${PATH}" +echo "export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" +echo "export LD_PRELOAD=${LD_PRELOAD}" +cat << EOF > $test +import meep as mp +cell = mp.Vector3(16,8,0) +exit() +EOF + +set -x +cat $test +python3 $test +set +x + +######## diff --git a/python/meep.i b/python/meep.i index cddc9fc1f..50570624b 100644 --- a/python/meep.i +++ b/python/meep.i @@ -1563,8 +1563,8 @@ PyObject *_get_array_slice_dimensions(meep::fields *f, const meep::volume &where if with_mpi(): try: from mpi4py import MPI - except ImportError: - print('\n**\n** failed to load python MPI module (mpi4py)\n**\n') + except ImportError as e: + print('\n**\n** failed to load python MPI module (mpi4py)\n**', e, '\n**\n') pass else: # this variable reference is needed for lazy initialization of MPI From 68846ea574b11bfba5e720c6179f06c451834274 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 29 Jan 2020 11:37:06 +0100 Subject: [PATCH 2/7] more cmdline options to separate deps installations, compilation-installation and testing --- contrib/build-meep.sh | 140 +++++++++++++++++++----------------------- 1 file changed, 64 insertions(+), 76 deletions(-) diff --git a/contrib/build-meep.sh b/contrib/build-meep.sh index 15c7a6077..363d976f3 100755 --- a/contrib/build-meep.sh +++ b/contrib/build-meep.sh @@ -16,32 +16,55 @@ EOF exit 1 } -[ -z "$1" ] && echo "(use -h for help)" +gitclone () +{ + repo=${1##*/} + name=${repo%%.*} + echo $repo $name + if [ -d $name ]; then + ( cd $name; git pull; ) + else + [ -z "$2" ] || branch="-b $2" + git clone --depth=1 $1 $branch + fi +} + +autogensh () +{ + LIB64="${DESTDIR}/lib" + $centos && LIB64="${DESTDIR}/lib64" + LLP="${LD_LIBRARY_PATH}:${LIB64}" + sh autogen.sh PKG_CONFIG_PATH="${PKG_CONFIG_PATH}" RPATH_FLAGS="${RPATH_FLAGS}" LDFLAGS="${LDFLAGS}" CFLAGS="${CFLAGS}" CPPFLAGS="${CPPFLAGS}" LD_LIBRARY_PATH=${LLP} \ + --disable-static --enable-shared --prefix="${DESTDIR}" --libdir=${LIB64} \ + --with-libctl=${DESTDIR}/share/libctl \ + "$@" +} -test=false +compile=true installdeps=true +unset DESTDIR while [ ! -z "$1" ]; do case "$1" in -h) # help help "$0" ;; - -d) # (default: current directory) + -d) # (mandatory) DESTDIR="$2" shift ;; -s) # use 'sudo' for 'make install' SUDO=sudo ;; - -n) # do not check for distribution dependencies - installdeps=false - ;; -S) # source directory (default: /src) SRCDIR="$2" shift ;; - -t) # basic test - test=true + -n) # skip checking for distribution dependencies + installdeps=false + ;; + -c) # skip build+install + compile=false ;; *) echo "'$1' ?" @@ -52,26 +75,11 @@ while [ ! -z "$1" ]; do done +[ -z "${DESTDIR}" ] && { echo "-d option is missing" ; help "$0"; } # detect wether DESTDIR is ending with src/ -[ -z "${DESTDIR}" ] && DESTDIR=$(pwd) [ "${DESTDIR##*/}" = src ] && DESTDIR=$(cd $(pwd)/..; pwd) [ -z "$SRCDIR" ] && SRCDIR=${DESTDIR}/src -cat << EOF - -This sript will download or update sources, compile and install MEEP. -Please ensure the following final paths fit your needs -Or use help '$0 -h' to change them: - '${DESTDIR}/bin/meep' - '${DESTDIR}/lib(64)/...' - '${DESTDIR}/share/...' - '${DESTDIR}/...' - '${SRCDIR}/' - -Press return to continue -EOF -read junk - if $ubuntu; then RPATH_FLAGS="-Wl,-rpath,${DESTDIR}/lib:/usr/lib/x86_64-linux-gnu/hdf5/openmpi" LDFLAGS="-L${DESTDIR}/lib -L/usr/lib/x86_64-linux-gnu/hdf5/openmpi ${RPATH_FLAGS}" @@ -85,16 +93,18 @@ if $centos; then RPATH_FLAGS="-Wl,-rpath,${DESTDIR}/lib64:/usr/lib64/openmpi/lib" LDFLAGS="-L${DESTDIR}/lib64 -L/usr/lib64/openmpi/lib ${RPATH_FLAGS}" CFLAGS="-I${DESTDIR}/include -I/usr/include/openmpi-x86_64/" - export PYTHONPATH=${DESTDIR}/lib/python3.6/site-packages - export PYTHONPATH=${PYTHONPATH}:/usr/local/lib64/python3.6/site-packages - export PYTHONPATH=${PYTHONPATH}:/usr/local/lib64/python3.6/site-packages/mpi4py - export LD_LIBRARY_PATH=${DESTDIR}/lib64:/usr/lib64/openmpi/lib:/usr/local/lib64/python3.6/site-packages/mpi4py/lib-pmpi:/usr/local/lib64/python3.6/site-packages/mpi4py - export LD_PRELOAD=/usr/lib64/openmpi/lib/libmpi.so -fi -if ! $test; then + showenv() + { + echo export PYTHONPATH+=:${DESTDIR}/lib/python3.6/site-packages + echo export PYTHONPATH+=:/usr/local/lib64/python3.6/site-packages + echo export LD_LIBRARY_PATH+=:${DESTDIR}/lib64 + echo export LD_PRELOAD+=:/usr/lib64/openmpi/lib/libmpi.so + } + eval $(showenv) +fi -if ! lsb_release; then +if ! lsb_release > /dev/null; then echo "Minimum requirements:" echo " Ubuntu:" echo " sudo apt-get -y install lsb-release sudo git" @@ -104,7 +114,7 @@ if ! lsb_release; then exit 1 fi -set -ex +set -e ubuntu=false centos=false @@ -130,32 +140,6 @@ case "$distrib" in ;; esac -mkdir -p ${SRCDIR} -cd ${SRCDIR} - -gitclone () -{ - repo=${1##*/} - name=${repo%%.*} - echo $repo $name - if [ -d $name ]; then - ( cd $name; git pull; ) - else - git clone --depth=1 $1 - fi -} - -autogensh () -{ - LIB64="${DESTDIR}/lib" - $centos && LIB64="${DESTDIR}/lib64" - LLP="${LD_LIBRARY_PATH}:${LIB64}" - sh autogen.sh PKG_CONFIG_PATH="${PKG_CONFIG_PATH}" RPATH_FLAGS="${RPATH_FLAGS}" LDFLAGS="${LDFLAGS}" CFLAGS="${CFLAGS}" CPPFLAGS="${CPPFLAGS}" LD_LIBRARY_PATH=${LLP} \ - --disable-static --enable-shared --prefix="${DESTDIR}" --libdir=${LIB64} \ - --with-libctl=${DESTDIR}/share/libctl \ - "$@" -} - if $installdeps && $ubuntu; then sudo apt-get update @@ -256,40 +240,43 @@ PKG_CONFIG_PATH=${DESDTIR}/pkgconfig export PKG_CONFIG_PATH export PATH=${DESTDIR}/bin:${PATH} -mkdir -p $SRCDIR +if $compile; then + +mkdir -p ${SRCDIR} -cd $SRCDIR +cd ${SRCDIR} gitclone https://github.com/NanoComp/harminv.git cd harminv/ autogensh make -j && $SUDO make install -cd $SRCDIR +cd ${SRCDIR} gitclone https://github.com/NanoComp/libctl.git cd libctl/ autogensh make -j && $SUDO make install -cd $SRCDIR +cd ${SRCDIR} gitclone https://github.com/NanoComp/h5utils.git cd h5utils/ autogensh CC=mpicc make -j && $SUDO make install -cd $SRCDIR +cd ${SRCDIR} gitclone https://github.com/NanoComp/mpb.git cd mpb/ autogensh CC=mpicc --with-hermitian-eps make -j && $SUDO make install -cd $SRCDIR +cd ${SRCDIR} gitclone https://github.com/HomerReid/libGDSII.git cd libGDSII/ autogensh make -j && $SUDO make install -cd $SRCDIR -gitclone https://github.com/NanoComp/meep.git +cd ${SRCDIR} +#gitclone https://github.com/NanoComp/meep.git +gitclone https://github.com/d-a-v/meep.git fixCentos7Installer cd meep/ autogensh --with-mpi --with-openmp PYTHON=python3 make -j && $SUDO make install @@ -303,26 +290,27 @@ if $centos; then done fi -fi # ! $test +fi # install ######## # test test=/tmp/test-meep.py -echo "export PYTHONPATH=${PYTHONPATH}" -echo "export PATH=${PATH}" -echo "export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" -echo "export LD_PRELOAD=${LD_PRELOAD}" cat << EOF > $test import meep as mp cell = mp.Vector3(16,8,0) exit() EOF -set -x + +echo "------------ ENV (commands)" +showenv +echo "------------ ENV (result)" +echo export LD_LIBRARY_PATH=${LD_LIBRARY_PATH} +echo export PYTHONPATH=${PYTHONPATH} +echo export LD_PRELOAD=${LD_PRELOAD} +echo "------------ $test" cat $test +echo "------------ EXEC python3 $test" python3 $test -set +x - -######## From 8e5f93c3e331a2d8f254205afda23228be8bf89a Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 29 Jan 2020 12:20:48 +0100 Subject: [PATCH 3/7] remove depedency on lsb_release --- contrib/build-meep.sh | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/contrib/build-meep.sh b/contrib/build-meep.sh index 363d976f3..97b41ec67 100755 --- a/contrib/build-meep.sh +++ b/contrib/build-meep.sh @@ -104,14 +104,10 @@ if $centos; then eval $(showenv) fi -if ! lsb_release > /dev/null; then - echo "Minimum requirements:" - echo " Ubuntu:" - echo " sudo apt-get -y install lsb-release sudo git" - echo " CentOS:" - echo " sudo yum -y install redhat-lsb-core sudo git" - echo "" - exit 1 + +if [ ! -r /etc/os-release ]; then + echo "Error: cannot read /etc/os-release" + false fi set -e @@ -119,23 +115,24 @@ set -e ubuntu=false centos=false -distrib=$(lsb_release -r -s) +. /etc/os-release +distrib="${ID}${VERSION_ID}" case "$distrib" in - 18.04) # ubuntu 18.04 bionic + ubuntu18.04) # ubuntu 18.04 bionic libpng=libpng-dev libpython=libpython3-dev ubuntu=true ;; - 16.04) # ubuntu 16.04 xenial + ubuntu16.04) # ubuntu 16.04 xenial libpng=libpng16-dev libpython=libpython3.5-dev ubuntu=true ;; - 7.*) # CentOS 7.x + centos7) # CentOS 7.x centos=true ;; *) - echo "unsupported distribution '$(lsb_release -a)', edit and fix!" + echo "Error: unsupported distribution '${distrib}'" false ;; esac @@ -145,6 +142,7 @@ if $installdeps && $ubuntu; then sudo apt-get update sudo apt-get -y install \ + git \ build-essential \ gfortran \ libblas-dev \ @@ -178,6 +176,7 @@ if $installdeps && $centos; then sudo yum -y --enablerepo=extras install epel-release sudo yum -y install \ + git \ bison \ byacc \ cscope \ From 47819e7447c55a1a48a97d2dad4d23a5b54c8d3a Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 29 Jan 2020 12:21:14 +0100 Subject: [PATCH 4/7] verbosity in test script --- contrib/build-meep.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/build-meep.sh b/contrib/build-meep.sh index 97b41ec67..d0d2156ce 100755 --- a/contrib/build-meep.sh +++ b/contrib/build-meep.sh @@ -299,6 +299,7 @@ test=/tmp/test-meep.py cat << EOF > $test import meep as mp cell = mp.Vector3(16,8,0) +print(cell) exit() EOF From 2e10a6591103388c79aa9e4144e078afe161f1ba Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 2 Mar 2020 17:25:20 +0100 Subject: [PATCH 5/7] add options for building in docker --- contrib/build-meep.sh | 95 +++++++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 25 deletions(-) diff --git a/contrib/build-meep.sh b/contrib/build-meep.sh index d0d2156ce..cf7582440 100755 --- a/contrib/build-meep.sh +++ b/contrib/build-meep.sh @@ -42,6 +42,7 @@ autogensh () compile=true installdeps=true +bashrc=false unset DESTDIR while [ ! -z "$1" ]; do @@ -66,6 +67,12 @@ while [ ! -z "$1" ]; do -c) # skip build+install compile=false ;; + -Du1804) # build a raw ubuntu-18.04 docker image + docker=ubuntu:18.04;; + -Dcentos7) # build a raw centos-7 docker image + docker=centos:7;; + --bashrc) + bashrc=true;; # undocumented internal to store env in ~/.bashrc *) echo "'$1' ?" help "$0" @@ -74,36 +81,42 @@ while [ ! -z "$1" ]; do shift done - [ -z "${DESTDIR}" ] && { echo "-d option is missing" ; help "$0"; } -# detect wether DESTDIR is ending with src/ -[ "${DESTDIR##*/}" = src ] && DESTDIR=$(cd $(pwd)/..; pwd) -[ -z "$SRCDIR" ] && SRCDIR=${DESTDIR}/src -if $ubuntu; then - RPATH_FLAGS="-Wl,-rpath,${DESTDIR}/lib:/usr/lib/x86_64-linux-gnu/hdf5/openmpi" - LDFLAGS="-L${DESTDIR}/lib -L/usr/lib/x86_64-linux-gnu/hdf5/openmpi ${RPATH_FLAGS}" - CFLAGS="-I${DESTDIR}/include -I/usr/include/hdf5/openmpi" -fi +if [ ! -z "${docker}" ]; then + ddir="docker-${docker}" + mkdir ${ddir} + cp "$0" ${ddir}/ + cd ${ddir} + case ${docker} in + *ubuntu*) + echo "FROM ${docker}" > Dockerfile + echo "RUN apt-get update && apt-get -y install apt-utils sudo" >> Dockerfile + echo "ADD \"$0\" \"$0\"" >> Dockerfile + echo "RUN mkdir -p ${DESTDIR}; ./\"$0\" -d ${DESTDIR} --bashrc" >> Dockerfile + echo "CMD /bin/bash" >> Dockerfile + exec docker build -t "meep-${docker}" . + ;; -if $centos; then - export CC=/usr/lib64/openmpi/bin/mpicc - export CXX=/usr/lib64/openmpi/bin/mpicxx - export PATH=${PATH}:/usr/lib64/openmpi/bin - RPATH_FLAGS="-Wl,-rpath,${DESTDIR}/lib64:/usr/lib64/openmpi/lib" - LDFLAGS="-L${DESTDIR}/lib64 -L/usr/lib64/openmpi/lib ${RPATH_FLAGS}" - CFLAGS="-I${DESTDIR}/include -I/usr/include/openmpi-x86_64/" + *centos*) + echo "FROM ${docker}" > Dockerfile + echo "RUN yum -y install sudo" >> Dockerfile + echo "ADD \"$0\" \"$0\"" >> Dockerfile + echo "RUN mkdir -p ${DESTDIR}; ./\"$0\" -d ${DESTDIR} --bashrc" >> Dockerfile + echo "CMD /bin/bash" >> Dockerfile + exec docker build -t "meep-${docker}" . + exit 1;; - showenv() - { - echo export PYTHONPATH+=:${DESTDIR}/lib/python3.6/site-packages - echo export PYTHONPATH+=:/usr/local/lib64/python3.6/site-packages - echo export LD_LIBRARY_PATH+=:${DESTDIR}/lib64 - echo export LD_PRELOAD+=:/usr/lib64/openmpi/lib/libmpi.so - } - eval $(showenv) + *) + echo "can't build a docker file for '${docker}'" + help "$0" + exit 1;; + esac fi +# detect wether DESTDIR is ending with src/ +[ "${DESTDIR##*/}" = src ] && DESTDIR=$(cd $(pwd)/..; pwd) +[ -z "$SRCDIR" ] && SRCDIR=${DESTDIR}/src if [ ! -r /etc/os-release ]; then echo "Error: cannot read /etc/os-release" @@ -136,6 +149,36 @@ case "$distrib" in false ;; esac +echo "-- ubuntu:$ubuntu centos:$centos" + +if $ubuntu; then + RPATH_FLAGS="-Wl,-rpath,${DESTDIR}/lib:/usr/lib/x86_64-linux-gnu/hdf5/openmpi" + LDFLAGS="-L${DESTDIR}/lib -L/usr/lib/x86_64-linux-gnu/hdf5/openmpi ${RPATH_FLAGS}" + CFLAGS="-I${DESTDIR}/include -I/usr/include/hdf5/openmpi" +fi + +showenv() +{ + echo export PATH+=:${DESTDIR}/bin + echo export LD_LIBRARY_PATH+=:${DESTDIR}/lib + echo export PYTHONPATH+=:${DESTDIR}/lib/python3.6/site-packages + if $centos; then + echo export LD_LIBRARY_PATH+=:${DESTDIR}/lib64 + echo export PYTHONPATH+=:/usr/local/lib64/python3.6/site-packages + echo export LD_PRELOAD+=:/usr/lib64/openmpi/lib/libmpi.so + fi +} + +if $centos; then + export CC=/usr/lib64/openmpi/bin/mpicc + export CXX=/usr/lib64/openmpi/bin/mpicxx + export PATH=${PATH}:/usr/lib64/openmpi/bin + RPATH_FLAGS="-Wl,-rpath,${DESTDIR}/lib64:/usr/lib64/openmpi/lib" + LDFLAGS="-L${DESTDIR}/lib64 -L/usr/lib64/openmpi/lib ${RPATH_FLAGS}" + CFLAGS="-I${DESTDIR}/include -I/usr/include/openmpi-x86_64/" +fi + +eval $(showenv) if $installdeps && $ubuntu; then @@ -205,7 +248,7 @@ if $installdeps && $centos; then sudo yum -y install \ python3 \ python3-devel \ - python36-numpy \ + python36-numpy \ python36-scipy sudo yum -y install \ @@ -306,6 +349,8 @@ EOF echo "------------ ENV (commands)" showenv +showenv > ${DESTDIR}/meep-env.sh +$bashrc && { showenv >> ~/.bashrc; } echo "------------ ENV (result)" echo export LD_LIBRARY_PATH=${LD_LIBRARY_PATH} echo export PYTHONPATH=${PYTHONPATH} From 39d8a3a92f17479e20b4a6fb1d68d617cf6c4963 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 2 Mar 2020 19:27:28 +0100 Subject: [PATCH 6/7] fixes per review, fixes for ubuntu 16.04 --- contrib/build-meep.sh | 150 ++++++++++++++++++++++-------------------- 1 file changed, 80 insertions(+), 70 deletions(-) diff --git a/contrib/build-meep.sh b/contrib/build-meep.sh index cf7582440..6d8abb173 100755 --- a/contrib/build-meep.sh +++ b/contrib/build-meep.sh @@ -7,12 +7,14 @@ help () { cat << EOF -$1: Download MEEP sources and dependencies, compile, and install +$1: Download MEEP sources and dependencies, build, and install Usage: $1 [options] EOF sed -ne 's,[ \t]*\(-[^ \t]*\))[^#]*#[ \t]*\(.*\), \1 \2,p' "$1" echo "" + echo "After installation, environment file 'meep-env.sh' is created in destination path." + echo "" exit 1 } @@ -40,7 +42,19 @@ autogensh () "$@" } -compile=true +showenv() +{ + echo export PATH+=:${DESTDIR}/bin + echo export LD_LIBRARY_PATH+=:${DESTDIR}/lib + echo export PYTHONPATH+=:${DESTDIR}/lib/${python}/site-packages + if $centos; then + echo export LD_LIBRARY_PATH+=:${DESTDIR}/lib64 + echo export PYTHONPATH+=:/usr/local/lib64/${python}/site-packages + echo export LD_PRELOAD+=:/usr/lib64/openmpi/lib/libmpi.so + fi +} + +buildinstall=true installdeps=true bashrc=false unset DESTDIR @@ -65,11 +79,13 @@ while [ ! -z "$1" ]; do installdeps=false ;; -c) # skip build+install - compile=false + buildinstall=false ;; - -Du1804) # build a raw ubuntu-18.04 docker image + -Du1604) # build 'meep-ubuntu:16.04' docker image + docker=ubuntu:16.04;; + -Du1804) # build 'meep-ubuntu:18.04' docker image docker=ubuntu:18.04;; - -Dcentos7) # build a raw centos-7 docker image + -Dcentos7) # build 'meep-centos:7' docker image docker=centos:7;; --bashrc) bashrc=true;; # undocumented internal to store env in ~/.bashrc @@ -134,14 +150,17 @@ case "$distrib" in ubuntu18.04) # ubuntu 18.04 bionic libpng=libpng-dev libpython=libpython3-dev + python=python3.6 ubuntu=true ;; ubuntu16.04) # ubuntu 16.04 xenial libpng=libpng16-dev libpython=libpython3.5-dev + python=python3.5 ubuntu=true ;; centos7) # CentOS 7.x + python=python3.6 centos=true ;; *) @@ -149,7 +168,10 @@ case "$distrib" in false ;; esac -echo "-- ubuntu:$ubuntu centos:$centos" + +# these are passed to configure on demand with: 'autogensh ... CC=${CC} CXX=${CXX}' +export CC=mpicc +export CXX=mpicxx if $ubuntu; then RPATH_FLAGS="-Wl,-rpath,${DESTDIR}/lib:/usr/lib/x86_64-linux-gnu/hdf5/openmpi" @@ -157,22 +179,11 @@ if $ubuntu; then CFLAGS="-I${DESTDIR}/include -I/usr/include/hdf5/openmpi" fi -showenv() -{ - echo export PATH+=:${DESTDIR}/bin - echo export LD_LIBRARY_PATH+=:${DESTDIR}/lib - echo export PYTHONPATH+=:${DESTDIR}/lib/python3.6/site-packages - if $centos; then - echo export LD_LIBRARY_PATH+=:${DESTDIR}/lib64 - echo export PYTHONPATH+=:/usr/local/lib64/python3.6/site-packages - echo export LD_PRELOAD+=:/usr/lib64/openmpi/lib/libmpi.so - fi -} - if $centos; then + # mpicc is not in PATH export CC=/usr/lib64/openmpi/bin/mpicc export CXX=/usr/lib64/openmpi/bin/mpicxx - export PATH=${PATH}:/usr/lib64/openmpi/bin + RPATH_FLAGS="-Wl,-rpath,${DESTDIR}/lib64:/usr/lib64/openmpi/lib" LDFLAGS="-L${DESTDIR}/lib64 -L/usr/lib64/openmpi/lib ${RPATH_FLAGS}" CFLAGS="-I${DESTDIR}/include -I/usr/include/openmpi-x86_64/" @@ -207,7 +218,7 @@ if $installdeps && $ubuntu; then python3-pip \ ffmpeg \ - [ "$distrib" = 16.04 ] && sudo -H pip3 install --upgrade pip + [ "$distrib" = ubuntu16.04 ] && sudo -H pip3 install --upgrade pip sudo -H pip3 install --no-cache-dir mpi4py export HDF5_MPI="ON" sudo -H pip3 install --no-binary=h5py h5py @@ -282,57 +293,57 @@ PKG_CONFIG_PATH=${DESDTIR}/pkgconfig export PKG_CONFIG_PATH export PATH=${DESTDIR}/bin:${PATH} -if $compile; then - -mkdir -p ${SRCDIR} - -cd ${SRCDIR} -gitclone https://github.com/NanoComp/harminv.git -cd harminv/ -autogensh -make -j && $SUDO make install - -cd ${SRCDIR} -gitclone https://github.com/NanoComp/libctl.git -cd libctl/ -autogensh -make -j && $SUDO make install - -cd ${SRCDIR} -gitclone https://github.com/NanoComp/h5utils.git -cd h5utils/ -autogensh CC=mpicc -make -j && $SUDO make install - -cd ${SRCDIR} -gitclone https://github.com/NanoComp/mpb.git -cd mpb/ -autogensh CC=mpicc --with-hermitian-eps -make -j && $SUDO make install - -cd ${SRCDIR} -gitclone https://github.com/HomerReid/libGDSII.git -cd libGDSII/ -autogensh -make -j && $SUDO make install - -cd ${SRCDIR} -#gitclone https://github.com/NanoComp/meep.git -gitclone https://github.com/d-a-v/meep.git fixCentos7Installer -cd meep/ -autogensh --with-mpi --with-openmp PYTHON=python3 -make -j && $SUDO make install - -# all done +if $buildinstall; then + + mkdir -p ${SRCDIR} + + cd ${SRCDIR} + gitclone https://github.com/NanoComp/harminv.git + cd harminv/ + autogensh + make -j && $SUDO make install + + cd ${SRCDIR} + gitclone https://github.com/NanoComp/libctl.git + cd libctl/ + autogensh + make -j && $SUDO make install + + cd ${SRCDIR} + gitclone https://github.com/NanoComp/h5utils.git + cd h5utils/ + autogensh CC=${CC} + make -j && $SUDO make install + + cd ${SRCDIR} + gitclone https://github.com/NanoComp/mpb.git + cd mpb/ + autogensh CC=${CC} --with-hermitian-eps + make -j && $SUDO make install + + cd ${SRCDIR} + gitclone https://github.com/HomerReid/libGDSII.git + cd libGDSII/ + autogensh + make -j && $SUDO make install + + cd ${SRCDIR} + #gitclone https://github.com/NanoComp/meep.git + gitclone https://github.com/d-a-v/meep.git fixCentos7Installer + cd meep/ + autogensh --with-mpi --with-openmp PYTHON=python3 + make -j && $SUDO make install + + # all done -if $centos; then - cd ${DESTDIR}/lib/python3.6/site-packages/meep/ - for i in ../../../../lib64/python3.6/site-packages/meep/*meep*; do - ln -sf $i - done -fi + if $centos; then + cd ${DESTDIR}/lib/${python}/site-packages/meep/ + for i in ../../../../lib64/${python}/site-packages/meep/*meep*; do + ln -sf $i + done + fi -fi # install +fi # buildinstall ######## # test @@ -346,7 +357,6 @@ print(cell) exit() EOF - echo "------------ ENV (commands)" showenv showenv > ${DESTDIR}/meep-env.sh From 57c3c12f2bbcbc2c8b1edf395fda1b85cda0dd9b Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 13 May 2020 23:02:20 +0200 Subject: [PATCH 7/7] fix MPI builds automation for ubuntu and centos --- contrib/build-meep.sh | 157 ++++++++++++++++++++++++------------------ 1 file changed, 91 insertions(+), 66 deletions(-) diff --git a/contrib/build-meep.sh b/contrib/build-meep.sh index 6d8abb173..a0cc6c278 100755 --- a/contrib/build-meep.sh +++ b/contrib/build-meep.sh @@ -3,6 +3,12 @@ # Latest version of this script can be found at: # https://github.com/NanoComp/meep/blob/master/contrib/build-meep.sh +# included LD_PRELOAD for CentOS is needed otherwise +# this error message is displayed when starting python: +# python3 /tmp/test-meep.py +# ** failed to load python MPI module (mpi4py) +# ** /usr/local/lib64/python3.6/site-packages/mpi4py/MPI.cpython-36m-x86_64-linux-gnu.so: undefined symbol: ompi_mpi_logical8 + help () { cat << EOF @@ -11,7 +17,7 @@ $1: Download MEEP sources and dependencies, build, and install Usage: $1 [options] EOF - sed -ne 's,[ \t]*\(-[^ \t]*\))[^#]*#[ \t]*\(.*\), \1 \2,p' "$1" + sed -ne 's,^[ \t]*\(-[^ \t]*\))[^#]*#[ \t]*\(.*\), \1 \2,p' "$1" echo "" echo "After installation, environment file 'meep-env.sh' is created in destination path." echo "" @@ -36,20 +42,23 @@ autogensh () LIB64="${DESTDIR}/lib" $centos && LIB64="${DESTDIR}/lib64" LLP="${LD_LIBRARY_PATH}:${LIB64}" - sh autogen.sh PKG_CONFIG_PATH="${PKG_CONFIG_PATH}" RPATH_FLAGS="${RPATH_FLAGS}" LDFLAGS="${LDFLAGS}" CFLAGS="${CFLAGS}" CPPFLAGS="${CPPFLAGS}" LD_LIBRARY_PATH=${LLP} \ - --disable-static --enable-shared --prefix="${DESTDIR}" --libdir=${LIB64} \ + set -x + sh autogen.sh PKG_CONFIG_PATH="${PKG_CONFIG_PATH}" RPATH_FLAGS="${RPATH_FLAGS}" \ + PYTHON=python3 CC="${CC}" LDFLAGS="${LDFLAGS}" CFLAGS="${CFLAGS}" CPPFLAGS="${CPPFLAGS}" LD_LIBRARY_PATH=${LLP} \ + --enable-shared --prefix="${DESTDIR}" --libdir=${LIB64} \ --with-libctl=${DESTDIR}/share/libctl \ "$@" + set -x } showenv() { - echo export PATH+=:${DESTDIR}/bin - echo export LD_LIBRARY_PATH+=:${DESTDIR}/lib - echo export PYTHONPATH+=:${DESTDIR}/lib/${python}/site-packages + echo export PATH=${DESTDIR}/bin:\${PATH} + echo export LD_LIBRARY_PATH=${DESTDIR}/lib:\${LD_LIBRARY_PATH} + echo export PYTHONPATH=${DESTDIR}/lib/${python}/site-packages:\${PYTHONPATH} if $centos; then - echo export LD_LIBRARY_PATH+=:${DESTDIR}/lib64 - echo export PYTHONPATH+=:/usr/local/lib64/${python}/site-packages + echo export LD_LIBRARY_PATH=${DESTDIR}/lib64:\${LD_LIBRARY_PATH} + echo export PYTHONPATH=/usr/local/lib64/${python}/site-packages:\${PYTHONPATH} echo export LD_PRELOAD+=:/usr/lib64/openmpi/lib/libmpi.so fi } @@ -57,6 +66,7 @@ showenv() buildinstall=true installdeps=true bashrc=false +BLAS="" unset DESTDIR while [ ! -z "$1" ]; do @@ -87,6 +97,12 @@ while [ ! -z "$1" ]; do docker=ubuntu:18.04;; -Dcentos7) # build 'meep-centos:7' docker image docker=centos:7;; + -Batlas) # blas: use atlas + BLAS=atlas;; + -Bopenblas) # blas: use openblas + BLAS=openblas;; + -Bgslcblas) # blas: use gsl+openblas (test) + BLAS=gslcblas;; --bashrc) bashrc=true;; # undocumented internal to store env in ~/.bashrc *) @@ -97,7 +113,8 @@ while [ ! -z "$1" ]; do shift done -[ -z "${DESTDIR}" ] && { echo "-d option is missing" ; help "$0"; } +$buildinstall && [ -z "${DESTDIR}" ] && { echo "-d option is missing" ; help "$0"; } +$buildinstall && [ -z "${BLAS}" ] && { echo "blas taste is missing" ; help "$0"; } if [ ! -z "${docker}" ]; then ddir="docker-${docker}" @@ -109,18 +126,18 @@ if [ ! -z "${docker}" ]; then echo "FROM ${docker}" > Dockerfile echo "RUN apt-get update && apt-get -y install apt-utils sudo" >> Dockerfile echo "ADD \"$0\" \"$0\"" >> Dockerfile - echo "RUN mkdir -p ${DESTDIR}; ./\"$0\" -d ${DESTDIR} --bashrc" >> Dockerfile + echo "RUN mkdir -p ${DESTDIR}; ./\"$0\" -d ${DESTDIR} --bashrc -B${BLAS}" >> Dockerfile echo "CMD /bin/bash" >> Dockerfile - exec docker build -t "meep-${docker}" . + exec docker build -t "meep-${docker}-${BLAS}" . ;; *centos*) echo "FROM ${docker}" > Dockerfile echo "RUN yum -y install sudo" >> Dockerfile echo "ADD \"$0\" \"$0\"" >> Dockerfile - echo "RUN mkdir -p ${DESTDIR}; ./\"$0\" -d ${DESTDIR} --bashrc" >> Dockerfile + echo "RUN mkdir -p ${DESTDIR}; ./\"$0\" -d ${DESTDIR} --bashrc -B${BLAS}" >> Dockerfile echo "CMD /bin/bash" >> Dockerfile - exec docker build -t "meep-${docker}" . + exec docker build -t "meep-${docker}-${BLAS}" . exit 1;; *) @@ -172,11 +189,12 @@ esac # these are passed to configure on demand with: 'autogensh ... CC=${CC} CXX=${CXX}' export CC=mpicc export CXX=mpicxx +export CFLAGS="-O3 -mtune=native" if $ubuntu; then RPATH_FLAGS="-Wl,-rpath,${DESTDIR}/lib:/usr/lib/x86_64-linux-gnu/hdf5/openmpi" LDFLAGS="-L${DESTDIR}/lib -L/usr/lib/x86_64-linux-gnu/hdf5/openmpi ${RPATH_FLAGS}" - CFLAGS="-I${DESTDIR}/include -I/usr/include/hdf5/openmpi" + CFLAGS="${CFLAGS} -I${DESTDIR}/include -I/usr/include/hdf5/openmpi" fi if $centos; then @@ -186,7 +204,7 @@ if $centos; then RPATH_FLAGS="-Wl,-rpath,${DESTDIR}/lib64:/usr/lib64/openmpi/lib" LDFLAGS="-L${DESTDIR}/lib64 -L/usr/lib64/openmpi/lib ${RPATH_FLAGS}" - CFLAGS="-I${DESTDIR}/include -I/usr/include/openmpi-x86_64/" + CFLAGS="${CFLAGS} -I${DESTDIR}/include -I/usr/include/openmpi-x86_64/" fi eval $(showenv) @@ -195,15 +213,18 @@ if $installdeps && $ubuntu; then sudo apt-get update + case ${BLAS} in + atlas*) BLAS=atlas; bpkg=libatlas-base-dev;; + openblas) bpkg=libopenblas-dev;; + gslcblas) BLAS=openblas; bpkg="libgsl-dev libgslcblas0 libopenblas-dev";; + esac + sudo apt-get -y install \ git \ build-essential \ gfortran \ - libblas-dev \ - liblapack-dev \ libgmp-dev \ swig \ - libgsl-dev \ autoconf \ pkg-config \ $libpng \ @@ -217,56 +238,49 @@ if $installdeps && $ubuntu; then python3-scipy \ python3-pip \ ffmpeg \ + ${bpkg} \ - [ "$distrib" = ubuntu16.04 ] && sudo -H pip3 install --upgrade pip - sudo -H pip3 install --no-cache-dir mpi4py - export HDF5_MPI="ON" - sudo -H pip3 install --no-binary=h5py h5py - sudo -H pip3 install matplotlib\>3.0.0 fi if $installdeps && $centos; then sudo yum -y --enablerepo=extras install epel-release - sudo yum -y install \ - git \ - bison \ - byacc \ - cscope \ - ctags \ - cvs \ - diffstat \ - oxygen \ - flex \ - gcc \ - gcc-c++ \ - gcc-gfortran \ - gettext \ - git \ - indent \ - intltool \ - libtool \ - patch \ - patchutils \ - rcs \ - redhat-rpm-config \ - rpm-build \ - subversion \ - systemtap \ - wget + case ${BLAS} in + atlas) bpkg="atlas atlas-devel"; LDFLAGS="${LDFLAGS} -L/usr/lib64/${BLAS}"; BLAS=tatlas;; + gslcblas|openblas) bpkg=openblas-devel; BLAS=openblas;; + esac sudo yum -y install \ + git \ + bison \ + byacc \ + cscope \ + ctags \ + cvs \ + diffstat \ + oxygen \ + flex \ + gcc \ + gcc-c++ \ + gcc-gfortran \ + gettext \ + git \ + indent \ + intltool \ + libtool \ + patch \ + patchutils \ + redhat-rpm-config \ + rpm-build \ + systemtap \ + wget \ python3 \ python3-devel \ python36-numpy \ - python36-scipy - - sudo yum -y install \ - openblas-devel \ + python36-scipy \ fftw3-devel \ libpng-devel \ - gsl-devel \ gmp-devel \ pcre-devel \ libtool-ltdl-devel \ @@ -277,15 +291,13 @@ if $installdeps && $centos; then openssl-devel \ sqlite-devel \ bzip2-devel \ - ffmpeg - - sudo yum -y install \ + ffmpeg \ openmpi-devel \ hdf5-openmpi-devel \ guile-devel \ - swig + swig \ + ${bpkg} - sudo -E pip3 install mpi4py fi CPPFLAGS=${CFLAGS} @@ -300,13 +312,13 @@ if $buildinstall; then cd ${SRCDIR} gitclone https://github.com/NanoComp/harminv.git cd harminv/ - autogensh + autogensh --with-blas=${BLAS} make -j && $SUDO make install cd ${SRCDIR} gitclone https://github.com/NanoComp/libctl.git cd libctl/ - autogensh + autogensh --with-blas=${BLAS} make -j && $SUDO make install cd ${SRCDIR} @@ -318,7 +330,7 @@ if $buildinstall; then cd ${SRCDIR} gitclone https://github.com/NanoComp/mpb.git cd mpb/ - autogensh CC=${CC} --with-hermitian-eps + autogensh CC=${CC} --with-hermitian-eps --with-blas=${BLAS} make -j && $SUDO make install cd ${SRCDIR} @@ -327,11 +339,24 @@ if $buildinstall; then autogensh make -j && $SUDO make install +if $ubuntu; then + sudo -E -H python3 -m pip install --upgrade pip + sudo -E -H python3 -m pip install --no-cache-dir mpi4py + export HDF5_MPI="ON" # for python h5py + sudo -E -H python3 -m pip install cython + sudo -E -H python3 -m pip install --no-cache-dir --no-binary=h5py h5py + sudo -E -H python3 -m pip install --no-cache-dir matplotlib>3.0.0 +else + sudo -E -H python3 -m pip install --no-cache-dir mpi4py + #sudo -E -H python3 -m pip install --no-binary=h5py h5py + sudo -E -H python3 -m pip install h5py + sudo -E -H python3 -m pip install matplotlib>3.0.0 +fi + cd ${SRCDIR} - #gitclone https://github.com/NanoComp/meep.git - gitclone https://github.com/d-a-v/meep.git fixCentos7Installer + gitclone https://github.com/NanoComp/meep.git cd meep/ - autogensh --with-mpi --with-openmp PYTHON=python3 + autogensh --with-mpi --with-openmp --with-blas=${BLAS} make -j && $SUDO make install # all done @@ -358,7 +383,6 @@ exit() EOF echo "------------ ENV (commands)" -showenv showenv > ${DESTDIR}/meep-env.sh $bashrc && { showenv >> ~/.bashrc; } echo "------------ ENV (result)" @@ -368,4 +392,5 @@ echo export LD_PRELOAD=${LD_PRELOAD} echo "------------ $test" cat $test echo "------------ EXEC python3 $test" +. ${DESTDIR}/meep-env.sh python3 $test