|
Installation_CrayXT4
Adventures in installing python, boost::python and a number of python extensions on the Cray XT4 system.
Phase-Deploy IntroductionThe Cray XT4 uses a simplified linux kernel known as Compute Node Linux (CNL) on its compute nodes. CNL has the advantage that it is very light weight, and therefore has higher performance compared to a full linux kernel. However, this comes at a sacrifice: CNL does not support dynamically shared libraries. This is a real pain for pyprop, as it is based on making small python extensions loaded on run time. There are two related problems with the lack of dynamic linking. The first is that the required extension modules numpy, pytables, etc. have c-extensions which are normally compiled as shared objects and loaded at runtime. This can be remedied by compiling the c-extensions as static objects, and link them to the python executable at compile time. The second problem is that examples in pyprop usually has potentials and other functions implemented as an c-extension module using boost python. It is not pratcical to keep a separate python installation for each pyprop application, so we need an alternative. The Way(TM) to run pyprop on a statically linked system, is first to make a grand libpython.a containing all the required modules like numpy, pytables, etc. and then link a separate executable using libpython.a, a static libpyprop.a as well as the current pyprop projects own module. My adventures making all this work is described below. My gratitude and respect to the GPAW team for making a brilliant effort into making a statically linked python work more smoothly.
Before starting, make sure to set gcc as the programming environment on hexagon, I have to swap it with the pgi compiler. Furthermore, i whish to use the gfortran compiler which is only available in gcc-4, i therefore swap gcc/3.3.3 (the default gcc on hexagon) with gcc/4.2.1 module swap PrgEnv-pgi PrgEnv-gnu module swap gcc/3.3.3 gcc/4.2.1 This can with success be done in .bashrc or similar. UPDATE: with the quad core installed on hexagon, gcc/4.2.0 is the default gcc on hexagon, so we'll use this. Second, because we are compiling applications for CNL, set the cnl compilers to be the default export CC=cc export CXX=CC export FC=ftn export F77=f77 This will make many programs use the correct compilers by default. However, when compiling for the front nodes, these environment variables should not be set. UPDATE (27/05/10): Some of these steps may require a little tweaking and creativity when using newer versions of the various libraries (had some problems with numpy 1.4.1 for instance. EDIT: This turned out be caused by linking to the wrong version of libsci_quadcore.). Installing Python
./configure --prefix=/work/torebi/sys_cnl/python SO=.a DYNLOADFILE=dynload_redstorm.o MACHDEP=hexagon --host=x86_64-unknown-linux-gnu --disable-sockets --disable-ssl --enable-static --disable-shared make install make bininstall make inclinstall make libainstall in my case make install fails when byte-compiling some of the modules, therefore the additional make installs are needed. Installing CBLASIt is easier to get numpy working properly (with a high speed BLAS implementation) if we use CBLAS to expose the fortran BLAS functions to C.
ln -s Makefile.Linux Makefile.in CBDIR = /work/torebi/sys_cnl/CBLAS FC = ftn make alllib cd /work/torebi/sys_cnl/CBLAS/lib ln -s LINUX/cblas_LINUX.a libcblas.a ln -s /opt/xt-libsci/default/gnu/lib/libsci_quadcore.a libsci.a Installing numpyDue to the smart hack suggested by the GPAW team, distutils will work more or less as for a dynamically linked python, with the difference being that the extension modules will be compiled into static .a libs. These .a files must then be linked with the python executable to make them available to the python runtime.
[DEFAULT] search_static_first = true [blas] blas_libs = cblas, sci library_dirs = /work/torebi/sys_cnl/CBLAS/lib [lapack] lapack_libs = sci library_dirs = /work/torebi/sys_cnl/CBLAS/lib [blas_opt] blas_libs = cblas, sci libraries = cblas, sci [lapack_opt] libraries = sci [fftw] libraries = fftw3 python setup.py install The output should say, among other things, blas_info: FOUND, and lapack_info: FOUND
python setup.py build python setup.py install --prefix=/work/torebi/sys_cnl/python If the build complains about not being able to find _MAIN, rerun the build process a couple of times. There is a bug in numpy-distutils which causes it to try to compile the .a-files into executables, but it tries only once for each library file. If this does not work, try manually creating the archive files, i.e. 'ar cr libname.a file1.o file2.o ...'. This should build all the necessary c-extensions to numpy and install everything into /work/torebi/sys_cnl/python/lib/python/numpy.
NUMPY=/work/torebi/sys_cnl/python/lib/python2.5/site-packages multiarray $(NUMPY)/numpy/core/multiarray.a umath $(NUMPY)/numpy/core/umath.a _sort $(NUMPY)/numpy/core/_sort.a scalarmath $(NUMPY)/numpy/core/scalarmath.a _compiled_base $(NUMPY)/numpy/lib/_compiled_base.a _capi $(NUMPY)/numpy/numarray/_capi.a fftpack_lite $(NUMPY)/numpy/fft/fftpack_lite.a lapack_lite $(NUMPY)/numpy/linalg/lapack_lite.a mtrand $(NUMPY)/numpy/random/mtrand.a python >>> import numpy >>> x = numpy.r_[0:10] >>> x**2 Installing boost::python
/configure --prefix=/work/torebi/sys_cnl/boost --with-libraries=python # Boost.Build Configuration # Automatically generated by Boost configure # Compiler configuration using gcc : : CC ; # Python configuration using python : 2.5 : /work/torebi/sys_cnl/python ; make make install or run jam manually./tools/jam/src/bin.linux/bjam --user-config=user-config.jam --with-python --prefix=/work/torebi/sys_cnl/boost --layout=system ./tools/jam/src/bin.linux/bjam --user-config=user-config.jam --with-python --prefix=/work/torebi/sys_cnl/boost --layout=system install Installing HDF and pytablesInstalling HDF5 is relatively straight forward
./configure --prefix=/work/torebi/sys_cnl/hdf5 --disable-shared --enable-static --enable-fortran make make install Installing pytables is slightly more tricky
export CFLAGS="-D H5_USE_16_API" UPDATE: pytables 2.0.3 supports hdf5 1.8 out of the box, so the above is not necessary
python setup.py build python setup.py install --prefix=/work/torebi/sys_cnl/python PYTABLES=/work/torebi/sys_cnl/python/lib/python2.5/site-packages/tables interpreter $(PYTABLES)/numexpr/interpreter.a hdf5Extension $(PYTABLES)/hdf5Extension.a tableExtension $(PYTABLES)/tableExtension.a utilsExtension $(PYTABLES)/utilsExtension.a _comp_lzo $(PYTABLES)/_comp_lzo.a _comp_bzip2 $(PYTABLES)/_comp_bzip2.a /work/torebi/sys_cnl/hdf5/lib/libhdf5.a -lbz2 make make bininstall expatUPDATE: Expat is included in Python these days, so this should not be necessary(?) Expat is an xml parser for python. It is required if we want to use pyste using the statically linked python.
./configure --prefix=/work/torebi/sys_cnl/expat --enable-static --disable-shared make make install EXPAT_DIR=/work/torebi/sys_cnl/expat pyexpat pyexpat.c -DHAVE_EXPAT_H -I$(EXPAT_DIR)/include -L$(EXPAT_DIR) $(EXPAT_DIR)/lib/libexpat.a pyparWe need something to start MPI_Init. Certainly, we could do it our main(), but it is nice to have mpi-functionality in python as well (otherwise we'll have to send ProcId and ProcCount out to python at some stage. Pyprop uses pypar to start mpi.
wget http://pyprop.googlecode.com/svn/trunk/patch/pypar_1.9.3.patch patch -p0 < pypar_1.9.3.patch ... 695 696 if sys.platform in ['linux2', 'sunos5', 'win32', 'darwin', "hexagon"]: 697 #Linux (LAM,MPICH) or Sun (MPICH) ... rm -f mpiext.o mpiext.a cc -I/work/torebi/sys_cnl/python/include/python2.5 -I/work/torebi/sys_cnl/python/lib/python2.5/site-packages/numpy/core/include lib/pypar/mpiext.c -o mpiext.o -c ar cr mpiext.a mpiext.o mkdir /work/torebi/sys_cnl/python/lib/python2.5/site-packages/pypar cp mpiext.a /work/torebi/sys_cnl/python/lib/python2.5/site-packages/pypar/ cp lib/pypar/pypar.py /work/torebi/sys_cnl/python/lib/python2.5/site-packages PYPAR=/work/torebi/sys_cnl/python/lib/python2.5/site-packages/pypar mpiext $(PYPAR)/mpiext.a make make bininstall If you get a the error message Starting mpi[0] assertion: st == sizeof ident at file mptalps.c line 93, pid <...> it means you are trying to start mpi outside the aprun environment. To test pypar, create a file test.py import pypar print "Hello World from %i" % pypar.rank() and test it with aprun -n 16 python test.py matplotlibmatplotlib is not strictly necessary to run pyprop, and as interactive python on the Cray is not very pleasant, installing matplot is optional. That said, a lot of the pyprop examples does a import pylab, and will fail if matplotlib is not available.
'hexagon' : ["/usr"], python setup.py build python setup.py install --prefix=/work/torebi/sys_cnl/python #matplotlib MATPLOTLIB=/work/torebi/sys_cnl/python/lib/python2.5/site-packages/matplotlib LIBPNG=/usr/lib64/libpng.a LIBFREETYPE=/usr/lib64/libfreetype.a ft2font $(MATPLOTLIB)/ft2font.a $(LIBFREETYPE) -lz -lstdc++ -lm ttconv $(MATPLOTLIB)/ttconv.a _cntr $(MATPLOTLIB)/_cntr.a nxutils $(MATPLOTLIB)/nxutils.a _agg $(MATPLOTLIB)/_agg.a -lstdc++ -lm _transforms $(MATPLOTLIB)/_transforms.a -lstdc++ -lm _backend_agg $(MATPLOTLIB)/backends/_backend_agg.a $(LIBPNG) -lz -lm $(LIBFREETYPE) -lz -lstdc++ -lm _image $(MATPLOTLIB)/_image.a $(LIBPNG) -lz -lm ctraits $(MATPLOTLIB)/../enthought/traits/ctraits.a #datetime module is required by matplotlib datetime datetimemodule.c Links |
Thanks. It's really helpful
glad to be of help :)
Do you have any tips on how to install Scipy ? I used your advices to install Python and Numpy with shared libraries. Now I have problems with Scipy, which is supposed to use Numpy's settings ... Thank you
I'm afraid not. I've tried getting scipy to work several times with only partial success. I believe the problem is with the generated code from f2py, as I have been able to make the non-f2py modules work.
On the other hand, I've heard somewhere that the XT4-nodes actually support shared libraries, they just don't ship with the standard libaries as shard libs. So if I could figure out a way to compile the standard library statically into the python executable or something, I could use dynamic loading for the modules. But I haven't had time to look into this.
This tutorial has helped me installing Python and NumPy? on a Cray XK6, but I still don't manage to have Matplotlib working. I'm using newer versions of all these tools: Python 2.6.7, NumPy? 1.6.1 and MatPlotlib? 1.1.0 so I had to adapt a bit compared to this tutorial. I also had to comment a line in matplotlib's setupext.py: ('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API') Which apparently forces to define MPL_ARRAY_API in every .a files produced, thus when re-compiling Python it cannot link against all the .a files required by matplotlib. By commenting this line I managed to compile everything, but this simple script crashes with a "Memory Error":
Your tutorial is based on Cray XT4, which does not allow dynamic libraries. Do you have already experienced with a Cray XK6, and with more recent versions of Python, NumPy? and Matplotlib ? Thank you