# CP2K Build on CentOS 7

**URL:** <https://ask.cyberinfrastructure.org/t/cp2k-build-on-centos-7/1726>\
**Category:** Q&A\
**Tags:** qow, researcher, centos, cp2k\
**Created:** [February 2, 2021, 5:14pm UTC](https://ask.cyberinfrastructure.org/t/cp2k-build-on-centos-7/1726 "2021-02-02T17:14:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndanes](https://ask.cyberinfrastructure.org/user_avatar/ask.cyberinfrastructure.org/ndanes/32/768_2.png) [@ndanes](https://ask.cyberinfrastructure.org/u/ndanes)\
**Post date:** [February 2, 2021, 5:14pm UTC](https://ask.cyberinfrastructure.org/t/cp2k-build-on-centos-7/1726/1 "2021-02-02T17:14:31Z")

</div>

Hello! I have been struggling to build CP2K 7.1 on our clusters on one of our HPC clusters and I was wondering if people have had success with builds, depending on their toolchain.

Without getting into incredible detail of all the things I’ve tried, here is the build script I’ve put together (the modules loaded should be self explanatory). I should note that the CP2k 7.1 tarball was decompressed under /sw/apps/cp2k/7.1-gcc-mpich/.

```
#!/bin/bash
module load compilers/intel/2019 # for mkl
module load compilers/devtoolset/7 # gcc 7.3.0
module load mpi/mpich/3.0.4-gnu-nodep
module load utility/standard/cmake/3.16.2
mkdir -p /sw/BUILD/scratch/apps/cp2k/build
rm -rf /sw/apps/cp2k/7.1-gcc-mpich/tools/toolchain/build/
rm -rf /sw/apps/cp2k/7.1-gcc-mpich/tools/toolchain/install/
ulimit -s unlimited

export MAKEFLAGS='-j 12'

echo "Installing Toolchain"
cd /sw/apps/cp2k/7.1-gcc-mpich/tools/toolchain
bash install_cp2k_toolchain.sh --with-gcc=system --with-cmake=system --with-libxsmm=install --with-openblas=install --with-mpich=system \
--with-fftw=install --with-libxc=install --with-hdf5=install --with-elpa=install --with-reflapack=no --with-mkl=system --enable-omp --with-libxc=install --with-sirius=install

echo "Copying toolchain build over to arch"
cp /sw/apps/cp2k/7.1-gcc-mpich/tools/toolchain/install/arch/* /sw/apps/cp2k/7.1-gcc-mpich/arch/

#echo "Sourcing toolchain setup"
source /sw/apps/cp2k/7.1-gcc-mpich/tools/toolchain/install/setup

#echo "Building CP2K"
cd /sw/apps/cp2k/7.1-gcc-mpich
make ARCH=local VERSION="sopt sdbg ssmp popt pdbg psmp"

```

The toolchain builds fine, but I get an internal compiler error during the final build related to gfortran:

```
Error: The element in the structure constructor at (1), for pointer component ‘’ should be a POINTER or a TARGET
/beegfs/x86_64/sw/apps/cp2k/7.1-gcc-mpich/exts/dbcsr/src/utils/dbcsr_btree.F:31:46:

 $:ts
                                              1
Error: Pointer initialization target at (1) must have the SAVE attribute
gfortran: internal compiler error: Killed (program f951)

```

Note that the error above, may not be 1:1 with the build script I shared. It’s just one of cases that come up.

This seems to be related to this error:  
[[Bug fortran/89219] New: [gfortran 7.3] compiler throws internal compiler error: segmentation fault](https://gcc.gnu.org/pipermail/gcc-bugs/2019-February/652689.html)

I should note I’m trying to build this on a Skylake based nodes (e.g. Intel(R) Xeon(R) Gold 6148 CPU) if this helps with suggestions.

I’ve tried a newer version of GCC, as well as our system builds of OpenMPI, with all varying degrees of errors. Just wanted to some suggestions from folks who’ve had success building this program! Thanks!

---

<div class="post-metadata">

**Author:** ![dchaffin](https://ask.cyberinfrastructure.org/letter_avatar_proxy/v4/letter/d/e0b2c6/32.png) [@dchaffin](https://ask.cyberinfrastructure.org/u/dchaffin)\
**Post date:** [February 15, 2021, 5:12pm UTC](https://ask.cyberinfrastructure.org/t/cp2k-build-on-centos-7/1726/3 "2021-02-15T17:12:48Z")

</div>

According to [compile error in exts/dbcsr/src/utils/dbcsr\_btree.F · Issue #250 · cp2k/cp2k · GitHub](https://github.com/cp2k/cp2k/issues/250) , bug is fixed with 8.3 compiler (which is devtoolset-8).

---

<div class="post-metadata">

**Author:** ![Chrisreidy](https://ask.cyberinfrastructure.org/user_avatar/ask.cyberinfrastructure.org/chrisreidy/32/538_2.png) [@Chrisreidy](https://ask.cyberinfrastructure.org/u/Chrisreidy)\
**Post date:** [February 15, 2021, 3:47pm UTC](https://ask.cyberinfrastructure.org/t/cp2k-build-on-centos-7/1726/2 "2021-02-15T15:47:17Z")

</div>

Hi  
I made CP2K a while ago with minimal options and it built fine, but there were problems running it because it does not place files in the usual bin, lib, share directory structure. So the user reported it was not finding libraries like hdf5 and fftw. So I remade it and that took a while getting the right toolchain dependencies that would work.  
My environment is OpenHPC / Centos7 / GCC 8.3 / Openmpi3, AMD Rome. I only build with Intel, MPICH etc when there is a particular reason.  
So here are my relevant instructions:  
git clone --recursive [https://github.com/cp2k/cp2k.git](https://github.com/cp2k/cp2k.git) cp2k  
cd cp2k  
cd tools/toolchain && ./install\_cp2k\_toolchain.sh --with-cmake=system --with-openblas=system --with-fftw=system --with-hdf5=system --with-libxsmm=install --with-gsl=system --with-libxc=install --with-elpa=no --with-scalapack --with-spglib --with-sirius=no  
cp /opt/ohpc/admin/UAbuild/cp2k/cp2k/tools/toolchain/install/arch/\* /opt/ohpc/admin/UAbuild/cp2k/cp2k/arch/

# hack to find libsymspg.so.1

cp /opt/ohpc/admin/UAbuild/cp2k/cp2k/tools/toolchain/install/spglib-1.16.0/lib64/ /opt/ohpc/pub/apps/cp2k/${Ver}/lib  
source /opt/ohpc/admin/UAbuild/cp2k/cp2k/tools/toolchain/install/setup  
cd cp2k/  
make -j 4 ARCH=local VERSION=psmp  
make -j 4 test

[Next page](https://ask.cyberinfrastructure.org/t/cp2k-build-on-centos-7/1726.md?page=2)
