This tutorial will explain how to install VASP 4.6.38 from scratch on a Linux system.
For VASP 5, please see this blogpost.
(VASP)[http://www.vasp.at/] relies on a couple of libraries which you have to install. You can install these system-wide (assuming you have root privileges) or locally. For the sake of this tutorial, I will consider that you do not have root privileges and install everything locally. If you want to install things system-wide though, just change the --prefix
tags to something like /opt/software/version-x
and perform the last make install
or cp
step as a root user.
Furthermore, I assume you have some basic understanding of make
and have some basic software such as wget
, tar
, git
, and grep
installed. (most systems have this software installed by default)
A couple of things before I start:
This tutorial proceeds in 6 steps:
If you run into problems, please have a look at this section.
OK, let's start!
Make sure you have a sufficient amount of space available in your /home
folder and start by creating a build and compile directory:
mkdir -pv $HOME/vasp/{libraries,compilation,software}
INSTALL=$HOME/vasp
In my previous post, I mentioned that gcc-4.8.3 gave the best performance for my type of processor. Therefore, I would like to show here how to compile your own compiler. If you don't think this is necessary or if it sounds overcomplicated to you, feel free to skip this step.
Start by grabbing the tarball of gcc-4.8.3.
mkdir -pv $INSTALL/compilation/gcc
cd $INSTALL/compilation/gcc
wget ftp://ftp.nluug.nl/mirror/languages/gcc/releases/gcc-4.8.3/gcc-4.8.3.tar.bz2
tar -xvjf gcc-4.8.3.tar.bz2
gcc-4.8.3 relies on a couple of other packages, which you can conveniently grab by executing the following commands:
cd gcc-4.8.3
./contrib/download_prerequisites
gcc needs to be compiled in a separate folder, create a separate build
folder (the name is arbitrary), configure, make and make install. I assume that you have at least a quad-core machine, so we are going to compile with five threads. Feel free to change the -j5
flag to something more appropriate for your machine.
mkdir -v $INSTALL/compilation/gcc/build
cd $INSTALL/compilation/gcc/build
../gcc-4.8.3/configure --enable-languages=c,c++,fortran \
--enable-shared --enable-linker-build-id --with-system-zlib \
--without-included-gettext --enable-threads=posix \
--enable-nls --enable-clocale=gnu --enable-libstdcxx-debug \
--enable-libstdcxx-time=yes --enable-gnu-unique-object \
--enable-plugin --with-tune=generic --enable-checking=release \
--disable-multilib --prefix=$INSTALL/software/gcc/4.8.3
make -j5
To make sure that gcc-4.8.3 is going to be used for compiling the libraries and the VASP program, prepend the bin
folder to the PATH
like so
PATH=$INSTALL/software/gcc/4.8.3/bin:$PATH
jhpowell_at_odu_dot_edu
(see the comment below) suggested to also append the lib and lib64 folders of gcc-4.8.3 to the LD_LIBRARY PATH variable, like so:
LD_LIBRARY_PATH=$INSTALL/software/gcc/4.8.3/lib:$INSTALL/software/gcc/4.8.3/lib64 :$LD_LIBRARY_PATH
to check if your gcc compiler is correctly added to the PATH
, test the following
which gcc
which gfortran
it should output something like:
/home/user/vasp/software/gcc/4.8.3/bin/gcc
/home/user/vasp/software/gcc/4.8.3/bin/gfortran
Finally, it is time to test your freshly built compiler by creating a very small program:
cd $INSTALL/software
echo "int main(){return 0;}" > test.c
gcc test.c -o test
./test && echo 'Success!' || echo 'Something went wrong'
if you get the 'Success!' statement, feel free to remove the files:
rm -v test.c test
Download the latest tarball of the stable release.
cd $INSTALL/compilation
wget http://www.open-mpi.org/software/ompi/v1.8/downloads/openmpi-1.8.1.tar.bz2
tar -xvjf openmpi-1.8.1.tar.bz2
cd openmpi-1.8.1
./configure --prefix=$INSTALL/libraries/openmpi/1.8.1
At this point, you probably want to make sure that the proper version of gcc is going to be used. Especially if you have spend some effort and time in building one yourself. To do so, check for the OPAL_CC_ABSOLUTE
and OMPI_FC_ABSOLUTE
patterns in config.log
like so:
grep -E "OPAL_CC_ABSOLUTE=|OMPI_FC_ABSOLUTE=" config.log
which should give you something like:
OMPI_FC_ABSOLUTE='/home/user/vasp/software/gcc/4.8.3/bin/gfortran'
OPAL_CC_ABSOLUTE='/home/user/vasp/software/gcc/4.8.3/bin/gcc'
If everything looks OK. It is time to build and install the package.
make -j5
make install -j5
Testing OpenMPI is a bit more difficult as testing GCC, moreover, it really isn't that necessary. From personal experience I found out that if OpenMPI compiles without any errors, it will run just fine.
In my previous post, I mentioned that OpenBLAS gave better performance than ATLAS, as such, we are going to install OpenBLAS.
Grab the latest version from Github:
cd $INSTALL/compilation
git clone https://github.com/xianyi/OpenBLAS.git --depth 1
cd OpenBLAS
We should use the non-threaded variant of OpenBLAS, as such, build the library using
make USE_THREAD=0
Finally install the library
make PREFIX=$INSTALL/libraries/openblas/1.13 install
Grab the package from the repository and extract it. ScaLAPACK reads the compilation instructions from SLmake.inc, which does not exist yet. Copy SLmake.inc.example to SLmake.inc and refer to our previously built OpenBLAS library. In the listing below, we use sed
to do this for us. By adding the bin
folder of our OpenMPI installation to the PATH, we will use our own mpicc compiler for building ScaLAPACK. Acter properly configuring, we can now use make
to build the library.
cd $INSTALL/compilation
wget http://www.netlib.org/scalapack/scalapack-2.0.2.tgz
tar -xvzf scalapack-2.0.2.tgz
cd scalapack-2.0.2
PATH=$PATH:$INSTALL/libraries/openmpi/1.8.1/bin
OPENBLASPATH=$INSTALL/libraries/openblas/1.13/lib
cp SLmake.inc.example SLmake.inc
sed -i "s,^BLASLIB.*$,BLASLIB = ${OPENBLASPATH}/libopenblas.a,g" SLmake.inc
sed -i "s,^LAPACKLIB.*$,LAPACKLIB = ${OPENBLASPATH}/libopenblas.a,g" SLmake.inc
make
Now, we copy the freshly built libopenblas.a file to our custom installation directory.
mkdir -pv $INSTALL/libraries/scalapack/2.0.2/lib
cp -v libscalapack.a $INSTALL/libraries/scalapack/2.0.2/lib
Finally, we are ready to build VASP. VASP is build in two steps. First, we have to build a VASP library and finally we can build a VASP executable. Start by downloading the two corresponding TAR files from the VASP repository (or get them from your system administrator).
mkdir -pv $INSTALL/compilation/vasp
# I assume that you have placed here your vasp.4.6.tar.gz and vasp.4.lib.tar.gz files
tar -xvzf vasp.4.6.tar.gz
tar -xvzf vasp.4.lib.tar.gz
cd vasp.4.lib
cp makefile.linux_gfortran Makefile
At this point, make sure that which gfortran
refers to the correct version of gfortran
. That is, either the one your compiled previously, or the one of your system! If you have compiled gfortran yourself and which gfortran
refers to the wrong version, execute the command below:
PATH=$INSTALL/software/gcc/4.8.3/bin:$PATH
If everything is set up correct, you are ready to build the VASP library.
make
Now it is time to build the VASP executable, start by going to the source folder, copy the example makefile.linux_gfortran
to Makefile
and edit this file.
cd ../vasp.4.6
cp makefile.linux_gfortran Makefile
nano Makefile
We have to change a couple of directives in this file. To start, we are going to link to OpenBLAS.
# Atlas based libraries
#ATLASHOME= /usr/lib/blas/threaded-atlas
# BLAS= -L/usr/lib/blas/atlas -lblas #!! this line has to be commented out
#BLAS= -L$(ATLASHOME) -lf77blas -latlas
# use specific libraries (default library path points to other libraries)
#BLAS= $(ATLASHOME)/libf77blas.a $(ATLASHOME)/libatlas.a
# use the mkl Intel libraries for p4 (www.intel.com)
#BLAS=-L/opt/intel/mkl/lib/32 -lmkl_p4 -lpthread
# LAPACK, simplest use vasp.4.lib/lapack_double
#LAPACK= ../vasp.4.lib/lapack_double.o
# use atlas optimized part of lapack
#LAPACK= ../vasp.4.lib/lapack_atlas.o -llapack -lblas
# use the mkl Intel lapack
#LAPACK= -lmkl_lapack
#LAPACK= -L/usr/lib/lapack/atlas -llapack #!! this line has to be commented out
# Use our own OpenBLAS
LAPACK=/home/user/vasp/libraries/openblas/1.13/lib/libopenblas.a
Take care to change user
to the proper folder name!
We are going to use MPI, so set the proper compiler below.
#-----------------------------------------------------------------------
# fortran linker for mpi: if you use LAM and compiled it with the options
# suggested above, you can use the following lines
#-----------------------------------------------------------------------
FC=mpif90
FCL=$(FC)
#-----------------------------------------------------------------------
# additional options for CPP in parallel version (see also above):
# NGZhalf charge density reduced in Z direction
# wNGZhalf gamma point only reduced in Z direction
# scaLAPACK use scaLAPACK (usually slower on 100 Mbit Net)
#-----------------------------------------------------------------------
CPP = $(CPP_) -DMPI -DHOST=\"LinuxPgi\" \
-Dkind8 -DNGZhalf -DCACHE_SIZE=2000 -DPGF90 -Davoidalloc -DRPROMU_DGEMV \
-DscaLAPACK #!! note the addition here
#-----------------------------------------------------------------------
# location of SCALAPACK
# if you do not use SCALAPACK simply uncomment the line SCA
#-----------------------------------------------------------------------
BLACS=/usr/local/BLACS_lam
SCA_= /usr/local/SCALAPACK_lam
SCA= $(SCA_)/scalapack_LINUX.a $(SCA_)/pblas_LINUX.a $(SCA_)/tools_LINUX.a \
$(BLACS)/LIB/blacsF77init_MPI-LINUX-0.a $(BLACS)/LIB/blacs_MPI-LINUX-0.a $(BLACS)/LIB/blacsF77init_MPI$
SCA=/home/user/vasp/libraries/scalapack/2.0.2/lib/libscalapack.a
#-----------------------------------------------------------------------
# libraries for mpi
#-----------------------------------------------------------------------
LIB = -L../vasp.4.lib -ldmy \
../vasp.4.lib/linpack_double.o $(LAPACK) \
$(SCA) $(BLAS)
# FFT: only option fftmpi.o with fft3dlib of Juergen Furthmueller
FFT3D = fftmpi.o fftmpi_map.o fft3dlib.o
Now we are ready to build vasp:
make
If you get an error message such as:
base.f:1.1:
/* Copyright (C) 1991-2014 Free Software Foundation, Inc.
1
Error: Invalid character in name at (1)
then you have to remove the -C
directive from the CPP line in the Makefile as below and run make
again.
#-----------------------------------------------------------------------
# whereis CPP ?? (I need CPP, can't use gcc with proper options)
# that's the location of gcc for SUSE 5.3
#
# CPP_ = /usr/lib/gcc-lib/i486-linux/2.7.2/cpp -P -C
#
# that's probably the right line for some Red Hat distribution:
#
# CPP_ = /usr/lib/gcc-lib/i386-redhat-linux/2.7.2.3/cpp -P -C
#
# SUSE 6.X, maybe some Red Hat distributions:
#!! I removed the -C directive in the line below
CPP_ = ./preprocess <$*.F | /usr/bin/cpp -P -traditional >$*$(SUFFIX)
So far, I have only seen this error occurring on Arch Linux. Most likely because this is a very cutting-edge distro. For Debian and Ubuntu, you should be fine. For any other distro, I am not aware.
If you encounter the error below compiling VASP
/opt/scalapack/2.0.2-gcc-4.8.3/lib/libscalapack.a(PB_Cztypeset.o): In function `PB_Cztypeset':
PB_Cztypeset.c:(.text+0x233): undefined reference to `zgeru_'
PB_Cztypeset.c:(.text+0x249): undefined reference to `zher_'
PB_Cztypeset.c:(.text+0x275): undefined reference to `zsymm_'
PB_Cztypeset.c:(.text+0x28b): undefined reference to `zsyrk_'
PB_Cztypeset.c:(.text+0x296): undefined reference to `zherk_'
PB_Cztypeset.c:(.text+0x2a1): undefined reference to `zsyr2k_'
/opt/scalapack/2.0.2-gcc-4.8.3/lib/libscalapack.a(zvvdotu.o): In function `zvvdotu_':
zvvdotu.f:(.text+0x2b): undefined reference to `zdotu_'
collect2: error: ld returned 1 exit status
Makefile:264: recipe for target 'vasp' failed
make: *** [vasp] Error 1
Then you have to change the order in which the libraries are linked, like so:
LIB = -L../vasp.4.lib -ldmy \
../vasp.4.lib/linpack_double.o \
$(SCA) $(BLAS) $(LAPACK)