Skip to content

Commit

Permalink
Replace dbcsr_copy_into_existing(...) with dbcsr_copy(..., keep_spars…
Browse files Browse the repository at this point in the history
…ity=.TRUE.)
  • Loading branch information
oschuett committed Jun 2, 2024
1 parent 50e1bb5 commit 217d986
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 74 deletions.
14 changes: 7 additions & 7 deletions src/almo_scf_qs.F
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ MODULE almo_scf_qs
pbc
USE cp_control_types, ONLY: dft_control_type
USE cp_dbcsr_api, ONLY: &
dbcsr_complete_redistribute, dbcsr_copy, dbcsr_copy_into_existing, dbcsr_create, &
dbcsr_desymmetrize, dbcsr_distribution_get, dbcsr_distribution_new, &
dbcsr_distribution_release, dbcsr_distribution_type, dbcsr_filter, dbcsr_finalize, &
dbcsr_get_block_p, dbcsr_get_info, dbcsr_get_num_blocks, dbcsr_get_stored_coordinates, &
dbcsr_multiply, dbcsr_nblkcols_total, dbcsr_nblkrows_total, dbcsr_p_type, dbcsr_release, &
dbcsr_reserve_block2d, dbcsr_set, dbcsr_type, dbcsr_type_no_symmetry, dbcsr_work_create
dbcsr_complete_redistribute, dbcsr_copy, dbcsr_create, dbcsr_desymmetrize, &
dbcsr_distribution_get, dbcsr_distribution_new, dbcsr_distribution_release, &
dbcsr_distribution_type, dbcsr_filter, dbcsr_finalize, dbcsr_get_block_p, dbcsr_get_info, &
dbcsr_get_num_blocks, dbcsr_get_stored_coordinates, dbcsr_multiply, dbcsr_nblkcols_total, &
dbcsr_nblkrows_total, dbcsr_p_type, dbcsr_release, dbcsr_reserve_block2d, dbcsr_set, &
dbcsr_type, dbcsr_type_no_symmetry, dbcsr_work_create
USE cp_dbcsr_cp2k_link, ONLY: cp_dbcsr_alloc_block_from_nbl
USE cp_dbcsr_operations, ONLY: dbcsr_allocate_matrix_set
USE cp_fm_struct, ONLY: cp_fm_struct_create,&
Expand Down Expand Up @@ -486,7 +486,7 @@ SUBROUTINE matrix_almo_to_qs(matrix_almo, matrix_qs, mat_distr_aos)

SELECT CASE (mat_distr_aos)
CASE (almo_mat_distr_atomic)
CALL dbcsr_copy_into_existing(matrix_qs, matrix_almo)
CALL dbcsr_copy(matrix_qs, matrix_almo, keep_sparsity=.TRUE.)
CASE (almo_mat_distr_molecular)
CALL dbcsr_set(matrix_qs, 0.0_dp)
CALL dbcsr_complete_redistribute(matrix_almo, matrix_qs, keep_sparsity=.TRUE.)
Expand Down
12 changes: 0 additions & 12 deletions src/dbx/cp_dbcsr_api.F
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ MODULE cp_dbcsr_api
dbcsr_convert_offsets_to_sizes, &
dbcsr_convert_sizes_to_offsets, &
dbcsr_copy_prv => dbcsr_copy, &
dbcsr_copy_into_existing_prv => dbcsr_copy_into_existing, &
dbcsr_create_prv => dbcsr_create, &
dbcsr_csr_create, &
dbcsr_csr_create_from_dbcsr_prv => dbcsr_csr_create_from_dbcsr, &
Expand Down Expand Up @@ -157,7 +156,6 @@ MODULE cp_dbcsr_api
PUBLIC :: dbcsr_transposed
PUBLIC :: dbcsr_multiply
PUBLIC :: dbcsr_copy
PUBLIC :: dbcsr_copy_into_existing
PUBLIC :: dbcsr_desymmetrize
PUBLIC :: dbcsr_add_on_diag
PUBLIC :: dbcsr_get_block_diag
Expand Down Expand Up @@ -506,16 +504,6 @@ SUBROUTINE dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
keep_imaginary=keep_imaginary)
END SUBROUTINE dbcsr_copy

! **************************************************************************************************
!> \brief ...
! **************************************************************************************************
SUBROUTINE dbcsr_copy_into_existing(matrix_b, matrix_a)
TYPE(dbcsr_type), INTENT(INOUT) :: matrix_b
TYPE(dbcsr_type), INTENT(IN) :: matrix_a

CALL dbcsr_copy_into_existing_prv(matrix_b%prv, matrix_a%prv)
END SUBROUTINE dbcsr_copy_into_existing

! **************************************************************************************************
!> \brief ...
! **************************************************************************************************
Expand Down
24 changes: 8 additions & 16 deletions src/dm_ls_scf_qs.F
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ MODULE dm_ls_scf_qs
USE atomic_kind_types, ONLY: atomic_kind_type
USE cp_control_types, ONLY: dft_control_type
USE cp_dbcsr_api, ONLY: &
dbcsr_complete_redistribute, dbcsr_copy, dbcsr_copy_into_existing, dbcsr_create, &
dbcsr_desymmetrize, dbcsr_distribution_get, dbcsr_distribution_hold, &
dbcsr_distribution_new, dbcsr_distribution_release, dbcsr_distribution_type, &
dbcsr_finalize, dbcsr_get_info, dbcsr_multiply, dbcsr_nblkrows_total, dbcsr_p_type, &
dbcsr_release, dbcsr_set, dbcsr_type, dbcsr_type_real_8
dbcsr_complete_redistribute, dbcsr_copy, dbcsr_create, dbcsr_desymmetrize, &
dbcsr_distribution_get, dbcsr_distribution_hold, dbcsr_distribution_new, &
dbcsr_distribution_release, dbcsr_distribution_type, dbcsr_finalize, dbcsr_get_info, &
dbcsr_multiply, dbcsr_nblkrows_total, dbcsr_p_type, dbcsr_release, dbcsr_set, dbcsr_type, &
dbcsr_type_real_8
USE cp_dbcsr_cp2k_link, ONLY: cp_dbcsr_alloc_block_from_nbl
USE cp_dbcsr_operations, ONLY: dbcsr_allocate_matrix_set
USE cp_log_handling, ONLY: cp_get_default_logger,&
Expand Down Expand Up @@ -297,7 +297,7 @@ END SUBROUTINE matrix_cluster
!> \param matrix_ls ...
!> \param ls_mstruct ...
!> \param covariant ...
!> \param keep_sparsity If set dbcsr_copy_into_existing will be used, by default set to .TRUE.
!> \param keep_sparsity will be passed on to dbcsr_copy, by default set to .TRUE.
!> \par History
!> 2010.10 created [Joost VandeVondele]
!> 2015.09 add support for PAO [Ole Schuett]
Expand Down Expand Up @@ -327,11 +327,7 @@ SUBROUTINE matrix_ls_to_qs(matrix_qs, matrix_ls, ls_mstruct, covariant, keep_spa
IF (.NOT. ls_mstruct%do_pao) THEN
CALL dbcsr_create(matrix_declustered, template=matrix_qs)
CALL matrix_decluster(matrix_declustered, matrix_ls, ls_mstruct)
IF (my_keep_sparsity) THEN
CALL dbcsr_copy_into_existing(matrix_qs, matrix_declustered) ! preserve sparsity of matrix_qs
ELSE
CALL dbcsr_copy(matrix_qs, matrix_declustered) ! overwrite sparsity of matrix_qs
END IF
CALL dbcsr_copy(matrix_qs, matrix_declustered, keep_sparsity=my_keep_sparsity)
CALL dbcsr_release(matrix_declustered)

ELSE ! using pao
Expand All @@ -349,11 +345,7 @@ SUBROUTINE matrix_ls_to_qs(matrix_qs, matrix_ls, ls_mstruct, covariant, keep_spa
CALL dbcsr_create(matrix_tmp2, template=matrix_qs)
CALL dbcsr_multiply("N", "N", 1.0_dp, matrix_trafo, matrix_declustered, 0.0_dp, matrix_tmp1)
CALL dbcsr_multiply("N", "T", 1.0_dp, matrix_tmp1, matrix_trafo, 0.0_dp, matrix_tmp2)
IF (my_keep_sparsity) THEN
CALL dbcsr_copy_into_existing(matrix_qs, matrix_tmp2) ! preserve sparsity of matrix_qs
ELSE
CALL dbcsr_copy(matrix_qs, matrix_tmp2) ! overwrite sparsity of matrix_qs
END IF
CALL dbcsr_copy(matrix_qs, matrix_tmp2, keep_sparsity=my_keep_sparsity)
CALL dbcsr_release(matrix_declustered)
CALL dbcsr_release(matrix_tmp1)
CALL dbcsr_release(matrix_tmp2)
Expand Down
10 changes: 5 additions & 5 deletions src/emd/rt_propagation_utils.F
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ MODULE rt_propagation_utils
USE cp_control_types, ONLY: dft_control_type,&
rtp_control_type
USE cp_dbcsr_api, ONLY: &
dbcsr_add, dbcsr_binary_read, dbcsr_checksum, dbcsr_copy, dbcsr_copy_into_existing, &
dbcsr_create, dbcsr_deallocate_matrix, dbcsr_desymmetrize, dbcsr_distribution_type, &
dbcsr_filter, dbcsr_get_info, dbcsr_iterator_blocks_left, dbcsr_iterator_next_block, &
dbcsr_add, dbcsr_binary_read, dbcsr_checksum, dbcsr_copy, dbcsr_create, &
dbcsr_deallocate_matrix, dbcsr_desymmetrize, dbcsr_distribution_type, dbcsr_filter, &
dbcsr_get_info, dbcsr_iterator_blocks_left, dbcsr_iterator_next_block, &
dbcsr_iterator_start, dbcsr_iterator_stop, dbcsr_iterator_type, dbcsr_p_type, dbcsr_scale, &
dbcsr_set, dbcsr_type
USE cp_dbcsr_operations, ONLY: cp_dbcsr_plus_fm_fm_t,&
Expand Down Expand Up @@ -547,9 +547,9 @@ SUBROUTINE calc_update_rho_sparse(qs_env)
IF (rtp%track_imag_density) CALL qs_rho_get(rho_struct=rho, rho_ao_im=rho_ao_im)
DO ispin = 1, SIZE(rho_ao)
CALL dbcsr_set(rho_ao(ispin)%matrix, zero)
CALL dbcsr_copy_into_existing(rho_ao(ispin)%matrix, rho_new(ispin*2 - 1)%matrix)
CALL dbcsr_copy(rho_ao(ispin)%matrix, rho_new(ispin*2 - 1)%matrix, keep_sparsity=.TRUE.)
IF (rtp%track_imag_density) THEN
CALL dbcsr_copy_into_existing(rho_ao_im(ispin)%matrix, rho_new(ispin*2)%matrix)
CALL dbcsr_copy(rho_ao_im(ispin)%matrix, rho_new(ispin*2)%matrix, keep_sparsity=.TRUE.)
END IF
END DO

Expand Down
7 changes: 3 additions & 4 deletions src/mp2_ri_grad.F
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ MODULE mp2_ri_grad
USE cp_blacs_env, ONLY: cp_blacs_env_type
USE cp_control_types, ONLY: dft_control_type
USE cp_dbcsr_api, ONLY: &
dbcsr_add, dbcsr_copy, dbcsr_copy_into_existing, dbcsr_create, dbcsr_multiply, &
dbcsr_p_type, dbcsr_release, dbcsr_set, dbcsr_transposed, dbcsr_type, &
dbcsr_type_no_symmetry, dbcsr_type_symmetric
dbcsr_add, dbcsr_copy, dbcsr_create, dbcsr_multiply, dbcsr_p_type, dbcsr_release, &
dbcsr_set, dbcsr_transposed, dbcsr_type, dbcsr_type_no_symmetry, dbcsr_type_symmetric
USE cp_dbcsr_operations, ONLY: copy_dbcsr_to_fm,&
dbcsr_deallocate_matrix_set
USE cp_eri_mme_interface, ONLY: cp_eri_mme_param
Expand Down Expand Up @@ -521,7 +520,7 @@ SUBROUTINE G_P_transform_MO_to_AO(G_P_munu, G_P_munu_nosym, mat_munu, G_P_ia, G_
CALL dbcsr_add(G_P_munu, G_P_munu_nosym, &
alpha_scalar=2.0_dp, beta_scalar=2.0_dp)
! this is a trick to avoid that integrate_v_rspace starts to cry
CALL dbcsr_copy_into_existing(mat_munu, G_P_munu)
CALL dbcsr_copy(mat_munu, G_P_munu, keep_sparsity=.TRUE.)
CALL dbcsr_copy(G_P_munu, mat_munu)

CALL timestop(handle)
Expand Down
14 changes: 7 additions & 7 deletions src/pao_methods.F
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ MODULE pao_methods
cite_reference
USE cp_control_types, ONLY: dft_control_type
USE cp_dbcsr_api, ONLY: &
dbcsr_add, dbcsr_binary_read, dbcsr_checksum, dbcsr_complete_redistribute, &
dbcsr_copy_into_existing, dbcsr_create, dbcsr_desymmetrize, dbcsr_distribution_get, &
dbcsr_distribution_new, dbcsr_distribution_type, dbcsr_dot, dbcsr_filter, &
dbcsr_get_block_p, dbcsr_get_info, dbcsr_iterator_blocks_left, dbcsr_iterator_next_block, &
dbcsr_iterator_start, dbcsr_iterator_stop, dbcsr_iterator_type, dbcsr_p_type, &
dbcsr_release, dbcsr_reserve_diag_blocks, dbcsr_scale, dbcsr_set, dbcsr_type
dbcsr_add, dbcsr_binary_read, dbcsr_checksum, dbcsr_complete_redistribute, dbcsr_copy, &
dbcsr_create, dbcsr_desymmetrize, dbcsr_distribution_get, dbcsr_distribution_new, &
dbcsr_distribution_type, dbcsr_dot, dbcsr_filter, dbcsr_get_block_p, dbcsr_get_info, &
dbcsr_iterator_blocks_left, dbcsr_iterator_next_block, dbcsr_iterator_start, &
dbcsr_iterator_stop, dbcsr_iterator_type, dbcsr_p_type, dbcsr_release, &
dbcsr_reserve_diag_blocks, dbcsr_scale, dbcsr_set, dbcsr_type
USE cp_log_handling, ONLY: cp_get_default_logger,&
cp_logger_type,&
cp_to_string
Expand Down Expand Up @@ -584,7 +584,7 @@ SUBROUTINE pao_read_preopt_dm(pao, qs_env)
cs_pos = dbcsr_checksum(matrix_tmp, pos=.TRUE.)
IF (pao%iw > 0) WRITE (pao%iw, *) "PAO| Read restart DM "// &
TRIM(pao%preopt_dm_file)//" with checksum: ", cs_pos
CALL dbcsr_copy_into_existing(rho_ao(ispin)%matrix, matrix_tmp)
CALL dbcsr_copy(rho_ao(ispin)%matrix, matrix_tmp, keep_sparsity=.TRUE.)
CALL dbcsr_release(matrix_tmp)
END DO

Expand Down
17 changes: 8 additions & 9 deletions src/pexsi_methods.F
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ MODULE pexsi_methods
set_arnoldi_initial_vector,&
setup_arnoldi_data
USE cp_dbcsr_api, ONLY: &
dbcsr_convert_csr_to_dbcsr, dbcsr_convert_dbcsr_to_csr, dbcsr_copy, &
dbcsr_copy_into_existing, dbcsr_create, dbcsr_csr_create, dbcsr_csr_create_from_dbcsr, &
dbcsr_csr_destroy, dbcsr_csr_eqrow_floor_dist, dbcsr_csr_print_sparsity, &
dbcsr_desymmetrize, dbcsr_distribution_get, dbcsr_distribution_type, dbcsr_get_info, &
dbcsr_has_symmetry, dbcsr_p_type, dbcsr_release, dbcsr_scale, dbcsr_set, dbcsr_type, &
dbcsr_type_no_symmetry, dbcsr_type_real_8
dbcsr_convert_csr_to_dbcsr, dbcsr_convert_dbcsr_to_csr, dbcsr_copy, dbcsr_create, &
dbcsr_csr_create, dbcsr_csr_create_from_dbcsr, dbcsr_csr_destroy, &
dbcsr_csr_eqrow_floor_dist, dbcsr_csr_print_sparsity, dbcsr_desymmetrize, &
dbcsr_distribution_get, dbcsr_distribution_type, dbcsr_get_info, dbcsr_has_symmetry, &
dbcsr_p_type, dbcsr_release, dbcsr_scale, dbcsr_set, dbcsr_type, dbcsr_type_no_symmetry, &
dbcsr_type_real_8
USE cp_dbcsr_cp2k_link, ONLY: cp_dbcsr_to_csr_screening
USE cp_dbcsr_operations, ONLY: dbcsr_allocate_matrix_set
USE cp_log_handling, ONLY: cp_get_default_logger,&
Expand Down Expand Up @@ -360,12 +360,11 @@ SUBROUTINE density_matrix_pexsi(pexsi_env, matrix_p, matrix_w, kTS, matrix_ks, m
! Convert DBCSR matrices to PEXSI CSR format. Intermediate step to template matrix
! needed in order to retain the initial sparsity pattern that is required for the
! conversion to CSR format.
CALL dbcsr_copy_into_existing(pexsi_env%dbcsr_template_matrix_sym, matrix_s)
CALL dbcsr_copy(pexsi_env%dbcsr_template_matrix_sym, matrix_s, keep_sparsity=.TRUE.)
CALL dbcsr_convert_dbcsr_to_csr(pexsi_env%dbcsr_template_matrix_sym, &
pexsi_env%csr_mat_s)

CALL dbcsr_copy_into_existing(pexsi_env%dbcsr_template_matrix_sym, &
matrix_ks)
CALL dbcsr_copy(pexsi_env%dbcsr_template_matrix_sym, matrix_ks, keep_sparsity=.TRUE.)
CALL dbcsr_convert_dbcsr_to_csr(pexsi_env%dbcsr_template_matrix_sym, &
pexsi_env%csr_mat_ks)

Expand Down
9 changes: 4 additions & 5 deletions src/qs_energy_window.F
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
MODULE qs_energy_window
USE cp_blacs_env, ONLY: cp_blacs_env_type
USE cp_dbcsr_api, ONLY: &
dbcsr_add, dbcsr_copy, dbcsr_copy_into_existing, dbcsr_create, dbcsr_desymmetrize, &
dbcsr_frobenius_norm, dbcsr_get_info, dbcsr_multiply, dbcsr_p_type, dbcsr_release, &
dbcsr_type
dbcsr_add, dbcsr_copy, dbcsr_create, dbcsr_desymmetrize, dbcsr_frobenius_norm, &
dbcsr_get_info, dbcsr_multiply, dbcsr_p_type, dbcsr_release, dbcsr_type
USE cp_dbcsr_operations, ONLY: copy_dbcsr_to_fm,&
copy_fm_to_dbcsr
USE cp_fm_basic_linalg, ONLY: cp_fm_trace
Expand Down Expand Up @@ -203,7 +202,7 @@ SUBROUTINE energy_windows(qs_env)
!ensure the correct sparsity
CALL copy_fm_to_dbcsr(P_window_fm, tmp)
CALL dbcsr_copy(window, matrix_ks(1)%matrix)
CALL dbcsr_copy_into_existing(window, tmp)
CALL dbcsr_copy(window, tmp, keep_sparsity=.TRUE.)
CALL calculate_rho_elec(matrix_p=window, &
rho=rho_r, &
rho_gspace=rho_g, &
Expand Down Expand Up @@ -270,7 +269,7 @@ SUBROUTINE energy_windows(qs_env)
CALL copy_fm_to_dbcsr(P_window_fm, tmp)
!ensure the correct sparsity
CALL dbcsr_copy(window, matrix_ks(1)%matrix)
CALL dbcsr_copy_into_existing(window, tmp)
CALL dbcsr_copy(window, tmp, keep_sparsity=.TRUE.)
CALL calculate_rho_elec(matrix_p=window, &
rho=rho_r, &
rho_gspace=rho_g, &
Expand Down
17 changes: 8 additions & 9 deletions src/transport.F
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ MODULE transport
cite_reference
USE cp_control_types, ONLY: dft_control_type
USE cp_dbcsr_api, ONLY: &
dbcsr_convert_csr_to_dbcsr, dbcsr_convert_dbcsr_to_csr, dbcsr_copy, &
dbcsr_copy_into_existing, dbcsr_create, dbcsr_csr_create, dbcsr_csr_create_from_dbcsr, &
dbcsr_csr_dbcsr_blkrow_dist, dbcsr_csr_print_sparsity, dbcsr_csr_type, &
dbcsr_deallocate_matrix, dbcsr_desymmetrize, dbcsr_has_symmetry, dbcsr_set, dbcsr_type, &
dbcsr_type_no_symmetry, dbcsr_type_real_8
dbcsr_convert_csr_to_dbcsr, dbcsr_convert_dbcsr_to_csr, dbcsr_copy, dbcsr_create, &
dbcsr_csr_create, dbcsr_csr_create_from_dbcsr, dbcsr_csr_dbcsr_blkrow_dist, &
dbcsr_csr_print_sparsity, dbcsr_csr_type, dbcsr_deallocate_matrix, dbcsr_desymmetrize, &
dbcsr_has_symmetry, dbcsr_set, dbcsr_type, dbcsr_type_no_symmetry, dbcsr_type_real_8
USE cp_dbcsr_cp2k_link, ONLY: cp_dbcsr_to_csr_screening
USE cp_log_handling, ONLY: cp_get_default_logger,&
cp_logger_get_default_unit_nr,&
Expand Down Expand Up @@ -405,16 +404,16 @@ SUBROUTINE external_scf_method(transport_env, matrix_s, matrix_ks, matrix_p, &
CALL csr_interop_nullify(p_mat)
CALL csr_interop_nullify(imagp_mat)
CALL dbcsr_copy_into_existing(transport_env%template_matrix_sym, matrix_s)
CALL dbcsr_copy(transport_env%template_matrix_sym, matrix_s, keep_sparsity=.TRUE.)
CALL convert_dbcsr_to_csr_interop(transport_env%template_matrix_sym, transport_env%s_matrix, s_mat)
CALL dbcsr_copy_into_existing(transport_env%template_matrix_sym, matrix_ks)
CALL dbcsr_copy(transport_env%template_matrix_sym, matrix_ks, keep_sparsity=.TRUE.)
CALL convert_dbcsr_to_csr_interop(transport_env%template_matrix_sym, transport_env%ks_matrix, ks_mat)
CALL dbcsr_copy_into_existing(transport_env%template_matrix_sym, matrix_p)
CALL dbcsr_copy(transport_env%template_matrix_sym, matrix_p, keep_sparsity=.TRUE.)
CALL convert_dbcsr_to_csr_interop(transport_env%template_matrix_sym, transport_env%p_matrix, p_mat)
CALL dbcsr_copy_into_existing(transport_env%template_matrix_sym, matrix_s)
CALL dbcsr_copy(transport_env%template_matrix_sym, matrix_s, keep_sparsity=.TRUE.)
CALL convert_dbcsr_to_csr_interop(transport_env%template_matrix_sym, transport_env%imagp_matrix, imagp_mat)
CALL c_method(transport_env%params, s_mat, ks_mat, p_mat, imagp_mat)
Expand Down

0 comments on commit 217d986

Please sign in to comment.