(git:6344619)
Loading...
Searching...
No Matches
dbt_matrix_redistribution.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Redistribute matrices between full-matrix and tensor process layouts.
10! **************************************************************************************************
12 USE cp_dbcsr_api, ONLY: dbcsr_filter,&
14 dbcsr_set,&
20 USE cp_fm_types, ONLY: cp_fm_type
21 USE dbt_api, ONLY: dbt_clear,&
22 dbt_copy,&
23 dbt_copy_matrix_to_tensor,&
24 dbt_copy_tensor_to_matrix,&
25 dbt_create,&
26 dbt_destroy,&
27 dbt_type
28 USE kinds, ONLY: dp
30#include "../base/base_uses.f90"
31
32 IMPLICIT NONE
33 PRIVATE
34 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'dbt_matrix_redistribution'
36
37CONTAINS
38
39! **************************************************************************************************
40!> \brief ...
41!> \param fm_global ...
42!> \param mat_global ...
43!> \param mat_local ...
44!> \param tensor ...
45!> \param para_env communicator covering the full matrix and all subgroups
46!> \param num_pe_sub number of ranks per subgroup
47!> \param eps_filter DBCSR filtering threshold before subgroup distribution
48!> \param block_row_ranges ...
49! **************************************************************************************************
50 SUBROUTINE cp_fm_to_dbt(fm_global, mat_global, mat_local, tensor, para_env, num_pe_sub, eps_filter, block_row_ranges)
51
52 TYPE(cp_fm_type) :: fm_global
53 TYPE(dbcsr_type) :: mat_global, mat_local
54 TYPE(dbt_type) :: tensor
55 TYPE(mp_para_env_type), INTENT(IN), POINTER :: para_env
56 INTEGER, INTENT(IN) :: num_pe_sub
57 REAL(kind=dp), INTENT(IN) :: eps_filter
58 INTEGER, DIMENSION(:, :), OPTIONAL :: block_row_ranges
59
60 CHARACTER(LEN=*), PARAMETER :: routinen = 'cp_fm_to_dbt'
61
62 INTEGER :: handle
63 TYPE(dbt_type) :: tensor_tmp
64
65 CALL timeset(routinen, handle)
66
67 CALL dbt_clear(tensor)
68 CALL copy_fm_to_dbcsr(fm_global, mat_global, keep_sparsity=.false.)
69 CALL dbcsr_filter(mat_global, eps_filter)
70 CALL cp_dbcsr_to_subgroups(mat_global, mat_local, para_env, num_pe_sub, block_row_ranges)
71 CALL dbt_create(mat_local, tensor_tmp)
72 CALL dbt_copy_matrix_to_tensor(mat_local, tensor_tmp)
73 CALL dbt_copy(tensor_tmp, tensor, move_data=.true.)
74 CALL dbt_destroy(tensor_tmp)
75 CALL dbcsr_set(mat_local, 0.0_dp)
76 CALL dbcsr_filter(mat_local, 1.0_dp)
77
78 CALL timestop(handle)
79
80 END SUBROUTINE cp_fm_to_dbt
81
82! **************************************************************************************************
83!> \brief ...
84!> \param tensor ...
85!> \param mat_tensor ...
86!> \param mat_global ...
87!> \param para_env ...
88! **************************************************************************************************
89 SUBROUTINE cp_dbt_to_dbcsr(tensor, mat_tensor, mat_global, para_env)
90
91 TYPE(dbt_type) :: tensor
92 TYPE(dbcsr_type) :: mat_tensor, mat_global
93 TYPE(mp_para_env_type), POINTER :: para_env
94
95 CHARACTER(LEN=*), PARAMETER :: routinen = 'cp_dbt_to_dbcsr'
96
97 INTEGER :: handle
98
99 CALL timeset(routinen, handle)
100
101 CALL dbt_copy_tensor_to_matrix(tensor, mat_tensor)
102 CALL dbt_clear(tensor)
103 ! the next para_env%sync is not mandatory, but it makes the timing output
104 ! of cp_dbcsr_from_subgroups correct
105 CALL para_env%sync()
106 CALL cp_dbcsr_from_subgroups(mat_tensor, mat_global, para_env)
107
108 CALL timestop(handle)
109
110 END SUBROUTINE cp_dbt_to_dbcsr
111
112! **************************************************************************************************
113!> \brief ...
114!> \param t_R ...
115!> \param fm_R ...
116!> \param mat_global ...
117!> \param mat_local ...
118!> \param para_env ...
119! **************************************************************************************************
120 SUBROUTINE cp_dbt_to_fm(t_R, fm_R, mat_global, mat_local, para_env)
121 TYPE(dbt_type), DIMENSION(:) :: t_r
122 TYPE(cp_fm_type), DIMENSION(:) :: fm_r
123 TYPE(dbcsr_p_type) :: mat_global, mat_local
124 TYPE(mp_para_env_type), INTENT(IN), POINTER :: para_env
125
126 CHARACTER(LEN=*), PARAMETER :: routinen = 'cp_dbt_to_fm'
127
128 INTEGER :: handle, i_cell, n_images
129
130 CALL timeset(routinen, handle)
131
132 n_images = SIZE(t_r)
133
134 cpassert(n_images == SIZE(fm_r))
135
136 DO i_cell = 1, n_images
137 CALL cp_dbt_to_dbcsr(t_r(i_cell), mat_local%matrix, mat_global%matrix, &
138 para_env)
139 CALL copy_dbcsr_to_fm(mat_global%matrix, fm_r(i_cell))
140 END DO
141
142 CALL timestop(handle)
143
144 END SUBROUTINE cp_dbt_to_fm
145
struct tensor_ tensor
subroutine, public dbcsr_filter(matrix, eps)
...
subroutine, public dbcsr_set(matrix, alpha)
...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm, plan, check_plan)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
Redistribution of DBCSR blocks and distributed matrix slices.
subroutine, public cp_dbcsr_to_subgroups(mat_global, mat_local, para_env, num_pe_sub, block_row_ranges)
...
subroutine, public cp_dbcsr_from_subgroups(mat_local, mat_global, para_env, row_mapping, copy_only)
Sum subgroup blocks into the global layout, or copy mapped blocks.
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
This is the start of a dbt_api, all publically needed functions are exported here....
Definition dbt_api.F:17
Redistribute matrices between full-matrix and tensor process layouts.
subroutine, public cp_dbt_to_dbcsr(tensor, mat_tensor, mat_global, para_env)
...
subroutine, public cp_dbt_to_fm(t_r, fm_r, mat_global, mat_local, para_env)
...
subroutine, public cp_fm_to_dbt(fm_global, mat_global, mat_local, tensor, para_env, num_pe_sub, eps_filter, block_row_ranges)
...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
represent a full matrix
stores all the informations relevant to an mpi environment