Monday, February 1, 2010

Playing with SciPy (install part 2)

I'm following the instructions in this blog entry (AKA: hyperjeff) to build and install a 64-bit Python-Numpy-SciPy thingie to fool around with. I posted about building Python here and here. (Note that there are some components---I'm not quite sure of all of them---that are not there yet, and care has to be taken in building them. But this whole project is mainly a way for me to get SciPy without paying for Enthought's work).

The easiest piece of the whole puzzle is:

• fortran universal binary
http://r.research.att.com/gfortran-4.2.3.dmg

It's simple. All files go into /usr/local.


$ ls -al /usr/local/bin/gf*
lrwxr-xr-x 1 root admin 12 Feb 1 14:38 /usr/local/bin/gfortran -> gfortran-4.2
lrwxr-xr-x 1 root wheel 12 Feb 1 14:38 /usr/local/bin/gfortran-4.0 -> gfortran-4.2
-rwxrwxr-x 1 root wheel 84580 Apr 21 2008 /usr/local/bin/gfortran-4.2
-rwxrwxr-x 1 root wheel 5348 Apr 21 2008 /usr/local/bin/gfortran-uninstall

$ file /usr/local/bin/gfortran
/usr/local/bin/gfortran: Mach-O universal binary with 2 architectures
/usr/local/bin/gfortran (for architecture i386): Mach-O executable i386
/usr/local/bin/gfortran (for architecture ppc): Mach-O executable ppc

$ /usr/local/bin/gfortran --version
GNU Fortran (GCC) 4.2.3

# it's on my path:
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:



It's 32-bit, but that doesn't matter, right?

While the gfortran binary itself is i386/ppc, it does create i386/x86_64 binaries just fine...to have gfortran build a 64-bit binary, pass it the flag "-m64".


A second dependency we can deal with easily is FFTW

FFTW is a C subroutine library for computing the discrete Fourier transform (DFT) in one or more dimensions...Our benchmarks, performed on on a variety of platforms, show that FFTW's performance is typically superior to that of other publicly available FFT software, and is even competitive with vendor-tuned codes. In contrast to vendor-tuned codes, however, FFTW's performance is portable: the same program will perform well on most architectures without modification. Hence the name, "FFTW," which stands for the somewhat whimsical title of "Fastest Fourier Transform in the West."


According to hyperjeff, it's important to pass configure some info about what we want:


./configure CC="gcc -arch i386 -arch x86_64" \
CXX="g++ -arch i386 -arch x86_64" CPP="gcc -E" CXXCPP="g++ -E"

make
sudo make install


If you want to know how FFTW works, there is some very high-class documentation included. It takes a bit to build.



Next up is some complexity that we are going to ignore for now. I'll put my notes here in case I change my mind later, but I decided not to bother with this for the moment.

According to hyperjeff, we need to install UMFPACK and its friends AMD an UFconfig. However, I think UMFPACK is not actually "required." It's not mentioned in the install from source notes for SciPy on OS X.

I have a note that these are listed as required in the SciPy instructions, but I'm not sure where I got that at the moment.

UMFPACK ("Umph Pack") is a set of routines for solving unsymmetric sparse linear systems
• AMD is a set of routines for ordering a sparse matrix prior to Cholesky factorization
• UFconfig is required by nearly all sparse matrix packages

UMFPACK depends on AMD and both depend on UFconfig. These also somehow use BLAS/LAPACK.

BLAS (Basic Linear Algebra Subprograms)
LAPACK

which in turn have something to do with ATLAS

Got that? But it shouldn't be that hard. Just follow the instructions. Download the packages, change a line here to point to the correct fortran compiler, a line there to change some flags for the gcc compiler, and tell it that BLAS and LAPACK depend on the Accelerate framework, copy all the files and make (no install?).

What is the "Accelerate" framework on OS X? According to these Apple docs:

the Accelerate framework includes the vImage image processing framework, the vDSP digital signal processing framework, and the LAPACK and BLAS libraries for Linear Algebra, among others.


That explains why we didn't need to install them. Other notes here, from which hyperjeff developed his instructions.

OK. All that remains is Numpy and Scipy!