96 INTEGER,
DIMENSION(:),
INTENT(in) :: atomlist_row, atomlist_col
99 CHARACTER(LEN=*),
PARAMETER :: routinen =
'negf_copy_fm_submat_to_dbcsr'
101 INTEGER :: first_sgf_col, first_sgf_row, handle, iatom_col, iatom_row, icol, irow, &
102 natoms_col, natoms_row, ncols, nparticles, nrows
103 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: nsgfs
105 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: fm_block
106 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: sm_block
108 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
110 CALL timeset(routinen, handle)
112 cpassert(
ASSOCIATED(matrix))
113 cpassert(
ASSOCIATED(subsys))
117 CALL qs_subsys_get(subsys, particle_set=particle_set, qs_kind_set=qs_kind_set)
119 natoms_row =
SIZE(atomlist_row)
120 natoms_col =
SIZE(atomlist_col)
121 nparticles =
SIZE(particle_set)
123 ALLOCATE (nsgfs(nparticles))
126 ALLOCATE (fm_block(nrows, ncols))
130 DO iatom_col = 1, natoms_col
132 DO iatom_row = 1, natoms_row
133 CALL dbcsr_get_block_p(matrix=matrix, row=atomlist_row(iatom_row), col=atomlist_col(iatom_col), &
134 block=sm_block, found=found)
139 nrows = nsgfs(atomlist_row(iatom_row))
140 ncols = nsgfs(atomlist_col(iatom_col))
143 sm_block(irow, icol) = fm_block(first_sgf_row + irow - 1, first_sgf_col + icol - 1)
148 first_sgf_row = first_sgf_row + nsgfs(atomlist_row(iatom_row))
150 first_sgf_col = first_sgf_col + nsgfs(atomlist_col(iatom_col))
153 DEALLOCATE (fm_block)
156 CALL timestop(handle)
180 mpi_comm_global, do_upper_diag, do_lower)
183 INTEGER,
DIMENSION(:),
INTENT(in) :: atomlist_row, atomlist_col
187 LOGICAL,
INTENT(in) :: do_upper_diag, do_lower
189 CHARACTER(LEN=*),
PARAMETER :: routinen =
'negf_copy_sym_dbcsr_to_fm_submat'
191 INTEGER :: handle, iatom_col, iatom_row, icol, irow, natoms_col, natoms_row, ncols_fm, &
192 nparticles, nrows_fm, offset_sgf_col, offset_sgf_row
193 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: nsgfs
195 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: r2d
196 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: sm_block
199 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
201 CALL timeset(routinen, handle)
203 cpassert(
ASSOCIATED(matrix))
204 cpassert(
ASSOCIATED(subsys))
206 CALL qs_subsys_get(subsys, particle_set=particle_set, qs_kind_set=qs_kind_set)
208 natoms_row =
SIZE(atomlist_row)
209 natoms_col =
SIZE(atomlist_col)
210 nparticles =
SIZE(particle_set)
212 ALLOCATE (nsgfs(nparticles))
215 CALL cp_fm_get_info(fm, nrow_global=nrows_fm, ncol_global=ncols_fm, para_env=para_env)
217 IF (debug_this_module)
THEN
218 cpassert(sum(nsgfs(atomlist_row(:))) == nrows_fm)
219 cpassert(sum(nsgfs(atomlist_col(:))) == ncols_fm)
222 ALLOCATE (r2d(nrows_fm, ncols_fm))
226 DO iatom_col = 1, natoms_col
229 DO iatom_row = 1, natoms_row
230 IF (atomlist_row(iatom_row) <= atomlist_col(iatom_col))
THEN
231 IF (do_upper_diag)
THEN
232 CALL dbcsr_get_block_p(matrix=matrix, row=atomlist_row(iatom_row), col=atomlist_col(iatom_col), &
233 block=sm_block, found=found)
237 CALL dbcsr_get_block_p(matrix=matrix, row=atomlist_col(iatom_col), col=atomlist_row(iatom_row), &
238 block=sm_block, found=found)
243 IF (atomlist_row(iatom_row) <= atomlist_col(iatom_col))
THEN
244 IF (do_upper_diag)
THEN
245 DO icol = nsgfs(atomlist_col(iatom_col)), 1, -1
246 DO irow = nsgfs(atomlist_row(iatom_row)), 1, -1
247 r2d(offset_sgf_row + irow, offset_sgf_col + icol) = sm_block(irow, icol)
253 DO icol = nsgfs(atomlist_col(iatom_col)), 1, -1
254 DO irow = nsgfs(atomlist_row(iatom_row)), 1, -1
255 r2d(offset_sgf_row + irow, offset_sgf_col + icol) = sm_block(icol, irow)
262 offset_sgf_row = offset_sgf_row + nsgfs(atomlist_row(iatom_row))
264 offset_sgf_col = offset_sgf_col + nsgfs(atomlist_col(iatom_col))
267 CALL mpi_comm_global%sum(r2d)
274 CALL timestop(handle)
296 atom_list0, atom_list1, subsys, mpi_comm_global, is_same_cell, matrix_ref)
297 TYPE(
cp_fm_type),
INTENT(IN) :: fm_cell0, fm_cell1
298 INTEGER,
INTENT(in) :: direction_axis
299 TYPE(
dbcsr_p_type),
DIMENSION(:),
INTENT(in) :: matrix_kp
300 INTEGER,
DIMENSION(:, :),
INTENT(in) :: index_to_cell
301 INTEGER,
DIMENSION(:),
INTENT(in) :: atom_list0, atom_list1
305 INTEGER,
DIMENSION(:, :),
INTENT(inout) :: is_same_cell
306 TYPE(
dbcsr_type),
OPTIONAL,
POINTER :: matrix_ref
308 CHARACTER(LEN=*),
PARAMETER :: routinen =
'negf_copy_contact_matrix'
310 INTEGER :: direction_axis_abs, handle, iatom_col, &
311 iatom_row, image, natoms, nimages, &
314 REAL(kind=
dp) :: error_diff, error_same
315 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block_dest, block_src
316 TYPE(
dbcsr_p_type),
ALLOCATABLE,
DIMENSION(:) :: matrix_cells_raw
317 TYPE(
dbcsr_type),
POINTER :: matrix_cell_0, matrix_cell_1, &
320 CALL timeset(routinen, handle)
322 cpassert(
ASSOCIATED(subsys))
324 nimages =
SIZE(index_to_cell, 2)
325 direction_axis_abs = abs(direction_axis)
332 ALLOCATE (matrix_cells_raw(-2:2))
334 NULLIFY (matrix_cells_raw(rep)%matrix)
336 CALL dbcsr_copy(matrix_cells_raw(rep)%matrix, matrix_kp(1)%matrix)
337 CALL dbcsr_set(matrix_cells_raw(rep)%matrix, 0.0_dp)
340 NULLIFY (matrix_cell_0, matrix_cell_1, matrix_cell_minus1)
343 CALL dbcsr_copy(matrix_cell_0, matrix_kp(1)%matrix)
347 CALL dbcsr_copy(matrix_cell_1, matrix_kp(1)%matrix)
351 CALL dbcsr_copy(matrix_cell_minus1, matrix_kp(1)%matrix)
352 CALL dbcsr_set(matrix_cell_minus1, 0.0_dp)
354 DO image = 1, nimages
355 rep = index_to_cell(direction_axis_abs, image)
358 CALL dbcsr_add(matrix_cells_raw(rep)%matrix, matrix_kp(image)%matrix, 1.0_dp, 1.0_dp)
363 IF (
PRESENT(matrix_ref))
THEN
366 is_same_cell(:, :) = 0
368 DO iatom_col = 1, natoms
369 DO iatom_row = 1, iatom_col
371 row=iatom_row, col=iatom_col, &
372 block=block_src, found=found)
377 IF (mod(iatom_col - iatom_row, 2) == 0)
THEN
384 row=iatom_row, col=iatom_col, &
385 block=block_dest, found=found)
388 error_same = maxval(abs(block_dest(:, :) - block_src(:, :)))
391 row=iatom_row, col=iatom_col, &
392 block=block_dest, found=found)
394 error_diff = maxval(abs(block_dest(:, :) - block_src(:, :)))
396 IF (error_same <= error_diff)
THEN
397 is_same_cell(iatom_row, iatom_col) = 0
399 is_same_cell(iatom_row, iatom_col) = 1
406 DO iatom_col = 1, natoms
407 DO iatom_row = 1, iatom_col
409 row=iatom_row, col=iatom_col, block=block_dest, found=found)
413 IF (mod(iatom_col - iatom_row, 2) == 0)
THEN
418 rep = phase*is_same_cell(iatom_row, iatom_col)
424 row=iatom_row, col=iatom_col, block=block_src, found=found)
426 block_dest(:, :) = block_src(:, :)
432 row=iatom_row, col=iatom_col, block=block_dest, found=found)
435 row=iatom_row, col=iatom_col, block=block_src, found=found)
437 block_dest(:, :) = block_src(:, :)
443 row=iatom_row, col=iatom_col, block=block_dest, found=found)
446 row=iatom_row, col=iatom_col, block=block_src, found=found)
448 block_dest(:, :) = block_src(:, :)
453 IF (direction_axis >= 0)
THEN
456 subsys, mpi_comm_global, do_upper_diag=.true., do_lower=.false.)
459 subsys, mpi_comm_global, do_upper_diag=.false., do_lower=.true.)
463 subsys, mpi_comm_global, do_upper_diag=.true., do_lower=.false.)
466 subsys, mpi_comm_global, do_upper_diag=.false., do_lower=.true.)
473 subsys, mpi_comm_global, do_upper_diag=.true., do_lower=.true.)
482 DEALLOCATE (matrix_cells_raw)
484 CALL timestop(handle)
497 TYPE(
dbcsr_type),
POINTER :: matrix_contact, matrix_device
498 INTEGER,
DIMENSION(:),
INTENT(in) :: atom_list
502 CHARACTER(LEN=*),
PARAMETER :: routinen =
'negf_reference_contact_matrix'
504 INTEGER :: handle, i1, i2, iatom_col, iatom_row, &
505 icol, iproc, irow, max_atom, &
506 mepos_plus1, n1, n2, natoms, offset
507 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: recv_nelems, send_nelems
508 INTEGER,
ALLOCATABLE,
DIMENSION(:, :) :: rank_contact, rank_device
509 LOGICAL :: found, transp
510 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: rblock
511 TYPE(
mp_request_type),
ALLOCATABLE,
DIMENSION(:) :: recv_handlers, send_handlers
513 DIMENSION(:) :: recv_packed_blocks, send_packed_blocks
515 CALL timeset(routinen, handle)
516 mepos_plus1 = para_env%mepos + 1
518 natoms =
SIZE(atom_list)
520 DO iatom_row = 1, natoms
521 IF (atom_map(iatom_row)%iatom > max_atom) max_atom = atom_map(iatom_row)%iatom
525 ALLOCATE (rank_contact(max_atom, max_atom))
526 ALLOCATE (rank_device(max_atom, max_atom))
528 rank_contact(:, :) = 0
529 rank_device(:, :) = 0
531 DO iatom_col = 1, natoms
532 DO iatom_row = 1, iatom_col
533 IF (atom_map(iatom_row)%iatom <= atom_map(iatom_col)%iatom)
THEN
534 icol = atom_map(iatom_col)%iatom
535 irow = atom_map(iatom_row)%iatom
537 icol = atom_map(iatom_row)%iatom
538 irow = atom_map(iatom_col)%iatom
542 row=atom_list(iatom_row), col=atom_list(iatom_col), &
543 block=rblock, found=found)
544 IF (found) rank_device(irow, icol) = mepos_plus1
546 CALL dbcsr_get_block_p(matrix=matrix_contact, row=irow, col=icol, block=rblock, found=found)
547 IF (found) rank_contact(irow, icol) = mepos_plus1
551 CALL para_env%sum(rank_device)
552 CALL para_env%sum(rank_contact)
555 ALLOCATE (recv_nelems(para_env%num_pe))
556 ALLOCATE (send_nelems(para_env%num_pe))
560 DO iatom_col = 1, natoms
561 DO iatom_row = 1, iatom_col
562 IF (atom_map(iatom_row)%iatom <= atom_map(iatom_col)%iatom)
THEN
563 icol = atom_map(iatom_col)%iatom
564 irow = atom_map(iatom_row)%iatom
566 icol = atom_map(iatom_row)%iatom
567 irow = atom_map(iatom_col)%iatom
571 row=atom_list(iatom_row), col=atom_list(iatom_col), &
572 block=rblock, found=found)
574 iproc = rank_contact(irow, icol)
576 send_nelems(iproc) = send_nelems(iproc) +
SIZE(rblock)
579 CALL dbcsr_get_block_p(matrix=matrix_contact, row=irow, col=icol, block=rblock, found=found)
581 iproc = rank_device(irow, icol)
583 recv_nelems(iproc) = recv_nelems(iproc) +
SIZE(rblock)
589 ALLOCATE (recv_packed_blocks(para_env%num_pe))
590 DO iproc = 1, para_env%num_pe
591 IF (iproc /= mepos_plus1 .AND. recv_nelems(iproc) > 0) &
592 ALLOCATE (recv_packed_blocks(iproc)%vector(recv_nelems(iproc)))
595 ALLOCATE (send_packed_blocks(para_env%num_pe))
596 DO iproc = 1, para_env%num_pe
597 IF (send_nelems(iproc) > 0) &
598 ALLOCATE (send_packed_blocks(iproc)%vector(send_nelems(iproc)))
602 DO iatom_col = 1, natoms
603 DO iatom_row = 1, iatom_col
604 IF (atom_map(iatom_row)%iatom <= atom_map(iatom_col)%iatom)
THEN
605 icol = atom_map(iatom_col)%iatom
606 irow = atom_map(iatom_row)%iatom
609 icol = atom_map(iatom_row)%iatom
610 irow = atom_map(iatom_col)%iatom
614 iproc = rank_contact(irow, icol)
617 row=atom_list(iatom_row), col=atom_list(iatom_col), &
618 block=rblock, found=found)
620 offset = send_nelems(iproc)
627 send_packed_blocks(iproc)%vector(offset + i2) = rblock(i1, i2)
634 send_packed_blocks(iproc)%vector(offset + i1) = rblock(i1, i2)
640 send_nelems(iproc) = offset
647 ALLOCATE (recv_handlers(para_env%num_pe), send_handlers(para_env%num_pe))
649 DO iproc = 1, para_env%num_pe
650 IF (iproc /= mepos_plus1 .AND. send_nelems(iproc) > 0)
THEN
651 CALL para_env%isend(send_packed_blocks(iproc)%vector, iproc - 1, send_handlers(iproc), 1)
656 DO iproc = 1, para_env%num_pe
657 IF (iproc /= mepos_plus1)
THEN
658 IF (recv_nelems(iproc) > 0)
THEN
659 CALL para_env%irecv(recv_packed_blocks(iproc)%vector, iproc - 1, recv_handlers(iproc), 1)
662 IF (
ALLOCATED(send_packed_blocks(iproc)%vector)) &
663 CALL move_alloc(send_packed_blocks(iproc)%vector, recv_packed_blocks(iproc)%vector)
668 DO iproc = 1, para_env%num_pe
669 IF (iproc /= mepos_plus1 .AND. recv_nelems(iproc) > 0) &
670 CALL recv_handlers(iproc)%wait()
674 DO iatom_col = 1, natoms
675 DO iatom_row = 1, iatom_col
676 IF (atom_map(iatom_row)%iatom <= atom_map(iatom_col)%iatom)
THEN
677 icol = atom_map(iatom_col)%iatom
678 irow = atom_map(iatom_row)%iatom
680 icol = atom_map(iatom_row)%iatom
681 irow = atom_map(iatom_col)%iatom
684 iproc = rank_device(irow, icol)
686 CALL dbcsr_get_block_p(matrix=matrix_contact, row=irow, col=icol, block=rblock, found=found)
689 offset = recv_nelems(iproc)
695 rblock(i1, i2) = recv_packed_blocks(iproc)%vector(offset + i1)
700 recv_nelems(iproc) = offset
706 DO iproc = 1, para_env%num_pe
707 IF (iproc /= mepos_plus1 .AND. send_nelems(iproc) > 0) &
708 CALL send_handlers(iproc)%wait()
712 DEALLOCATE (recv_handlers, send_handlers)
714 DO iproc = para_env%num_pe, 1, -1
715 IF (
ALLOCATED(send_packed_blocks(iproc)%vector)) &
716 DEALLOCATE (send_packed_blocks(iproc)%vector)
718 DEALLOCATE (send_packed_blocks)
720 DO iproc = para_env%num_pe, 1, -1
721 IF (
ALLOCATED(recv_packed_blocks(iproc)%vector)) &
722 DEALLOCATE (recv_packed_blocks(iproc)%vector)
724 DEALLOCATE (recv_packed_blocks)
726 DEALLOCATE (rank_contact, rank_device)
727 CALL timestop(handle)
subroutine, public get_particle_set(particle_set, qs_kind_set, first_sgf, last_sgf, nsgf, nmao, basis)
Get the components of a particle set.
subroutine, public qs_subsys_get(subsys, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell, cell_ref, use_ref_cell, energy, force, qs_kind_set, cp_subsys, nelectron_total, nelectron_spin)
...