(git:6344619)
Loading...
Searching...
No Matches
qs_kpoint_operators Module Reference

Assembly of real and complex k-point operators from real-space DBCSR matrices. Outputs use the distribution of the k-point group; real operators transfer one part only. The module splits this work into a start step and a finish step. One process can start many operators before it finishes any of them. The STANDARD k-point driver uses this order. The routines start, finish and get are collective over the environment-wide communicator. Every rank must call the same sequence of service calls. A context references its host kpoint environment without owning it, so it must not outlive that environment. An explicitly prepared, immutable operator batch can instead be built from bounded context-owned real-space snapshots inside each group. The public round and output-ownership contracts stay the same. Start/finish/get/prepare are not thread safe: serialize them, because their collective communication tolerates no concurrent service call. A separate context per thread only keeps the scratch from aliasing. More...

Data Types

type  kpoint_operator_context_type
 Caller-owned assembly context for one driver call. Created and released in the same driver routine and passed to helpers as an argument; never stored on the host kpoint_type. Components are private and touched only by this module. More...

Functions/Subroutines

subroutine kpoint_operator_densify (ctx, rsmat, matrix_row, ik, grid, use_grid)
 Transform and densify one operator using the context-owned workspaces and routing plans.
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 first use and released with the context.
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 created the context. Every started instance must be idle at this point. The call aborts when a transfer is still in flight, because nothing would ever wait for its MPI requests.
subroutine, public kpoint_operator_prepare (ctx, rsmat, slot, prepared, matrix_row, target)
 Prepare an immutable operator slot for group-local assembly. Refresh after the source values change, with every instance idle. Other prepared slots and structural routing remain valid. Without matrix_row, capture one row per instance spin; with matrix_row, store one row shared by all instance spins. Failure clears this slot on all ranks and retains the existing transfer fallback.
subroutine, public kpoint_operator_work_size (ctx, nentry)
 Size per-worker phase scratch for direct assembly into a solver matrix.
subroutine, public kpoint_operator_evaluate (ctx, ispin, slot, ik, phase, target, fm_re, fm_im)
 Evaluate an immutable prepared operator with exclusively caller-owned output and scratch. Prepare/refresh/release remain collective and serialized. Evaluate contains no MPI, DBCSR lookup, window update or nested OpenMP region. Source blocks must stay unchanged.
subroutine, public kpoint_operator_start (ctx, ikp, ispin, rsmat, slot, grid, use_grid, matrix_row)
 Start one operator for one global round and spin. The service walks all groups with a k point in this round; groups without one still participate in the transfers. Every rank must iterate through the maximum local k-point count. Finish every started instance with kpoint_operator_finish. The first start also creates the slot bookkeeping of the context. Collective over the environment-wide communicator: every rank must call the same sequence of service calls.
subroutine, public kpoint_operator_finish (ctx, ikp, ispin, slot, cmat, fm_re)
 Finish one started instance: build its prepared group-local operator, or merge received parts into cmat (real part first, overwrite then add) and reclaim the send side on every group. The slot returns to idle. Collective over the environment-wide communicator: every rank must call the same sequence of service calls.
subroutine, public kpoint_operator_get (ctx, ikp, ispin, rsmat, cmat, fm_re, fm_im, mat_re, mat_im, matrix_row, slot, grid)
 Assemble one operator for one global round and spin in one call: run the single-group transfer of the service for every group and finish it immediately, through transfer states local to this call. The persistent slot machinery stays with start and finish. Exactly one output flavor must be present: cmat receives the complex operator (real part overwrites, imaginary part adds) through the context buffer; the fm pair receives the two parts separately, transferred directly into fm_re and fm_im on the owning group (any distribution: the general copy redistributes); or the dbcsr pair receives the two parts as block-cyclic matrices built by the service, replacing the caller-side copy_fm_to_dbcsr_bc detour. The dbcsr matrices must be freshly initialized (dbcsr_init_p) and the cmat flavor must share the distribution of the k-point group. Collective over the environment-wide communicator: every rank must call the same sequence of service calls.
subroutine, public kpoint_operator_get_local (matrix_rs, kpoints, kp, ispin, cache_re, cache_im, matrix_re, matrix_im)
 Read an operator inside a group-local OT loop, after collective cache preparation. One group retains the sparse transform and distribution required by OT's DBCSR kernels. Multiple groups read their owned cache; no world collective may occur in this loop.
subroutine, public kpoint_operator_get_all (kpoints, ao_ao_fm, rsmat, slot, cmat, matrix_row)
 Fill caller-owned matrices for one operator row, including independent history snapshots. Prepare and fallback transfers are collective. Prepared one-rank groups evaluate k points concurrently, with no MPI or matrix allocation/refcounts inside the worker loop.
subroutine, public kpoint_operator_store (kpoints, ao_ao_fm, matrix_ks, matrix_s, matrix_t)
 Prepare owned split-FM operators for OT without entering an SCF eigensolver. H (or the initialization density) retains all source spins; S/T are built only once. Outputs survive the transient context. Compatible cache storage is reused, values refreshed.

Variables

integer, parameter, public kpoint_slot_ks = 1
integer, parameter, public kpoint_slot_s = 2
integer, parameter, public kpoint_slot_t = 3
integer, parameter, public kpoint_spin_free = 1
 Row of rsmat that carries the spin-free operator image. S and T carry no spin copies: drivers launch one instance per spin of their loop and read this same row in every instance.
integer, parameter rs_batch_size = 4

Detailed Description

Assembly of real and complex k-point operators from real-space DBCSR matrices. Outputs use the distribution of the k-point group; real operators transfer one part only. The module splits this work into a start step and a finish step. One process can start many operators before it finishes any of them. The STANDARD k-point driver uses this order. The routines start, finish and get are collective over the environment-wide communicator. Every rank must call the same sequence of service calls. A context references its host kpoint environment without owning it, so it must not outlive that environment. An explicitly prepared, immutable operator batch can instead be built from bounded context-owned real-space snapshots inside each group. The public round and output-ownership contracts stay the same. Start/finish/get/prepare are not thread safe: serialize them, because their collective communication tolerates no concurrent service call. A separate context per thread only keeps the scratch from aliasing.

Function/Subroutine Documentation

◆ kpoint_operator_densify()

subroutine qs_kpoint_operators::kpoint_operator_densify ( type(kpoint_operator_context_type), intent(inout) ctx,
type(dbcsr_p_type), dimension(:, :), pointer rsmat,
integer, intent(in) matrix_row,
integer, intent(in) ik,
type(rskp_grid_type), intent(in), optional grid,
logical, intent(in) use_grid )

Transform and densify one operator using the context-owned workspaces and routing plans.

Parameters
ctxinitialized transfer context
rsmatreal-space operator images
matrix_rowoperator row, independent of the instance spin
ikglobal k-point index
gridcaller-owned reciprocal-grid cache
use_gridextract from grid instead of a direct phase sum

Definition at line 203 of file qs_kpoint_operators.F.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kpoint_operator_context_create()

subroutine, public qs_kpoint_operators::kpoint_operator_context_create ( type(kpoint_operator_context_type), intent(out) ctx,
type(kpoint_type), pointer kpoints,
type(cp_fm_type), intent(in) ao_ao_fm,
integer, intent(in) nspin )

Create an empty operator context. The context owns no buffers after this call; they are created on first use and released with the context.

Parameters
ctxcontext to initialize
kpointshost k-point environment, referenced, not copied
ao_ao_fmany square full matrix on the environment-wide communicator; its matrix struct is the template for the context work buffers, which densify on the source side of transfers that cross into the k-point groups
nspininstance spin space of the owning driver call: the bound of the spin loop its start and finish calls iterate. Fixed for the lifetime of the context

Definition at line 377 of file qs_kpoint_operators.F.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kpoint_operator_context_release()

subroutine, public qs_kpoint_operators::kpoint_operator_context_release ( type(kpoint_operator_context_type), intent(inout) ctx)

Release the context together with every buffer it created. Call once, at the exit of the routine that created the context. Every started instance must be idle at this point. The call aborts when a transfer is still in flight, because nothing would ever wait for its MPI requests.

Parameters
ctxcontext to release

Definition at line 414 of file qs_kpoint_operators.F.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kpoint_operator_prepare()

subroutine, public qs_kpoint_operators::kpoint_operator_prepare ( type(kpoint_operator_context_type), intent(inout) ctx,
type(dbcsr_p_type), dimension(:, :), pointer rsmat,
integer, intent(in) slot,
logical, intent(out), optional prepared,
integer, intent(in), optional matrix_row,
type(cp_fm_type), intent(in), optional target )

Prepare an immutable operator slot for group-local assembly. Refresh after the source values change, with every instance idle. Other prepared slots and structural routing remain valid. Without matrix_row, capture one row per instance spin; with matrix_row, store one row shared by all instance spins. Failure clears this slot on all ranks and retains the existing transfer fallback.

Parameters
ctxcontext spanning the current initialized k-point environment
rsmatcurrent real-space operator images
slotslot to replace (KS, S or T)
preparedoptional collective success flag
matrix_rowoptional explicit spin-free operator row
TARGEToptional group-local FM layout for prepared get outputs; otherwise use the host AO/AO pool layout. One layout per context

Definition at line 561 of file qs_kpoint_operators.F.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kpoint_operator_work_size()

subroutine, public qs_kpoint_operators::kpoint_operator_work_size ( type(kpoint_operator_context_type), intent(in) ctx,
integer, intent(out) nentry )

Size per-worker phase scratch for direct assembly into a solver matrix.

Parameters
ctxprepared context
nentrynumber of route entries

Definition at line 1334 of file qs_kpoint_operators.F.

Here is the caller graph for this function:

◆ kpoint_operator_evaluate()

subroutine, public qs_kpoint_operators::kpoint_operator_evaluate ( type(kpoint_operator_context_type), intent(in) ctx,
integer, intent(in) ispin,
integer, intent(in) slot,
integer, intent(in) ik,
complex(kind=dp), dimension(:, :), intent(inout), target phase,
type(cp_cfm_type), intent(inout), optional target,
type(cp_fm_type), intent(inout), optional fm_re,
type(cp_fm_type), intent(inout), optional fm_im )

Evaluate an immutable prepared operator with exclusively caller-owned output and scratch. Prepare/refresh/release remain collective and serialized. Evaluate contains no MPI, DBCSR lookup, window update or nested OpenMP region. Source blocks must stay unchanged.

Parameters
ctxprepared read-only context
ispininstance spin
slotoperator slot
ikglobal k index owned by this group
phaseprivate phase scratch, sized with work_size
TARGEToptional private complex singleton output
fm_reoptional private real output instead of TARGET
fm_imoptional private imaginary output, accompanying fm_re for a complex operator

Definition at line 1355 of file qs_kpoint_operators.F.

Here is the caller graph for this function:

◆ kpoint_operator_start()

subroutine, public qs_kpoint_operators::kpoint_operator_start ( type(kpoint_operator_context_type), intent(inout) ctx,
integer, intent(in) ikp,
integer, intent(in) ispin,
type(dbcsr_p_type), dimension(:, :), pointer rsmat,
integer, intent(in) slot,
type(rskp_grid_type), intent(in), optional grid,
logical, intent(in) use_grid,
integer, intent(in) matrix_row )

Start one operator for one global round and spin. The service walks all groups with a k point in this round; groups without one still participate in the transfers. Every rank must iterate through the maximum local k-point count. Finish every started instance with kpoint_operator_finish. The first start also creates the slot bookkeeping of the context. Collective over the environment-wide communicator: every rank must call the same sequence of service calls.

Parameters
ctxcontext created by kpoint_operator_context_create
ikpglobal round, up to the maximum k-point count across groups
ispininstance spin: keys the bookkeeping
rsmatreal-space image matrices of the operator. A prepared operator batch uses the values captured by prepare; otherwise start reads the current values. The matching finish never reads rsmat
slotinstance slot, optionally backed by a prepared snapshot
gridprepared reciprocal-grid cache of the caller
use_gridextract from grid instead of a direct phase sum
matrix_rowrow of rsmat to transform. Spin-free operators such as S and T must pass kpoint_spin_free: their first matrix dimension counts derivatives, not spins. A spin index is out of bounds in plain SCF, but with derivatives stored it reads another valid row silently

Definition at line 1404 of file qs_kpoint_operators.F.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kpoint_operator_finish()

subroutine, public qs_kpoint_operators::kpoint_operator_finish ( type(kpoint_operator_context_type), intent(inout) ctx,
integer, intent(in) ikp,
integer, intent(in) ispin,
integer, intent(in) slot,
type(cp_cfm_type), optional cmat,
type(cp_fm_type), optional fm_re )

Finish one started instance: build its prepared group-local operator, or merge received parts into cmat (real part first, overwrite then add) and reclaim the send side on every group. The slot returns to idle. Collective over the environment-wide communicator: every rank must call the same sequence of service calls.

Parameters
ctxcontext that started the instance
ikpglobal round of the start call
ispinspin component of the start call
slotslot of the start call; the slot must be in flight
cmatcaller-allocated complex matrix that receives the operator. It must share the distribution of the k-point group. Unchanged on groups without a k point in this round
fm_reoptional real FM output instead of cmat for real wavefunctions, on the group layout

Definition at line 1490 of file qs_kpoint_operators.F.

Here is the caller graph for this function:

◆ kpoint_operator_get()

subroutine, public qs_kpoint_operators::kpoint_operator_get ( type(kpoint_operator_context_type), intent(inout) ctx,
integer, intent(in) ikp,
integer, intent(in) ispin,
type(dbcsr_p_type), dimension(:, :), pointer rsmat,
type(cp_cfm_type), optional cmat,
type(cp_fm_type), optional fm_re,
type(cp_fm_type), optional fm_im,
type(dbcsr_type), intent(inout), optional mat_re,
type(dbcsr_type), intent(inout), optional mat_im,
integer, intent(in) matrix_row,
integer, intent(in), optional slot,
type(rskp_grid_type), intent(in), optional grid )

Assemble one operator for one global round and spin in one call: run the single-group transfer of the service for every group and finish it immediately, through transfer states local to this call. The persistent slot machinery stays with start and finish. Exactly one output flavor must be present: cmat receives the complex operator (real part overwrites, imaginary part adds) through the context buffer; the fm pair receives the two parts separately, transferred directly into fm_re and fm_im on the owning group (any distribution: the general copy redistributes); or the dbcsr pair receives the two parts as block-cyclic matrices built by the service, replacing the caller-side copy_fm_to_dbcsr_bc detour. The dbcsr matrices must be freshly initialized (dbcsr_init_p) and the cmat flavor must share the distribution of the k-point group. Collective over the environment-wide communicator: every rank must call the same sequence of service calls.

Parameters
ctxcontext created by kpoint_operator_context_create
ikpglobal round, up to the maximum k-point count across groups
ispininstance spin: bounds-checked against the context spin space
rsmatreal-space image matrices of the operator
cmatcomplex matrix output
fm_rereal-part matrix output
fm_imimaginary-part output; may be omitted for real wavefunctions
mat_rereal-part block-cyclic dbcsr output
mat_imimaginary-part block-cyclic dbcsr output
matrix_rowrow of rsmat to transform. Spin-free operators such as S and T must pass kpoint_spin_free: their first matrix dimension counts derivatives, not spins. A spin index is out of bounds in plain SCF, but with derivatives stored it reads another valid row silently
slotoptional prepared slot: opt in to its immutable snapshot. Without slot, get always reads current source values. A missing or mismatched snapshot retains the original transfer path. Prepared FM targets must match the layout selected at prepare; inactive groups do not inspect or modify their output arguments.
gridoptional lattice-FFT grid, overriding a prepared snapshot for this request

Definition at line 1587 of file qs_kpoint_operators.F.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kpoint_operator_get_local()

subroutine, public qs_kpoint_operators::kpoint_operator_get_local ( type(dbcsr_p_type), dimension(:, :), pointer matrix_rs,
type(kpoint_type), pointer kpoints,
type(kpoint_env_type), pointer kp,
integer, intent(in) ispin,
type(cp_fm_type), intent(in) cache_re,
type(cp_fm_type), intent(in) cache_im,
type(dbcsr_type), pointer matrix_re,
type(dbcsr_type), pointer matrix_im )

Read an operator inside a group-local OT loop, after collective cache preparation. One group retains the sparse transform and distribution required by OT's DBCSR kernels. Multiple groups read their owned cache; no world collective may occur in this loop.

Parameters
matrix_rscurrent real-space operator
kpointshost environment
kplocal k-point state
ispinsource row (one for spin-free S/T)
cache_reowned real part, used with multiple groups
cache_imowned imaginary part, used with multiple groups
matrix_renewly initialized sparse real output
matrix_imnewly initialized sparse imaginary output

Definition at line 1684 of file qs_kpoint_operators.F.

Here is the caller graph for this function:

◆ kpoint_operator_get_all()

subroutine, public qs_kpoint_operators::kpoint_operator_get_all ( type(kpoint_type), pointer kpoints,
type(cp_fm_type), intent(in) ao_ao_fm,
type(dbcsr_p_type), dimension(:, :), pointer rsmat,
integer, intent(in) slot,
type(cp_cfm_type), dimension(:), intent(inout) cmat,
integer, intent(in) matrix_row )

Fill caller-owned matrices for one operator row, including independent history snapshots. Prepare and fallback transfers are collective. Prepared one-rank groups evaluate k points concurrently, with no MPI or matrix allocation/refcounts inside the worker loop.

Parameters
kpointshost environment
ao_ao_fmglobal-layout template
rsmatcurrent real-space images
slotoperator slot
cmatallocated group-local outputs, one per locally owned k point
matrix_rowsource row; S/T use kpoint_spin_free

Definition at line 1742 of file qs_kpoint_operators.F.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kpoint_operator_store()

subroutine, public qs_kpoint_operators::kpoint_operator_store ( type(kpoint_type), pointer kpoints,
type(cp_fm_type), intent(in) ao_ao_fm,
type(dbcsr_p_type), dimension(:, :), pointer matrix_ks,
type(dbcsr_p_type), dimension(:, :), pointer matrix_s,
type(dbcsr_p_type), dimension(:, :), optional, pointer matrix_t )

Prepare owned split-FM operators for OT without entering an SCF eigensolver. H (or the initialization density) retains all source spins; S/T are built only once. Outputs survive the transient context. Compatible cache storage is reused, values refreshed.

Parameters
kpointshost environment and owned OT caches
ao_ao_fmglobal-layout template
matrix_ksHamiltonian or initialization density
matrix_sspin-free overlap
matrix_toptional spin-free kinetic operator; absent leaves the existing kinetic cache alone

Definition at line 1803 of file qs_kpoint_operators.F.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ kpoint_slot_ks

integer, parameter, public qs_kpoint_operators::kpoint_slot_ks = 1

Definition at line 88 of file qs_kpoint_operators.F.

◆ kpoint_slot_s

integer, parameter, public qs_kpoint_operators::kpoint_slot_s = 2

Definition at line 88 of file qs_kpoint_operators.F.

◆ kpoint_slot_t

integer, parameter, public qs_kpoint_operators::kpoint_slot_t = 3

Definition at line 88 of file qs_kpoint_operators.F.

◆ kpoint_spin_free

integer, parameter, public qs_kpoint_operators::kpoint_spin_free = 1

Row of rsmat that carries the spin-free operator image. S and T carry no spin copies: drivers launch one instance per spin of their loop and read this same row in every instance.

Definition at line 95 of file qs_kpoint_operators.F.

◆ rs_batch_size

integer, parameter qs_kpoint_operators::rs_batch_size = 4

Definition at line 146 of file qs_kpoint_operators.F.