30#include "./base/base_uses.f90"
35 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'gw_compute_Z_lP_utils'
36 REAL(KIND=
dp),
PARAMETER,
PRIVATE :: jacobi_floor = 1.0e-16_dp
64 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: phi_local
65 INTEGER,
INTENT(IN) :: n_local_grid, n_ao_used
66 REAL(kind=
dp),
INTENT(IN) :: tikhonov
67 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :), &
68 INTENT(OUT) :: d_local
69 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: d_vec_local
71 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_gram_jacobi_blas'
73 INTEGER :: handle, handle_dsyrk, i, j
75 CALL timeset(routinen, handle)
77 ALLOCATE (d_local(n_local_grid, n_local_grid))
80 CALL timeset(routinen//
'_dsyrk', handle_dsyrk)
81 CALL dsyrk(
"L",
"N", n_local_grid, n_ao_used, 1.0_dp, phi_local, &
82 n_local_grid, 0.0_dp, d_local, n_local_grid)
83 CALL timestop(handle_dsyrk)
89 DO i = 1, n_local_grid
90 d_local(i, i) = d_local(i, i)**2
91 d_vec_local(i) = 1.0_dp/sqrt(max(d_local(i, i), jacobi_floor))
92 d_local(i, i) = (d_local(i, i)*d_vec_local(i)**2) + tikhonov
100 DO j = 1, n_local_grid
101 DO i = j + 1, n_local_grid
102 d_local(i, j) = d_local(i, j)**2
103 d_local(i, j) = d_local(i, j)*d_vec_local(i)*d_vec_local(j)
104 d_local(j, i) = d_local(i, j)
109 CALL timestop(handle)
122 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: phi_local
123 INTEGER,
INTENT(IN) :: n_local_grid, n_ao_used
124 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: d_vec_local
126 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_jacobi_diag_from_phi'
128 INTEGER :: handle, i, j
130 CALL timeset(routinen, handle)
136 DO i = 1, n_local_grid
137 d_vec_local(i) = 0.0_dp
139 d_vec_local(i) = d_vec_local(i) + phi_local(i, j)*phi_local(i, j)
141 d_vec_local(i) = 1.0_dp/max(d_vec_local(i), jacobi_floor)
145 CALL timestop(handle)
159 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: matrix
160 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: diagonal
161 INTEGER,
INTENT(IN) :: nrow, ncol
163 CHARACTER(LEN=*),
PARAMETER :: routinen =
'scale_rows_by_diag'
165 INTEGER :: handle, i, j
167 CALL timeset(routinen, handle)
175 matrix(i, j) = matrix(i, j)*diagonal(i)
180 CALL timestop(handle)
197 atom_P, r_blk_sizes, row_offset, eps_filter)
200 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: z_local
201 INTEGER,
DIMENSION(:),
INTENT(IN) :: local_grid_idx
202 INTEGER,
INTENT(IN) :: n_local_grid, n_loc_ri, atom_p
203 INTEGER,
DIMENSION(:),
INTENT(IN) :: r_blk_sizes, row_offset
204 REAL(kind=
dp),
INTENT(IN) :: eps_filter
206 CHARACTER(LEN=*),
PARAMETER :: routinen =
'store_Z_lP_columns'
208 INTEGER :: current_chunk_size, g_pt, handle, i_blk, &
209 loc_ptr, r_end, r_start
210 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: z_blk
212 CALL timeset(routinen, handle)
214 ALLOCATE (z_blk(maxval(r_blk_sizes), n_loc_ri))
217 DO i_blk = 1,
SIZE(r_blk_sizes)
218 r_start = row_offset(i_blk) + 1
219 r_end = row_offset(i_blk) + r_blk_sizes(i_blk)
220 current_chunk_size = r_blk_sizes(i_blk)
223 DO WHILE (loc_ptr <= n_local_grid)
224 g_pt = local_grid_idx(loc_ptr)
225 IF (g_pt > r_end)
EXIT
226 z_blk(g_pt - r_start + 1, 1:n_loc_ri) = z_local(loc_ptr, 1:n_loc_ri)
227 loc_ptr = loc_ptr + 1
230 IF (maxval(abs(z_blk(1:current_chunk_size, 1:n_loc_ri))) > eps_filter)
THEN
232 block=z_blk(1:current_chunk_size, 1:n_loc_ri))
238 CALL timestop(handle)
266 tikhonov, para_env_sub, blacs_env_sub, &
267 fm_struct_D, fm_struct_b, fm_D, fm_b, info)
269 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: phi_local
270 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: d_vec
271 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: d_lp
272 INTEGER,
INTENT(IN) :: n_loc, n_ao, n_rhs
273 REAL(kind=
dp),
INTENT(IN) :: tikhonov
278 INTEGER,
INTENT(OUT) :: info
280 CHARACTER(LEN=*),
PARAMETER :: routinen =
'solve_D_lp_distributed'
282 INTEGER :: handle, i_loc, ig, j_loc, jg, &
283 ncol_local, nrow_local
284 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
285 REAL(kind=
dp),
CONTIGUOUS,
DIMENSION(:, :), &
286 POINTER :: local_data
288 CALL timeset(routinen, handle)
291 NULLIFY (fm_struct_d, fm_struct_b)
293 context=blacs_env_sub, &
294 nrow_global=n_loc, ncol_global=n_loc)
296 context=blacs_env_sub, &
297 nrow_global=n_loc, ncol_global=n_rhs)
301 CALL cp_fm_get_info(fm_d, nrow_local=nrow_local, ncol_local=ncol_local, &
302 row_indices=row_indices, col_indices=col_indices, &
303 local_data=local_data)
305 IF (nrow_local > 0 .AND. ncol_local > 0)
THEN
307 INTEGER,
PARAMETER :: ntile = 1024
308 INTEGER :: ib, ie, jb, je, mb, kb, ti, tj, handle_dgemm
309 REAL(kind=
dp),
ALLOCATABLE :: gram_t(:, :), phi_cols_t(:, :), phi_rows_t(:, :)
310 ALLOCATE (phi_rows_t(ntile, n_ao), phi_cols_t(n_ao, ntile), gram_t(ntile, ntile))
311 DO ib = 1, nrow_local, ntile
312 ie = min(ib + ntile - 1, nrow_local)
319 phi_rows_t(ti, j_loc) = phi_local(row_indices(ib + ti - 1), j_loc)
323 DO jb = 1, ncol_local, ntile
324 je = min(jb + ntile - 1, ncol_local)
331 phi_cols_t(i_loc, tj) = phi_local(col_indices(jb + tj - 1), i_loc)
335 CALL timeset(routinen//
'_dgemm', handle_dgemm)
336 CALL dgemm(
'N',
'N', mb, kb, n_ao, &
337 1.0_dp, phi_rows_t, ntile, phi_cols_t, n_ao, &
338 0.0_dp, gram_t, ntile)
339 CALL timestop(handle_dgemm)
345 jg = col_indices(jb + tj - 1)
347 ig = row_indices(ib + ti - 1)
348 local_data(ib + ti - 1, jb + tj - 1) = &
349 gram_t(ti, tj)*gram_t(ti, tj)*d_vec(ig)*d_vec(jg)
351 local_data(ib + ti - 1, jb + tj - 1) = &
352 local_data(ib + ti - 1, jb + tj - 1) + tikhonov
359 DEALLOCATE (phi_rows_t, phi_cols_t, gram_t)
366 IF (info /= 0) cpabort(
"pdpotrf failed in solve_D_lp_distributed")
369 IF (info /= 0) cpabort(
"pdpotrs failed in solve_D_lp_distributed")
378 CALL timestop(handle)
static void dgemm(const char transa, const char transb, const int m, const int n, const int k, const double alpha, const double *a, const int lda, const double *b, const int ldb, const double beta, double *c, const int ldc)
Convenient wrapper to hide Fortran nature of dgemm_, swapping a and b.
methods related to the blacs parallel environment
subroutine, public dbcsr_put_block(matrix, row, col, block, summation)
...
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_solve(matrix, matrixb, n, info_out)
solves A*X = B for X, given the Cholesky decomposition U of the symmetric positive def....
subroutine, public cp_fm_cholesky_decompose(matrix, n, info_out)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_set_submatrix(fm, new_values, start_row, start_col, n_rows, n_cols, alpha, beta, transpose)
sets a submatrix of a full matrix fm(start_row:start_row+n_rows,start_col:start_col+n_cols) = alpha*o...
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
subroutine, public cp_fm_get_submatrix(fm, target_m, start_row, start_col, n_rows, n_cols, transpose)
gets a submatrix of a full matrix op(target_m)(1:n_rows,1:n_cols) =fm(start_row:start_row+n_rows,...
Shared numerical operations for computing the RI-RS matrix Z_lP.
subroutine, public build_gram_jacobi_blas(phi_local, n_local_grid, n_ao_used, tikhonov, d_local, d_vec_local)
Forms the conditioned dense RI-RS matrix.
subroutine, public solve_d_lp_distributed(phi_local, d_vec, d_lp, n_loc, n_ao, n_rhs, tikhonov, para_env_sub, blacs_env_sub, fm_struct_d, fm_struct_b, fm_d, fm_b, info)
Solves D Z = d with ScaLAPACK for one RI atom and replicated inputs.
subroutine, public scale_rows_by_diag(matrix, diagonal, nrow, ncol)
Multiplies every matrix row by the corresponding diagonal entry: A(l, :) <- d_l A(l,...
subroutine, public store_z_lp_columns(mat_z_lp, z_local, local_grid_idx, n_local_grid, n_loc_ri, atom_p, r_blk_sizes, row_offset, eps_filter)
Stores dense Z_lP columns in the distributed block-sparse matrix.
subroutine, public build_jacobi_diag_from_phi(phi_local, n_local_grid, n_ao_used, d_vec_local)
Computes d_l = 1/sqrt(D_ll) = 1/Σ_μ Φ_μ(r_l)² without forming D.
Defines the basic variable types.
integer, parameter, public dp
Interface to the message passing library MPI.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
stores all the informations relevant to an mpi environment