29 dbcsr_type, dbcsr_type_antisymmetric, dbcsr_type_no_symmetry, dbcsr_type_symmetric
60#include "./base/base_uses.f90"
66 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_kpoint_operators'
86 INTEGER,
PARAMETER,
PRIVATE :: kpoint_part_re = 1, &
91 INTEGER,
PARAMETER,
PRIVATE :: kpoint_slot_idle = 0, &
92 kpoint_slot_in_flight = 1
117 POINTER :: trio_sab => null()
131 INTEGER,
ALLOCATABLE,
DIMENSION(:, :, :) :: status
157 rmatrix, cmatrix, tmpmat, fm_re, fm_im)
160 INTEGER,
INTENT(IN) :: matrix_row, ik
161 REAL(KIND=
dp),
DIMENSION(3),
INTENT(IN) :: xkp
162 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
166 LOGICAL,
INTENT(IN) :: use_grid
170 CHARACTER(LEN=*),
PARAMETER :: routineN =
'kpoint_operator_densify'
174 CALL timeset(routinen, handle)
177 cpassert(
PRESENT(grid))
182 CALL rskp_transform(rmatrix=rmatrix, cmatrix=cmatrix, rsmat=rsmat, ispin=matrix_row, &
183 xkp=xkp, cell_to_index=cell_to_index, sab_nl=sab_nl)
190 CALL timestop(handle)
227 SUBROUTINE kpoint_operator_launch(rsmat, matrix_row, ik, xkp, cell_to_index, sab_nl, &
228 grid, use_grid, rmatrix, cmatrix, tmpmat, fm_re, fm_im, &
229 target_re, target_im, fmdummy, my_kpgrp, para_env, &
233 INTEGER,
INTENT(IN) :: matrix_row, ik
234 REAL(KIND=
dp),
DIMENSION(3),
INTENT(IN) :: xkp
235 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
239 LOGICAL,
INTENT(IN) :: use_grid
241 TYPE(
cp_fm_type) :: fm_re, fm_im, target_re, target_im, &
243 LOGICAL,
INTENT(IN) :: my_kpgrp
247 CHARACTER(LEN=*),
PARAMETER :: routineN =
'kpoint_operator_launch'
251 CALL timeset(routinen, handle)
254 rmatrix, cmatrix, tmpmat, fm_re, fm_im)
264 CALL timestop(handle)
266 END SUBROUTINE kpoint_operator_launch
282 SUBROUTINE kpoint_operator_raw_finish_cfm(fmlocal, info, cmat, imaginary_part)
287 LOGICAL,
INTENT(IN) :: imaginary_part
289 CHARACTER(LEN=*),
PARAMETER :: routineN =
'kpoint_operator_raw_finish_cfm'
293 CALL timeset(routinen, handle)
296 IF (imaginary_part)
THEN
302 CALL timestop(handle)
304 END SUBROUTINE kpoint_operator_raw_finish_cfm
318 REAL(kind=
dp),
DIMENSION(:) :: eigenvalues
320 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_operator_cfm_to_mo'
325 CALL timeset(routinen, handle)
329 mo_im%eigenvalues = eigenvalues
332 CALL timestop(handle)
355 INTEGER,
INTENT(IN) :: nspin
357 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_operator_context_create'
361 CALL timeset(routinen, handle)
365 cpassert(
ASSOCIATED(kpoints))
366 ctx%kpoints => kpoints
368 cpassert(
ASSOCIATED(ctx%ao_ao_fmstruct))
371 cpassert(
ASSOCIATED(ctx%ao_ao_fmstruct%para_env, kpoints%blacs_env_all%para_env))
373 CALL timestop(handle)
389 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_operator_context_release'
391 INTEGER :: handle, iwork
393 CALL timeset(routinen, handle)
397 IF (
ALLOCATED(ctx%status))
THEN
398 cpassert(all(ctx%status == kpoint_slot_idle))
404 NULLIFY (ctx%rmatrix, ctx%cmatrix, ctx%tmpmat, ctx%trio_sab)
405 IF (
ALLOCATED(ctx%fmwork))
THEN
406 DO iwork = 1,
SIZE(ctx%fmwork)
409 DEALLOCATE (ctx%fmwork)
411 IF (
ALLOCATED(ctx%fmlocal))
THEN
412 IF (
ASSOCIATED(ctx%group_fm_pools))
THEN
417 DEALLOCATE (ctx%fmlocal)
419 IF (
ALLOCATED(ctx%info))
DEALLOCATE (ctx%info)
420 IF (
ALLOCATED(ctx%status))
DEALLOCATE (ctx%status)
421 NULLIFY (ctx%kpoints, ctx%ao_ao_fmstruct, ctx%group_mpools, ctx%group_fm_pools)
423 CALL timestop(handle)
443 SUBROUTINE kpoint_operator_ensure(ctx, rsmat)
448 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_operator_ensure'
452 CALL timeset(routinen, handle)
457 IF (
ASSOCIATED(ctx%rmatrix))
THEN
458 cpassert(
ASSOCIATED(ctx%trio_sab, ctx%kpoints%sab_nl))
460 IF (.NOT.
ASSOCIATED(ctx%rmatrix))
THEN
461 ALLOCATE (ctx%rmatrix, ctx%cmatrix, ctx%tmpmat)
462 CALL dbcsr_create(ctx%rmatrix, template=rsmat(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
463 CALL dbcsr_create(ctx%cmatrix, template=rsmat(1, 1)%matrix, matrix_type=dbcsr_type_antisymmetric)
464 CALL dbcsr_create(ctx%tmpmat, template=rsmat(1, 1)%matrix, matrix_type=dbcsr_type_no_symmetry)
467 ctx%trio_sab => ctx%kpoints%sab_nl
470 IF (.NOT.
ALLOCATED(ctx%fmwork))
THEN
471 ALLOCATE (ctx%fmwork(kpoint_part_im))
472 CALL cp_fm_create(ctx%fmwork(kpoint_part_re), ctx%ao_ao_fmstruct, &
473 name=
"KPOINT-OPERATOR-WORK-RE")
474 CALL cp_fm_create(ctx%fmwork(kpoint_part_im), ctx%ao_ao_fmstruct, &
475 name=
"KPOINT-OPERATOR-WORK-IM")
478 IF (.NOT.
ALLOCATED(ctx%fmlocal))
THEN
481 ctx%group_mpools => ctx%kpoints%mpools
482 CALL mpools_get(ctx%group_mpools, ao_ao_fm_pools=ctx%group_fm_pools)
483 ALLOCATE (ctx%fmlocal)
487 CALL timestop(handle)
489 END SUBROUTINE kpoint_operator_ensure
518 INTEGER,
INTENT(IN) :: ikp, ispin
520 INTEGER,
INTENT(IN) :: slot
522 LOGICAL,
INTENT(IN) :: use_grid
523 INTEGER,
INTENT(IN) :: matrix_row
525 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_operator_start'
527 INTEGER :: handle, igroup, ik, indx, kplocal
528 INTEGER,
DIMENSION(2) :: kp_range
529 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
533 CALL timeset(routinen, handle)
535 cpassert(
ASSOCIATED(ctx%kpoints))
536 cpassert(
ASSOCIATED(ctx%kpoints%sab_nl))
541 cpassert(ispin >= 1 .AND. ispin <= ctx%nspin)
542 cpassert(matrix_row >= 1 .AND. matrix_row <=
SIZE(rsmat, 1))
543 kplocal = ctx%kpoints%kp_range(2) - ctx%kpoints%kp_range(1) + 1
544 cpassert(ikp >= 1 .AND. ikp <= kplocal)
546 IF (
ALLOCATED(ctx%status))
THEN
547 cpassert(ctx%status(ikp, ispin, slot) == kpoint_slot_idle)
550 CALL kpoint_operator_ensure(ctx, rsmat)
558 IF (.NOT.
ALLOCATED(ctx%status))
THEN
559 ALLOCATE (ctx%status(kplocal, ctx%nspin, kpoint_num_slots))
560 ctx%status = kpoint_slot_idle
563 ALLOCATE (ctx%info(kplocal*ctx%kpoints%nkp_groups, ctx%nspin, &
564 kpoint_num_slots, kpoint_part_im))
567 kp_range = ctx%kpoints%kp_range
568 kp_dist => ctx%kpoints%kp_dist
569 para_env => ctx%kpoints%blacs_env_all%para_env
570 DO igroup = 1, ctx%kpoints%nkp_groups
571 ik = kp_dist(1, igroup) + ikp - 1
572 my_kpgrp = (ik >= kp_range(1) .AND. ik <= kp_range(2))
573 indx = ikp + (igroup - 1)*kplocal
574 CALL kpoint_operator_launch(rsmat, matrix_row, ik, ctx%kpoints%xkp(1:3, ik), &
575 ctx%kpoints%cell_to_index, ctx%kpoints%sab_nl, grid, use_grid, &
576 ctx%rmatrix, ctx%cmatrix, ctx%tmpmat, &
577 ctx%fmwork(kpoint_part_re), ctx%fmwork(kpoint_part_im), &
578 target_re=ctx%fmlocal, target_im=ctx%fmlocal, fmdummy=ctx%fmdummy, &
579 my_kpgrp=my_kpgrp, para_env=para_env, &
580 info_re=ctx%info(indx, ispin, slot, kpoint_part_re), &
581 info_im=ctx%info(indx, ispin, slot, kpoint_part_im))
583 ctx%status(ikp, ispin, slot) = kpoint_slot_in_flight
585 CALL timestop(handle)
606 INTEGER,
INTENT(IN) :: ikp, ispin, slot
609 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_operator_finish'
611 INTEGER :: handle, igroup, ik, indx, kplocal
612 INTEGER,
DIMENSION(2) :: kp_range
613 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
616 CALL timeset(routinen, handle)
618 cpassert(
ASSOCIATED(ctx%kpoints))
619 cpassert(
ALLOCATED(ctx%status))
620 cpassert(ctx%status(ikp, ispin, slot) == kpoint_slot_in_flight)
625 kplocal = ctx%kpoints%kp_range(2) - ctx%kpoints%kp_range(1) + 1
626 kp_range = ctx%kpoints%kp_range
627 kp_dist => ctx%kpoints%kp_dist
628 DO igroup = 1, ctx%kpoints%nkp_groups
629 ik = kp_dist(1, igroup) + ikp - 1
630 my_kpgrp = (ik >= kp_range(1) .AND. ik <= kp_range(2))
631 indx = ikp + (igroup - 1)*kplocal
633 CALL kpoint_operator_raw_finish_cfm(ctx%fmlocal, ctx%info(indx, ispin, slot, kpoint_part_re), &
635 CALL kpoint_operator_raw_finish_cfm(ctx%fmlocal, ctx%info(indx, ispin, slot, kpoint_part_im), &
641 ctx%status(ikp, ispin, slot) = kpoint_slot_idle
643 CALL timestop(handle)
679 mat_re, mat_im, matrix_row)
682 INTEGER,
INTENT(IN) :: ikp, ispin
686 TYPE(
dbcsr_type),
INTENT(INOUT),
OPTIONAL :: mat_re, mat_im
687 INTEGER,
INTENT(IN) :: matrix_row
689 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_operator_get'
691 INTEGER :: handle, igroup, ik, kplocal
692 INTEGER,
DIMENSION(2) :: kp_range
693 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
698 CALL timeset(routinen, handle)
700 cpassert(count([
PRESENT(cmat),
PRESENT(fm_re),
PRESENT(mat_re)]) == 1)
701 IF (
PRESENT(fm_re) .OR.
PRESENT(fm_im))
THEN
702 cpassert(
PRESENT(fm_re) .AND.
PRESENT(fm_im))
704 IF (
PRESENT(mat_re) .OR.
PRESENT(mat_im))
THEN
705 cpassert(
PRESENT(mat_re) .AND.
PRESENT(mat_im))
708 cpassert(
ASSOCIATED(ctx%kpoints))
709 cpassert(
ASSOCIATED(ctx%kpoints%sab_nl))
710 cpassert(ispin >= 1 .AND. ispin <= ctx%nspin)
711 cpassert(matrix_row >= 1 .AND. matrix_row <=
SIZE(rsmat, 1))
712 CALL kpoint_operator_ensure(ctx, rsmat)
713 kplocal = ctx%kpoints%kp_range(2) - ctx%kpoints%kp_range(1) + 1
714 cpassert(ikp >= 1 .AND. ikp <= kplocal)
715 IF (
PRESENT(cmat))
THEN
721 kp_range = ctx%kpoints%kp_range
722 kp_dist => ctx%kpoints%kp_dist
723 para_env => ctx%kpoints%blacs_env_all%para_env
724 DO igroup = 1, ctx%kpoints%nkp_groups
725 ik = kp_dist(1, igroup) + ikp - 1
726 my_kpgrp = (ik >= kp_range(1) .AND. ik <= kp_range(2))
727 IF (
PRESENT(cmat))
THEN
730 CALL kpoint_operator_launch(rsmat, matrix_row, ik, ctx%kpoints%xkp(1:3, ik), &
731 ctx%kpoints%cell_to_index, ctx%kpoints%sab_nl, &
732 use_grid=.false., rmatrix=ctx%rmatrix, cmatrix=ctx%cmatrix, &
733 tmpmat=ctx%tmpmat, fm_re=ctx%fmwork(kpoint_part_re), &
734 fm_im=ctx%fmwork(kpoint_part_im), target_re=ctx%fmlocal, &
735 target_im=ctx%fmlocal, fmdummy=ctx%fmdummy, my_kpgrp=my_kpgrp, &
736 para_env=para_env, info_re=info_re, info_im=info_im)
738 CALL kpoint_operator_raw_finish_cfm(ctx%fmlocal, info_re, cmat, .false.)
739 CALL kpoint_operator_raw_finish_cfm(ctx%fmlocal, info_im, cmat, .true.)
741 ELSE IF (
PRESENT(fm_re))
THEN
743 CALL kpoint_operator_launch(rsmat, matrix_row, ik, ctx%kpoints%xkp(1:3, ik), &
744 ctx%kpoints%cell_to_index, ctx%kpoints%sab_nl, &
745 use_grid=.false., rmatrix=ctx%rmatrix, cmatrix=ctx%cmatrix, &
746 tmpmat=ctx%tmpmat, fm_re=ctx%fmwork(kpoint_part_re), &
747 fm_im=ctx%fmwork(kpoint_part_im), target_re=fm_re, &
748 target_im=fm_im, fmdummy=ctx%fmdummy, my_kpgrp=my_kpgrp, &
749 para_env=para_env, info_re=info_re, info_im=info_im)
757 CALL kpoint_operator_launch(rsmat, matrix_row, ik, ctx%kpoints%xkp(1:3, ik), &
758 ctx%kpoints%cell_to_index, ctx%kpoints%sab_nl, &
759 use_grid=.false., rmatrix=ctx%rmatrix, cmatrix=ctx%cmatrix, &
760 tmpmat=ctx%tmpmat, fm_re=ctx%fmwork(kpoint_part_re), &
761 fm_im=ctx%fmwork(kpoint_part_im), target_re=ctx%fmlocal, &
762 target_im=ctx%fmlocal, fmdummy=ctx%fmdummy, my_kpgrp=my_kpgrp, &
763 para_env=para_env, info_re=info_re, info_im=info_im)
775 CALL timestop(handle)
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_scale_and_add_fm(alpha, matrix_a, beta, matrix_b)
Scale and add two BLACS matrices (a = alpha*a + beta*b). where b is a real matrix (adapted from cp_cf...
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_to_fm(msource, mtargetr, mtargeti)
Copy real and imaginary parts of a complex full matrix into separate real-value full matrices.
subroutine, public dbcsr_deallocate_matrix(matrix)
...
subroutine, public dbcsr_desymmetrize(matrix_a, matrix_b)
...
subroutine, public dbcsr_set(matrix, alpha)
...
Routines that link DBCSR and CP2K concepts together.
subroutine, public cp_dbcsr_alloc_block_from_nbl(matrix, sab_orb, desymmetrize)
allocate the blocks of a dbcsr based on the neighbor list
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr_bc(fm, bc_mat)
Copy a BLACS matrix to a dbcsr matrix with a special block-cyclic distribution, which requires no com...
pool for for elements that are retained and released
subroutine, public fm_pool_create_fm(pool, element, name)
returns an element, allocating it if none is in the pool
subroutine, public fm_pool_give_back_fm(pool, element)
returns the element to the pool
represent the structure of a full matrix
logical function, public cp_fm_struct_equivalent(fmstruct1, fmstruct2)
returns true if the two matrix structures are equivalent, false otherwise.
represent a full matrix distributed on many processors
subroutine, public cp_fm_start_copy_general(source, destination, para_env, info)
Initiates the copy operation: get distribution data, post MPI isend and irecvs.
subroutine, public cp_fm_cleanup_copy_general(info)
Completes the copy operation: wait for comms clean up MPI state.
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
subroutine, public cp_fm_finish_copy_general(destination, info)
Completes the copy operation: wait for comms, unpack, clean up MPI state.
Defines the basic variable types.
integer, parameter, public dp
Routines needed for kpoint calculation.
subroutine, public rskp_transform(rmatrix, cmatrix, rsmat, ispin, xkp, cell_to_index, sab_nl, is_complex, rs_sign)
Transformation of real space matrices to a kpoint.
subroutine, public rskp_transform_grid_extract(grid, ikp, rmatrix, cmatrix)
Extract one reciprocal-grid matrix from a prepared local DBCSR block cache.
Types and basic routines needed for a kpoint calculation.
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_one
complex(kind=dp), parameter, public gaussi
complex(kind=dp), parameter, public z_zero
Interface to the message passing library MPI.
Assembly of complex k-point operators from real-space DBCSR matrices. The output is a complex full ma...
subroutine, public kpoint_operator_context_create(ctx, kpoints, ao_ao_fm, nspin)
Create an empty operator context. The context owns no buffers after this call; they are created on fi...
subroutine, public kpoint_operator_cfm_to_mo(cmat, mo_re, mo_im, eigenvalues)
Split a complex matrix into the real and imaginary MO sets and copy the eigenvalues to the imaginary ...
subroutine kpoint_operator_densify(rsmat, matrix_row, ik, xkp, cell_to_index, sab_nl, grid, use_grid, rmatrix, cmatrix, tmpmat, fm_re, fm_im)
Transform one real-space operator to one k point and densify the result: the real part into fm_re and...
integer, parameter, public kpoint_spin_free
Row of rsmat that carries the spin-free operator image. S and T carry no spin copies: drivers launch ...
subroutine, public kpoint_operator_get(ctx, ikp, ispin, rsmat, cmat, fm_re, fm_im, mat_re, mat_im, matrix_row)
Assemble one operator for one local k point and spin in one call: run the single-group transfer of th...
integer, parameter, public kpoint_slot_s
integer, parameter, public kpoint_slot_t
integer, parameter, public kpoint_slot_ks
subroutine, public kpoint_operator_finish(ctx, ikp, ispin, slot, cmat)
Finish the transfers of one started instance: on the group that owns the k point, merge the received ...
subroutine, public kpoint_operator_start(ctx, ikp, ispin, rsmat, slot, grid, use_grid, matrix_row)
Start the assembly of one operator for one local k point and spin and launch its transfers to every k...
subroutine, public kpoint_operator_context_release(ctx)
Release the context together with every buffer it created. Call once, at the exit of the routine that...
wrapper for the pools of matrixes
subroutine, public mpools_get(mpools, ao_mo_fm_pools, ao_ao_fm_pools, mo_mo_fm_pools, ao_mosub_fm_pools, mosub_mosub_fm_pools, maxao_maxmo_fm_pool, maxao_maxao_fm_pool, maxmo_maxmo_fm_pool)
returns various attributes of the mpools (notably the pools contained in it)
Definition and initialisation of the mo data type.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count)
Get the components of a MO set data structure.
Define the neighbor list data types and the corresponding functionality.
Represent a complex full matrix.
to create arrays of pools
keeps the information about the structure of a full matrix
Stores the state of a copy between cp_fm_start_copy_general and cp_fm_finish_copy_general.
Contains information about kpoints.
stores all the informations relevant to an mpi environment
Caller-owned assembly context for one driver call. Created and released in the same driver routine an...
container for the pools of matrixes used by qs