88 complex(real64),
allocatable :: phase(:, :)
91 complex(real64),
public,
allocatable :: phase_corr(:,:)
94 complex(real64),
allocatable :: phase_k(:, :)
96 complex(real64),
allocatable :: phase_corr_k(:,:)
97 complex(real64),
allocatable :: vp_phase(:)
98 complex(real64),
allocatable :: vp_phase_corr(:)
99 complex(real64),
allocatable :: phase_spiral(:,:)
102 type(accel_mem_t) :: buff_phase
103 type(accel_mem_t) :: buff_phase_spiral
104 type(accel_mem_t),
public :: buff_phase_corr
105 integer :: buff_phase_qn_start
106 real(real64),
public,
pointer :: spin(:,:,:) => null()
136 class(phase_t),
intent(inout) :: phase
137 class(mesh_t),
intent(in) :: gr
138 type(distributed_t),
intent(in) :: kpt
139 type(kpoints_t),
intent(in) :: kpoints
140 type(states_elec_dim_t),
intent(in) :: d
141 type(space_t),
intent(in) :: space
143 integer :: ip, ik, sp
144 integer(int64) :: ip_inner_global
145 real(real64) :: kpoint(space%dim), x_global(space%dim)
152 phase%buff_phase_qn_start = kpt%start
154 if(kpoints%gamma_only())
then
159 safe_allocate(phase%phase(1:gr%np_part, kpt%start:kpt%end))
160 safe_allocate(phase%phase_corr(gr%np+1:gr%np_part, kpt%start:kpt%end))
162 do ik = kpt%start, kpt%end
164 do ip = gr%np + 1, gr%np_part
165 phase%phase_corr(ip, ik) =
m_one
174 if (gr%der%boundaries%spiralBC)
then
176 if (gr%parallel_in_domains) sp = gr%np + gr%pv%np_ghost
182 safe_allocate(phase%phase_spiral(1:gr%np_part-sp, 1:2))
185 do ip = sp + 1, gr%np_part
189 phase%phase_spiral(ip-sp, 1) = &
190 exp(
m_zi * sum((gr%x(1:space%dim, ip)-x_global(1:space%dim)) * gr%der%boundaries%spiral_q(1:space%dim)))
191 phase%phase_spiral(ip-sp, 2) = &
192 exp(-
m_zi * sum((gr%x(1:space%dim, ip)-x_global(1:space%dim)) * gr%der%boundaries%spiral_q(1:space%dim)))
197 call accel_write_buffer(phase%buff_phase_spiral, gr%np_part-sp, 2, phase%phase_spiral)
205 kpoint(1:space%dim) =
m_zero
208 if (gr%parallel_in_domains) sp = gr%np + gr%pv%np_ghost
211 do ik = kpt%start, kpt%end
212 kpoint(1:space%dim) = kpoints%get_point(d%get_kpoint_index(ik))
214 do ip = 1, gr%np_part
215 phase%phase(ip, ik) =
exp(-
m_zi * sum(gr%x(1:space%dim, ip) * kpoint(1:space%dim)))
221 do ip = sp + 1, gr%np_part
227 phase%phase_corr(ip, ik) = phase%phase(ip, ik)* &
228 exp(
m_zi * sum(x_global(1:space%dim) * kpoint(1:space%dim)))
238 call accel_write_buffer(phase%buff_phase_corr, gr%np_part - gr%np, kpt%nlocal(), phase%phase_corr)
246 subroutine phase_update_phases(phase, mesh, kpt, kpoints, d, space, uniform_vector_potential)
247 class(
phase_t),
intent(inout) :: phase
248 class(
mesh_t),
intent(in) :: mesh
252 type(
space_t),
intent(in) :: space
253 real(real64),
allocatable,
intent(in) :: uniform_vector_potential(:)
255 integer :: ik, ip, sp
256 integer(int64),
dimension(2) :: np, gsize, bsize
257 integer(int64) :: ip_inner_global
258 real(real64) :: kpoint(space%dim)
259 real(real64),
allocatable :: x_global(:,:), kpt_vec_pot(:,:)
260 type(
accel_mem_t) :: buff_vec_pot, buff_x_global, buff_x
263 character(len=128) :: kernel_name
264 real(real64) :: tmp_sum
266 if (.not.
allocated(uniform_vector_potential))
return
271 if (.not.
allocated(phase%phase))
then
272 safe_allocate(phase%phase(1:mesh%np_part, kpt%start:kpt%end))
275 mesh%np_part*kpt%nlocal())
279 if (.not.
allocated(phase%phase_corr))
then
280 safe_allocate(phase%phase_corr(mesh%np+1:mesh%np_part, kpt%start:kpt%end))
283 (mesh%np_part - mesh%np)*kpt%nlocal())
292 if (mesh%parallel_in_domains) sp = mesh%np + mesh%pv%np_ghost
294 safe_allocate(x_global(1:space%dim,(sp + 1):mesh%np_part))
297 do ip = sp + 1, mesh%np_part
301 x_global(:,ip) =
mesh_x_global(mesh, ip_inner_global) - mesh%x(1:space%dim, ip)
309 if (.not.
allocated(phase%phase_k))
then
310 safe_allocate(phase%phase_k(1:mesh%np_part, kpt%start:kpt%end))
311 safe_allocate(phase%phase_corr_k(sp + 1:mesh%np_part, kpt%start:kpt%end))
312 safe_allocate(phase%vp_phase(1:mesh%np_part))
313 safe_allocate(phase%vp_phase_corr(sp + 1:mesh%np_part))
315 do ik = kpt%start, kpt%end
316 kpoint(1:space%dim) = kpoints%get_point(d%get_kpoint_index(ik))
318 do ip = 1, mesh%np_part
319 tmp_sum = sum(mesh%x(1:space%dim, ip)*kpoint(1:space%dim))
320 phase%phase_k(ip, ik) = cmplx(
cos(tmp_sum), -
sin(tmp_sum), real64)
324 do ip = sp + 1, mesh%np_part
325 tmp_sum = sum(x_global(1:space%dim, ip)*kpoint(1:space%dim))
326 phase%phase_corr_k(ip, ik) = cmplx(
cos(tmp_sum),
sin(tmp_sum), real64)
336 do ip = 1, mesh%np_part
337 tmp_sum = sum(mesh%x(1:space%dim, ip)*uniform_vector_potential(1:space%dim))
338 phase%vp_phase(ip) = cmplx(
cos(tmp_sum), -
sin(tmp_sum), real64)
342 do ip = sp + 1, mesh%np_part
343 tmp_sum = sum(x_global(1:space%dim, ip)*uniform_vector_potential(1:space%dim))
344 phase%vp_phase_corr(ip) = cmplx(
cos(tmp_sum),
sin(tmp_sum), real64)
349 do ik = kpt%start, kpt%end
351 do ip = 1, mesh%np_part
352 phase%phase(ip, ik) = phase%phase_k(ip, ik) * phase%vp_phase(ip)
356 do ip = sp + 1, mesh%np_part
357 phase%phase_corr(ip, ik) = phase%phase_corr_k(ip, ik) * phase%vp_phase_corr(ip)
366 safe_allocate(kpt_vec_pot(1:space%dim,kpt%start:kpt%end))
367 do ik = kpt%start, kpt%end
368 kpoint(1:space%dim) = kpoints%get_point(d%get_kpoint_index(ik))
369 kpt_vec_pot(1:space%dim, ik) = kpoint(1:space%dim) + uniform_vector_potential(1:space%dim)
378 call accel_write_buffer(buff_x_global, space%dim, mesh%np_part-sp, x_global(1:space%dim,(sp + 1):mesh%np_part), async=.
true.)
380 write(kernel_name,
'(a,i1,a)')
'update_phases<double, Dim::D', space%dim,
'>'
381 kernel => kernels(space%dim)
396 np = (/mesh%np_part, kpt%nlocal()/)
403 call accel_read_buffer(phase%buff_phase_corr, mesh%np_part - mesh%np, kpt%nlocal(), phase%phase_corr)
408 safe_deallocate_a(kpt_vec_pot)
411 safe_deallocate_a(x_global)
419 class(
phase_t),
intent(inout) :: phase
432 safe_deallocate_a(phase%phase)
433 safe_deallocate_a(phase%phase_corr)
434 safe_deallocate_a(phase%phase_k)
435 safe_deallocate_a(phase%phase_corr_k)
436 safe_deallocate_a(phase%vp_phase)
437 safe_deallocate_a(phase%vp_phase_corr)
438 safe_deallocate_a(phase%phase_spiral)
446 class(
phase_t),
intent(inout) :: phase
447 class(
mesh_t),
intent(in) :: mesh
459 phase%buff_phase_qn_start = kpt%start
465 if (
allocated(phase%phase))
then
466 assert(
size(phase%phase, 1) == mesh%np_part)
467 nlocal = ubound(phase%phase, dim=2) - lbound(phase%phase, dim=2) + 1
472 if (
allocated(phase%phase_corr))
then
473 assert(
size(phase%phase_corr, 1) == mesh%np_part - mesh%np)
474 nlocal = ubound(phase%phase_corr, dim=2) - lbound(phase%phase_corr, dim=2) + 1
476 size(phase%phase_corr, 1)*nlocal)
477 call accel_write_buffer(phase%buff_phase_corr,
size(phase%phase_corr, 1), nlocal, phase%phase_corr)
480 if (
allocated(phase%phase_spiral))
then
482 size(phase%phase_spiral, 1)*
size(phase%phase_spiral, 2))
484 size(phase%phase_spiral, 2), phase%phase_spiral)
494 class(
phase_t),
intent(in) :: phase
495 class(
mesh_t),
intent(in) :: mesh
497 logical,
optional,
intent(in) :: async
500 logical :: phase_correction
505 phase_correction = phase%is_allocated()
509 if (phase_correction)
then
510 call phase%apply_to(mesh, mesh%np, .false., psib, async=async)
520 class(
phase_t),
intent(in) :: phase
521 class(
mesh_t),
intent(in) :: mesh
523 logical,
optional,
intent(in) :: async
525 logical :: phase_correction
530 phase_correction = phase%is_allocated()
534 if (phase_correction)
then
535 call phase%apply_to(mesh, mesh%np, .
true., psib, async=async)
545 class(
phase_t),
intent(in) :: this
546 class(
mesh_t),
intent(in) :: mesh
547 integer,
intent(in) :: np
548 logical,
intent(in) :: conjugate
549 type(
wfs_elec_t),
target,
intent(inout) :: psib
550 type(
wfs_elec_t),
optional,
target,
intent(in) :: src
551 logical,
optional,
intent(in) :: async
553 integer :: ip, ii, sp
555 complex(real64) :: phase
556 integer(int64),
dimension(3) :: gsizes, bsizes
564 assert(np <= mesh%np_part)
566 assert(psib%ik >= lbound(this%phase, dim=2))
567 assert(psib%ik <= ubound(this%phase, dim=2))
570 if (
present(src)) src_ => src
572 assert(src_%has_phase .eqv. conjugate)
573 assert(src_%ik == psib%ik)
577 sp = min(np, mesh%np)
578 if (np > mesh%np .and. mesh%parallel_in_domains) sp = mesh%np + mesh%pv%np_ghost
580 select case (psib%status())
587 do ip = 1, min(mesh%np, np)
588 phase = conjg(this%phase(ip, psib%ik))
590 do ii = 1, psib%nst_linear
591 psib%zff_pack(ii, ip) = phase*src_%zff_pack(ii, ip)
599 phase = conjg(this%phase(ip, psib%ik))
601 do ii = 1, psib%nst_linear
602 psib%zff_pack(ii, ip) = phase*src_%zff_pack(ii, ip)
611 do ip = 1, min(mesh%np, np)
612 phase = this%phase(ip, psib%ik)
614 do ii = 1, psib%nst_linear
615 psib%zff_pack(ii, ip) = phase*src_%zff_pack(ii, ip)
623 phase = this%phase(ip, psib%ik)
625 do ii = 1, psib%nst_linear
626 psib%zff_pack(ii, ip) = phase*src_%zff_pack(ii, ip)
638 do ii = 1, psib%nst_linear
640 do ip = 1, min(mesh%np, np)
641 psib%zff_linear(ip, ii) = conjg(this%phase(ip, psib%ik))*src_%zff_linear(ip, ii)
648 psib%zff_linear(ip, ii) = conjg(this%phase(ip, psib%ik))*src_%zff_linear(ip, ii)
656 do ii = 1, psib%nst_linear
658 do ip = 1, min(mesh%np, np)
659 psib%zff_linear(ip, ii) = this%phase(ip, psib%ik)*src_%zff_linear(ip, ii)
666 psib%zff_linear(ip, ii) = this%phase(ip, psib%ik)*src_%zff_linear(ip, ii)
700 psib%has_phase = .not. conjugate
713 class(
phase_t),
intent(in) :: this
714 complex(real64),
intent(inout) :: psi(:, :)
715 integer,
intent(in) :: np
716 integer,
intent(in) :: dim
717 integer,
intent(in) :: ik
718 logical,
intent(in) :: conjugate
724 assert(ik >= lbound(this%phase, dim=2))
725 assert(ik <= ubound(this%phase, dim=2))
734 psi(ip, idim) = conjg(this%phase(ip, ik))*psi(ip, idim)
743 psi(ip, idim) = this%phase(ip, ik)*psi(ip, idim)
764 class(
mesh_t),
intent(in) :: mesh
765 integer,
intent(in) :: np
766 real(real64),
contiguous,
intent(in) :: kvector(:)
767 logical,
intent(in) :: conjugate
768 complex(real64),
contiguous,
intent(out) :: phase(:)
771 complex(real64) :: factor
775 assert(
size(phase) >= np)
777 factor = merge(
m_zi, -
m_zi, conjugate)
781 phase(ip) =
exp(factor*dot_product(mesh%x(1:
size(kvector), ip), kvector))
793 class(
phase_t),
intent(in) :: this
797 integer :: ip, ii, sp
798 integer,
allocatable :: spin_label(:)
800 integer(int64) :: bsize
801 integer(int64),
dimension(2) :: np, gsizes, bsizes
808 assert(der%boundaries%spiral)
812 if (der%mesh%parallel_in_domains) sp = der%mesh%np + der%mesh%pv%np_ghost
815 select case (psib%status())
819 do ip = sp + 1, der%mesh%np_part
820 do ii = 1, psib%nst_linear, 2
821 if (this%spin(3,psib%linear_to_ist(ii), psib%ik)>0)
then
822 psib%zff_pack(ii+1, ip) = psib%zff_pack(ii+1, ip)*this%phase_spiral(ip-sp, 1)
824 psib%zff_pack(ii, ip) = psib%zff_pack(ii, ip)*this%phase_spiral(ip-sp, 2)
833 do ii = 1, psib%nst_linear, 2
834 if (this%spin(3,psib%linear_to_ist(ii), psib%ik)>0)
then
836 do ip = sp + 1, der%mesh%np_part
837 psib%zff_linear(ip, ii+1) = psib%zff_linear(ip, ii+1)*this%phase_spiral(ip-sp, 1)
842 do ip = sp + 1, der%mesh%np_part
843 psib%zff_linear(ip, ii) = psib%zff_linear(ip, ii)*this%phase_spiral(ip-sp, 2)
859 safe_allocate(spin_label(1:psib%nst_linear))
861 do ii = 1, psib%nst_linear, 2
862 if (this%spin(3, psib%linear_to_ist(ii), psib%ik) > 0) spin_label(ii)=1
880 np = (/psib%pack_size(1)/2_int64, int(der%mesh%np_part - sp, int64)/)
881 bsizes = (/psib%pack_size(1)/2, 2*bsize/)
890 safe_deallocate_a(spin_label)
900 logical pure function phase_is_allocated(this)
901 class(
phase_t),
intent(in) :: this
903 phase_is_allocated =
allocated(this%phase)
914 class(
phase_t),
intent(in) :: phase
915 type(grid_t),
intent(in) :: gr
916 type(distributed_t),
intent(in) :: kpt
917 type(wfs_elec_t),
intent(in) :: psib
918 type(wfs_elec_t),
intent(out) :: psib_with_phase
920 integer :: k_offset, n_boundary_points
924 call psib%copy_to(psib_with_phase)
925 if (phase%is_allocated())
then
926 call phase%apply_to(gr, gr%np, conjugate = .false., psib = psib_with_phase, src = psib, async=.
true.)
929 k_offset = psib%ik - kpt%start
930 n_boundary_points = int(gr%np_part - gr%np)
931 call boundaries_set(gr%der%boundaries, gr, psib_with_phase, phase_correction = phase%phase_corr(:, psib%ik), &
932 buff_phase_corr = phase%buff_phase_corr, offset=k_offset*n_boundary_points, async=.
true.)
934 call psib%copy_data_to(gr%np, psib_with_phase)
935 call boundaries_set(gr%der%boundaries, gr, psib_with_phase)
938 call psib_with_phase%do_pack(copy = .
true.)
952 class(
phase_t),
intent(in) :: this
953 class(mesh_t),
intent(in) :: mesh
954 type(boundaries_t),
intent(in) :: boundaries
955 type(wfs_elec_t),
intent(inout) :: ffb
957 integer :: k_offset, n_boundary_points
961 if (this%is_allocated())
then
962 assert(ffb%has_phase)
963 k_offset = ffb%ik - lbound(this%phase_corr, dim=2)
964 n_boundary_points = mesh%np_part - mesh%np
965 call boundaries_set(boundaries, mesh, ffb, phase_correction = this%phase_corr(:, ffb%ik), &
966 buff_phase_corr = this%buff_phase_corr, offset = k_offset*n_boundary_points)
968 assert(.not. ffb%has_phase)
969 call boundaries_set(boundaries, mesh, ffb)
double exp(double __x) __attribute__((__nothrow__
double sin(double __x) __attribute__((__nothrow__
double cos(double __x) __attribute__((__nothrow__
integer function, public accel_kernel_block_size(kernel)
subroutine, public accel_free_buffer(this, async)
subroutine, public accel_kernel_start_call(this, file_name, kernel_name, flags)
subroutine, public accel_finish()
subroutine, public accel_detach_buffer(this)
Clear a buffer handle without freeing device memory.
integer, parameter, public accel_mem_read_write
type(accel_kernel_t), target, save, public kernel_phase_spiral
pure logical function, public accel_is_enabled()
integer, parameter, public accel_mem_read_only
This module implements batches of mesh functions.
integer, parameter, public batch_not_packed
functions are stored in CPU memory, unpacked order
integer, parameter, public batch_device_packed
functions are stored in device memory in packed order
integer, parameter, public batch_packed
functions are stored in CPU memory, in transposed (packed) order
This module implements common operations on batches of mesh functions.
Module implementing boundary conditions in Octopus.
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
real(real64), parameter, public m_zero
complex(real64), parameter, public m_zi
real(real64), parameter, public m_one
This module implements the underlying real-space grid.
This module is intended to contain "only mathematical" functions and procedures.
This module defines the meshes, which are used in Octopus.
integer(int64) function, public mesh_periodic_point(mesh, space, ip)
This function returns the point inside the grid corresponding to a boundary point when PBCs are used....
real(real64) function, dimension(1:mesh%box%dim), public mesh_x_global(mesh, ipg)
Given a global point index, this function returns the coordinates of the point.
subroutine phase_phase_spiral(this, der, psib)
apply spiral phase
subroutine phase_unset_phase_corr(phase, mesh, psib, async)
unset the phase correction (if necessary)
subroutine, public phase_accel_rebuild(phase, mesh, kpt)
Rebuild phase accelerator buffers after an intrinsic copy.
subroutine phase_copy_and_set_phase(phase, gr, kpt, psib, psib_with_phase)
Copy a batch to another batch and apply the Bloch phase to it.
subroutine phase_init_phases(phase, gr, kpt, kpoints, d, space)
Initiliaze the phase arrays and copy to GPU the data.
subroutine phase_end(phase)
Releases the memory of the phase object.
subroutine phase_update_phases(phase, mesh, kpt, kpoints, d, space, uniform_vector_potential)
Update the phases.
subroutine, public phase_build_vector(mesh, np, kvector, conjugate, phase)
tabulate an explicitly supplied reciprocal-vector phase.
logical pure function phase_is_allocated(this)
subroutine phase_apply_batch(this, mesh, np, conjugate, psib, src, async)
apply (remove) the phase to the wave functions before (after) applying the Hamiltonian
subroutine phase_set_phase_corr(phase, mesh, psib, async)
set the phase correction (if necessary)
subroutine phase_apply_mf(this, psi, np, dim, ik, conjugate)
apply (or remove) the phase to a wave function psi
subroutine phase_set_boundaries(this, mesh, boundaries, ffb)
Set the boundary points of a (possibly Bloch-phased) batch.
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
This module handles spin dimensions of the states and the k-point distribution.
type(type_t), parameter, public type_cmplx
type(type_t), parameter, public type_integer
type(type_t), parameter, public type_float
class representing derivatives
Distribution of N instances over mpi_grpsize processes, for the local rank mpi_grprank....
Description of the grid, containing information on derivatives, stencil, and symmetries.
Describes mesh distribution to nodes.
A container for the phase.
class for organizing spins and k-points
batches of electronic states