The most complete CP2K 7.1.0 installation tutorial in history

Introduction to the installation environment:
CPU: AMD
OS: CentOS 7
MPI: OpenMPI 4.0.4
GCC: 10.2.0

Really install from scratch (new machine, only OpenMPI and Gcc are installed). In theory, this method is applicable to all machines. There is no difficulty in installing OpenMPI and Gcc. The only thing you need to pay attention to is that you need to turn on an option when installing OpenMPI to support the syntax of the old version. Otherwise, some syntax errors may occur. You can only modify the source at that time. The code can be installed successfully, which is very troublesome.

Download the CP2K 7.1.0 source code, and view the required dependent libraries

The source code is on github , the point to note here is that you need to use the git command to download the source code

	$ git clone --recursive -b support/v7.1 https://github.com/cp2k/cp2k.git cp2k

If you download the .gz compressed package directly from Releases on the right side of the github page, you will be prompted that some files are missing when you start to compile. According to the prompt, you need to use the git command to download, which leads to the fact that if you did not use the git command to download, the folder after the compressed package is decompressed is not a git repository, so it cannot be downloaded.

Solution : Drop the .github folder from the git repository and place it in the folder you decompressed (no experiment, the theory is feasible)

Then execute

    $ git submodule update --init --recursive

This will automatically download the submodule

Check if there is any configuration file you need in the cp2k/arch folder. For example, the configuration file I need is Linux-x86-64-gfortran.psmp .

After opening, you can see the information of other packages required for this installation at the top, for example:

  • GFortran 7.4.0
  • MPICH 3.3
  • LAPACK 3.8.0
  • ScaLAPACK 2.0.2、
  • FFTW 3.3
  • Libint 2.6.0
  • Libxc 4.3.4
  • libxsmm 1.14
  • ELPA 2019.05.001
  • PLUMED 2.5.2
  • SPGLIB 1.12.2

The next thing we need to do is to download all the above packages in turn, and install them (super invincible huge pits!!!), follow the article step by step to avoid 99% of pits.

I will ignore all the downloading and decompression processes below (special cases will be explained in the text). After decompressing all the compressed packages, I will put them in the same directory. The installation steps are slightly more and cumbersome, and a certain amount of patience and care is required.

Install lapack-3.8.0

	$ cd lapack-3.8.0/
	$ cp make.inc.example make.inc
	$ vim make.inc
	# 修改下面几处
	CC      = mpicc
	CFLAGS = -O3 -fPIC
	FORTRAN = mpifort
	OPTS    = -O2 -frecursive -fallow-argument-mismatch -fPIC
	NOOPT   = -O0 -frecursive -fallow-argument-mismatch -fPIC
	LOADER   = mpifort
	LOADOPTS = -fallow-argument-mismatch -fPIC
	# 最下方还有一处需要更改
	BLASLIB = ../../libblas.a

It should be noted here that you need to add -fPIC after all the compilation options, otherwise you will be reminded to recompile later, and the last place that needs to be modified, here is librefblas.a. The lapack library is mostly used when compiling other software later using -lblas, if it is not modified, the usr/bin/ld: cannot find -lblas error will occur.

	$ make -j 32

After compiling, you can see three library files: libblas.a , liblapack.a and libtmglib.a .

Install scalapack-2.0.2

It seems that not compiling the library will not cause any errors when compiling CP2K, but just install it just in case.

	$ vim SLmake.inc
	# 修改下面几处
	FC            = mpif90
	CC            = mpicc
	# 最下方还有一处需要更改
	LIBS          = -L../lapack-3.8.0/ $(LAPACKLIB) $(BLASLIB)	

The last modification here is to add the path of lapack-3.8.0 just installed.

	$ make -j 32

After the compilation is complete, you can see libscalapack.a

Install fftw-3.3.8

	$ cd fftw-3.3.8
	$ ./configure --prefix=./install --enable-threads --enable-avx512 --enable-avx2 --enable-avx --enable-sse2
	$ make -j 32
	$ make install

It should be noted here that in ./configure, you must add the –enable-threads option, otherwise the libfftw3_threads.la library will be missing later.

Install libxc-4.3.4

Here I provide a shell script, which can be executed directly

#!/bin/bash
###############################################################################
# Copyright (c) Intel Corporation - All rights reserved.                      #
# This file is part of the XCONFIGURE project.                                #
#                                                                             #
# For information on the license, see the LICENSE file.                       #
# Further information: https://github.com/hfp/xconfigure/                     #
# SPDX-License-Identifier: BSD-3-Clause                                       #
###############################################################################
# Hans Pabst (Intel Corp.)
###############################################################################

if [ "" = "$1" ]; then PRFX=gnu-; else PRFX=$1-; shift; fi
HERE=$(cd $(dirname $0); pwd -P)
DEST=${HERE}/../libxc/${PRFX}skx

if [ ! -e ${HERE}/configure.ac ] || [ "${HERE}" != "$(pwd -P)" ]; then
  echo "Error: XCONFIGURE scripts must be located and executed in the application folder!"
  exit 1
fi

if [ "${HERE}" = "${DEST}" ]; then
  echo "Warning: LIBXC source directory equals installation folder!"
  read -p "Are you sure? Y/N" -n 1 -r
  if [[ ! $REPLY =~ ^[Yy]$ ]]; then
    exit 1
  fi
fi

CONFOPTS=""
TARGET="-mavx512f -mavx512cd -mavx512dq -mavx512bw -mavx512vl -mfma -L../lapack-3.8.0 -L../scalapack-2.0.2"

export FLAGS="-O3 ${TARGET}"
export LDFLAGS="-llapack -blas"
export CFLAGS="${FLAGS}"
export CXXFLAGS="${FLAGS}"
export FCFLAGS="${FLAGS}"
export LIBS=""

export AR="gcc-ar"
export FC="mpifort"
export CC="mpicc"
export CXX="mpicxx"

libtoolize
aclocal
autoheader
automake -a
autoconf

./configure \
  --prefix=./install \
  CC=mpicc CXX=mpicxx FC=mpifort \
  $*

Points to note here 1. Modify the compiler to mpi compiler, 2. You need to add the lapack and scalapack previously installed.
The source code of this script is at https://github.com/hfp/xconfigure/raw/master/config, but the original script will report an error when compiling version 4.3.4.

Copy it to the libxc-4.3.4 folder and save it as make.sh

	$ chmod +x make.sh
	$ ./make.sh
	$ make -j 32
	$ make install

Install spglib-1.12.2

There is nothing to pay attention to here.

	$ cd spglib-1.12.2
	$ mkdir _build
	$ cd _build
	$ cmake -DCMAKE_INSTALL_PREFIX="../install" ..
	$ make -j 32
	$ make install

Install elpa-2019.05.001

There is also provided a script that can be used, the use of reference install 4.3.4-libxc .


export LDFLAGS="-fPIC -L../lapack-3.8.0 -L../scalapack-2.0.2"
export CFLAGS="-march=knl -fPIC -L../lapack-3.8.0 -L../scalapack-2.0.2"
export CXXFLAGS="-march=knl -fPIC -L../lapack-3.8.0 -L../scalapack-2.0.2"
export FCFLAGS="-march=knl -fPIC -fallow-argument-mismatch -L../lapack-3.8.0 -L../scalapack-2.0.2 -L/path/to/zlib/lib"
export LIBS="-llapack -lblas"

export AR="gcc-ar"
export FC="mpifort"
export CC="mpicc"
export CXX="mpicxx"

./configure 
	--enable-openmp \
	--enable-shared=no \
	--disable-sse --disable-sse-assembly \
	--disable-avx --disable-avx2 \
	--prefix=./install 

The compiler, installation path, and compilation options such as LDFLAGS need to be modified here. It should be noted that since the machine installed this time is AMD's cpu, the -march=knl option is required, otherwise an error will be reported: avx512. . . . (I don't remember the specific error).

After executing the script to perform the make -j 32 , the make install to

Install gsl-2.6

There is nothing to pay attention to here.

	$ cd spglib-1.12.2
	$ ./configure --prefix=./install CC=mpicc CXX=mpicxx FC=mpifort 
	$ make -j 32
	$ make install

Install plumed2-2.5.5

Here only need to pay attention to add the path of lapack, fftw and gsl.

	$ cd spglib-1.12.2
	$ ./configure --prefix=./install CXX=mpicxx CC=mpicc LDFLAGS="-L../lapack-3.8.0 -L../fftw-3.3.8/install/lib -L../gsl-2.6/install/lib" LIBS="-llapack -lblas -lfftw3" --enable-gsl
	$ make -j 32
	$ make install

Install libxsmm-1.16

$ cd libxsmm-1.16
$ make INTRINSICS=1  SSE=2 AVX=2 ROW_MAJOR=0 INDICES_M="$(echo $(seq 1 24))" INDICES_N="$(echo $(seq 1 24))" INDICES_K="$(echo $(seq 1 24))"

Special attention should be paid to the INTRINSICS=1 option, because the high version of gcc is used here, and the specific instructions are explained on the libxsmm official website.

If you are using a lower version of gcc, adding this option may report an error, just delete this option.

Install boost-1_74_0

If you have boost in your system, and the version is >= 1.30, you don't need to install boost.
The installation process of boost is different from other software, but there is nothing special to pay attention to.

	$ cd boost_1_74_0/
	$ ./bootstrap.sh --with-libraries=all --with-toolset=gcc
	# 这时候会出现一个新的文件 b2
	$ ./b2 install --prefix=./install

Install gmp-6.2.0

Some students may have questions here: Why install gmp? Haven't we already installed gcc when we installed it?

Reason: The gcc in the system is compiled by the administrator, and gmp has been installed, but the C++ syntax is not supported during the installation process, which leads to an error when we use mpicxx to compile the program. If your system already contains libgmpxx.so in gmp/lib , then there is no need to reinstall gmp here.

The process of installing gmp is not complicated.

	$ cd gmp-6.2.0
	$ ./configure --prefix=./install  --enable-cxx
	$ make -j 32
	$ make install

Be sure to add the -enable-cxx option, otherwise the above error will still occur.

Install libint-v2.6.0

This is where I stepped on the most pits, please be sure to follow the steps below to install.

  1. Download
    I did not expect to start the download overturned, the official version libint on github does not apply to cp2k-7.1.0 installed, we must use a specific installation package cp2k provided to compile https://github.com/cp2k /libint-cp2k/releases/tag/v2.6.0.

    According to netizens, the official version will also fail to compile. It may be that I was lucky enough to compile it once.

    The version I downloaded is libint-v2.6.0-cp2k-lmax-6.tgz . There are a total of four official versions. I chose one at random and it succeeded. I'm so touched.

    Don’t write the wrong Source Code here, there are only 3 unrelated files (I don’t want to complain anymore)

  2. Compilation
    Congratulations when you are here, there are basically no other questions later, let's continue!

	$ cd libint-v2.6.0-cp2k-lmax-6
	$ ./configure --prefix=./install  --enable-fortran CC=mpicc CXX=mpicxx CXXFLAGS="-O3 -I../gmp-6.2.0/install/include -L../gmp-6.2.0/install/lib -L/apps/software/zlib/1.2.11/gcc/10.2.0/lib" CFLAGS="-O3 -I../gmp-6.2.0/install/include -L../gmp-6.2.0/install/lib -L/apps/software/zlib/1.2.11/gcc/10.2.0/lib" --with-boost=../boost_1_74_0/install FC=mpifort FCFLAGS="-O3 -I../gmp-6.2.0/install/include -L../gmp-6.2.0/install/lib -L/apps/software/zlib/1.2.11/gcc/10.2.0/lib"
	$ make -j 32
	$ make install

The zlib used here comes with the system. If you don't have zlib in your system, you can install one yourself, which is very simple.

Install CP2K

Finally, our protagonist is on the stage. The installation process is actually very fast and simple, but the cumbersome steps here are really prohibitive.

First of all, we modify the required configuration file, I am using arch/Linux-x86-64-gfortran.psmp here

CC          = mpicc
FC          = mpif90
LD          = mpif90
AR          = ar -r

include     /path/to/plumed2-2.5.5/install/lib/plumed/src/lib/Plumed.inc.static

ELPA_VER    = 2019.05.001
ELPA_INC    =  /path/to/elpa-2019.05.001/install/include/elpa_openmp-$(ELPA_VER)
ELPA_LIB    =  /path/to/elpa-2019.05.001/install/lib

FFTW_INC    =  /path/to/fftw-3.3.8/install/include
FFTW_LIB    =  /path/to/fftw-3.3.8/install/lib

LIBINT_INC  =  /path/to/libint-v2.6.0-cp2k-lmax-6/install/include
LIBINT_LIB  =  /path/to/libint-v2.6.0-cp2k-lmax-6/install/lib

LIBXC_INC   =  /path/to/libxc-4.3.4/install/include
LIBXC_LIB   =  /path/to/libxc-4.3.4/install/lib

LIBXSMM_INC =  /path/to/libxsmm-1.16/include
LIBXSMM_LIB =  /path/to/libxsmm-1.16/lib

SPGLIB_INC  =  /path/to/spglib-1.12.2/install/include
SPGLIB_LIB  =  /path/to/spglib-1.12.2/install/lib

# 下面这些是原来没有的,请自行添加

LAPACK_LIB  =  /path/to/lapack-3.8.0
SCALA_LIB   =  /path/to/scalapack-2.0.2
GSLBLAS_LIB =  /path/to/gsl-2.6/install/lib
GSLBLAS_INC =  /path/to/gsl-2.6/install/include
ZLIB_LIB    =  /path/to/zlib-1.2.11/lib
PLUMED_LIB  =  /path/to/plumed2-2.5.5/install/lib
PLUMED_INC  =  /path/to/plumed2-2.5.5/install/include


CFLAGS      = -O2 -g -mtune=native

DFLAGS      = -D__ELPA -D__FFTW3 -D__LIBINT -D__LIBXC -D__LIBXSMM
DFLAGS     += -D__MPI_VERSION=3 -D__PLUMED2 -D__SPGLIB
DFLAGS     += -D__parallel -D__SCALAPACK

FCFLAGS     = $(CFLAGS) $(DFLAGS)
FCFLAGS    += -ffree-form -ffree-line-length-none
FCFLAGS    += -fopenmp -fallow-argument-mismatch
FCFLAGS    += -ftree-vectorize -funroll-loops -std=f2008
FCFLAGS    += -I$(ELPA_INC)/elpa -I$(ELPA_INC)/modules
FCFLAGS    += -I$(FFTW_INC) -I$(LIBINT_INC) -I$(LIBXC_INC) -I$(LIBXSMM_INC) -I$(GSLBLAS_INC) -I$(PLUMED_INC) -I$(SPGLIB_INC)

LDFLAGS     = $(FCFLAGS) -static-libgfortran

LIBS        = -L$(PLUMED_LIB) -L$(GSLBLAS_LIB) -L$(ZLIB_LIB) -lgsl -lgslcblas -lz -L$(LIBXSMM_LIB) -L$(FFTW_LIB)
LIBS       += $(ELPA_LIB)/libelpa_openmp.a
LIBS       += $(LIBXC_LIB)/libxcf03.a
LIBS       += $(LIBXC_LIB)/libxc.a
LIBS       += $(LIBINT_LIB)/libint2.a
LIBS       += $(SPGLIB_LIB)/libsymspg.a
LIBS       += $(LIBXSMM_LIB)/libxsmmf.a
LIBS       += $(LIBXSMM_LIB)/libxsmm.a
LIBS       += $(FFTW_LIB)/libfftw3.a
LIBS       += $(FFTW_LIB)/libfftw3_threads.a
LIBS       += $(SCALA_LIB)/libscalapack.a
LIBS       += $(LAPACK_LIB)/liblapack.a
LIBS       += $(LAPACK_LIB)/libblas.a
LIBS       += -ldl -lpthread -lstdc++

The above configuration file only needs to change /path/to to your own address.

 	$ make ARCH=Linux-x86-64-gfortran VERSION=psmp -j 32

You may be prompted to execute a git command, just execute the download directly. If the machine cannot be connected to the Internet, you can upload it again after the execution is completed in a networked environment.

Next, you just need to wait quietly for the installation to complete.

After the installation is complete, you can see the executable file cp2k.psmp in the exe/Linux-x86-64-gfortran folder

At this point, the installation is all over

use

All the above installed dependent libraries/lib folders need to be added to LD_LIBRARY_PATH, and dependent libraries/bin must be added to PATH

Tear eyes, sprinkle flowers QAQ

The following is a technical summary

I don’t remember where the following error occurred, but the solution can still be used.

  1. missing'(' before “__has_include” operand
    find the file where the error occurred, adjust the if statement in it, mainly to annotate the statement containing __has_include, but still need to keep the judgment result accurate.

  2. can not find libint_f.mod
    reasons for this error is that you are using the libint official, the solution is referenced article install libint a re-install.

  3. Undefined reference to'dfftw_plan_with_nthreads_'
    The reason for this error is that –enable-threads was not added when fftw was installed . The solution is to reinstall fftw

  4. Error when running after compiling: Error in `cp2k-7.1/exe/Linux-x86-64-gfortran/cp2k.psmp': munmap_chunk(): invalid pointer: 0x000000000e9d1800
    This error is when compiling the elpa library without adding –enable- The openmp option, a few days ago (2020.09.27) I was so confused by this error, I don't know the reason. I did not add this option when compiling the elpa library, and then changed the libelpa_openmp.a in the arch/Linux-x86-64-gfortran.psmp configuration file to libelpa.a . The compilation passed, but it just couldn't run. It took two days to find the cause of this error. It hurts too much.

Please indicate the source for reprinting, thank you.

Guess you like

Origin blog.csdn.net/qq_32115939/article/details/108751525