20 deallocate_arnoldi_env,&
21 get_selected_ritz_val,&
22 get_selected_ritz_vector,&
23 set_arnoldi_initial_vector,&
28 dbcsr_csr_eqrow_floor_dist, dbcsr_csr_print_sparsity, dbcsr_csr_type_real_8, &
31 dbcsr_type_no_symmetry
58#include "./base/base_uses.f90"
63 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'pexsi_methods'
65 LOGICAL,
PARAMETER,
PRIVATE :: careful_mod = .false.
84 INTEGER :: isinertiacount_int, maxpexsiiter, &
85 min_ranks_per_pole, npsymbfact, &
86 numpole, ordering, rowordering, &
88 LOGICAL :: csr_screening, isinertiacount
89 REAL(kind=
dp) :: gap, muinertiaexpansion, muinertiatolerance, mumax0, mumin0, &
90 mupexsisafeguard, numelectroninitialtolerance, numelectrontargettolerance, temperature
104 l_val=isinertiacount)
112 r_val=muinertiatolerance)
114 r_val=muinertiaexpansion)
116 r_val=mupexsisafeguard)
118 r_val=numelectroninitialtolerance)
120 r_val=numelectrontargettolerance)
130 i_val=min_ranks_per_pole)
134 isinertiacount_int = merge(1, 0, isinertiacount)
141 numpole=numpole, isinertiacount=isinertiacount_int, maxpexsiiter=maxpexsiiter, &
142 mumin0=mumin0, mumax0=mumax0, muinertiatolerance=muinertiatolerance, &
143 muinertiaexpansion=muinertiaexpansion, mupexsisafeguard=mupexsisafeguard, &
144 ordering=ordering, rowordering=rowordering, npsymbfact=npsymbfact, verbosity=verbosity)
146 pexsi_env%num_ranks_per_pole = min_ranks_per_pole
147 pexsi_env%csr_screening = csr_screening
149 IF (numelectroninitialtolerance .LT. numelectrontargettolerance) &
150 numelectroninitialtolerance = numelectrontargettolerance
152 pexsi_env%tol_nel_initial = numelectroninitialtolerance
153 pexsi_env%tol_nel_target = numelectrontargettolerance
167 TYPE(
dbcsr_type),
INTENT(IN) :: template_matrix
169 CHARACTER(len=*),
PARAMETER :: routinen =
'pexsi_init_scf'
171 INTEGER :: handle, ispin, unit_nr
174 CALL timeset(routinen, handle)
177 IF (logger%para_env%is_source())
THEN
186 CALL dbcsr_copy(pexsi_env%dbcsr_template_matrix_sym, template_matrix, &
187 "symmetric template matrix for CSR conversion")
189 pexsi_env%dbcsr_template_matrix_nonsym)
191 CALL dbcsr_copy(pexsi_env%dbcsr_template_matrix_nonsym, template_matrix, &
192 "non-symmetric template matrix for CSR conversion")
193 CALL dbcsr_copy(pexsi_env%dbcsr_template_matrix_sym, template_matrix, &
194 "symmetric template matrix for CSR conversion")
197 CALL dbcsr_create(pexsi_env%csr_sparsity,
"CSR sparsity", &
198 template=pexsi_env%dbcsr_template_matrix_sym)
199 CALL dbcsr_copy(pexsi_env%csr_sparsity, pexsi_env%dbcsr_template_matrix_sym)
203 IF (.NOT. pexsi_env%csr_screening)
CALL dbcsr_set(pexsi_env%csr_sparsity, 1.0_dp)
205 pexsi_env%csr_mat_s, &
206 dbcsr_csr_eqrow_floor_dist, &
207 csr_sparsity=pexsi_env%csr_sparsity, &
208 numnodes=pexsi_env%num_ranks_per_pole)
210 IF (unit_nr > 0)
WRITE (unit_nr,
"(/T2,A)")
"SPARSITY OF THE OVERLAP MATRIX IN CSR FORMAT"
211 CALL dbcsr_csr_print_sparsity(pexsi_env%csr_mat_s, unit_nr)
215 CALL dbcsr_csr_create(pexsi_env%csr_mat_ks, pexsi_env%csr_mat_s)
216 CALL dbcsr_csr_create(pexsi_env%csr_mat_p, pexsi_env%csr_mat_s)
217 CALL dbcsr_csr_create(pexsi_env%csr_mat_E, pexsi_env%csr_mat_s)
218 CALL dbcsr_csr_create(pexsi_env%csr_mat_F, pexsi_env%csr_mat_s)
220 DO ispin = 1, pexsi_env%nspin
222 CALL dbcsr_create(pexsi_env%matrix_w(ispin)%matrix,
"W matrix", &
223 template=template_matrix, matrix_type=dbcsr_type_no_symmetry)
226 CALL cp_pexsi_set_options(pexsi_env%options, numelectronpexsitolerance=pexsi_env%tol_nel_initial)
228 CALL timestop(handle)
239 REAL(kind=
dp),
DIMENSION(2),
INTENT(IN) :: mu_spin
241 CHARACTER(len=*),
PARAMETER :: routinen =
'pexsi_finalize_scf'
243 INTEGER :: handle, ispin, unit_nr
244 REAL(kind=
dp) :: kts_total, mu_total
247 CALL timeset(routinen, handle)
250 IF (logger%para_env%is_source())
THEN
256 mu_total = sum(mu_spin(1:pexsi_env%nspin))/real(pexsi_env%nspin, kind=
dp)
257 kts_total = sum(pexsi_env%kTS)
258 IF (pexsi_env%nspin .EQ. 1) kts_total = kts_total*2.0_dp
260 IF (unit_nr > 0)
THEN
261 WRITE (unit_nr,
"(/A,T55,F26.15)") &
262 " PEXSI| Electronic entropic energy (a.u.):", kts_total
263 WRITE (unit_nr,
"(A,T55,F26.15)") &
264 " PEXSI| Chemical potential (a.u.):", mu_total
270 CALL dbcsr_csr_destroy(pexsi_env%csr_mat_p)
271 CALL dbcsr_csr_destroy(pexsi_env%csr_mat_ks)
272 CALL dbcsr_csr_destroy(pexsi_env%csr_mat_s)
273 CALL dbcsr_csr_destroy(pexsi_env%csr_mat_E)
274 CALL dbcsr_csr_destroy(pexsi_env%csr_mat_F)
275 DO ispin = 1, pexsi_env%nspin
279 CALL timestop(handle)
280 pexsi_env%tol_nel_initial = pexsi_env%tol_nel_target
301 nelectron_exact, mu, iscf, ispin)
305 REAL(kind=
dp),
INTENT(OUT) :: kts
306 TYPE(
dbcsr_type),
INTENT(IN),
TARGET :: matrix_ks, matrix_s
307 INTEGER,
INTENT(IN) :: nelectron_exact
308 REAL(kind=
dp),
INTENT(OUT) :: mu
309 INTEGER,
INTENT(IN) :: iscf, ispin
311 CHARACTER(LEN=*),
PARAMETER :: routinen =
'density_matrix_pexsi'
312 INTEGER,
PARAMETER :: s_not_identity = 0
314 INTEGER :: handle, is_symbolic_factorize, isinertiacount, isinertiacount_out, mynode, &
315 n_total_inertia_iter, n_total_pexsi_iter, unit_nr
316 LOGICAL :: first_call, pexsi_convergence
317 REAL(kind=
dp) :: delta_e, energy_h, energy_s, free_energy, mu_max_in, mu_max_out, mu_min_in, &
318 mu_min_out, nel_tol, nelectron_diff, nelectron_exact_pexsi, nelectron_out
319 TYPE(arnoldi_env_type) :: arnoldi_env
322 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: arnoldi_matrices
324 CALL timeset(routinen, handle)
328 IF (logger%para_env%is_source())
THEN
334 first_call = (iscf .EQ. 1) .AND. (ispin .EQ. 1)
341 cpabort(
"PEXSI interface expects a non-symmetric DBCSR Kohn-Sham matrix")
343 cpabort(
"PEXSI interface expects a non-symmetric DBCSR overlap matrix")
346 IF ((pexsi_env%csr_mat_s%nzval_local%data_type .NE. dbcsr_csr_type_real_8) &
347 .OR. (pexsi_env%csr_mat_ks%nzval_local%data_type .NE. dbcsr_csr_type_real_8)) &
348 cpabort(
"Complex data type not supported by PEXSI")
352 IF (pexsi_env%csr_mat_s%nze_total .GE. int(2, kind=
int_8)**31) &
353 cpabort(
"Total number of non-zero elements of CSR matrix is too large to be handled by PEXSI")
362 CALL dbcsr_copy(pexsi_env%dbcsr_template_matrix_sym, matrix_s, keep_sparsity=.true.)
366 CALL dbcsr_copy(pexsi_env%dbcsr_template_matrix_sym, matrix_ks, keep_sparsity=.true.)
368 pexsi_env%csr_mat_ks)
371 NULLIFY (arnoldi_matrices)
373 arnoldi_matrices(1)%matrix => matrix_ks
374 arnoldi_matrices(2)%matrix => matrix_s
375 CALL setup_arnoldi_env(arnoldi_env, arnoldi_matrices, max_iter=20, &
376 threshold=1.0e-2_dp, selection_crit=2, nval_request=1, nrestarts=21, &
377 generalized_ev=.true., iram=.false.)
378 IF (iscf .GT. 1)
CALL set_arnoldi_initial_vector(arnoldi_env, pexsi_env%max_ev_vector(ispin))
379 CALL arnoldi_ev(arnoldi_matrices, arnoldi_env)
380 delta_e = real(get_selected_ritz_val(arnoldi_env, 1),
dp)
382 delta_e = delta_e + 1.0e-2_dp*abs(delta_e)
383 CALL get_selected_ritz_vector(arnoldi_env, 1, arnoldi_matrices(1)%matrix, &
384 pexsi_env%max_ev_vector(ispin))
385 CALL deallocate_arnoldi_env(arnoldi_env)
386 DEALLOCATE (arnoldi_matrices)
388 nelectron_exact_pexsi = nelectron_exact
393 IF (iscf .EQ. 1)
THEN
397 issymbolicfactorize=1)
402 issymbolicfactorize=is_symbolic_factorize, &
403 mumin0=mu_min_in, mumax0=mu_max_in, &
404 numelectronpexsitolerance=nel_tol)
409 IF (unit_nr > 0)
WRITE (unit_nr,
'(/A,T41,L20)')
" PEXSI| Do inertia counting?", &
410 isinertiacount_out .EQ. 1
411 IF (unit_nr > 0)
WRITE (unit_nr,
'(A,T50,F5.2,T56,F5.2)') &
412 " PEXSI| Guess for min mu, max mu", mu_min_in, mu_max_in
414 IF (unit_nr > 0)
WRITE (unit_nr,
'(A,T41,E20.3)') &
415 " PEXSI| Tolerance in number of electrons", nel_tol
420 IF (unit_nr > 0)
WRITE (unit_nr,
'(A,T41,F20.2)') &
421 " PEXSI| Arnoldi est. spectral radius", delta_e
427 pexsi_env%csr_mat_ks%nrows_total, &
428 int(pexsi_env%csr_mat_ks%nze_total, kind=
int_4), &
429 pexsi_env%csr_mat_ks%nze_local, &
430 pexsi_env%csr_mat_ks%nrows_local, &
431 pexsi_env%csr_mat_ks%rowptr_local, &
432 pexsi_env%csr_mat_ks%colind_local, &
433 pexsi_env%csr_mat_ks%nzval_local%r_dp, &
435 pexsi_env%csr_mat_s%nzval_local%r_dp)
439 numelectron=nelectron_exact_pexsi)
443 nelectron_exact_pexsi, mu, nelectron_out, mu_min_out, mu_max_out, &
444 n_total_inertia_iter, n_total_pexsi_iter)
447 nelectron_diff = nelectron_out - nelectron_exact_pexsi
448 pexsi_convergence = abs(nelectron_diff) .LT. nel_tol
450 IF (unit_nr > 0)
THEN
451 IF (pexsi_convergence)
THEN
452 WRITE (unit_nr,
'(/A)')
" PEXSI| Converged"
454 WRITE (unit_nr,
'(/A)')
" PEXSI| PEXSI did not converge!"
460 WRITE (unit_nr,
'(A,T41,F20.6)')
" PEXSI| Chemical potential", mu
462 WRITE (unit_nr,
'(A,T41,I20)')
" PEXSI| PEXSI iterations", n_total_pexsi_iter
463 WRITE (unit_nr,
'(A,T41,I20/)')
" PEXSI| Inertia counting iterations", &
467 IF (.NOT. pexsi_convergence) &
468 cpabort(
"PEXSI did not converge. Consider logPEXSI0 for more information.")
471 IF (mynode < pexsi_env%mp_dims(1)*pexsi_env%mp_dims(2))
THEN
474 pexsi_env%csr_mat_p%nzval_local%r_dp, &
475 pexsi_env%csr_mat_E%nzval_local%r_dp, &
476 pexsi_env%csr_mat_F%nzval_local%r_dp, &
477 energy_h, energy_s, free_energy)
479 kts = (free_energy - energy_h)
483 CALL pexsi_env%mp_group%bcast(kts, 0)
488 CALL dbcsr_copy(matrix_p, pexsi_env%dbcsr_template_matrix_nonsym)
491 CALL dbcsr_copy(matrix_w%matrix, pexsi_env%dbcsr_template_matrix_nonsym)
495 matrix_w=matrix_w, kts=kts)
502 IF (iscf .EQ. 1)
THEN
512 CALL timestop(handle)
536 REAL(kind=
dp),
INTENT(IN) :: delta_scf, eps_scf
537 LOGICAL,
INTENT(IN) :: initialize
538 LOGICAL,
INTENT(OUT) :: check_convergence
540 CHARACTER(len=*),
PARAMETER :: routinen =
'pexsi_set_convergence_tolerance'
543 REAL(kind=
dp) :: tol_nel
545 CALL timeset(routinen, handle)
547 tol_nel = pexsi_env%tol_nel_initial
550 pexsi_env%adaptive_nel_alpha = &
551 (pexsi_env%tol_nel_initial - pexsi_env%tol_nel_target)/(abs(delta_scf) - eps_scf)
552 pexsi_env%adaptive_nel_beta = &
553 pexsi_env%tol_nel_initial - pexsi_env%adaptive_nel_alpha*abs(delta_scf)
554 pexsi_env%do_adaptive_tol_nel = .true.
556 IF (pexsi_env%do_adaptive_tol_nel)
THEN
557 tol_nel = pexsi_env%adaptive_nel_alpha*abs(delta_scf) + pexsi_env%adaptive_nel_beta
558 tol_nel = max(tol_nel, pexsi_env%tol_nel_target)
559 tol_nel = min(tol_nel, pexsi_env%tol_nel_initial)
562 check_convergence = (tol_nel .LE. pexsi_env%tol_nel_target)
565 CALL timestop(handle)
582 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN),
OPTIONAL :: kts
586 CHARACTER(len=*),
PARAMETER :: routinen =
'pexsi_to_qs'
588 INTEGER :: handle, ispin, unit_nr
589 REAL(kind=
dp) :: kts_total
591 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_w_qs
594 CALL timeset(routinen, handle)
600 IF (logger%para_env%is_source())
THEN
606 CALL get_qs_env(qs_env, energy=energy, matrix_w=matrix_w_qs)
608 IF (
PRESENT(matrix_w))
THEN
609 DO ispin = 1, ls_scf_env%nspins
610 CALL matrix_ls_to_qs(matrix_w_qs(ispin)%matrix, matrix_w(ispin)%matrix, &
611 ls_scf_env%ls_mstruct, covariant=.false.)
612 IF (ls_scf_env%nspins .EQ. 1)
CALL dbcsr_scale(matrix_w_qs(ispin)%matrix, 2.0_dp)
616 IF (
PRESENT(kts))
THEN
618 IF (ls_scf_env%nspins .EQ. 1) kts_total = kts_total*2.0_dp
619 energy%kTS = kts_total
622 CALL timestop(handle)
arnoldi iteration using dbcsr
subroutine, public arnoldi_ev(matrix, arnoldi_env)
Driver routine for different arnoldi eigenvalue methods the selection which one is to be taken is mad...
logical function, public dbcsr_has_symmetry(matrix)
...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
subroutine, public dbcsr_convert_dbcsr_to_csr(dbcsr_mat, csr_mat)
...
subroutine, public dbcsr_convert_csr_to_dbcsr(dbcsr_mat, csr_mat)
...
subroutine, public dbcsr_desymmetrize(matrix_a, matrix_b)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_csr_create_from_dbcsr(dbcsr_mat, csr_mat, dist_format, csr_sparsity, numnodes)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_distribution_get(dist, row_dist, col_dist, nrows, ncols, has_threads, group, mynode, numnodes, nprows, npcols, myprow, mypcol, pgrid, subgroups_defined, prow_group, pcol_group)
...
Routines that link DBCSR and CP2K concepts together.
subroutine, public cp_dbcsr_to_csr_screening(ks_env, csr_sparsity)
Apply distance screening to refine sparsity pattern of matrices in CSR format (using eps_pgf_orb)....
DBCSR operations in CP2K.
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
Routines for a linear scaling quickstep SCF run based on the density matrix, with a focus on the inte...
subroutine, public matrix_ls_to_qs(matrix_qs, matrix_ls, ls_mstruct, covariant, keep_sparsity)
second link to QS, copy a LS matrix to QS matrix used to isolate QS style matrices from LS style will...
Types needed for a linear scaling quickstep SCF run based on the density matrix.
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
integer, parameter, public int_4
Interface to the PEXSI library, providing wrappers for all PEXSI routines that are called inside CP2K...
subroutine, public cp_pexsi_set_options(pexsi_options, temperature, gap, deltae, numpole, isinertiacount, maxpexsiiter, mumin0, mumax0, mu0, muinertiatolerance, muinertiaexpansion, mupexsisafeguard, numelectronpexsitolerance, matrixtype, issymbolicfactorize, ordering, rowordering, npsymbfact, verbosity)
Set PEXSI internal options.
subroutine, public cp_pexsi_retrieve_real_dft_matrix(plan, dmnzvallocal, edmnzvallocal, fdmnzvallocal, totalenergyh, totalenergys, totalfreeenergy)
...
subroutine, public cp_pexsi_get_options(pexsi_options, temperature, gap, deltae, numpole, isinertiacount, maxpexsiiter, mumin0, mumax0, mu0, muinertiatolerance, muinertiaexpansion, mupexsisafeguard, numelectronpexsitolerance, matrixtype, issymbolicfactorize, ordering, rowordering, npsymbfact, verbosity)
Access PEXSI internal options.
subroutine, public cp_pexsi_load_real_hs_matrix(plan, pexsi_options, nrows, nnz, nnzlocal, numcollocal, colptrlocal, rowindlocal, hnzvallocal, issidentity, snzvallocal)
...
subroutine, public cp_pexsi_set_default_options(pexsi_options)
...
subroutine, public cp_pexsi_dft_driver(plan, pexsi_options, numelectronexact, mupexsi, numelectronpexsi, mumininertia, mumaxinertia, numtotalinertiaiter, numtotalpexsiiter)
...
Methods using the PEXSI library to calculate the density matrix and related quantities using the Kohn...
subroutine, public pexsi_to_qs(ls_scf_env, qs_env, kts, matrix_w)
Pass energy weighted density matrix and entropic energy contribution to QS environment.
subroutine, public density_matrix_pexsi(pexsi_env, matrix_p, matrix_w, kts, matrix_ks, matrix_s, nelectron_exact, mu, iscf, ispin)
Calculate density matrix, energy-weighted density matrix and entropic energy contribution with the DF...
subroutine, public pexsi_init_read_input(pexsi_section, pexsi_env)
Read CP2K input section PEXSI and pass it to the PEXSI environment.
subroutine, public pexsi_finalize_scf(pexsi_env, mu_spin)
Deallocations and post-processing after SCF.
subroutine, public pexsi_init_scf(ks_env, pexsi_env, template_matrix)
Initializations needed before SCF.
subroutine, public pexsi_set_convergence_tolerance(pexsi_env, delta_scf, eps_scf, initialize, check_convergence)
Set PEXSI convergence tolerance (numElectronPEXSITolerance), adapted to the convergence error of the ...
Environment storing all data that is needed in order to call the DFT driver of the PEXSI library with...
subroutine, public convert_nspin_cp2k_pexsi(direction, numelectron, matrix_p, matrix_w, kts)
Scale various quantities with factors of 2. This converts spin restricted DFT calculations (PEXSI) to...
integer, parameter, public cp2k_to_pexsi
integer, parameter, public pexsi_to_cp2k
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...