CP2K at NSC


Level of support

Tier 2 NSC has only limited experience with this software, but we will try to help as much as possible. We have ran some tests, for example, if the program comes with a test suite, but they may be far from exhaustive. We will try to install and test new versions, as soon as we can.

Please see the page describing our software support categories for more information.
You can also contact support@nsc.liu.se for further information.

CP2K is a program to perform atomistic and molecular simulations of solid state, liquid, molecular, and biological systems. It provides a general framework for different methods such as e.g., density functional theory (DFT) using a mixed Gaussian and plane waves approach (GPW) and classical pair and many-body potentials.

How to run

Load the CP2K module corresponding to the version you want to use. For instance

module load cp2k/2.3

Then run the launcher script, giving the input file as the first (and only) argument and redirect the output to desired output file.

cp2k.run inputfile.inp > outputfile.out

For cp2k version 2.3, the runscript is influenced by the environment variable OMP_NUM_THREADS, which by default is set to 4. Setting this variable to 1 turns off OpenMP parallelism off entirely, while setting it to 16 on Triolith will maximise OpenMP parallelism and minimise node memory usage. This is done at the expense of time of execution. The default of 4 is set with respect to execution time and memory footprint only. Changing the OMP_NUM_THREADS variable can be done like

export OMP_NUM_THREADS=8

and can be set in the batch job sumission file before invoking the CP2K run script.

Example batch script

A minimum batch script for running CP2K version 2.3 looks like this:

#!/bin/bash
#SBATCH -N 4
#SBATCH -t 4:00:00
#SBATCH -J jobname
#SBATCH --exclusive
#SBATCH -A SNIC-xxx-yyy

module load cp2k/2.3
cp2k.run inputfile.inp > outputfile.out # This example assumes you submit this script from your working directory

(Note that you should edit the jobname, account number, number of nodes and requested walltime before submitting.)

Running your CP2K simulation in this manner will make use of all CPU cores accessible within your job. In the above example running on Triolith 4 * 16 CPU cores would be used, 16 MPI tasks à 4 OpenMP threads.

To provide a better launch and performance of cp2k versions following v. 2.3 the batch script is best modified as follows:

#!/bin/bash
#SBATCH -N 4  # Allocates 4 nodes
#SBATCH -c 4  # OPTIONAL. Use four cores per MPI rank. If you want to run OpenMP+MPI hybrid cp2k.
#SBATCH -t 4:00:00
#SBATCH -J jobname
#SBATCH --exclusive
#SBATCH -A SNIC-xxx-yyy

# OPTIONAL. Should be set equal to the "-c" argument to SBATCH above. Omit this if you've omitted the "-c" flag to SBATCH above.
export OMP_NUM_THREADS=4    

module load cp2k/2.4 # for instance
cp2k.run inputfile.inp > outputfile.out

The run script will start an appropriate number of ranks within the job in the example. The number of ranks can also be set explicitly of course using the “-n” option to SBATCH. The crucial thing is to make sure the argument to “-c” is equal to the OMP_NUM_THREADS value if you intend to use the OpenMP+MPI hybrid capabilities. If not, just omit the optional lines in the example batch script.

Known problems

  • None so far.