forked from comp-chem/cp2k-c
Compare commits
2 commits
main
...
old_versio
| Author | SHA1 | Date | |
|---|---|---|---|
| 41a835d68d | |||
| 97f109d458 |
9 changed files with 3078 additions and 0 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -110,6 +110,9 @@ auto-save-list
|
|||
tramp
|
||||
.\#*
|
||||
|
||||
### VS Code ###
|
||||
.vscode
|
||||
|
||||
# Org-mode
|
||||
.org-id-locations
|
||||
*_archive
|
||||
|
|
|
|||
150
Makefile
Normal file
150
Makefile
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
.SUFFIXES: .dep .o .cu .c
|
||||
SHELL = /bin/sh
|
||||
|
||||
CP2KHOME := $(PWD)/..
|
||||
ARCH := $(shell $(CP2KHOME)/tools/get_arch_code)
|
||||
LIB1 = cp2k_base_lib
|
||||
LIB2 = cp2k_fft_lib
|
||||
LIBCP2K = cp2k_lib
|
||||
export VERSION=sopt
|
||||
export WHAT =_progr
|
||||
|
||||
### Dependent variables ###
|
||||
|
||||
ARCHDIR = $(CP2KHOME)/arch
|
||||
DOCDIR = $(CP2KHOME)/doc
|
||||
MAINEXEDIR = $(CP2KHOME)/exe
|
||||
MAINLIBDIR = $(CP2KHOME)/lib
|
||||
MAINOBJDIR = $(CP2KHOME)/obj
|
||||
PRETTYOBJDIR = $(CP2KHOME)/obj/prettified
|
||||
TOOLDIR = $(OBJDIR)/tools
|
||||
TOOLSRC = $(CP2KHOME)/tools
|
||||
SRCDIR = $(CP2KHOME)/src
|
||||
SRCDIRS = $(SRCDIR):$(SRCDIR)/lib:$(TOOLSRC)/metadyn:$(CP2KHOME)/cuda_tools
|
||||
MAKEFILE = $(CP2KHOME)/makefiles/Makefile
|
||||
MACHINEDEFS = $(ARCHDIR)/$(ARCH).$(VERSION)
|
||||
PROG = $(EXEDIR)/cp2k.$(VERSION)
|
||||
CP2KSHELL = $(EXEDIR)/cp2k_shell.$(VERSION)
|
||||
FES = $(EXEDIR)/fes.$(VERSION)
|
||||
EXEDIR = $(MAINEXEDIR)/$(ARCH)
|
||||
LIBDIR = $(MAINLIBDIR)/$(ARCH)
|
||||
OBJDIR = $(MAINOBJDIR)/$(ARCH)
|
||||
OBJECTDEFS = $(SRCDIR)/OBJECTDEFS
|
||||
LIBOBJECTDEFS= $(SRCDIR)/lib/OBJECTDEFS
|
||||
LIBNVOBJECTDEFS= $(CP2KHOME)/cuda_tools/NVOBJECTDEFS
|
||||
LIB1_ARCHIVE = $(LIBDIR)/$(VERSION)/lib$(LIB1).a
|
||||
LIB2_ARCHIVE = $(LIBDIR)/$(VERSION)/lib$(LIB2).a
|
||||
LIB_CP2K_ARCHIVE = $(LIBDIR)/$(VERSION)/lib$(LIBCP2K).a
|
||||
SRCENTRY = $(wildcard $(SRCDIR)/CVS/Entr*)
|
||||
FESOBJECTDEFS = $(TOOLSRC)/metadyn/OBJECTDEFS
|
||||
DOXYGENDIR = $(DOCDIR)/doxygen
|
||||
|
||||
### Definition of the multiple targets ###
|
||||
#
|
||||
VERSION_TARGETS = sopt sdbg popt pdbg ssmp psmp
|
||||
#
|
||||
# uses an ugly trick, these are disguised as file names, the directory (@D) part
|
||||
# is used as a version, the file (@F) part is used as the target.
|
||||
#
|
||||
LIB_TARGETS = $(addsuffix /lib ,$(VERSION_TARGETS))
|
||||
ALL_TARGETS = $(addsuffix /all ,$(VERSION_TARGETS))
|
||||
CLEAN_TARGETS = $(addsuffix /clean ,$(VERSION_TARGETS)) $(addsuffix /realclean
|
||||
,$(VERSION_TARGETS))
|
||||
|
||||
.PHONY : _all libs _progr _lib build clean realclean distclean $(CLEAN_TARGETS)\
|
||||
$(ALL_TARGETS) $(LIB_TARGETS) $(VERSION_TARGETS) fes dirs deptool
|
||||
|
||||
### Master rules ###
|
||||
build: dirs deptool
|
||||
$(MAKE) -C $(SRCDIR) -f $(MAKEFILE) all.dep
|
||||
$(MAKE) -C $(SRCDIR)/lib -f $(MAKEFILE) lib.dep
|
||||
$(MAKE) -C $(OBJDIR)/$(VERSION) -f $(MAKEFILE) $(WHAT)
|
||||
|
||||
fes: dirs deptool
|
||||
$(MAKE) -C $(TOOLSRC)/metadyn/ -f $(MAKEFILE) fes.dep
|
||||
$(MAKE) -C $(OBJDIR)/$(VERSION) -f $(MAKEFILE) VERSION=$(VERSION) $(FES)
|
||||
|
||||
dirs:
|
||||
@mkdir -p $(EXEDIR)
|
||||
@mkdir -p $(LIBDIR)/$(VERSION)
|
||||
@mkdir -p $(TOOLDIR)
|
||||
@mkdir -p $(OBJDIR)/$(VERSION)
|
||||
@mkdir -p $(PRETTYOBJDIR)
|
||||
|
||||
realpretty: prettyclean pretty
|
||||
|
||||
pretty: dirs
|
||||
$(MAKE) -C $(SRCDIR) -f $(MAKEFILE) _pretty
|
||||
|
||||
deptool: dirs
|
||||
$(MAKE) -C $(TOOLDIR) -f $(MAKEFILE) makedepf90
|
||||
|
||||
libs:
|
||||
$(MAKE) -f $(MAKEFILE) VERSION=$(VERSION) WHAT=_lib build
|
||||
all:
|
||||
$(MAKE) -f $(MAKEFILE) VERSION=$(VERSION) WHAT=_all build
|
||||
progr:
|
||||
$(MAKE) -f $(MAKEFILE) VERSION=$(VERSION) WHAT=_progr build
|
||||
cpshell:
|
||||
$(MAKE) -f $(MAKEFILE) VERSION=$(VERSION) WHAT=_cpshell build
|
||||
|
||||
#
|
||||
# on a parallel build only one task should go a build the deptool
|
||||
#
|
||||
$(VERSION_TARGETS): dirs deptool
|
||||
$(MAKE) -f $(MAKEFILE) VERSION=$@ build
|
||||
|
||||
$(CLEAN_TARGETS):
|
||||
$(MAKE) -f $(MAKEFILE) VERSION=$(@D) $(@F)
|
||||
|
||||
$(ALL_TARGETS) $(LIB_TARGETS):
|
||||
$(MAKE) -f $(MAKEFILE) VERSION=$(@D) WHAT=_$(@F) build
|
||||
#
|
||||
# here we try to include all the objects that might need considering
|
||||
#
|
||||
|
||||
include $(OBJECTDEFS)
|
||||
include $(LIBOBJECTDEFS)
|
||||
include $(FESOBJECTDEFS)
|
||||
include $(MACHINEDEFS)
|
||||
include $(LIBNVOBJECTDEFS)
|
||||
|
||||
OBJECTS = $(OBJECTS_GENERIC) $(OBJECTS_ARCHITECTURE)
|
||||
FESOBJS = $(FESOBJ) $(OBJECTS_ARCHITECTURE)
|
||||
|
||||
# Cuda specific instructions
|
||||
ifneq ($(NVCC),)
|
||||
LIBNV_ARCHIVE= $(LIBDIR)/$(VERSION)/libcp2k_cuda.a
|
||||
endif
|
||||
|
||||
# Define the whole bunch of libraries needed
|
||||
ALL_LIB = $(LIB_CP2K_ARCHIVE) $(LIB2_ARCHIVE) $(LIB1_ARCHIVE) $(LIBNV_ARCHIVE)
|
||||
|
||||
#
|
||||
# some practical variables for the build.
|
||||
# note that the last cvs entry is not necessarily the most recent
|
||||
#
|
||||
ifeq ($(CPPSHELL),)
|
||||
CPPSHELL := -D__COMPILE_ARCH="\"$(ARCH)\""\
|
||||
-D__COMPILE_DATE="\"$(shell date)\""\
|
||||
-D__COMPILE_HOST="\"$(shell hostname)\""\
|
||||
-D__COMPILE_LASTCVS="\"$(shell tail -n1 $(SRCDIR)/CVS/Entries)\""
|
||||
endif
|
||||
|
||||
ifneq ($(CPP),)
|
||||
#
|
||||
# always add the SRCDIR to the include path (-I here might not be portable)
|
||||
#
|
||||
CPPFLAGS += $(CPPSHELL) -I$(SRCDIR)
|
||||
else
|
||||
FCFLAGS += $(CPPSHELL)
|
||||
endif
|
||||
|
||||
|
||||
### Slave rules ###
|
||||
vpath %.h $(SRCDIRS)
|
||||
vpath %.c $(SRCDIRS)
|
||||
vpath %.cpp $(SRCDIRS)
|
||||
vpath %.dep $(OBJDIR)/$(VERSION)
|
||||
vpath %.pretty $(PRETTYOBJDIR)
|
||||
vpath %.cu $(SRCDIRS)
|
||||
533
src/admm_dm_methods.cpp
Normal file
533
src/admm_dm_methods.cpp
Normal file
|
|
@ -0,0 +1,533 @@
|
|||
/*--------------------------------------------------------------------------------------------------
|
||||
CP2K: A general program to perform molecular dynamics simulations
|
||||
Copyright 2000-2023 CP2K developers group <https://cp2k.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
--------------------------------------------------------------------------------------------------*/
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief Contains ADMM methods which only require the density matrix
|
||||
\par History
|
||||
11.2014 created [Ole Schuett]
|
||||
\author Ole Schuett
|
||||
***************************************************************************************************/
|
||||
|
||||
#include "./base/base_uses.h"
|
||||
|
||||
class admm_dm_methods {
|
||||
|
||||
public:
|
||||
void admm_dm_calc_rho_aux(struct qs_environment_type);
|
||||
void admm_dm_merge_ks_matrix(struct qs_environment_type);
|
||||
|
||||
private:
|
||||
char *moduleN = "admm_dm_methods";
|
||||
|
||||
};
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief Entry methods: Calculates auxiliary density matrix from primary one.
|
||||
\param qs_env ...
|
||||
\author Ole Schuett
|
||||
***************************************************************************************************/
|
||||
void admm_dm_methods::admm_dm_calc_rho_aux(struct qs_environment_type *qs_env)
|
||||
{
|
||||
|
||||
char *routineN = "admm_dm_calc_rho_aux";
|
||||
|
||||
int handle;
|
||||
struct admm_dm_type *admm_dm;
|
||||
|
||||
NULLIFY (admm_dm);
|
||||
timeset(routineN, handle);
|
||||
get_admm_env(qs_env.admm_env, admm_dm=admm_dm);
|
||||
|
||||
SELECT CASE (admm_dm.method)
|
||||
CASE (do_admm_basis_projection)
|
||||
CALL map_dm_projection(qs_env)
|
||||
|
||||
CASE (do_admm_blocked_projection)
|
||||
CALL map_dm_blocked(qs_env)
|
||||
|
||||
CASE DEFAULT
|
||||
CPABORT("admm_dm_calc_rho_aux: unknown method")
|
||||
END SELECT
|
||||
|
||||
if (admm_dm.purify) purify_mcweeny(qs_env);
|
||||
|
||||
update_rho_aux(qs_env);
|
||||
|
||||
timestop(handle);
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief Entry methods: Merges auxiliary Kohn-Sham matrix into primary one.
|
||||
\param qs_env ...
|
||||
\author Ole Schuett
|
||||
***************************************************************************************************/
|
||||
void admm_dm_methods::admm_dm_merge_ks_matrix(struct qs_environment_type *qs_env)
|
||||
{
|
||||
char *routineN = "admm_dm_merge_ks_matrix";
|
||||
|
||||
int handle;
|
||||
struct admm_dm_type *admm_dm;
|
||||
struct dbcsr_p_type *matrix_ks_merge;
|
||||
|
||||
timeset(routineN, handle);
|
||||
NULLIFY (admm_dm, matrix_ks_merge);
|
||||
|
||||
get_admm_env(qs_env.dmm_env, admm_dm=admm_dm);
|
||||
|
||||
IF (admm_dm.purify) THEN
|
||||
CALL revert_purify_mcweeny(qs_env, matrix_ks_merge)
|
||||
ELSE
|
||||
CALL get_admm_env(qs_env.admm_env, matrix_ks_aux_fit=matrix_ks_merge)
|
||||
END IF
|
||||
|
||||
SELECT CASE (admm_dm.method)
|
||||
CASE (do_admm_basis_projection)
|
||||
CALL merge_dm_projection(qs_env, matrix_ks_merge)
|
||||
|
||||
CASE (do_admm_blocked_projection)
|
||||
CALL merge_dm_blocked(qs_env, matrix_ks_merge)
|
||||
|
||||
CASE DEFAULT
|
||||
CPABORT("admm_dm_merge_ks_matrix: unknown method")
|
||||
END SELECT
|
||||
|
||||
IF (admm_dm.purify) &
|
||||
CALL dbcsr_deallocate_matrix_set(matrix_ks_merge)
|
||||
|
||||
CALL timestop(handle)
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief Calculates auxiliary density matrix via basis projection.
|
||||
\param qs_env ...
|
||||
\author Ole Schuett
|
||||
***************************************************************************************************/
|
||||
void admm_dm_methods::map_dm_projection(qs_env)
|
||||
{
|
||||
TYPE(qs_environment_type), POINTER :: qs_env
|
||||
|
||||
INTEGER :: ispin
|
||||
LOGICAL :: s_mstruct_changed
|
||||
REAL(KIND=dp) :: threshold
|
||||
TYPE(admm_dm_type), POINTER :: admm_dm
|
||||
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s_aux, matrix_s_mixed, rho_ao, &
|
||||
rho_ao_aux
|
||||
TYPE(dbcsr_type) :: matrix_s_aux_inv, matrix_tmp
|
||||
TYPE(dft_control_type), POINTER :: dft_control
|
||||
TYPE(qs_rho_type), POINTER :: rho, rho_aux
|
||||
|
||||
NULLIFY (dft_control, admm_dm, matrix_s_aux, matrix_s_mixed, rho, rho_aux)
|
||||
NULLIFY (rho_ao, rho_ao_aux)
|
||||
|
||||
CALL get_qs_env(qs_env, dft_control=dft_control, s_mstruct_changed=s_mstruct_changed,
|
||||
rho=rho)
|
||||
CALL get_admm_env(qs_env.admm_env, matrix_s_aux_fit=matrix_s_aux, rho_aux_fit=rho_aux, &
|
||||
matrix_s_aux_fit_vs_orb=matrix_s_mixed, admm_dm=admm_dm)
|
||||
|
||||
CALL qs_rho_get(rho, rho_ao=rho_ao)
|
||||
CALL qs_rho_get(rho_aux, rho_ao=rho_ao_aux)
|
||||
|
||||
IF (s_mstruct_changed) THEN
|
||||
! Calculate A = S_aux^(-1) * S_mixed
|
||||
CALL dbcsr_create(matrix_s_aux_inv, template=matrix_s_aux[0].matrix, matrix_type="N")
|
||||
threshold = MAX(admm_dm.eps_filter, 1.0e-12_dp)
|
||||
CALL invert_Hotelling(matrix_s_aux_inv, matrix_s_aux[0].matrix, threshold)
|
||||
|
||||
IF (.NOT. ASSOCIATED(admm_dm.matrix_A)) THEN
|
||||
ALLOCATE (admm_dm.matrix_A)
|
||||
CALL dbcsr_create(admm_dm.matrix_A, template=matrix_s_mixed[0].matrix, matrix_type="N")
|
||||
END IF
|
||||
CALL dbcsr_multiply("N", "N", 1.0_dp, matrix_s_aux_inv, matrix_s_mixed[0].matrix, &
|
||||
0.0_dp, admm_dm.matrix_A)
|
||||
CALL dbcsr_release(matrix_s_aux_inv)
|
||||
END IF
|
||||
|
||||
! Calculate P_aux = A * P * A^T
|
||||
CALL dbcsr_create(matrix_tmp, template=admm_dm.matrix_A)
|
||||
DO ispin = 1, dft_control.nspins
|
||||
CALL dbcsr_multiply("N", "N", 1.0_dp, admm_dm.matrix_A, rho_ao(ispin).matrix, &
|
||||
0.0_dp, matrix_tmp)
|
||||
CALL dbcsr_multiply("N", "T", 1.0_dp, matrix_tmp, admm_dm.matrix_A, &
|
||||
0.0_dp, rho_ao_aux(ispin).matrix)
|
||||
END DO
|
||||
CALL dbcsr_release(matrix_tmp);
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief Calculates auxiliary density matrix via blocking.
|
||||
\param qs_env ...
|
||||
\author Ole Schuett
|
||||
***************************************************************************************************/
|
||||
void admm_dm_methods::map_dm_blocked(qs_env)
|
||||
{
|
||||
TYPE(qs_environment_type), POINTER :: qs_env
|
||||
|
||||
INTEGER :: blk, iatom, ispin, jatom
|
||||
LOGICAL :: found
|
||||
REAL(dp), DIMENSION(:, :), POINTER :: sparse_block, sparse_block_aux
|
||||
TYPE(admm_dm_type), POINTER :: admm_dm
|
||||
TYPE(dbcsr_iterator_type) :: iter
|
||||
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho_ao, rho_ao_aux
|
||||
TYPE(dft_control_type), POINTER :: dft_control
|
||||
TYPE(qs_rho_type), POINTER :: rho, rho_aux
|
||||
|
||||
NULLIFY (dft_control, admm_dm, rho, rho_aux, rho_ao, rho_ao_aux)
|
||||
|
||||
CALL get_qs_env(qs_env, dft_control=dft_control, rho=rho)
|
||||
CALL get_admm_env(qs_env.admm_env, rho_aux_fit=rho_aux, admm_dm=admm_dm)
|
||||
|
||||
CALL qs_rho_get(rho, rho_ao=rho_ao)
|
||||
CALL qs_rho_get(rho_aux, rho_ao=rho_ao_aux)
|
||||
|
||||
! ** set blocked density matrix to 0
|
||||
DO ispin = 1, dft_control.nspins
|
||||
CALL dbcsr_set(rho_ao_aux(ispin).matrix, 0.0_dp)
|
||||
! ** now loop through the list and copy corresponding blocks
|
||||
CALL dbcsr_iterator_start(iter, rho_ao(ispin).matrix)
|
||||
DO WHILE (dbcsr_iterator_blocks_left(iter))
|
||||
CALL dbcsr_iterator_next_block(iter, iatom, jatom, sparse_block, blk)
|
||||
IF (admm_dm.block_map(iatom, jatom) == 1) THEN
|
||||
CALL dbcsr_get_block_p(rho_ao_aux(ispin).matrix, &
|
||||
row=iatom, col=jatom, BLOCK=sparse_block_aux, found=found)
|
||||
IF (found) &
|
||||
sparse_block_aux = sparse_block
|
||||
END IF
|
||||
END DO
|
||||
CALL dbcsr_iterator_stop(iter)
|
||||
END DO
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief Call calculate_rho_elec() for auxiliary density
|
||||
\param qs_env ...
|
||||
***************************************************************************************************/
|
||||
void admm_dm_methods::update_rho_aux(qs_env)
|
||||
{
|
||||
TYPE(qs_environment_type), POINTER :: qs_env
|
||||
|
||||
INTEGER :: ispin
|
||||
REAL(KIND=dp), DIMENSION(:), POINTER :: tot_rho_r_aux
|
||||
TYPE(admm_dm_type), POINTER :: admm_dm
|
||||
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho_ao_aux
|
||||
TYPE(dft_control_type), POINTER :: dft_control
|
||||
TYPE(pw_type), DIMENSION(:), POINTER :: rho_g_aux, rho_r_aux
|
||||
TYPE(qs_ks_env_type), POINTER :: ks_env
|
||||
TYPE(qs_rho_type), POINTER :: rho_aux
|
||||
TYPE(task_list_type), POINTER :: task_list_aux_fit
|
||||
|
||||
NULLIFY (dft_control, admm_dm, rho_aux, rho_ao_aux, rho_r_aux, rho_g_aux, tot_rho_r_aux, &
|
||||
task_list_aux_fit, ks_env)
|
||||
|
||||
CALL get_qs_env(qs_env, ks_env=ks_env, dft_control=dft_control)
|
||||
CALL get_admm_env(qs_env.admm_env, task_list_aux_fit=task_list_aux_fit, rho_aux_fit=rho_aux,
|
||||
&
|
||||
admm_dm=admm_dm)
|
||||
|
||||
CALL qs_rho_get(rho_aux, &
|
||||
rho_ao=rho_ao_aux, &
|
||||
rho_r=rho_r_aux, &
|
||||
rho_g=rho_g_aux, &
|
||||
tot_rho_r=tot_rho_r_aux)
|
||||
|
||||
DO ispin = 1, dft_control.nspins
|
||||
CALL calculate_rho_elec(ks_env=ks_env, &
|
||||
matrix_p=rho_ao_aux(ispin).matrix, &
|
||||
rho=rho_r_aux(ispin), &
|
||||
rho_gspace=rho_g_aux(ispin), &
|
||||
total_rho=tot_rho_r_aux(ispin), &
|
||||
soft_valid=.FALSE., &
|
||||
basis_type="AUX_FIT", &
|
||||
task_list_external=task_list_aux_fit)
|
||||
END DO
|
||||
|
||||
CALL qs_rho_set(rho_aux, rho_r_valid=.TRUE., rho_g_valid=.TRUE.)
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief Merges auxiliary Kohn-Sham matrix via basis projection.
|
||||
\param qs_env ...
|
||||
\param matrix_ks_merge Input: The KS matrix to be merged
|
||||
\author Ole Schuett
|
||||
***************************************************************************************************/
|
||||
void admm_dm_methods::merge_dm_projection(qs_env, matrix_ks_merge)
|
||||
{
|
||||
TYPE(qs_environment_type), POINTER :: qs_env
|
||||
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks_merge
|
||||
|
||||
INTEGER :: ispin
|
||||
TYPE(admm_dm_type), POINTER :: admm_dm
|
||||
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks
|
||||
TYPE(dbcsr_type) :: matrix_tmp
|
||||
TYPE(dft_control_type), POINTER :: dft_control
|
||||
|
||||
NULLIFY (admm_dm, dft_control, matrix_ks)
|
||||
|
||||
CALL get_qs_env(qs_env, dft_control=dft_control, matrix_ks=matrix_ks)
|
||||
CALL get_admm_env(qs_env.admm_env, admm_dm=admm_dm)
|
||||
|
||||
! Calculate K += A^T * K_aux * A
|
||||
CALL dbcsr_create(matrix_tmp, template=admm_dm.matrix_A, matrix_type="N")
|
||||
|
||||
DO ispin = 1, dft_control.nspins
|
||||
CALL dbcsr_multiply("N", "N", 1.0_dp, matrix_ks_merge(ispin).matrix, admm_dm.matrix_A, &
|
||||
0.0_dp, matrix_tmp)
|
||||
CALL dbcsr_multiply("T", "N", 1.0_dp, admm_dm.matrix_A, matrix_tmp, &
|
||||
1.0_dp, matrix_ks(ispin).matrix)
|
||||
END DO
|
||||
|
||||
CALL dbcsr_release(matrix_tmp)
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief Merges auxiliary Kohn-Sham matrix via blocking.
|
||||
\param qs_env ...
|
||||
\param matrix_ks_merge Input: The KS matrix to be merged
|
||||
\author Ole Schuett
|
||||
***************************************************************************************************/
|
||||
void admm_dm_methods::merge_dm_blocked(qs_env, matrix_ks_merge)
|
||||
{
|
||||
TYPE(qs_environment_type), POINTER :: qs_env
|
||||
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks_merge
|
||||
|
||||
INTEGER :: blk, iatom, ispin, jatom
|
||||
REAL(dp), DIMENSION(:, :), POINTER :: sparse_block
|
||||
TYPE(admm_dm_type), POINTER :: admm_dm
|
||||
TYPE(dbcsr_iterator_type) :: iter
|
||||
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks
|
||||
TYPE(dft_control_type), POINTER :: dft_control
|
||||
|
||||
NULLIFY (admm_dm, dft_control, matrix_ks)
|
||||
|
||||
CALL get_qs_env(qs_env, dft_control=dft_control, matrix_ks=matrix_ks)
|
||||
CALL get_admm_env(qs_env.admm_env, admm_dm=admm_dm)
|
||||
|
||||
DO ispin = 1, dft_control.nspins
|
||||
CALL dbcsr_iterator_start(iter, matrix_ks_merge(ispin).matrix)
|
||||
DO WHILE (dbcsr_iterator_blocks_left(iter))
|
||||
CALL dbcsr_iterator_next_block(iter, iatom, jatom, sparse_block, blk)
|
||||
IF (admm_dm.block_map(iatom, jatom) == 0) &
|
||||
sparse_block = 0.0_dp
|
||||
END DO
|
||||
CALL dbcsr_iterator_stop(iter)
|
||||
CALL dbcsr_add(matrix_ks(ispin).matrix, matrix_ks_merge(ispin).matrix, 1.0_dp, 1.0_dp)
|
||||
END DO
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief Apply McWeeny purification to auxiliary density matrix
|
||||
\param qs_env ...
|
||||
\author Ole Schuett
|
||||
***************************************************************************************************/
|
||||
void admm_dm_methods::purify_mcweeny(qs_env)
|
||||
{
|
||||
TYPE(qs_environment_type), POINTER :: qs_env
|
||||
|
||||
CHARACTER(LEN=*), PARAMETER :: routineN = 'purify_mcweeny'
|
||||
|
||||
INTEGER :: handle, ispin, istep, nspins, unit_nr
|
||||
REAL(KIND=dp) :: frob_norm
|
||||
TYPE(admm_dm_type), POINTER :: admm_dm
|
||||
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s_aux_fit, rho_ao_aux
|
||||
TYPE(dbcsr_type) :: matrix_ps, matrix_psp, matrix_test
|
||||
TYPE(dbcsr_type), POINTER :: matrix_p, matrix_s
|
||||
TYPE(dft_control_type), POINTER :: dft_control
|
||||
TYPE(mcweeny_history_type), POINTER :: history, new_hist_entry
|
||||
TYPE(qs_rho_type), POINTER :: rho_aux_fit
|
||||
|
||||
CALL timeset(routineN, handle)
|
||||
NULLIFY (dft_control, admm_dm, matrix_s_aux_fit, rho_aux_fit, new_hist_entry, &
|
||||
matrix_p, matrix_s, rho_ao_aux)
|
||||
|
||||
unit_nr = cp_logger_get_default_unit_nr()
|
||||
CALL get_qs_env(qs_env, dft_control=dft_control)
|
||||
CALL get_admm_env(qs_env.admm_env, matrix_s_aux_fit=matrix_s_aux_fit, &
|
||||
rho_aux_fit=rho_aux_fit, admm_dm=admm_dm)
|
||||
|
||||
CALL qs_rho_get(rho_aux_fit, rho_ao=rho_ao_aux)
|
||||
|
||||
matrix_p => rho_ao_aux[0].matrix
|
||||
CALL dbcsr_create(matrix_PS, template=matrix_p, matrix_type="N")
|
||||
CALL dbcsr_create(matrix_PSP, template=matrix_p, matrix_type="S")
|
||||
CALL dbcsr_create(matrix_test, template=matrix_p, matrix_type="S")
|
||||
|
||||
nspins = dft_control.nspins
|
||||
DO ispin = 1, nspins
|
||||
matrix_p => rho_ao_aux(ispin).matrix
|
||||
matrix_s => matrix_s_aux_fit[0].matrix
|
||||
history => admm_dm.mcweeny_history(ispin).p
|
||||
IF (ASSOCIATED(history)) CPABORT("purify_dm_mcweeny: history already associated")
|
||||
IF (nspins == 1) CALL dbcsr_scale(matrix_p, 0.5_dp)
|
||||
|
||||
DO istep = 1, admm_dm.mcweeny_max_steps
|
||||
! allocate new element in linked list
|
||||
ALLOCATE (new_hist_entry)
|
||||
new_hist_entry.next => history
|
||||
history => new_hist_entry
|
||||
history.count = istep
|
||||
NULLIFY (new_hist_entry)
|
||||
CALL dbcsr_create(history.m, template=matrix_p, matrix_type="N")
|
||||
CALL dbcsr_copy(history.m, matrix_p, name="P from McWeeny")
|
||||
|
||||
! calc PS and PSP
|
||||
CALL dbcsr_multiply("N", "N", 1.0_dp, matrix_p, matrix_s, &
|
||||
0.0_dp, matrix_ps)
|
||||
|
||||
CALL dbcsr_multiply("N", "N", 1.0_dp, matrix_ps, matrix_p, &
|
||||
0.0_dp, matrix_psp)
|
||||
|
||||
!test convergence
|
||||
CALL dbcsr_copy(matrix_test, matrix_psp)
|
||||
CALL dbcsr_add(matrix_test, matrix_p, 1.0_dp, -1.0_dp)
|
||||
frob_norm = dbcsr_frobenius_norm(matrix_test)
|
||||
IF (unit_nr > 0) WRITE (unit_nr, '(t3,a,i5,a,f16.8)') "McWeeny-Step", istep, &
|
||||
": Deviation of idempotency", frob_norm
|
||||
IF (frob_norm < 1000_dp*admm_dm.eps_filter .AND. istep > 1) EXIT
|
||||
|
||||
! build next P matrix
|
||||
CALL dbcsr_copy(matrix_p, matrix_PSP, name="P from McWeeny")
|
||||
CALL dbcsr_multiply("N", "N", -2.0_dp, matrix_PS, matrix_PSP, &
|
||||
3.0_dp, matrix_p)
|
||||
END DO
|
||||
admm_dm.mcweeny_history(ispin).p => history
|
||||
IF (nspins == 1) CALL dbcsr_scale(matrix_p, 2.0_dp)
|
||||
END DO
|
||||
|
||||
! clean up
|
||||
CALL dbcsr_release(matrix_PS)
|
||||
CALL dbcsr_release(matrix_PSP)
|
||||
CALL dbcsr_release(matrix_test)
|
||||
CALL timestop(handle)
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief Prepare auxiliary KS-matrix for merge using reverse McWeeny
|
||||
\param qs_env ...
|
||||
\param matrix_ks_merge Output: The KS matrix for the merge
|
||||
\author Ole Schuett
|
||||
***************************************************************************************************/
|
||||
void admm_dm_methods::revert_purify_mcweeny(qs_env, matrix_ks_merge)
|
||||
{
|
||||
TYPE(qs_environment_type), POINTER :: qs_env
|
||||
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks_merge
|
||||
|
||||
CHARACTER(LEN=*), PARAMETER :: routineN = 'revert_purify_mcweeny'
|
||||
|
||||
INTEGER :: handle, ispin, nspins, unit_nr
|
||||
TYPE(admm_dm_type), POINTER :: admm_dm
|
||||
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_ks_aux_fit, &
|
||||
matrix_s_aux_fit, &
|
||||
matrix_s_aux_fit_vs_orb
|
||||
TYPE(dbcsr_type), POINTER :: matrix_k
|
||||
TYPE(dft_control_type), POINTER :: dft_control
|
||||
TYPE(mcweeny_history_type), POINTER :: history_curr, history_next
|
||||
|
||||
CALL timeset(routineN, handle)
|
||||
unit_nr = cp_logger_get_default_unit_nr()
|
||||
NULLIFY (admm_dm, dft_control, matrix_ks, matrix_ks_aux_fit, &
|
||||
matrix_s_aux_fit, matrix_s_aux_fit_vs_orb, &
|
||||
history_next, history_curr, matrix_k)
|
||||
|
||||
CALL get_qs_env(qs_env, dft_control=dft_control, matrix_ks=matrix_ks)
|
||||
CALL get_admm_env(qs_env.admm_env, matrix_s_aux_fit=matrix_s_aux_fit, admm_dm=admm_dm, &
|
||||
matrix_s_aux_fit_vs_orb=matrix_s_aux_fit_vs_orb,
|
||||
matrix_ks_aux_fit=matrix_ks_aux_fit)
|
||||
|
||||
nspins = dft_control.nspins
|
||||
ALLOCATE (matrix_ks_merge(nspins))
|
||||
|
||||
DO ispin = 1, nspins
|
||||
ALLOCATE (matrix_ks_merge(ispin).matrix)
|
||||
matrix_k => matrix_ks_merge(ispin).matrix
|
||||
CALL dbcsr_copy(matrix_k, matrix_ks_aux_fit(ispin).matrix, name="K")
|
||||
history_curr => admm_dm.mcweeny_history(ispin).p
|
||||
NULLIFY (admm_dm.mcweeny_history(ispin).p)
|
||||
|
||||
! reverse McWeeny iteration
|
||||
DO WHILE (ASSOCIATED(history_curr))
|
||||
IF (unit_nr > 0) WRITE (unit_nr, '(t3,a,i5)') "Reverse McWeeny-Step ", history_curr.count
|
||||
CALL reverse_mcweeny_step(matrix_k=matrix_k, &
|
||||
matrix_s=matrix_s_aux_fit[0].matrix, &
|
||||
matrix_p=history_curr.m)
|
||||
CALL dbcsr_release(history_curr.m)
|
||||
history_next => history_curr.next
|
||||
DEALLOCATE (history_curr)
|
||||
history_curr => history_next
|
||||
NULLIFY (history_next)
|
||||
END DO
|
||||
|
||||
END DO
|
||||
|
||||
! clean up
|
||||
timestop(handle);
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief Multiply matrix_k with partial derivative of McWeeny by reversing it.
|
||||
\param matrix_k ...
|
||||
\param matrix_s ...
|
||||
\param matrix_p ...
|
||||
\author Ole Schuett
|
||||
***************************************************************************************************/
|
||||
void admm_dm_methods::reverse_mcweeny_step(matrix_k, matrix_s, matrix_p)
|
||||
{
|
||||
TYPE(dbcsr_type) :: matrix_k, matrix_s, matrix_p
|
||||
|
||||
char *routineN = "reverse_mcweeny_step";
|
||||
|
||||
int handle;
|
||||
TYPE(dbcsr_type) :: matrix_ps, matrix_sp, matrix_sum, &
|
||||
matrix_tmp
|
||||
|
||||
timeset(routineN, handle);
|
||||
dbcsr_create(matrix_ps, template=matrix_p, matrix_type="N");
|
||||
dbcsr_create(matrix_sp, template=matrix_p, matrix_type="N");
|
||||
dbcsr_create(matrix_tmp, template=matrix_p, matrix_type="N");
|
||||
dbcsr_create(matrix_sum, template=matrix_p, matrix_type="N");
|
||||
|
||||
dbcsr_multiply("N", "N", 1.0_dp, matrix_p, matrix_s,
|
||||
0.0_dp, matrix_ps);
|
||||
dbcsr_multiply("N", "N", 1.0_dp, matrix_s, matrix_p,
|
||||
0.0_dp, matrix_sp);
|
||||
|
||||
// TODO: can we exploid more symmetry?
|
||||
dbcsr_multiply("N", "N", 3.0_dp, matrix_k, matrix_ps,
|
||||
0.0_dp, matrix_sum);
|
||||
dbcsr_multiply("N", "N", 3.0_dp, matrix_sp, matrix_k,
|
||||
1.0_dp, matrix_sum);
|
||||
|
||||
// matrix_tmp = KPS
|
||||
dbcsr_multiply("N", "N", 1.0_dp, matrix_k, matrix_ps,
|
||||
0.0_dp, matrix_tmp);
|
||||
dbcsr_multiply("N", "N", -2.0_dp, matrix_tmp, matrix_ps,
|
||||
1.0_dp, matrix_sum);
|
||||
dbcsr_multiply("N", "N", -2.0_dp, matrix_sp, matrix_tmp,
|
||||
1.0_dp, matrix_sum);
|
||||
|
||||
// matrix_tmp = SPK
|
||||
dbcsr_multiply("N", "N", 1.0_dp, matrix_sp, matrix_k,
|
||||
0.0_dp, matrix_tmp);
|
||||
dbcsr_multiply("N", "N", -2.0_dp, matrix_sp, matrix_tmp,
|
||||
1.0_dp, matrix_sum);
|
||||
|
||||
// overwrite matrix_k
|
||||
dbcsr_copy(matrix_k, matrix_sum, name="K from reverse McWeeny");
|
||||
|
||||
// clean up
|
||||
dbcsr_release(matrix_sum);
|
||||
dbcsr_release(matrix_tmp);
|
||||
dbcsr_release(matrix_ps);
|
||||
dbcsr_release(matrix_sp);
|
||||
timestop(handle);
|
||||
|
||||
}
|
||||
8
src/base/base.h
Normal file
8
src/base/base.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _BASE_H
|
||||
#define _BASE_H
|
||||
|
||||
#define default_string_length 80
|
||||
#define default_path_length 1024
|
||||
const int max_line_length = 2*default_path_length;
|
||||
|
||||
#endif
|
||||
256
src/base/base_hooks.cpp
Normal file
256
src/base/base_hooks.cpp
Normal file
|
|
@ -0,0 +1,256 @@
|
|||
/*--------------------------------------------------------------------------------------------------
|
||||
CP2K: A general program to perform molecular dynamics simulations
|
||||
Copyright 2000-2023 CP2K developers group <https://cp2k.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
--------------------------------------------------------------------------------------------------*/
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief Central dispatch for basic hooks
|
||||
\author Ole Schuett
|
||||
***************************************************************************************************/
|
||||
class base_hooks {
|
||||
|
||||
private:
|
||||
|
||||
public:
|
||||
// API
|
||||
void cp_abort();
|
||||
void cp_warn();
|
||||
void cp_hint();
|
||||
void timeset();
|
||||
void timestop();
|
||||
void cp_abort_hook();
|
||||
void cp_warn_hook();
|
||||
void cp_hint_hook();
|
||||
void timeset_hook();
|
||||
void timestop_hook();
|
||||
void cp__a();
|
||||
void cp__b();
|
||||
void cp__w();
|
||||
void cp__h();
|
||||
void cp__l();
|
||||
|
||||
// this interface (with subroutines in it) must to be defined right before
|
||||
// the regular subroutines/functions - otherwise prettify.py will screw up.
|
||||
INTERFACE
|
||||
SUBROUTINE cp_abort_interface(location, message)
|
||||
CHARACTER(len=*), INTENT(in) :: location, message
|
||||
|
||||
END SUBROUTINE cp_abort_interface
|
||||
|
||||
SUBROUTINE cp_warn_interface(location, message)
|
||||
CHARACTER(len=*), INTENT(in) :: location, message
|
||||
|
||||
END SUBROUTINE cp_warn_interface
|
||||
|
||||
SUBROUTINE cp_hint_interface(location, message)
|
||||
CHARACTER(len=*), INTENT(in) :: location, message
|
||||
|
||||
END SUBROUTINE cp_hint_interface
|
||||
|
||||
SUBROUTINE timeset_interface(routineN, handle)
|
||||
CHARACTER(LEN=*), INTENT(IN) :: routineN
|
||||
INTEGER, INTENT(OUT) :: handle
|
||||
|
||||
END SUBROUTINE timeset_interface
|
||||
|
||||
SUBROUTINE timestop_interface(handle)
|
||||
INTEGER, INTENT(IN) :: handle
|
||||
|
||||
END SUBROUTINE timestop_interface
|
||||
END INTERFACE
|
||||
|
||||
PROCEDURE(cp_abort_interface), POINTER :: cp_abort_hook => Null()
|
||||
PROCEDURE(cp_warn_interface), POINTER :: cp_warn_hook => Null()
|
||||
PROCEDURE(cp_hint_interface), POINTER :: cp_hint_hook => Null()
|
||||
PROCEDURE(timeset_interface), POINTER :: timeset_hook => Null()
|
||||
PROCEDURE(timestop_interface), POINTER :: timestop_hook => Null()
|
||||
|
||||
}
|
||||
|
||||
!
|
||||
**************************************************************************************************
|
||||
!> \brief Terminate the program
|
||||
!> \param location ...
|
||||
!> \param message ...
|
||||
!> \author Ole Schuett
|
||||
!
|
||||
**************************************************************************************************
|
||||
SUBROUTINE cp_abort(location, message)
|
||||
CHARACTER(len=*), INTENT(in) :: location, message
|
||||
|
||||
IF (ASSOCIATED(cp_abort_hook)) THEN
|
||||
CALL cp_abort_hook(location, message)
|
||||
ELSE
|
||||
WRITE (default_output_unit, *) "ABORT in "//TRIM(location)//" "//TRIM(message)
|
||||
CALL m_flush(default_output_unit)
|
||||
CALL m_abort()
|
||||
END IF
|
||||
! compiler hint
|
||||
STOP "Never return from here"
|
||||
END SUBROUTINE cp_abort
|
||||
|
||||
!
|
||||
**************************************************************************************************
|
||||
!> \brief Issue a warning
|
||||
!> \param location ...
|
||||
!> \param message ...
|
||||
!> \author Ole Schuett
|
||||
!
|
||||
**************************************************************************************************
|
||||
SUBROUTINE cp_warn(location, message)
|
||||
CHARACTER(len=*), INTENT(in) :: location, message
|
||||
|
||||
IF (ASSOCIATED(cp_warn_hook)) THEN
|
||||
CALL cp_warn_hook(location, message)
|
||||
ELSE
|
||||
WRITE (default_output_unit, *) "WARNING in "//TRIM(location)//" "//TRIM(message)
|
||||
CALL m_flush(default_output_unit)
|
||||
END IF
|
||||
END SUBROUTINE cp_warn
|
||||
|
||||
!
|
||||
**************************************************************************************************
|
||||
!> \brief Issue a hint
|
||||
!> \param location ...
|
||||
!> \param message ...
|
||||
!> \author Hans Pabst
|
||||
!
|
||||
**************************************************************************************************
|
||||
SUBROUTINE cp_hint(location, message)
|
||||
CHARACTER(len=*), INTENT(in) :: location, message
|
||||
|
||||
IF (ASSOCIATED(cp_hint_hook)) THEN
|
||||
CALL cp_hint_hook(location, message)
|
||||
ELSE
|
||||
WRITE (default_output_unit, *) "HINT in "//TRIM(location)//" "//TRIM(message)
|
||||
CALL m_flush(default_output_unit)
|
||||
END IF
|
||||
END SUBROUTINE cp_hint
|
||||
|
||||
!
|
||||
**************************************************************************************************
|
||||
!> \brief Start timer
|
||||
!> \param routineN ...
|
||||
!> \param handle ...
|
||||
!> \author Ole Schuett
|
||||
!
|
||||
**************************************************************************************************
|
||||
SUBROUTINE timeset(routineN, handle)
|
||||
CHARACTER(LEN=*), INTENT(IN) :: routineN
|
||||
INTEGER, INTENT(OUT) :: handle
|
||||
|
||||
IF (ASSOCIATED(timeset_hook)) THEN
|
||||
CALL timeset_hook(routineN, handle)
|
||||
ELSE
|
||||
handle = -1
|
||||
END IF
|
||||
END SUBROUTINE timeset
|
||||
|
||||
!
|
||||
**************************************************************************************************
|
||||
!> \brief Stop timer
|
||||
!> \param handle ...
|
||||
!> \author Ole Schuett
|
||||
!
|
||||
**************************************************************************************************
|
||||
SUBROUTINE timestop(handle)
|
||||
INTEGER, INTENT(IN) :: handle
|
||||
|
||||
IF (ASSOCIATED(timestop_hook)) THEN
|
||||
CALL timestop_hook(handle)
|
||||
ELSE
|
||||
IF (handle /= -1) &
|
||||
CALL cp_abort(cp__l("base_hooks.F", __LINE__), "Got wrong handle")
|
||||
END IF
|
||||
END SUBROUTINE timestop
|
||||
|
||||
!
|
||||
**************************************************************************************************
|
||||
!> \brief CPASSERT handler
|
||||
!> \param filename ...
|
||||
!> \param lineNr ...
|
||||
!> \author Ole Schuett
|
||||
!
|
||||
**************************************************************************************************
|
||||
SUBROUTINE cp__a(filename, lineNr)
|
||||
CHARACTER(len=*), INTENT(in) :: filename
|
||||
INTEGER, INTENT(in) :: lineNr
|
||||
|
||||
CALL cp_abort(location=cp__l(filename, lineNr), message="CPASSERT failed")
|
||||
! compiler hint
|
||||
STOP "Never return from here"
|
||||
END SUBROUTINE cp__a
|
||||
|
||||
!
|
||||
**************************************************************************************************
|
||||
!> \brief CPABORT handler
|
||||
!> \param filename ...
|
||||
!> \param lineNr ...
|
||||
!> \param message ...
|
||||
!> \author Ole Schuett
|
||||
!
|
||||
**************************************************************************************************
|
||||
SUBROUTINE cp__b(filename, lineNr, message)
|
||||
CHARACTER(len=*), INTENT(in) :: filename
|
||||
INTEGER, INTENT(in) :: lineNr
|
||||
CHARACTER(len=*), INTENT(in) :: message
|
||||
|
||||
CALL cp_abort(location=cp__l(filename, lineNr), message=message)
|
||||
! compiler hint
|
||||
STOP "Never return from here"
|
||||
END SUBROUTINE cp__b
|
||||
|
||||
!
|
||||
**************************************************************************************************
|
||||
!> \brief CPWARN handler
|
||||
!> \param filename ...
|
||||
!> \param lineNr ...
|
||||
!> \param message ...
|
||||
!> \author Ole Schuett
|
||||
!
|
||||
**************************************************************************************************
|
||||
SUBROUTINE cp__w(filename, lineNr, message)
|
||||
CHARACTER(len=*), INTENT(in) :: filename
|
||||
INTEGER, INTENT(in) :: lineNr
|
||||
CHARACTER(len=*), INTENT(in) :: message
|
||||
|
||||
CALL cp_warn(location=cp__l(filename, lineNr), message=message)
|
||||
END SUBROUTINE cp__w
|
||||
|
||||
!
|
||||
**************************************************************************************************
|
||||
!> \brief CPHINT handler
|
||||
!> \param filename ...
|
||||
!> \param lineNr ...
|
||||
!> \param message ...
|
||||
!> \author Hans Pabst
|
||||
!
|
||||
**************************************************************************************************
|
||||
SUBROUTINE cp__h(filename, lineNr, message)
|
||||
CHARACTER(len=*), INTENT(in) :: filename
|
||||
INTEGER, INTENT(in) :: lineNr
|
||||
CHARACTER(len=*), INTENT(in) :: message
|
||||
|
||||
CALL cp_hint(location=cp__l(filename, lineNr), message=message)
|
||||
END SUBROUTINE cp__h
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief Helper routine to assemble __LOCATION__
|
||||
\param filename ...
|
||||
\param lineNr ...
|
||||
\return ...
|
||||
\author Ole Schuett
|
||||
***************************************************************************************************/
|
||||
char* cp__l(char *filename, int lineNr)
|
||||
{
|
||||
char *location;
|
||||
|
||||
char lineNr_str[15];
|
||||
|
||||
WRITE (lineNr_str, FMT='(I10)') lineNr
|
||||
location = TRIM(filename)//":"//TRIM(ADJUSTL(lineNr_str))
|
||||
|
||||
return location;
|
||||
}
|
||||
60
src/base/base_uses.cpp
Normal file
60
src/base/base_uses.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#ifndef _BASE_USES_H
|
||||
#define _BASE_USES_H
|
||||
|
||||
// Basic use statements and preprocessor macros
|
||||
// should be included in the use statements
|
||||
|
||||
int cp__a, cp__b, cp__w, cp__h, cp__l, cp_abort, cp_warn, cp_hint, timeset, timestop;
|
||||
|
||||
#if defined(__OFFLOAD_CUDA) || defined(__OFFLOAD_HIP)
|
||||
#define __OFFLOAD
|
||||
#endif
|
||||
|
||||
// Check for OpenMP early on - ideally before the compiler fails with a cryptic message.
|
||||
#if !defined(_OPENMP)
|
||||
"OpenMP is required. Please add the corresponding flag (eg. -fopenmp for GFortran) to your
|
||||
Fortran compiler flags."
|
||||
#endif
|
||||
|
||||
// Dangerous: Full path can be arbitrarily long and might overflow Fortran line.
|
||||
#if !defined(__SHORT_FILE__)
|
||||
#define __SHORT_FILE__ __FILE__
|
||||
#endif
|
||||
|
||||
#define __LOCATION__ cp__l(__SHORT_FILE__,__LINE__)
|
||||
#define CPWARN(msg) CALL cp__w(__SHORT_FILE__,__LINE__,msg)
|
||||
#define CPABORT(msg) CALL cp__b(__SHORT_FILE__,__LINE__,msg)
|
||||
// In contrast to CPWARN, the warning counter is not increased
|
||||
#define CPHINT(msg) CALL cp__h(__SHORT_FILE__,__LINE__,msg)
|
||||
|
||||
// CPASSERT can be elided if NDEBUG is defined.
|
||||
#if defined(NDEBUG)
|
||||
# define CPASSERT(cond)
|
||||
#else
|
||||
# define CPASSERT(cond) IF(.NOT.(cond))CALL cp__a(__SHORT_FILE__,__LINE__)
|
||||
#endif
|
||||
|
||||
// The MARK_USED macro can be used to mark an argument/variable as used. It is intended to make
|
||||
// it possible to switch on -Werror=unused-dummy-argument, but deal elegantly with, e.g.,
|
||||
// library wrapper routines that take arguments only used if the library is linked in.
|
||||
// This code should be valid for any Fortran variable, is always standard conforming,
|
||||
// and will be optimized away completely by the compiler
|
||||
#define MARK_USED(foo) IF(.FALSE.)THEN; DO ; IF(SIZE(SHAPE(foo))==-1) EXIT ; END DO ; ENDIF
|
||||
|
||||
// Calculate version number from 2 or 3 components. Can be used for comparison, e.g.,
|
||||
// CPVERSION3(4, 9, 0) <= CPVERSION3(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
|
||||
// CPVERSION(8, 0) <= CPVERSION(__GNUC__, __GNUC_MINOR__)
|
||||
#define CPVERSION2(MAJOR, MINOR) ((MAJOR) * 10000 + (MINOR) * 100)
|
||||
#define CPVERSION3(MAJOR, MINOR, UPDATE) (CPVERSION2(MAJOR, MINOR) + (UPDATE))
|
||||
#define CPVERSION CPVERSION2
|
||||
|
||||
// gfortran before 8.3 complains about internal symbols not being specified in
|
||||
// any data clause when using DEFAULT(NONE) and OOP procedures are called from
|
||||
// within the parallel region.
|
||||
#if __GNUC__ < 8 || (__GNUC__ == 8 && (__GNUC_MINOR__ < 3))
|
||||
#define OMP_DEFAULT_NONE_WITH_OOP SHARED
|
||||
#else
|
||||
#define OMP_DEFAULT_NONE_WITH_OOP NONE
|
||||
#endif
|
||||
|
||||
#endif
|
||||
52
src/base/kinds.cpp
Normal file
52
src/base/kinds.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*------------------------------------------------------------------------------------------------
|
||||
CP2K: A general program to perform molecular dynamics simulations
|
||||
Copyright 2000-2023 CP2K developers group <https://cp2k.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
-------------------------------------------------------------------------------------------------*/
|
||||
|
||||
class kinds {
|
||||
|
||||
public:
|
||||
/***************************************************************************************************
|
||||
\brief Print informations about the used data types.
|
||||
\param iw ...
|
||||
\par History
|
||||
Adapted by JGH for Cp2k
|
||||
\author Matthias Krack
|
||||
***************************************************************************************************/
|
||||
void print_kind_info(int iw)
|
||||
{
|
||||
|
||||
WRITE (iw, '( /, T2, A )') 'DATA TYPE INFORMATION:'
|
||||
|
||||
WRITE (iw, '( /,T2,A,T79,A,2(/,T2,A,T75,I6),3(/,T2,A,T67,E14.8) )') &
|
||||
'REAL: Data type name:', 'dp', ' Kind value:', KIND(0.0_dp), &
|
||||
' Precision:', PRECISION(0.0_dp), &
|
||||
' Smallest non-negligible quantity relative to 1:', &
|
||||
EPSILON(0.0_dp), &
|
||||
' Smallest positive number:', TINY(0.0_dp), &
|
||||
' Largest representable number:', HUGE(0.0_dp)
|
||||
WRITE (iw, '( /,T2,A,T79,A,2(/,T2,A,T75,I6),3(/,T2,A,T67,E14.8) )') &
|
||||
' Data type name:', 'sp', ' Kind value:', KIND(0.0_sp), &
|
||||
' Precision:', PRECISION(0.0_sp), &
|
||||
' Smallest non-negligible quantity relative to 1:', &
|
||||
EPSILON(0.0_sp), &
|
||||
' Smallest positive number:', TINY(0.0_sp), &
|
||||
' Largest representable number:', HUGE(0.0_sp)
|
||||
WRITE (iw, '( /,T2,A,T72,A,4(/,T2,A,T61,I20) )') &
|
||||
'INTEGER: Data type name:', '(default)', ' Kind value:', &
|
||||
KIND(0), &
|
||||
' Bit size:', BIT_SIZE(0), &
|
||||
' Largest representable number:', HUGE(0)
|
||||
WRITE (iw, '( /,T2,A,T72,A,/,T2,A,T75,I6,/ )') &
|
||||
'LOGICAL: Data type name:', '(default)', &
|
||||
' Kind value:', KIND(.TRUE.)
|
||||
WRITE (iw, '( /,T2,A,T72,A,/,T2,A,T75,I6,/ )') &
|
||||
'CHARACTER: Data type name:', '(default)', &
|
||||
' Kind value:', KIND('C')
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
341
src/cp2k_info.cpp
Normal file
341
src/cp2k_info.cpp
Normal file
|
|
@ -0,0 +1,341 @@
|
|||
/*--------------------------------------------------------------------------------------------------
|
||||
CP2K: A general program to perform molecular dynamics simulations
|
||||
Copyright 2000-2023 CP2K developers group <https://cp2k.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
--------------------------------------------------------------------------------------------------*/
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief some minimal info about CP2K, including its version and license
|
||||
\par History
|
||||
- created (2007-09, Joost VandeVondele)
|
||||
- moved into this module information related to runtime:pid, user_name,
|
||||
host_name, cwd, datx (2009-06, Teodoro Laino)
|
||||
\author Joost VandeVondele
|
||||
***************************************************************************************************/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "./base/base.h"
|
||||
|
||||
class cp2k_info {
|
||||
|
||||
private:
|
||||
char *moduleN = "cp2k_info";
|
||||
|
||||
public:
|
||||
void cp2k_flags();
|
||||
void print_cp2k_license();
|
||||
void get_runtime_info();
|
||||
void write_restart_header();
|
||||
int cp2k_version, cp2k_year, cp2k_home;
|
||||
int compile_arch, compile_date, compile_host, compile_revision;
|
||||
|
||||
#if defined(__COMPILE_REVISION)
|
||||
char *compile_revision = __COMPILE_REVISION;
|
||||
#else
|
||||
char *compile_revision = "unknown";
|
||||
#endif
|
||||
|
||||
char *cp2k_version = "CP2K version 2023.2 (Development Version)";
|
||||
char *cp2k_year = "2023";
|
||||
char *cp2k_home = "https://www.cp2k.org/";
|
||||
|
||||
// compile time information
|
||||
#if defined(__COMPILE_ARCH)
|
||||
char *compile_arch = __COMPILE_ARCH;
|
||||
#else
|
||||
char *compile_arch = "unknown: -D__COMPILE_ARCH=?";
|
||||
#endif
|
||||
|
||||
#if defined(__COMPILE_DATE)
|
||||
char *compile_date = __COMPILE_DATE;
|
||||
#else
|
||||
char *compile_date = "unknown: -D__COMPILE_DATE=?";
|
||||
#endif
|
||||
|
||||
#if defined(__COMPILE_HOST)
|
||||
char *compile_host = __COMPILE_HOST;
|
||||
#else
|
||||
char *compile_host = "unknown: -D__COMPILE_HOST=?";
|
||||
#endif
|
||||
|
||||
// Local runtime informations
|
||||
char r_datx[26];
|
||||
char r_cwd[default_path_length];
|
||||
char r_host_name[default_string_length], r_user_name[default_string_length];
|
||||
int r_pid;
|
||||
|
||||
|
||||
};
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief list all compile time options that influence the capabilities of cp2k.
|
||||
All new flags should be added here (and be unique grep-able)
|
||||
\return ...
|
||||
***************************************************************************************************/
|
||||
char* cp2k_info::cp2k_flags()
|
||||
{
|
||||
char flags[10*default_string_length];
|
||||
|
||||
char tmp_str[default_string_length];
|
||||
|
||||
std::strncpy(flags,"cp2kflags:", sizeof(flags));
|
||||
|
||||
// Ensure that tmp_str is used to silence compiler warnings
|
||||
std::strncpy(tmp_str, "", sizeof(tmp_str);
|
||||
flags = TRIM(flags)//TRIM(tmp_str)
|
||||
|
||||
#if defined(NDEBUG);
|
||||
flags = TRIM(flags)//" ndebug"
|
||||
#endif
|
||||
flags = TRIM(flags)//" omp"
|
||||
#if defined(__LIBINT)
|
||||
flags = TRIM(flags)//" libint"
|
||||
#endif
|
||||
#if defined(__FFTW3)
|
||||
flags = TRIM(flags)//" fftw3"
|
||||
#endif
|
||||
#if defined(__FFTW3_MKL)
|
||||
flags = TRIM(flags)//" fftw3_mkl"
|
||||
#endif
|
||||
#if defined(__LIBXC)
|
||||
flags = TRIM(flags)//" libxc"
|
||||
#endif
|
||||
#if defined(__LIBPEXSI)
|
||||
flags = TRIM(flags)//" pexsi"
|
||||
#endif
|
||||
#if defined(__ELPA)
|
||||
flags = TRIM(flags)//" elpa"
|
||||
#endif
|
||||
#if defined(__ELPA_NVIDIA_GPU)
|
||||
flags = TRIM(flags)//" elpa_nvidia_gpu"
|
||||
#endif
|
||||
#if defined(__ELPA_AMD_GPU)
|
||||
flags = TRIM(flags)//" elpa_amd_gpu"
|
||||
#endif
|
||||
#if defined(__ELPA_INTEL_GPU)
|
||||
flags = TRIM(flags)//" elpa_intel_gpu"
|
||||
#endif
|
||||
#if defined(__parallel)
|
||||
flags = TRIM(flags)//" parallel"
|
||||
#endif
|
||||
#if defined(__MPI_F08)
|
||||
flags = TRIM(flags)//" mpi_f08"
|
||||
#endif
|
||||
#if defined(__SCALAPACK)
|
||||
flags = TRIM(flags)//" scalapack"
|
||||
#endif
|
||||
#if defined(__COSMA)
|
||||
flags = TRIM(flags)//" cosma"
|
||||
#endif
|
||||
|
||||
#if defined(__QUIP)
|
||||
flags = TRIM(flags)//" quip"
|
||||
#endif
|
||||
|
||||
#if defined(__HAS_PATCHED_CUFFT_70)
|
||||
flags = TRIM(flags)//" patched_cufft_70"
|
||||
#endif
|
||||
|
||||
#if defined(__PW_FPGA)
|
||||
flags = TRIM(flags)//" pw_fpga"
|
||||
#endif
|
||||
#if defined(__PW_FPGA_SP)
|
||||
flags = TRIM(flags)//" pw_fpga_sp"
|
||||
#endif
|
||||
|
||||
#if defined(__LIBXSMM)
|
||||
flags = TRIM(flags)//" xsmm"
|
||||
#endif
|
||||
|
||||
#if defined(__CRAY_PM_ACCEL_ENERGY)
|
||||
flags = TRIM(flags)//" cray_pm_accel_energy"
|
||||
#endif
|
||||
#if defined(__CRAY_PM_ENERGY)
|
||||
flags = TRIM(flags)//" cray_pm_energy"
|
||||
#endif
|
||||
#if defined(__CRAY_PM_FAKE_ENERGY)
|
||||
flags = TRIM(flags)//" cray_pm_fake_energy"
|
||||
#endif
|
||||
#if defined(__DBCSR_ACC)
|
||||
flags = TRIM(flags)//" dbcsr_acc"
|
||||
#endif
|
||||
#if defined(__MAX_CONTR)
|
||||
CALL integer_to_string(__MAX_CONTR, tmp_str)
|
||||
flags = TRIM(flags)//" max_contr="//TRIM(tmp_str)
|
||||
#endif
|
||||
#if defined(__NO_SOCKETS)
|
||||
flags = TRIM(flags)//" no_sockets"
|
||||
#endif
|
||||
#if defined(__NO_MPI_THREAD_SUPPORT_CHECK)
|
||||
flags = TRIM(flags)//" no_mpi_thread_support_check"
|
||||
#endif
|
||||
#if defined(__NO_STATM_ACCESS)
|
||||
flags = TRIM(flags)//" no_statm_access"
|
||||
#endif
|
||||
#if defined(__MINGW)
|
||||
flags = TRIM(flags)//" mingw"
|
||||
#endif
|
||||
#if defined(__PW_CUDA_NO_HOSTALLOC)
|
||||
flags = TRIM(flags)//" pw_cuda_no_hostalloc"
|
||||
#endif
|
||||
#if defined(__STATM_RESIDENT)
|
||||
flags = TRIM(flags)//" statm_resident"
|
||||
#endif
|
||||
#if defined(__STATM_TOTAL)
|
||||
flags = TRIM(flags)//" statm_total"
|
||||
#endif
|
||||
#if defined(__PLUMED2)
|
||||
flags = TRIM(flags)//" plumed2"
|
||||
#endif
|
||||
#if defined(__HAS_IEEE_EXCEPTIONS)
|
||||
flags = TRIM(flags)//" has_ieee_exceptions"
|
||||
#endif
|
||||
#if defined(__NO_ABORT)
|
||||
flags = TRIM(flags)//" no_abort"
|
||||
#endif
|
||||
#if defined(__SPGLIB)
|
||||
flags = TRIM(flags)//" spglib"
|
||||
#endif
|
||||
#if defined(__ACCELERATE)
|
||||
flags = TRIM(flags)//" accelerate"
|
||||
#endif
|
||||
#if defined(__MKL)
|
||||
flags = TRIM(flags)//" mkl"
|
||||
#endif
|
||||
#if defined(__SIRIUS)
|
||||
flags = TRIM(flags)//" sirius"
|
||||
#endif
|
||||
#if defined(__CHECK_DIAG)
|
||||
flags = TRIM(flags)//" check_diag"
|
||||
#endif
|
||||
#if defined(__LIBVORI)
|
||||
flags = TRIM(flags)//" libvori"
|
||||
flags = TRIM(flags)//" libbqb"
|
||||
#endif
|
||||
#if defined(__LIBMAXWELL)
|
||||
flags = TRIM(flags)//" libmaxwell"
|
||||
#endif
|
||||
#if defined(__LIBTORCH)
|
||||
flags = TRIM(flags)//" libtorch"
|
||||
#endif
|
||||
#if defined(__OFFLOAD_CUDA)
|
||||
flags = TRIM(flags)//" offload_cuda"
|
||||
#endif
|
||||
#if defined(__OFFLOAD_HIP)
|
||||
flags = TRIM(flags)//" offload_hip"
|
||||
#endif
|
||||
#if defined(__NO_OFFLOAD_GRID)
|
||||
flags = TRIM(flags)//" no_offload_grid"
|
||||
#endif
|
||||
#if defined(__NO_OFFLOAD_DBM)
|
||||
flags = TRIM(flags)//" no_offload_dbm"
|
||||
#endif
|
||||
#if defined(__NO_OFFLOAD_PW)
|
||||
flags = TRIM(flags)//" no_offload_pw"
|
||||
#endif
|
||||
#if defined(__OFFLOAD_PROFILING)
|
||||
flags = TRIM(flags)//" offload_profiling"
|
||||
#endif
|
||||
|
||||
#if defined(__SPLA) && defined(__OFFLOAD_GEMM)
|
||||
flags = TRIM(flags)//" spla_gemm_offloading"
|
||||
#endif
|
||||
|
||||
#if defined(__CUSOLVERMP)
|
||||
flags = TRIM(flags)//" cusolvermp"
|
||||
#endif
|
||||
|
||||
#if defined(__LIBVDWXC)
|
||||
flags = TRIM(flags)//" libvdwxc"
|
||||
#endif
|
||||
|
||||
#if defined(__HDF5)
|
||||
flags = TRIM(flags)//" hdf5"
|
||||
#endif
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief ...
|
||||
\param iunit ...
|
||||
***************************************************************************************************/
|
||||
void cp2k_info::print_cp2k_license(int iunit)
|
||||
{
|
||||
|
||||
WRITE (UNIT=iunit, FMT="(T2,A)") &
|
||||
"******************************************************************************", &
|
||||
"* *", &
|
||||
"* CP2K: A general program to perform molecular dynamics simulations *", &
|
||||
"* Copyright (C) 2000-2023 CP2K developer group <https://www.cp2k.org/> *", &
|
||||
"* *", &
|
||||
"* This program is free software: you can redistribute it and/or modify *", &
|
||||
"* it under the terms of the GNU General Public License as published by *", &
|
||||
"* the Free Software Foundation, either version 2 of the License, or *", &
|
||||
"* (at your option) any later version. *", &
|
||||
"* *", &
|
||||
"* This program is distributed in the hope that it will be useful, *", &
|
||||
"* but WITHOUT ANY WARRANTY; without even the implied warranty of *", &
|
||||
"* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *", &
|
||||
"* GNU General Public License for more details. *", &
|
||||
"* *", &
|
||||
"* You should have received a copy of the GNU General Public License *", &
|
||||
"* along with this program. If not, see <https://www.gnu.org/licenses/>. *", &
|
||||
"* *", &
|
||||
"******************************************************************************";
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief ...
|
||||
***************************************************************************************************/
|
||||
void cp2k_info::get_runtime_info()
|
||||
{
|
||||
r_datx = "";
|
||||
r_cwd = "";
|
||||
r_host_name = "";
|
||||
r_user_name = "";
|
||||
r_pid = -1;
|
||||
|
||||
m_getpid(r_pid)
|
||||
CALL m_getlog(r_user_name)
|
||||
CALL m_hostnm(r_host_name)
|
||||
CALL m_datum(r_datx)
|
||||
CALL m_getcwd(r_cwd)
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
\brief Writes the header for the restart file
|
||||
\param iunit ...
|
||||
\par History
|
||||
01.2008 [created] - Split from write_restart
|
||||
\author Teodoro Laino - University of Zurich - 01.2008
|
||||
***************************************************************************************************/
|
||||
void cp2k_info::write_restart_header(int iunit)
|
||||
{
|
||||
char cwd[256], datx[256];
|
||||
|
||||
m_datum(datx);
|
||||
m_getcwd(cwd);
|
||||
|
||||
WRITE (UNIT=iunit, FMT="(T2,A)") "# Version information for this restart file "
|
||||
WRITE (UNIT=iunit, FMT="(T2,A)") "# current date "//TRIM(datx)
|
||||
WRITE (UNIT=iunit, FMT="(T2,A)") "# current working dir "//TRIM(cwd)
|
||||
|
||||
WRITE (UNIT=iunit, FMT="(T2,A,T31,A50)") &
|
||||
"# Program compiled at", &
|
||||
ADJUSTR(compile_date(1:MIN(50, LEN(compile_date))))
|
||||
WRITE (UNIT=iunit, FMT="(T2,A,T31,A50)") &
|
||||
"# Program compiled on", &
|
||||
ADJUSTR(compile_host(1:MIN(50, LEN(compile_host))))
|
||||
WRITE (UNIT=iunit, FMT="(T2,A,T31,A50)") &
|
||||
"# Program compiled for", &
|
||||
ADJUSTR(compile_arch(1:MIN(50, LEN(compile_arch))))
|
||||
WRITE (UNIT=iunit, FMT="(T2,A,T31,A50)") &
|
||||
"# Source code revision number", &
|
||||
ADJUSTR(compile_revision)
|
||||
|
||||
}
|
||||
1675
src/qs_environment_types.cpp
Normal file
1675
src/qs_environment_types.cpp
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue