Difference between revisions of "Compiling octopus in OS X"

From OctopusWiki
Jump to navigation Jump to search
 
(28 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
== Installation of octopus package from MacPorts ==
 +
 +
You can now simply install an octopus package from MacPorts ([http://trac.macports.org/browser/trunk/dports/science/octopus/Portfile]). See info in the next section about installing MacPorts, and then you can just do
 +
 +
sudo port install fftw-3 +gfortran octopus
 +
 +
You can specify various variants for octopus as well, which specify some optional supporting libraries and the compilers used.
 +
 +
sudo port install octopus +gcc11 +mpich +etsf_io +netcdf +sparskit +gdlib
 +
 +
Alternately, you can proceed with the full instructions to build by hand. This is probably not necessary unless you want to do development or install a pre-release version from svn.
 +
 
== Installing the GNU compilers and tools ==
 
== 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 [http://www.macports.org/ macports] or [http://www.finkproject.org/ fink]. These instructions always assume that you are using macports.  
+
Although OS X installs part of the GNU compiler tools automatically, it lacks a Fortran compiler. To install it one should use either [http://www.macports.org/ macports], [http://www.finkproject.org/ fink], or homebrew. 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 [http://developer.apple.com/tools/ Apple's Developer Connection].
+
Install Macports according to these instructions: https://www.macports.org/install.php
  
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.
+
Install gcc11 (or a different version of gcc if you prefer). To install the packages you just need to do {{code|port selfupdate}} to get the most recent package database and then {{code|port install gcc11}}. You'll have to login as root or use sudo to install packages. Leave your computer running and go for a looong coffee.
  
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 required libraries ==
  
== Installing the required libraries ==
+
FFTW3 is available in the "fftw-3" port, which must have the Fortan interface enabled by selecting a Fortran variant (as below). GSL is available in the "gsl" port; the {{code|+optimize}} variant may give you faster performance. libxc is available in the "libxc" port. Install as below. (If you like, you can first run {{code|sudo port test ...}} for each, to run its testsuite; then do {{code|install}} afterward if it succeeds.)
  
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...
+
sudo port install fftw-3 +gfortran
 +
sudo port install gsl +optimize
 +
sudo port install libxc
  
To be sure you are really compiling with gfortran in 64 bits, it is recommended to set these environment variables before building the libraries:
+
For BLAS and LAPACK, the easiest is to install the very small port veclibfort, which is an interface to the built-in optimized Accelerate framework. If you like, you can also try the ports atlas, openBLAS, or openBLAS-devel, which possibly will give better performance, but can take a long time to install. For development, the automake, autoconf, and libtool (for libxc) ports are needed too.
  
export FC="gfortran-mp-4.4 -m64"
+
== Installing optional libraries ==
<br />
 
export F77="gfortran-mp-4.4 -m64"
 
<br />
 
export F90="gfortran-mp-4.4 -m64"
 
<br />
 
export CC="gcc-mp-4.4 -m64"
 
<br />
 
export CXX="g++-mp-4.4 -m64"
 
<br />
 
export CPP="cpp-mp-4.4 -m64 -C -ansi"
 
<br />
 
export FCCPP="cpp-mp-4.4 -m64 -C -ansi"
 
<br />
 
export FCFLAGS="-O3 -I$HOME/include -L$HOME/lib"
 
<br />
 
export FFLAGS="-O3 -I$HOME/include -L$HOME/lib"
 
<br />
 
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:
+
You may optionally install ports gd2, netcdf-fortran, sparskit, etsf_io, and an MPI implementation (mpich or openmpi).
  
=== Build mpich2 (optional) ===
+
If you want to build them by hand for some reason, you could continue as below. Set these environment variables before building the libraries:
  
Get [http://www.mcs.anl.gov/research/projects/mpich2/ mpich2], untar it and ''cd'' to the directory where you untared it. Then type:
+
export FC="gfortran-mp-11"
   
+
  export F77="gfortran-mp-11"
./configure --prefix=$HOME --enable-smpcoll --enable-f77 --enable-f90 --enable-cxx --enable-mpe --enable-sharedlibs=osx-gcc --enable-fast
+
export F90="gfortran-mp-11"
<br />
+
export CC="gcc-mp-11"
make
+
export CXX="g++-mp-11"
<br />
+
export CPP="cpp-mp-11 -ansi"
make install
+
export FCCPP="cpp-mp-11 -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"
  
=== Build fftw ===
+
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 other libraries you just need to follow the standard ''configure'', ''make'', ''make install'' sequence, as below.
  
Get [http://www.fftw.org/ fftw], untar it and ''cd'' to the directory where you untared it. Then type:
+
=== Build etsf_io ===
  
./configure --prefix=$HOME --enable-shared --enable-sse2 --enable-static --enable-threads --with-combined-threads
+
Get [http://www.etsf.eu/resources/software/libraries_and_tools etsf_io], untar it and ''cd'' to the directory where you untared it. Then type:
<br />
 
make
 
<br />
 
make install
 
  
If you want to build fftw with MPI, add ''--enable-mpi'' to the configure line after changing these environment variables:
+
./configure --prefix=$HOME --with-netcdf-module-path=$HOME/include --with-netcdf-ldflags="-L$HOME/lib -lnetcdf" --with-moduledir=$HOME/include
 +
make install
 +
make check
  
export FC="$HOME/bin/mpif90"
+
=== Build SPARSKIT ===
<br />
 
export CC="$HOME/bin/mpicc"
 
  
Don't forget to change these variables back to their original values after compiling fftw.
+
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-11''. Save the makefile and type ''make''. When compilation finishes just copy ''libskit.a'' to $HOME/lib.
  
=== Build netcdf ===
+
=== Build NetCDF ===
  
 
Get [http://www.unidata.ucar.edu/software/netcdf/ netcdf], untar it and ''cd'' to the directory where you untared it. Then type:
 
Get [http://www.unidata.ucar.edu/software/netcdf/ netcdf], untar it and ''cd'' to the directory where you untared it. Then type:
  
./configure CPPFLAGS='-DpgiFortran' --disable-cxx --prefix=$HOME
+
./configure CPPFLAGS='-DpgiFortran' --disable-cxx --prefix=$HOME
<br />
+
make
make
+
make install
<br />
 
make install
 
  
 
You can ''make check'' just to confirm that everything went OK.
 
You can ''make check'' just to confirm that everything went OK.
  
=== Build etsf_io ===
+
== Build serial version of octopus ==
 +
 
 +
Now you need to tell octopus' configure script about all the libraries you have just compiled:
 +
 
 +
./configure --prefix=$HOME --enable-gdlib --disable-mpi --with-netcdf-prefix=$HOME --with-sparskit=$HOME/lib/libskit.a --with-etsf-io-prefix=$HOME --with-blas=-lveclibfort --with-fft-lib="-L$HOME/lib -lfftw3"
 +
make install
 +
 
 +
For ATLAS, you would use "
 +
 
 +
== 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. Install port {{code|mpich-default}} or {{code|openmpi-default}}. Start by exporting the same environment variables as in the serial case. Then remember that you need to use the 'MPI' compilers, ''e.g''
 +
 
 +
export CC=`which mpicc-mpich-mp`
 +
export FC=`which mpif90-mpich-mp`
 +
 
 +
You need to specify the full path to these compiler wrappers, otherwise octopus will use the system {{code|mpicc}} and {{code|mpif90}}, which will not work. Configure as above with the addition of {{code|---enable-mpi}}.
 +
 
 +
If you want to build your own versions of these libraries instead of using macports, see instructions below.
 +
 
 +
== Build mpich2 (optional) ==
 +
 
 +
Get [http://www.mcs.anl.gov/research/projects/mpich2/ 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
 +
make
 +
make install
 +
 
 +
== Build fftw ==
 +
 
 +
Get [http://www.fftw.org/ fftw], untar it and ''cd'' to the directory where you untared it. Then type:
  
Get [http://www.etsf.eu/resources/software/libraries_and_tools etsf_io], 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
 +
make
 +
make install
  
./configure --prefix=$HOME --with-netcdf-module-path=$HOME/include --with-netcdf-ldflags="-L$HOME/lib -lnetcdf" --with-moduledir=$HOME/include
+
If you want to build fftw with MPI, add ''--enable-mpi'' to the configure line after changing these environment variables:
<br />
 
make
 
<br />
 
make install
 
  
=== Build blas and lapack ===
+
export FC="$HOME/bin/mpif90"
 +
export CC="$HOME/bin/mpicc"
  
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''.
+
Don't forget to change these variables back to their original values after compiling fftw.

Latest revision as of 17:59, 10 September 2021

Installation of octopus package from MacPorts

You can now simply install an octopus package from MacPorts ([1]). See info in the next section about installing MacPorts, and then you can just do

sudo port install fftw-3 +gfortran octopus

You can specify various variants for octopus as well, which specify some optional supporting libraries and the compilers used.

sudo port install octopus +gcc11 +mpich +etsf_io +netcdf +sparskit +gdlib 

Alternately, you can proceed with the full instructions to build by hand. This is probably not necessary unless you want to do development or install a pre-release version from svn.

Installing the GNU compilers and tools

Although OS X installs part of the GNU compiler tools automatically, it lacks a Fortran compiler. To install it one should use either macports, fink, or homebrew. These instructions always assume that you are using macports.

Install Macports according to these instructions: https://www.macports.org/install.php

Install gcc11 (or a different version of gcc if you prefer). To install the packages you just need to do port selfupdate to get the most recent package database and then port install gcc11. You'll have to login as root or use sudo to install packages. Leave your computer running and go for a looong coffee.

Installing required libraries

FFTW3 is available in the "fftw-3" port, which must have the Fortan interface enabled by selecting a Fortran variant (as below). GSL is available in the "gsl" port; the +optimize variant may give you faster performance. libxc is available in the "libxc" port. Install as below. (If you like, you can first run sudo port test ... for each, to run its testsuite; then do install afterward if it succeeds.)

sudo port install fftw-3 +gfortran
sudo port install gsl +optimize
sudo port install libxc

For BLAS and LAPACK, the easiest is to install the very small port veclibfort, which is an interface to the built-in optimized Accelerate framework. If you like, you can also try the ports atlas, openBLAS, or openBLAS-devel, which possibly will give better performance, but can take a long time to install. For development, the automake, autoconf, and libtool (for libxc) ports are needed too.

Installing optional libraries

You may optionally install ports gd2, netcdf-fortran, sparskit, etsf_io, and an MPI implementation (mpich or openmpi).

If you want to build them by hand for some reason, you could continue as below. Set these environment variables before building the libraries:

export FC="gfortran-mp-11"
export F77="gfortran-mp-11"
export F90="gfortran-mp-11"
export CC="gcc-mp-11"
export CXX="g++-mp-11"
export CPP="cpp-mp-11 -ansi"
export FCCPP="cpp-mp-11 -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 other libraries you just need to follow the standard configure, make, make install sequence, as below.

Build etsf_io

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
make install
make check

Build SPARSKIT

Get SPARSKIT2, untar it and cd to the directory where you untared it. Then edit makefile and set F77=gfortran-mp-11. Save the makefile and type make. When compilation finishes just copy libskit.a to $HOME/lib.

Build NetCDF

Get netcdf, untar it and cd to the directory where you untared it. Then type:

./configure CPPFLAGS='-DpgiFortran' --disable-cxx --prefix=$HOME
make
make install

You can make check just to confirm that everything went OK.

Build serial version of octopus

Now you need to tell octopus' configure script about all the libraries you have just compiled:

./configure --prefix=$HOME --enable-gdlib --disable-mpi --with-netcdf-prefix=$HOME --with-sparskit=$HOME/lib/libskit.a --with-etsf-io-prefix=$HOME --with-blas=-lveclibfort --with-fft-lib="-L$HOME/lib -lfftw3"
make install

For ATLAS, you would use "

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. Install port mpich-default or openmpi-default. Start by exporting the same environment variables as in the serial case. Then remember that you need to use the 'MPI' compilers, e.g

export CC=`which mpicc-mpich-mp`
export FC=`which mpif90-mpich-mp`

You need to specify the full path to these compiler wrappers, otherwise octopus will use the system mpicc and mpif90, which will not work. Configure as above with the addition of ---enable-mpi.

If you want to build your own versions of these libraries instead of using macports, see instructions below.

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
make
make install

Build fftw

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
make
make install

If you want to build fftw with MPI, add --enable-mpi to the configure line after changing these environment variables:

export FC="$HOME/bin/mpif90"
export CC="$HOME/bin/mpicc"

Don't forget to change these variables back to their original values after compiling fftw.