9 USE omp_lib,
ONLY: omp_get_num_threads
22#include "../base/base_uses.f90"
53 TYPE(
dbcsr_type),
INTENT(IN) :: matrix_a, matrix_b
56 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_hadamard_product'
58 INTEGER :: col, handle, nblkrows_tot_a, &
59 nblkrows_tot_b, nblkrows_tot_c, row
61 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block_a, block_b
64 CALL timeset(routinen, handle)
65 cpassert(omp_get_num_threads() == 1)
70 IF (nblkrows_tot_a /= nblkrows_tot_b .OR. nblkrows_tot_a /= nblkrows_tot_c)
THEN
71 cpabort(
"matrices not consistent")
97 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_maxabs'
100 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
104 CALL timeset(routinen, handle)
105 cpassert(omp_get_num_threads() == 1)
111 norm = max(norm, maxval(abs(block)))
118 CALL timestop(handle)
130 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_frobenius_norm'
132 INTEGER :: col, handle, row
133 LOGICAL :: has_symmetry
134 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
138 CALL timeset(routinen, handle)
139 cpassert(omp_get_num_threads() == 1)
146 IF (has_symmetry .AND. row /= col)
THEN
147 norm = norm + 2.0_dp*sum(block**2)
149 norm = norm + sum(block**2)
158 CALL timestop(handle)
170 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_gershgorin_norm'
172 INTEGER :: col, col_offset, handle, i, j, ncol, &
173 nrow, row, row_offset
174 LOGICAL :: has_symmetry
175 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: buffer
176 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
180 CALL timeset(routinen, handle)
181 cpassert(omp_get_num_threads() == 1)
184 CALL dbcsr_get_info(matrix, nfullrows_total=nrow, nfullcols_total=ncol)
185 cpassert(nrow == ncol)
186 ALLOCATE (buffer(nrow))
192 DO j = 1,
SIZE(block, 2)
193 DO i = 1,
SIZE(block, 1)
194 buffer(row_offset + i - 1) = buffer(row_offset + i - 1) + abs(block(i, j))
195 IF (has_symmetry .AND. row /= col)
THEN
196 buffer(col_offset + j - 1) = buffer(col_offset + j - 1) + abs(block(i, j))
204 CALL group%sum(buffer)
205 norm = maxval(buffer)
208 CALL timestop(handle)
218 LOGICAL,
OPTIONAL :: keep_sparsity
220 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_init_random'
222 INTEGER :: col, col_size, handle, ncol, nrow, row, &
224 INTEGER,
DIMENSION(4) :: iseed
225 LOGICAL :: my_keep_sparsity
226 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
229 CALL timeset(routinen, handle)
230 cpassert(omp_get_num_threads() == 1)
232 my_keep_sparsity = .false.
233 IF (
PRESENT(keep_sparsity)) my_keep_sparsity = keep_sparsity
235 CALL dbcsr_get_info(matrix, nblkrows_total=nrow, nblkcols_total=ncol)
243 CALL dlarnv(1, iseed, row_size*col_size, block(1, 1))
247 CALL timestop(handle)
257 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_reserve_diag_blocks'
259 INTEGER :: handle, i, k, mynode, nblkcols_total, &
260 nblkrows_total, owner
261 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: local_diag
262 INTEGER,
DIMENSION(:),
POINTER :: local_rows
265 CALL timeset(routinen, handle)
266 cpassert(omp_get_num_threads() == 1)
268 CALL dbcsr_get_info(matrix, nblkrows_total=nblkrows_total, nblkcols_total=nblkcols_total)
269 cpassert(nblkrows_total == nblkcols_total)
271 CALL dbcsr_get_info(matrix, local_rows=local_rows, distribution=dist)
273 ALLOCATE (local_diag(
SIZE(local_rows)))
276 DO i = 1,
SIZE(local_rows)
278 IF (owner == mynode)
THEN
280 local_diag(k) = local_rows(i)
285 DEALLOCATE (local_diag)
287 CALL timestop(handle)
297 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_reserve_all_blocks'
299 INTEGER :: handle, i, j, k, n
300 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: cols, rows
301 INTEGER,
DIMENSION(:),
POINTER :: local_cols, local_rows
303 CALL timeset(routinen, handle)
304 cpassert(omp_get_num_threads() == 1)
306 CALL dbcsr_get_info(matrix, local_rows=local_rows, local_cols=local_cols)
307 n =
SIZE(local_rows)*
SIZE(local_cols)
308 ALLOCATE (rows(n), cols(n))
311 DO i = 1,
SIZE(local_rows)
312 DO j = 1,
SIZE(local_cols)
314 rows(k) = local_rows(i)
315 cols(k) = local_cols(j)
320 DEALLOCATE (rows, cols)
322 CALL timestop(handle)
332 REAL(kind=
dp),
INTENT(IN) :: alpha
334 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_add_on_diag'
336 INTEGER :: col, col_size, handle, i, row, row_size
337 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
340 CALL timeset(routinen, handle)
341 cpassert(omp_get_num_threads() == 1)
349 cpassert(row_size == col_size)
351 block(i, i) = block(i, i) + alpha
357 CALL timestop(handle)
367 TYPE(
dbcsr_type),
INTENT(IN) :: matrix_a, matrix_b
368 REAL(kind=
dp),
INTENT(OUT) :: trace
370 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_dot'
372 INTEGER :: col, handle, row
373 LOGICAL :: found_b, has_symmetry
374 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block_a, block_b
378 CALL timeset(routinen, handle)
379 cpassert(omp_get_num_threads() == 1)
388 IF (
SIZE(block_a) == 0) cycle
391 IF (has_symmetry .AND. row /= col)
THEN
392 trace = trace + 2.0_dp*sum(block_a*block_b)
394 trace = trace + sum(block_a*block_b)
401 CALL group%sum(trace)
403 CALL timestop(handle)
413 REAL(kind=
dp),
INTENT(OUT) :: trace
415 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_trace'
417 INTEGER :: col, col_size, handle, i, row, row_size
418 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
422 CALL timeset(routinen, handle)
423 cpassert(omp_get_num_threads() == 1)
430 cpassert(row_size == col_size)
432 trace = trace + block(i, i)
439 CALL group%sum(trace)
441 CALL timestop(handle)
453 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_get_block_diag'
455 CHARACTER(len=default_string_length) :: name
456 INTEGER :: col, handle, row
457 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
460 CALL timeset(routinen, handle)
461 cpassert(omp_get_num_threads() == 1)
464 CALL dbcsr_create(diag, template=matrix, name=
'diag of '//name)
476 CALL timestop(handle)
487 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: alpha
488 CHARACTER(LEN=*),
INTENT(IN) :: side
490 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_scale_by_vector'
492 INTEGER :: col_offset, col_size, handle, i, &
493 nfullcols_total, nfullrows_total, &
496 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
499 CALL timeset(routinen, handle)
500 cpassert(omp_get_num_threads() == 1)
502 IF (side ==
'right')
THEN
504 ELSE IF (side ==
'left')
THEN
507 cpabort(
"Unknown side: "//trim(side))
511 CALL dbcsr_get_info(matrix, nfullrows_total=nfullrows_total, nfullcols_total=nfullcols_total)
513 cpassert(nfullcols_total ==
SIZE(alpha))
515 cpassert(nfullrows_total ==
SIZE(alpha))
521 row_offset=row_offset, col_offset=col_offset)
522 IF (
SIZE(block) == 0) cycle
525 block(:, i) = block(:, i)*alpha(col_offset + i - 1)
529 block(i, :) = block(i, :)*alpha(row_offset + i - 1)
535 CALL timestop(handle)
545 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: diag
547 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_get_diag'
549 INTEGER :: col, col_size, handle, i, &
550 nfullcols_total, nfullrows_total, row, &
552 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
555 CALL timeset(routinen, handle)
556 cpassert(omp_get_num_threads() == 1)
558 CALL dbcsr_get_info(matrix, nfullrows_total=nfullrows_total, nfullcols_total=nfullcols_total)
559 cpassert(nfullrows_total == nfullcols_total)
560 cpassert(nfullrows_total ==
SIZE(diag))
566 col_size=col_size, row_offset=row_offset)
568 cpassert(row_size == col_size)
570 diag(row_offset + i - 1) = block(i, i)
576 CALL timestop(handle)
586 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: diag
588 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_set_diag'
590 INTEGER :: col, col_size, handle, i, &
591 nfullcols_total, nfullrows_total, row, &
593 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
596 CALL timeset(routinen, handle)
597 cpassert(omp_get_num_threads() == 1)
599 CALL dbcsr_get_info(matrix, nfullrows_total=nfullrows_total, nfullcols_total=nfullcols_total)
600 cpassert(nfullrows_total == nfullcols_total)
601 cpassert(nfullrows_total ==
SIZE(diag))
608 col_size=col_size, row_offset=row_offset)
610 cpassert(row_size == col_size)
612 block(i, i) = diag(row_offset + i - 1)
618 CALL timestop(handle)
630 LOGICAL,
INTENT(IN),
OPTIONAL :: pos
631 REAL(kind=
dp) :: checksum
633 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_checksum'
635 INTEGER :: col_offset, col_size, handle, i, j, &
638 REAL(kind=
dp) :: position_factor
639 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
643 CALL timeset(routinen, handle)
644 cpassert(omp_get_num_threads() == 1)
647 IF (
PRESENT(pos))
THEN
655 row_offset=row_offset, col_offset=col_offset)
659 position_factor = log(real((row_offset + i - 1)*(col_offset + j - 1), kind=
dp))
660 checksum = checksum + block(i, j)*position_factor
664 checksum = checksum + sum(block**2)
670 CALL group%sum(checksum)
672 CALL timestop(handle)
683 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: variable_name
684 INTEGER,
INTENT(IN),
OPTIONAL :: unit_nr
686 CHARACTER(len=*),
PARAMETER :: routinen =
'dbcsr_print'
688 CHARACTER(len=default_string_length) :: my_variable_name, name
689 INTEGER :: col_offset, col_size, handle, i, iw, j, nblkcols_total, nblkrows_total, &
690 nfullcols_total, nfullrows_total, row_offset, row_size
691 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
694 CALL timeset(routinen, handle)
695 cpassert(omp_get_num_threads() == 1)
698 IF (
PRESENT(unit_nr)) iw = unit_nr
700 my_variable_name =
'a'
701 IF (
PRESENT(variable_name)) my_variable_name = variable_name
705 nblkrows_total=nblkrows_total, nblkcols_total=nblkcols_total, &
706 nfullrows_total=nfullrows_total, nfullcols_total=nfullcols_total)
707 WRITE (iw, *)
"===", routinen,
"==="
708 WRITE (iw, *)
"Name:", name
713 WRITE (iw, *)
"Full size:", nfullrows_total,
"x", nfullcols_total
714 WRITE (iw, *)
"Blocked size:", nblkrows_total,
"x", nblkcols_total
720 row_offset=row_offset, col_offset=col_offset)
723 WRITE (iw,
'(A,I4,A,I4,A,E23.16,A)') trim(my_variable_name)//
'(', &
724 row_offset + i - 1,
',', col_offset + j - 1,
')=', block(i, j),
';'
730 CALL timestop(handle)
logical function, public dbcsr_has_symmetry(matrix)
...
integer function, public dbcsr_get_data_size(matrix)
...
subroutine, public dbcsr_get_readonly_block_p(matrix, row, col, block, found, row_size, col_size)
Like dbcsr_get_block_p() but with matrix being INTENT(IN). When invoking this routine,...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_reserve_blocks(matrix, rows, cols)
...
subroutine, public dbcsr_get_stored_coordinates(matrix, row, column, processor)
...
real(kind=dp) function, public dbcsr_get_occupation(matrix)
...
subroutine, public dbcsr_finalize(matrix)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
integer function, public dbcsr_get_num_blocks(matrix)
...
subroutine, public dbcsr_iterator_readonly_start(iterator, matrix, shared, dynamic, dynamic_byrows)
Like dbcsr_iterator_start() but with matrix being INTENT(IN). When invoking this routine,...
subroutine, public dbcsr_clear(matrix)
...
subroutine, public dbcsr_put_block(matrix, row, col, block, summation)
...
subroutine, public dbcsr_distribution_get(dist, row_dist, col_dist, nrows, ncols, has_threads, group, mynode, numnodes, nprows, npcols, myprow, mypcol, pgrid, subgroups_defined, prow_group, pcol_group)
...
subroutine, public dbcsr_set_diag(matrix, diag)
Copies the diagonal elements from the given array into the given matrix.
real(dp) function, public dbcsr_gershgorin_norm(matrix)
Compute the gershgorin norm of a dbcsr matrix.
real(kind=dp) function, public dbcsr_checksum(matrix, pos)
Calculates the checksum of a DBCSR matrix.
subroutine, public dbcsr_get_diag(matrix, diag)
Copies the diagonal elements from the given matrix into the given array.
subroutine, public dbcsr_add_on_diag(matrix, alpha)
Adds the given scalar to the diagonal of the matrix. Reserves any missing diagonal blocks.
subroutine, public dbcsr_print(matrix, variable_name, unit_nr)
Prints given matrix in matlab format (only present blocks).
real(dp) function, public dbcsr_maxabs(matrix)
Compute the maxabs norm of a dbcsr matrix.
subroutine, public dbcsr_trace(matrix, trace)
Computes the trace of the given matrix, also known as the sum of its diagonal elements.
subroutine, public dbcsr_reserve_all_blocks(matrix)
Reserves all blocks.
subroutine, public dbcsr_init_random(matrix, keep_sparsity)
Fills the given matrix with random numbers.
real(dp) function, public dbcsr_frobenius_norm(matrix)
Compute the frobenius norm of a dbcsr matrix.
subroutine, public dbcsr_dot(matrix_a, matrix_b, trace)
Computes the dot product of two matrices, also known as the trace of their matrix product.
subroutine, public dbcsr_hadamard_product(matrix_a, matrix_b, matrix_c)
Hadamard product: C = A . B (C needs to be different from A and B)
subroutine, public dbcsr_reserve_diag_blocks(matrix)
Reserves all diagonal blocks.
subroutine, public dbcsr_scale_by_vector(matrix, alpha, side)
Scales the rows/columns of given matrix.
subroutine, public dbcsr_get_block_diag(matrix, diag)
Copies the diagonal blocks of matrix into diag.
integer function, dimension(4), public generate_larnv_seed(irow, nrow, icol, ncol, ival)
Generate a seed respecting the lapack constraints,.
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
Machine interface based on Fortran 2003 and POSIX.
integer, parameter, public default_output_unit
Interface to the message passing library MPI.