Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow MPI compiler to be set with CXX=... instead of MPICXX=... #379

Open
kitchenknif opened this issue Jun 12, 2018 · 12 comments
Open

allow MPI compiler to be set with CXX=... instead of MPICXX=... #379

kitchenknif opened this issue Jun 12, 2018 · 12 comments

Comments

@kitchenknif
Copy link
Contributor

Using the build steps from the build script found the docs (http://meep.readthedocs.io/en/latest/Build_From_Source/),

cd ~/install
git clone https://github.com/stevengj/meep.git
cd meep/
sh autogen.sh --enable-shared --with-mpi PYTHON=python3 \
    CC=mpicc CXX=mpic++ LDFLAGS="${MY_LDFLAGS}" CPPFLAGS="${MY_CPPFLAGS}"
make && sudo make install

On CentOS 6.9, with a custom built OpenMPI, installed to /usr/local and a custom built HDF5, also in /usr/local, the link commands executed during sudo make install fall over because they are unable to find mpic++.
LDFLAGS, CC, CXX, CPPFLAGS are all modified to point to the correct directories.
CC and CXX point to the full paths of mpicc/mpic++, e.g. CXX=/usr/local/bin/mpic++.
Running make install from root works correctly, /usr/local/bin is in the system path.
Passing the environment variable to sudo with sudo -E doesn't help...

This is the exact command that falls over:

libtool: install: warning: relinking `libmeepgeom.la'
libtool: install: (cd /home/pdmitriev/install/meep/libmeepgeom; /bin/sh /home/pdmitriev/install/meep/libtool  --silent --tag CXX --mode=relink mpic++ -O3 -fstrict-aliasing -mtune=native -Wall -W -version-info 10:0:0 -L/usr/local/lib -L/usr/local/lib/openmpi -Wl,-rpath,/usr/local/lib:/usr/local/lib/openmpi -o libmeepgeom.la -rpath /usr/local/lib meepgeom.lo GDSIIgeom.lo ../src/libmeep.la -lhdf5 -lz -lgsl -lgslcblas -lm -lmpb -L/usr/local/lib -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../.. -lharminv -llapack -lblas -lgfortranbegin -lgfortran -lm -llapack -lblas -lfftw3 -lm -L/usr/local/lib -L/usr/local/lib/openmpi -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../.. -lfftw3 -lgfortranbegin -lgfortran -lm )
/home/pdmitriev/install/meep/libtool: line 7841: mpic++: command not found
libtool: install: error: relink `libmeepgeom.la' with the above command before installing it

Not sure if this is me having screwed up my setup or a bug in the makefiles...

@stevengj
Copy link
Collaborator

stevengj commented Jun 13, 2018

If mpic++ is not in your path, then you should either add /usr/local/bin to your PATH environment variable or specify the full path in CXX=/usr/local/bin/mpic++. See http://meep.readthedocs.io/en/latest/Build_From_Source/#installation-paths

@acmcclung
Copy link

acmcclung commented Jun 13, 2018

I have this problem too, despite mpic++ being in my path. I have gotten around it by manually editing libtool to the full path after getting the error (in my case on CentOS by changing CC="mpic++" to CC="/usr/lib64/openmpi/bin/mpic++") and calling sudo make install again.

Specifying the full path for autogen.sh on the command line strangely does not solve the problem, as the generated libtool file does not have the specified path.

@kitchenknif
Copy link
Contributor Author

That's the problem -
mpic++ is in the PATH and i've specified the full path to mpic++, CXX=/usr/local/bin/mpic++
and sudo -E make install still fails to find mpic++

@kitchenknif
Copy link
Contributor Author

This is the required modification to correctly make meep:

export RPATH_FLAGS="-Wl,-rpath,/usr/local/lib:/usr/local/lib/openmpi"
export MY_LDFLAGS="-L/usr/local/lib -L/usr/local/lib/openmpi ${RPATH_FLAGS}"
export MY_CPPFLAGS="-I/usr/local/include -I/usr/local/include/openmpi"

mkdir ~/install
cd ~/install
git clone https://github.com/stevengj/meep.git
cd meep/
sh autogen.sh --enable-shared --with-mpi PYTHON=python3 CC=/usr/local/bin/mpicc CXX=/usr/local/bin/mpic++ LDFLAGS="${MY_LDFLAGS}" CPPFLAGS="${MY_CPPFLAGS}"
make -j
sed -i 's/CC="mpic++"/CC="\/usr\/local\/bin\/mpic++"/g' libtool
sudo make install

@stevengj
Copy link
Collaborator

stevengj commented Jun 14, 2018

I'm guessing that the mpic++ in your PATH is not the same as /usr/local/bin/mpicc (i.e. you have two versions of MPI installed) … what does which mpic++ report at the shell prompt?

For --with-mpi, you have to set MPICXX=/usr/local/bin/mpic++, as otherwise it looks for mpic++ in your path first.

(I guess the ACX_MPI script could be updated to first check whether CXX is already an MPI compiler before looking for mpic++...)

@stevengj stevengj reopened this Jun 14, 2018
@stevengj stevengj changed the title Makefile falls over with non-standard paths for mpic++ allow MPI compiler to be set with CXX=... instead of MPICXX=... Jun 14, 2018
@kitchenknif
Copy link
Contributor Author

kitchenknif commented Jun 14, 2018 via email

@stevengj
Copy link
Collaborator

stevengj commented Jun 14, 2018

You shouldn’t run configure with sudo, generally. Only use sudo for the final make install step (after configure and make). The general principle is to do as little as possible with root privileges.

@kitchenknif
Copy link
Contributor Author

Passing mpicc, mpic++ as MPICC and MPICXX works, yes.

@kitchenknif
Copy link
Contributor Author

kitchenknif commented Jun 15, 2018

This script successfully builds meep on a clean CentOS 6 install.
Though I probably makes sense to break it up...
Building swig and Guile may not be necessary, though I remember having problems with the ones that came with CentOS 6

I build OpenMPI, HDF5 and Python3 because the versions that come with CentOS 6 are hopelessly out of date.

#!/bin/bash

set -e

RPATH_FLAGS="-Wl,-rpath,/usr/local/lib:/usr/local/lib/openmpi"
MY_LDFLAGS="-L/usr/local/lib -L/usr/local/lib/openmpi ${RPATH_FLAGS}"
MY_CPPFLAGS="-I/usr/local/include -I/usr/local/include/openmpi"

#
# yum installs
#
sudo yum -y --enablerepo=extras install epel-release
sudo yum -y install bison byacc cscope ctags cvs diffstat doxygen flex gcc gcc-c++ gcc-gfortran gettext git indent intltool libtool patch patchutils rcs redhat-rpm-config rpm-build subversion systemtap wget
sudo yum -y install openblas-devel fftw3-devel libpng-devel gsl-devel gmp-devel pcre-devel libtool-ltdl-devel libunistring-devel libffi-devel gc-devel zlib-devel openssl-devel sqlite-devel bzip2-devel

#
# time to build
#
sudo rm -rf ~/install
mkdir -p ~/install


cd ~/install
wget https://github.com/swig/swig/archive/rel-3.0.12.tar.gz
tar xvf rel-3.0.12.tar.gz
cd swig-rel-3.0.12
./autogen.sh
./configure
make -j
sudo make -j install


cd ~/install
wget https://ftp.gnu.org/gnu/guile/guile-2.0.11.tar.gz
tar xvf guile-2.0.11.tar.gz
cd guile-2.0.11
./configure
make -j
sudo make -j install


cd ~/install
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
tar xvf Python-3.6.5.tgz
cd Python-3.6.5
./configure --enable-optimizations
make -j
sudo make -j install


cd ~/install
wget https://download.open-mpi.org/release/open-mpi/v2.1/openmpi-2.1.1.tar.gz
tar xvf openmpi-2.1.1.tar.gz
cd openmpi-2.1.1/
./configure
make -j all
sudo make -j install


cd ~/install
git clone https://bitbucket.hdfgroup.org/scm/hdffv/hdf5.git
cd hdf5/
git checkout tags/hdf5-1_10_2
./configure --enable-parallel --enable-shared --prefix=/usr/local CC=/usr/local/bin/mpicc CXX=/usr/local/bin/mpic++
make -j
sudo make -j install


cd ~/install
git clone https://github.com/stevengj/harminv.git
cd harminv/
sh autogen.sh --enable-shared
make -j
sudo make -j install


cd ~/install
git clone https://github.com/stevengj/libctl.git
cd libctl/
sh autogen.sh  --enable-shared
make -j
sudo make -j install


cd ~/install
git clone https://github.com/stevengj/h5utils.git
cd h5utils/
sh autogen.sh CC=/usr/local/bin/mpicc LDFLAGS="${MY_LDFLAGS}" CPPFLAGS="${MY_CPPFLAGS}"
make -j
sudo make -j install

cd ~/install
git clone https://github.com/stevengj/mpb.git
cd mpb/
sh autogen.sh --enable-shared CC=/usr/local/bin/mpicc LDFLAGS="${MY_LDFLAGS}" CPPFLAGS="${MY_CPPFLAGS}" --with-hermitian-eps
make -j
sudo make -j install


cd ~/install
wget https://bitbucket.org/mpi4py/mpi4py/downloads/mpi4py-3.0.0.tar.gz
tar xvf mpi4py-3.0.0.tar.gz
cd mpi4py-3.0.0/
python3 setup.py build
sudo /usr/local/bin/python3 setup.py install


cd ~/install
wget https://github.com/h5py/h5py/archive/2.8.0.tar.gz
tar xvf 2.8.0.tar.gz
cd h5py-2.8.0/
python3 setup.py configure --mpi
python3 setup.py build
sudo /usr/local/bin/python3 setup.py install


cd ~/install
git clone https://github.com/stevengj/meep.git
cd meep/
sh autogen.sh --enable-shared --with-mpi PYTHON=python3 MPICC=/usr/local/bin/mpicc MPICXX=/usr/local/bin/mpic++ LDFLAGS="${MY_LDFLAGS}" CPPFLAGS="${MY_CPPFLAGS}"
#sh autogen.sh --enable-shared --with-mpi PYTHON=python3 CC=/usr/local/bin/mpicc CXX=/usr/local/bin/mpic++ LDFLAGS="${MY_LDFLAGS}" CPPFLAGS="${MY_CPPFLAGS}"
make -j
#sed -i 's/CC="mpic++"/CC="\/usr\/local\/bin\/mpic++"/g' libtool
sudo make install

And another issue - this builds a python wrapper that cannot be imported without appyling the patch

--- __init__.py	2018-06-15 20:15:11.062122018 +0800
+++ __init__.py_new	2018-06-15 20:15:48.622122038 +0800
@@ -8,7 +8,8 @@
 if _swig_python_version_info >= (2, 7, 0):
     def swig_import_helper():
         import importlib
-        pkg = __name__.rpartition('.')[0]
+        pkg_parts = __name__.rpartition('.')
+        pkg = pkg_parts[0] if pkg_parts[1] == '.' else pkg_parts[2]
         mname = '.'.join((pkg, '_meep')).lstrip('.')
         try:
             return importlib.import_module(mname)
@@ -4467,5 +4468,3 @@
 atexit.register(report_elapsed_time)
 
 # This file is compatible with both classic and new-style classes.
-
-

by
sudo patch /usr/local/lib/python3.6/site-packages/meep/__init__.py < import.patch

@stevengj
Copy link
Collaborator

stevengj commented Jun 15, 2018

For the swig patch, see #189. There is a bug for SWIG 3.0.[9,10,11,12] and currently we only work around the problem for 3.0.12. Updates for other SWIG versions would be welcome.

(Hmm, it looks like you are using SWIG 3.0.12, though, which should already be handled by a patch in our Makefile?)

@stevengj
Copy link
Collaborator

Note that 5ba3b72 fixes the documentation problem in the original post: setting CXX=... in the --with-mpi Ubuntu build instructions was not actually doing anything, nor was it needed.

@stevengj
Copy link
Collaborator

Note that to allow the MPI compiler to be set with CXX=..., the right way would be to modify https://github.com/NanoComp/meep/blob/master/m4/acx_mpi.m4 so that it first checks whether $CXX works for linking/compiling MPI code, and only afterwards try $MPICXX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants