Manual:Building from scratch

From OctopusWiki
Jump to navigation Jump to search

Compiling Octopus on some systems might be difficult, this is mainly because some libraries are required and they have to be all compiled with same Fortran compiler. This is a guide on how to compile Octopus and the required libraries starting from scratch (a Fortran compiler is required) in a standard Unix system.

NOTE: This page should be considered a last resort. On most systems you will be able to install many of these dependencies from a package manager or other pre-built binaries, which will save you a lot of effort.


You will need the following:

  • A standard Unix/Linux system, where you want to install Octopus.
  • A basic knowledge on how to use the system (manage files, edit text files, extract tar archives, etc.).
  • A directory where we will install the created binaries, this can be a specially created directory or even your $HOME. From now, we will assume that the directory is <basedir>, whenever it appears you should replace it with the actual directory you are using. Note that the files that you will download and the directories with the sources, including the ones of Octopus, don't need to be placed in this directory.
  • A working C compiler, gcc is the ideal choice for x86/x86_64 systems. For other platforms you might want to choose a compiler that produces more optimized code. We will assume that the command to run the compiler is <cc>.
  • A working Fortran 95 compiler, if you don't have one you can probably get gfortran or g95. We will assume that the command to run the Fortran compiler is <fc>.
  • If you are compiling for a dual 32/64 bits architecture, it is a good idea to tell the compilers explicitly what type of binaries you want, many problems are caused by unadvertedly mixing 32 and 64 bits code. For Octopus normally you will want a 64 bits binary (-m64 flag in most compilers). Since this flag should be passed always we recommend you to include it in the compiler command used in this guide (sometimes optimization flags are left out), so for example <cc> could be gcc -m64.

Compiler flags

Since probably you want Octopus to run fast, you will probably would to set optimization flags for both the C and Fortran compilers on your system (at least -O3). In general Octopus should run fine with aggressive optimization options. We will assume now that you have found a set of flags for <cc> and <fc>, we will call them <cflags> and <fcflags>. For example <cflags> could be -O3 -march=native.

Note: if <cc>, <fc>, <cflags> or <fcflags> contain spaces you should not enclose them in "". We will put the "" explicitly when it is necessary.

Compilation of libraries

First we will compile and install the libraries required by Octopus.


The first library we will compile is blas. We will use the generic reference implementation, this version is not highly optimized but it is free software and simple to install. So after you have a working version of Octopus you may want to use a more optimized blas implementation as libgoto, ATLAS, MKL, ACML, ESSL, etc.

  • Download the package from the netlib site:
  • Extract the package and enter into the newly created BLAS directory.
  • Edit the file and modify the definition of the fortran compiler that now should be:
FORTRAN  = <fc>
OPTS     = <fcflags>
NOOPT    =
LOADER   = <fc>
  • Now type make to compile, this will take a while.
  • One compilation is finished, create the directory <basedir>/lib
mkdir <basedir>/lib

and copy the file blas_LINUX.a to <basedir>/lib/libblas.a

cp blas_LINUX.a <basedir>/lib/libblas.a

Note: the generated file librrary will be always called blas_LINUX.a independently of the operating system you are using, this is just a name.


We will use the open source reference implementation of Lapack.

  • Edit to indicate the compiler the will be used. The relevant part of the file should look like:
FORTRAN  = <fc>
OPTS     = <fcflags>
NOOPT    =
LOADER   = <fc>
  • Now build the library with
make lib
  • Copy the newly created library lapack_LINUX.a to <basedir>/lib/liblapack.a .


./configure CC="<cc>" --prefix=<basedir> --disable-shared --enable-static
  • Compile and install:
make install


./configure  --prefix=<basedir> CC="<cc>" CFLAGS="<cflags>" F77="<fc>" F77FLAGS="<fcflags>"
  • Compile and install:
make install


tar -xvzf libxc-2.2.0.tar.gz
cd libxc-2.2.0
  • Configure:
./configure --prefix=<basedir> CC="<cc>" CFLAGS="<cflags>" FC="<fc>" FCFLAGS="<fcflags>"
  • Compile and install:
make install

Compilation of Octopus

After compiling the libraries, now we are ready to compile Octopus. These are the steps you have to follow:

export LIBS_BLAS=<basedir>/lib/libblas.a
export LIBS_LAPACK=<basedir>/lib/liblapack.a
export LIBS_FFT=<basedir>/lib/libfftw3.a
  • Now call the configure script:
./configure CC="<cc>" CFLAGS="<cflags>" FC="<fc>" FCFLAGS="<fcflags>" --prefix=<basedir> --with-gsl-prefix=<basedir> --with-libxc-prefix=<basedir>
  • Compile and install
make install
  • If everything went fine, you should have Octopus installed in the <basedir> directory, this means that the executables are in <basedir>/bin/. You may want to add this last directory to your path to run octopus commands directly, otherwise you will have to give the full path.
  • To test the compilation is correct, you can run the testsuite of Octopus, that compares the results obtained with the created version against reference values. To do it, run
make check

All tests should be passed if the compilation is correct. If all of them fail, there is probably a problem with your executable, typically missing dynamic libraries. If just some fail, there might be a more serious problem, we recommend you to look for help in the Mailing lists.

Previous Manual:Updating to a new version - Next Tutorial:Running Octopus on Graphical Processing Units (GPUs)

Back to Manual