Difference between revisions of "Compiling octopus in OS X"
|Line 93:||Line 93:|
=== Build SPARSKIT ===
=== Build SPARSKIT ===
Get [http://www-users.cs.umn.edu/~saad/software/SPARSKIT SPARSKIT2], untar it and ''cd'' to the directory where you untared it. Then edit ''makefile'' and set ''F77=gfortran-mp-4.4 -m64''. Save the makefile and type ''make''. When compilation finishes just copy ''libskit.a'' to $HOME/lib.
== Build serial version of octopus ==
== Build serial version of octopus ==
Revision as of 06:34, 10 September 2011
Installing the GNU compilers and tools
Although OS X installs part of the GNU compiler tools automatically, it lacks gfortran. To install it one should use either macports or fink. These instructions always assume that you are using macports.
As a first step, install Apple's XCode. It is included in the OS X install DVD but updated versions can be dowloaded from Apple's site if you register at Apple's Developer Connection.
Then download the most recent macports tool for your version of OS X and install it. This will install several TCL scripts in /opt/local/bin that will allow you to check what packages are available and install them. Macports is similar to the apt tools in linux systems. You should probably add /opt/local/bin to your PATH variable.
The packages you should now install are gcc44, automake, autoconf, and gsl (and gd2, if you'd like to have access to an esoteric feature of octopus). As OS X is a 64-bit system, try to install the 64-bit versions of these packages. In Snow Leopard (OS X 10.6.x) you don't need to do anything, everything is automatically 64-bit. But if you are running Leopard (OS X 10.5.x) you will have to edit /opt/local/etc/macports.conf before you install any package. Look for the line containing "build_arch" in this file, change it to "build_arch x86_64" and uncomment it (you'll have to be root or use sudo to do this). To install the packages you just need to do port selfupdate to get the most recent package database and then port install gcc44 automake autoconf gsl. Again, you'll have to login as root or use sudo to install packages. Leave your computer running and go for a looong coffee.
Installing the required libraries
Now you have to install the other libraries octopus requires: blas, lapack, sparskit, fftw, netcdf, etsf_io, and mpich2. Don't do it using macports or you'll get these libraries compiled with the system compiler instead of the just installed gfortran (with the possible exception of blas/lapack - see below). And you will not be able to link octopus with them...
To be sure you are really compiling with gfortran in 64 bits, it is recommended to set these environment variables before building the libraries:
export FC="gfortran-mp-4.4 -m64"
export F77="gfortran-mp-4.4 -m64"
export F90="gfortran-mp-4.4 -m64"
export CC="gcc-mp-4.4 -m64"
export CXX="g++-mp-4.4 -m64"
export CPP="cpp-mp-4.4 -m64 -ansi"
export FCCPP="cpp-mp-4.4 -m64 -ansi"
export FCFLAGS="-O3 -I$HOME/include -L$HOME/lib"
export FFLAGS="-O3 -I$HOME/include -L$HOME/lib"
export F90FLAGS="-O3 -I$HOME/include -L$HOME/lib"
All these variables might be overkill, as most of the libraries read only one or two of them, but it's better to be safe than sorry ;-) Now, in order to build the libraries you just need to follow the standard configure, make, make install sequence:
Build mpich2 (optional)
Get mpich2, untar it and cd to the directory where you untared it. Then type:
./configure --prefix=$HOME --enable-smpcoll --enable-f77 --enable-f90 --enable-cxx --enable-mpe --enable-sharedlibs=osx-gcc --enable-fast
Get fftw, untar it and cd to the directory where you untared it. Then type:
./configure --prefix=$HOME --enable-shared --enable-sse2 --enable-static --enable-threads --with-combined-threads
If you want to build fftw with MPI, add --enable-mpi to the configure line after changing these environment variables:
Don't forget to change these variables back to their original values after compiling fftw.
Get netcdf, untar it and cd to the directory where you untared it. Then type:
./configure CPPFLAGS='-DpgiFortran' --disable-cxx --prefix=$HOME
You can make check just to confirm that everything went OK.
Get etsf_io, untar it and cd to the directory where you untared it. Then type:
./configure --prefix=$HOME --with-netcdf-module-path=$HOME/include --with-netcdf-ldflags="-L$HOME/lib -lnetcdf" --with-moduledir=$HOME/include
Build blas and lapack
Now you need to install BLAS and LAPACK. The easiest solution is to get the original sources and just compile them. You will not have the fastest BLAS implementation, but it will work! Another option is to install ATLAS using macports. Note that macports currently compiles ATLAS with gcc/gfortran 4.3, and we have been assuming that everything is compiled with gcc/gfortran 4.4. There should be no problems with this, but to be on the safe side, just do port edit atlas and replace all references to the 4.3 version in the Portfile by references to the 4.4 version. Then compile as usual: port install atlas.
Get SPARSKIT2, untar it and cd to the directory where you untared it. Then edit makefile and set F77=gfortran-mp-4.4 -m64. Save the makefile and type make. When compilation finishes just copy libskit.a to $HOME/lib.
Build serial version of octopus
Now you need to tell octopus' configure script about all the libraries you have just compiled:
export LIBS_BLAS="-L/opt/local/lib -llapack -latlas -lptcblas -lptf77blas"
export LIBS_FFT="-L$HOME/lib -lfftw3"
export LIBS_NETCDF="-L$HOME/lib -lnetcdf"
export LIBS_ETSF_IO="$HOME/lib/libetsf_io.a $HOME/lib/libetsf_io_utils.a $HOME/lib/libetsf_io_low_level.a"
Then it is just a matter of typing:
./configure -prefix=$HOME --enable-gdlib --disable-libnbc --disable-mpi --with-netcdf="$LIBS_NETCDF" --with-sparskit=$HOME/lib/libskit.a --with-etsf-io="$LIBS_ETSF_IO"
Build parallel version of octopus
If you want to use all of your cores/cpus when running octopus, then you need to compile a parallel version of it. It is relatively straightforward. Start by exporting the same environment variables as in the serial case. Then remember that you need to use the 'MPI' compilers:
You need to specify the full path to these scripts, otherwise octopus will use the system mpicc and mpif90, which will not work. Then type:
./configure -prefix=$HOME --enable-gdlib --disable-libnbc --enable-mpi --with-netcdf="$LIBS_NETCDF" --with-sparskit=$HOME/lib/libskit.a --with-etsf-io="$LIBS_ETSF_IO"