Skip to content
README.md 13.5 KiB
Newer Older
Holly Judge's avatar
Holly Judge committed
# CP2K
Holly Judge's avatar
Holly Judge committed
## Summary Version
Holly Judge's avatar
Holly Judge committed
1.0
Holly Judge's avatar
Holly Judge committed
## Purpose of Benchmark
Holly Judge's avatar
Holly Judge committed
CP2K is a freely available quantum chemistry and solid-state physics software
package that can perform atomistic simulations of solid state, liquid,
molecular, periodic, material, crystal, and biological systems. 
Holly Judge's avatar
Holly Judge committed
## Characteristics of Benchmark
Holly Judge's avatar
Holly Judge committed
CP2K can be used to perform DFT calculations using the QuickStep algorithm. This
applies mixed  Gaussian and plane waves approaches (such as GPW and GAPW).
Supported theory levels include DFTB, LDA, GGA, MP2, RPA, semi-empirical methods
(AM1, PM3, PM6, RM1, MNDO, …), and classical force fields (AMBER, CHARMM, …).
CP2K can do simulations of molecular dynamics, metadynamics, Monte Carlo, 
Ehrenfest dynamics, vibrational analysis, core level spectroscopy, energy
minimisation, and transition state optimisation using NEB or dimer method.

CP2K is written in Fortran 2008 and can be run in parallel using a combination
of multi-threading, MPI, and CUDA. All of CP2K is MPI parallelised, with some 
additional loops also being OpenMP parallelised. It is therefore most important 
to take advantage of MPI parallelisation, however running one MPI rank per CPU
core often leads to memory shortage. At this point OpenMP threads can be used 
to utilise all CPU cores without suffering an overly large memory footprint. 
The optimal ratio between MPI ranks and OpenMP threads depends on the type of
simulation and the system in question. CP2K supports CUDA, allowing it to
offload some linear algebra operations including sparse matrix multiplications 
to the GPU through its DBCSR acceleration layer. FFTs can optionally also be 
offloaded to the GPU. Benefits of GPU offloading may yield improved performance
depending on the type of simulation and the system in question.
Holly Judge's avatar
Holly Judge committed
## Mechanics of Building Benchmark
Holly Judge's avatar
Holly Judge committed
GNU make and Python 3.x are required for the build process, as are a Fortran 
Holly Judge's avatar
Holly Judge committed
2003 compiler and matching C compiler, e.g. gcc/gfortran (gcc >=4.6 works, later
Holly Judge's avatar
Holly Judge committed
versions are recommended).
Holly Judge's avatar
Holly Judge committed

CP2K can benefit from a number of external libraries for improved performance. 
It is advised to use vendor-optimized versions of these libraries. If these are 
not available on your machine, there exist freely available implementations of
these libraries.
Holly Judge's avatar
Holly Judge committed
Overview of build process:
1. Install Libint and Libxc.
Holly Judge's avatar
Holly Judge committed
2. Install FFTW library (or use MKL's FFTW3 interface).
3. Check if LAPACK, BLAS, SCALAPACK and BLACS are provided and install if not.
4. Install optional performance libraries - ELPA (CPU and GPU), libxsmm (CPU).
5. Build CP2K and link to Libint, FFTW, LAPACK, BLAS, SCALAPACK and BLACS, and to relevant CUDA libraries if building for GPU.
Holly Judge's avatar
Holly Judge committed
<!--- (CP2K is built using a Fortran 2003 compiler and matching C compiler such as gfortran/gcc (version 4.6 and above) and compiled with GNU make. CP2K makes use of a variety of different libraries. Some are essential for running in parallel and others may be used to increase the performance. The steps to build CP2K are as follows:) -->
Holly Judge's avatar
Holly Judge committed
### Download the source code
Holly Judge's avatar
Holly Judge committed
     wget https://github.com/cp2k/cp2k/releases/download/v8.1.0/cp2k-8.1.tar.bz2
     bunzip2 cp2k-8.1.tar.bz2
     tar xvf cp2k-8.1.tar
     cd cp2k-8.1
Holly Judge's avatar
Holly Judge committed
### Install or locate libraries 
Holly Judge's avatar
Holly Judge committed
**LIBINT**
Holly Judge's avatar
Holly Judge committed
The following commands will uncompress and install the LIBINT library required for the UEABS benchmarks:
Holly Judge's avatar
Holly Judge committed
    wget https://github.com/cp2k/libint-cp2k/releases/download/v2.6.0/libint-v2.6.0-cp2k-lmax-4.tgz
    tar zxvf libint-v2.6.0-cp2k-lmax-4.tgz
    cd libint-v2.6.0-cp2k-lmax-4
    ./configure CC=mpicc CXX=mpicxx FC=mpif90 CFLAGS=$CFLAGS CXXFLAGS=$CFLAGS --enable-fortran --prefix=install_path 	               	 : must not be this directory
Holly Judge's avatar
Holly Judge committed
    make
    make install
Note: The environment variables ``CC`` and ``CXX`` are optional and can be used to specify the C and C++ compilers to use for the build.
**LIBXC**

    wget -O libxc-4.3.4.tar.gz https://www.tddft.org/programs/libxc/down.php?file=4.3.4/libxc-4.3.4.tar.gz
    tar xvf libxc-4.3.4.tar.gz
    CC=mpicc CXX=mpicxx FC=mpif90 CFLAGS=${CFLAGS} ./configure --prefix=install_path
    make
    make install
Holly Judge's avatar
Holly Judge committed
**FFTW**
Holly Judge's avatar
Holly Judge committed
    FFTW3	                                                       	: http://www.fftw.org or provided as an interface by MKL
Holly Judge's avatar
Holly Judge committed
**LAPACK & BLAS**
Holly Judge's avatar
Holly Judge committed
    Can be provided from:
Holly Judge's avatar
Holly Judge committed
    netlib	                                                      	: http://netlib.org/lapack & http://netlib.org/blas
    MKL	                                                      	: part of the Intel MKL installation
    LibSci                                                         	: installed on Cray platforms
    ATLAS	                                                      	: http://math-atlas.sf.net
    OpenBLAS                                                    	: http://www.openblas.net
    clBLAS	                                                        : http://gpuopen.com/compute-product/clblas/

**SCALAPACK and BLACS**

    Can be provided from:
Holly Judge's avatar
Holly Judge committed
    netlib	                                                       	: http://netlib.org/scalapack/
    MKL	                                                       	: part of the Intel MKL installation
    LibSci	                                                      	: installed on Cray platforms
Holly Judge's avatar
Holly Judge committed

**Optional libraries**

Holly Judge's avatar
Holly Judge committed
    ELPA	                                                       	: https://elpa.mpcdf.mpg.de/elpa-tar-archive (version 2020.05.001 required)
    libxsmm	                                                        : https://github.com/hfp/libxsmm (version 1.16.1 required)
**ELPA**

The following commands will uncompress and install ELPA for CPU build using MKL for Scalapack, Blas and Lapack

    wget https://elpa.mpcdf.mpg.de/software/tarball-archive/Releases/2020.05.001/elpa-2020.05.001.tar.gz
    tar xvf elpa-2020.05.001.tar.gz
    cd elpa-2020.05.001
    mkdir build-openmp
    cd build-openmp
    CC=mpicc CXX=mpicxx FC=mpif90            LIBS="-lmkl_scalapack_lp64 -lmkl_gf_lp64 -lmkl_sequential -lmkl_core \
                  -lmkl_blacs_openmpi_lp64 -lpthread -lm -ldl" CFLAGS="-march=native" \
                  ../configure --enable-openmp=yes  --enable-shared=no --prefix=install_path

   make
   make install 


Holly Judge's avatar
Holly Judge committed
### Create the arch file
Holly Judge's avatar
Holly Judge committed
Before compiling the choice of compilers, the library locations and compilation and linker flags need to be specified. This is done in an arch (architecture) file. Example arch files for a number of common architecture examples can be found inside the ``cp2k/arch`` directory. The names of these files match the pattern architecture.version (e.g., Linux-x86-64-gfortran.sopt). The case "version=psmp" corresponds to the hybrid MPI + OpenMP version that you should build to run the UEABS benchmarks. Machine specific examples can be found in the relevent subdirectory.
Holly Judge's avatar
Holly Judge committed
In most cases you need to create a custom arch file, either from scratch or by modifying an existing one that roughly fits the cpu type, compiler, and installation paths of libraries on your system. You can also consult https://dashboard.cp2k.org, which provides sample arch files as part of the testing reports for some platforms (click on the status field for a platform, and search for 'ARCH-file' in the resulting output).
Holly Judge's avatar
Holly Judge committed
As a guide for GNU compilers the following should be included in the ``arch`` file:
Holly Judge's avatar
Holly Judge committed
**Specification of which compiler and linker commands to use:**
Holly Judge's avatar
Holly Judge committed
    CC = gcc
    FC = mpif90
    LD = mpif90
    AR = ar -r
Holly Judge's avatar
Holly Judge committed
CP2K is primarily a Fortran code, so only the Fortran compiler needs to be MPI-enabled.
Holly Judge's avatar
Holly Judge committed
**Specification of the ``DFLAGS`` variable, which should include:**
Holly Judge's avatar
Holly Judge committed
	-D__parallel \	                                              	
	-D__SCALAPACK \	                                                
	-D__LIBINT \	
	-D__FFTW3 \    
	-D__LIBXC \     
    
    # Optional DFLAGS for linking performance libraries:
    
    -D__LIBXSMM \
Holly Judge's avatar
Holly Judge committed
    -D__ELPA=202005 \
Holly Judge's avatar
Holly Judge committed
    -D__MKL 		                                      	: if relying on MKL for ScaLAPACK and/or an FFTW interface
    
Holly Judge's avatar
Holly Judge committed
**Specification of compiler flags ``FCFLAGS`` (for gfortran):**
Holly Judge's avatar
Holly Judge committed
    FCFLAGS = $(DFLAGS) -ffree-form -fopenmp -std=f2008                                        : Required
    FCFLAGS = $(DFLAGS) -ffree-form -fopenmp -std=f2008 -O3 -ffast-math -funroll-loops         : Recommended

**Specification of the ``CFLAGS``**

    CFLAGS = $(DFLAGS) -fopenmp -std=c99                                     : Required
    CFLAGS = $(DFLAGS) -fopenmp -std=c99 -O3 -funroll-loops                  : Recommended
Holly Judge's avatar
Holly Judge committed

Holly Judge's avatar
Holly Judge committed
If you want to link any libraries containing header files you should pass the
Holly Judge's avatar
Holly Judge committed
path to the directory containing these to FCFLAGS and CFLAGS in the format 
Holly Judge's avatar
Holly Judge committed
``-I/path_to_include_dir``

    -I$(path_to_libint)/include 
Holly Judge's avatar
Holly Judge committed


**Specification of libraries to link to:**

Holly Judge's avatar
Holly Judge committed
    LIBS = -L$(path_to_libint)/lib -lint2                           : Required for LIBINT
           -L$(path_to_libxc)/lib -lxc90 -lxc03 -lxc                : Required for LIBXC
           -lfftw3 -lfftw3_threads -lz -ldl -lstdc++
Holly Judge's avatar
Holly Judge committed

If you use MKL to provide ScaLAPACK and/or an FFTW interface the LIBS variable should be used to pass the relevant flags provided by the MKL Link Line Advisor (https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor), which you should use carefully in order to generate the right options for your system.
Holly Judge's avatar
Holly Judge committed
### Build the executable
Holly Judge's avatar
Holly Judge committed
To build the hybrid MPI+OpenMP executable ``cp2k.psmp`` using ``your_arch_file.psmp`` run make in the cp2k directory.
Holly Judge's avatar
Holly Judge committed
 
Holly Judge's avatar
Holly Judge committed
    make -j N ARCH=your_arch_file VERSION=psmp	            	: on N threads
    make ARCH=your_arch_file VERSION=psmp	                     	: serially
Holly Judge's avatar
Holly Judge committed
The executable ``cp2k.psmp`` will then be located in:
Holly Judge's avatar
Holly Judge committed
    cp2k/exe/your_arch_file
Holly Judge's avatar
Holly Judge committed
### Compiling CP2K for CUDA enabled GPUs
Holly Judge's avatar
Holly Judge committed
The arch files for compiling CP2K for CUDA enabled GPUs can be found under the relavent machine example.
Holly Judge's avatar
Holly Judge committed
The additional steps for CUDA compilation are:
Holly Judge's avatar
Holly Judge committed
1. Load the cuda module.
2. Ensure that CUDA_PATH variable is set.
Holly Judge's avatar
Holly Judge committed
3. Add CUDA specific options to the arch file.
Holly Judge's avatar
Holly Judge committed
**Addtional required compiler and linker commands:**
Holly Judge's avatar
Holly Judge committed
    NVCC = nvcc
Holly Judge's avatar
Holly Judge committed
**Additional ``DFLAGS``:**
Holly Judge's avatar
Holly Judge committed
    -D__ACC -D__DBCSR_ACC -D__PW_CUDA
 
Holly Judge's avatar
Holly Judge committed
**Set ``NVFLAGS``:**
Holly Judge's avatar
Holly Judge committed
    NVFLAGS = $(DFLAGS) -O3 -arch sm_60
 
Holly Judge's avatar
Holly Judge committed
**Additional required libraries to link to:**
Holly Judge's avatar
Holly Judge committed
 
    -lcudart -lcublas -lcufft -lrt 
Holly Judge's avatar
Holly Judge committed
## Mechanics of Running Benchmark

The general way to run the benchmarks with the hybrid parallel executable is:

    export OMP_NUM_THREADS=X   
    parallel_launcher launcher_options path_to_/cp2k.psmp -i inputfile.inp -o logfile  

Where:

* The environment variable for the number of threads must be set before calling the executable.
* The parallel_launcher is mpirun, mpiexec, or some variant such as aprun on Cray systems or srun when using Slurm.
* launcher_options specifies parallel placement in terms of total numbers of nodes, MPI ranks/tasks, tasks per node, and OpenMP threads per task (which should be equal to the value given to OMP_NUM_THREADS). This is not necessary if parallel runtime options are picked up by the launcher from the job environment.
* You can try any combination of tasks per node and OpenMP threads per task to investigate absolute performance and scaling on the machine of interest.
* The inputfile usually has the extension .inp, and may specify within it further requried files (such as basis sets, potentials, etc.)
Holly Judge's avatar
Holly Judge committed
You can try any combination of tasks per node and OpenMP threads per task to investigate absolute performance and scaling on the machine of interest. For tier-1 systems the best performance is usually obtained with pure MPI, while for tier-0 systems the best performance is typically obtained using 1 MPI task per node with the number of threads being equal to the number of cores per node.
Holly Judge's avatar
Holly Judge committed
### UEABS benchmarks

**A) H2O-512**

* Ab initio molecular dynamics simulation of 512 water molecules (10 MD steps)
* Uses the Born-Oppenheimer approach via Quickstep DFT

**B) LiH-HFX**

* DFT energy calculation for a 216 atom LiH crystal
* Requires generation of initial wave function .wfn prior to run
* Run ``input_bulk_B88_3.inp`` to generate the wavefunction and then rename the resulting wfn file - ```cp LiH_bulk_3-RESTART.wfn B88.wfn```


**C) H2O-DFT-LS**

* Single energy calculation of 2048 water molecules
* Uses linear scaling DFT

Holly Judge's avatar
Holly Judge committed
Test Case | System     | Number of Atoms | Run type      | Description                                          | Location                        |
----------|------------|-----------------|---------------|------------------------------------------------------|---------------------------------|
a         | H2O-512    |   1236          | MD            | Uses the Born-Oppenheimer approach via Quickstep DFT | ``/tests/QS/benchmark/``        |
Holly Judge's avatar
Holly Judge committed
b         | LiH-HFX    |      216        | Single-energy | GAPW with hybrid Hartree-Fock exchange               | ``/tests/QS/benchmark_HFX/LiH`` |
Holly Judge's avatar
Holly Judge committed
c         | H2O-DFT-LS | 6144            | Single-energy | Uses linear scaling DFT                              | ``/tests/QS/benchmark_DM_LS``    |
 
More information in the form of a README and an example job script is included in each benchmark tar file.
Holly Judge's avatar
Holly Judge committed
## Verification of Results
Holly Judge's avatar
Holly Judge committed
The run walltime is reported near the end of logfile:
Holly Judge's avatar
Holly Judge committed
    grep "CP2K    " logfile | awk -F ' ' '{print $7}'
Holly Judge's avatar
Holly Judge committed
    

The expected energies in each case can be verified and should be
similar to the below in each case.

**A) H2O-512**

    grep 'Total energy:' logfile | awk -F ' ' '{print $3}'
    
    -8807.945767
    -8808.382808
    -8808.515922
    -8808.69591
    -8808.856357
    -8808.922371
    -8808.85672
    -8808.680214
    -8808.453006
    -8808.252216
    -8808.142547
Holly Judge's avatar
Holly Judge committed


**B) LiH-HFX**

    grep ' OT CG' logfile | awk -F ' ' '{print $7}

    -870.1543298
Holly Judge's avatar
Holly Judge committed


**C) H2O-DFT-LS**

    grep ENERGY logfile | awk -F ' ' '{print $9}'