9 USE omp_lib,
ONLY: omp_get_num_threads
23#include "../base/base_uses.f90"
54 TYPE(
dbcsr_type),
INTENT(IN) :: matrix_a, matrix_b
57 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_hadamard_product'
59 INTEGER :: col, handle, nblkrows_tot_a, &
60 nblkrows_tot_b, nblkrows_tot_c, row
62 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block_a, block_b
65 CALL timeset(routinen, handle)
66 cpassert(omp_get_num_threads() == 1)
71 IF (nblkrows_tot_a /= nblkrows_tot_b .OR. nblkrows_tot_a /= nblkrows_tot_c)
THEN
72 cpabort(
"matrices not consistent")
102 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_maxabs'
105 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
109 CALL timeset(routinen, handle)
110 cpassert(omp_get_num_threads() == 1)
117 norm = max(norm, maxval(abs(block)))
125 CALL timestop(handle)
137 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_frobenius_norm'
139 INTEGER :: col, handle, row
140 LOGICAL :: has_symmetry
141 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
145 CALL timeset(routinen, handle)
146 cpassert(omp_get_num_threads() == 1)
155 IF (has_symmetry .AND. row /= col)
THEN
156 norm = norm + 2.0_dp*sum(block**2)
158 norm = norm + sum(block**2)
168 CALL timestop(handle)
180 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_gershgorin_norm'
182 INTEGER :: col, col_offset, handle, i, j, ncol, &
183 nrow, row, row_offset
184 LOGICAL :: has_symmetry
185 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: buffer, buffer_priv
186 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
190 CALL timeset(routinen, handle)
191 cpassert(omp_get_num_threads() == 1)
194 CALL dbcsr_get_info(matrix, nfullrows_total=nrow, nfullcols_total=ncol)
195 cpassert(nrow == ncol)
196 ALLOCATE (buffer(nrow))
201 ALLOCATE (buffer_priv(nrow))
202 buffer_priv(:) = 0.0_dp
206 DO j = 1,
SIZE(block, 2)
207 DO i = 1,
SIZE(block, 1)
208 buffer_priv(row_offset + i - 1) = buffer_priv(row_offset + i - 1) + abs(block(i, j))
209 IF (has_symmetry .AND. row /= col)
THEN
210 buffer_priv(col_offset + j - 1) = buffer_priv(col_offset + j - 1) + abs(block(i, j))
217 buffer(:) = buffer(:) + buffer_priv(:)
219 DEALLOCATE (buffer_priv)
223 CALL group%sum(buffer)
224 norm = maxval(buffer)
227 CALL timestop(handle)
237 LOGICAL,
OPTIONAL :: keep_sparsity
239 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_init_random'
241 INTEGER :: col, col_size, handle, ncol, nrow, row, &
243 INTEGER,
DIMENSION(4) :: iseed
244 LOGICAL :: my_keep_sparsity
245 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
248 CALL timeset(routinen, handle)
249 cpassert(omp_get_num_threads() == 1)
251 my_keep_sparsity = .false.
252 IF (
PRESENT(keep_sparsity)) my_keep_sparsity = keep_sparsity
254 CALL dbcsr_get_info(matrix, nblkrows_total=nrow, nblkcols_total=ncol)
264 CALL dlarnv(1, iseed, row_size*col_size, block(1, 1))
269 CALL timestop(handle)
279 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_reserve_diag_blocks'
281 INTEGER :: handle, i, k, mynode, nblkcols_total, &
282 nblkrows_total, owner
283 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: local_diag
284 INTEGER,
DIMENSION(:),
POINTER :: local_rows
287 CALL timeset(routinen, handle)
288 cpassert(omp_get_num_threads() == 1)
290 CALL dbcsr_get_info(matrix, nblkrows_total=nblkrows_total, nblkcols_total=nblkcols_total)
291 cpassert(nblkrows_total == nblkcols_total)
293 CALL dbcsr_get_info(matrix, local_rows=local_rows, distribution=dist)
295 ALLOCATE (local_diag(
SIZE(local_rows)))
298 DO i = 1,
SIZE(local_rows)
300 IF (owner == mynode)
THEN
302 local_diag(k) = local_rows(i)
307 DEALLOCATE (local_diag)
309 CALL timestop(handle)
319 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_reserve_all_blocks'
321 INTEGER :: handle, i, j, k, n
322 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: cols, rows
323 INTEGER,
DIMENSION(:),
POINTER :: local_cols, local_rows
325 CALL timeset(routinen, handle)
326 cpassert(omp_get_num_threads() == 1)
328 CALL dbcsr_get_info(matrix, local_rows=local_rows, local_cols=local_cols)
329 n =
SIZE(local_rows)*
SIZE(local_cols)
330 ALLOCATE (rows(n), cols(n))
333 DO i = 1,
SIZE(local_rows)
334 DO j = 1,
SIZE(local_cols)
336 rows(k) = local_rows(i)
337 cols(k) = local_cols(j)
342 DEALLOCATE (rows, cols)
344 CALL timestop(handle)
354 REAL(kind=
dp),
INTENT(IN) :: alpha
356 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_add_on_diag'
358 INTEGER :: col, col_size, handle, i, row, row_size
359 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
362 CALL timeset(routinen, handle)
363 cpassert(omp_get_num_threads() == 1)
373 cpassert(row_size == col_size)
375 block(i, i) = block(i, i) + alpha
382 CALL timestop(handle)
392 TYPE(
dbcsr_type),
INTENT(IN),
TARGET :: matrix_a, matrix_b
393 REAL(kind=
dp),
INTENT(OUT) :: trace
395 REAL(kind=
dp) :: values(1)
398 a(1)%matrix => matrix_a
399 b(1)%matrix => matrix_b
412 TYPE(
dbcsr_p_type),
INTENT(IN) :: matrix_a(:), matrix_b(:)
413 REAL(kind=
dp),
INTENT(OUT) :: trace(
SIZE(matrix_a))
416 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_dot_batch'
418 INTEGER :: col, handle, i, row
419 LOGICAL :: found_b, has_symmetry
420 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block_a, block_b
424 CALL timeset(routinen, handle)
425 cpassert(omp_get_num_threads() == 1)
427 cpassert(
SIZE(matrix_a) ==
SIZE(matrix_b))
428 DO i = 1,
SIZE(matrix_a)
431 IF (
PRESENT(comm))
THEN
433 cpassert(group == comm)
440 DO i = 1,
SIZE(matrix_a)
445 IF (
SIZE(block_a) == 0) cycle
448 IF (has_symmetry .AND. row /= col)
THEN
449 trace(i) = trace(i) + 2.0_dp*sum(block_a*block_b)
451 trace(i) = trace(i) + sum(block_a*block_b)
459 IF (
PRESENT(comm))
THEN
460 IF (
SIZE(trace) > 0 .AND. comm%num_pe > 1)
CALL comm%sum(trace)
462 DO i = 1,
SIZE(matrix_a)
464 IF (group%num_pe > 1)
CALL group%sum(trace(i))
468 CALL timestop(handle)
478 REAL(kind=
dp),
INTENT(OUT) :: trace
480 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_trace'
482 INTEGER :: col, col_size, handle, i, row, row_size
483 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
487 CALL timeset(routinen, handle)
488 cpassert(omp_get_num_threads() == 1)
497 cpassert(row_size == col_size)
499 trace = trace + block(i, i)
507 CALL group%sum(trace)
509 CALL timestop(handle)
521 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_get_block_diag'
523 CHARACTER(LEN=default_string_length) :: name
524 INTEGER :: col, handle, row
525 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
528 CALL timeset(routinen, handle)
529 cpassert(omp_get_num_threads() == 1)
532 CALL dbcsr_create(diag, template=matrix, name=
'diag of '//name)
547 CALL timestop(handle)
558 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: alpha
559 CHARACTER(LEN=*),
INTENT(IN) :: side
561 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_scale_by_vector'
563 INTEGER :: col_offset, col_size, handle, i, &
564 nfullcols_total, nfullrows_total, &
567 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
570 CALL timeset(routinen, handle)
571 cpassert(omp_get_num_threads() == 1)
573 IF (side ==
'right')
THEN
575 ELSE IF (side ==
'left')
THEN
578 cpabort(
"Unknown side: "//trim(side))
582 CALL dbcsr_get_info(matrix, nfullrows_total=nfullrows_total, nfullcols_total=nfullcols_total)
584 cpassert(nfullcols_total ==
SIZE(alpha))
586 cpassert(nfullrows_total ==
SIZE(alpha))
594 row_offset=row_offset, col_offset=col_offset)
595 IF (
SIZE(block) == 0) cycle
598 block(:, i) = block(:, i)*alpha(col_offset + i - 1)
602 block(i, :) = block(i, :)*alpha(row_offset + i - 1)
609 CALL timestop(handle)
619 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: diag
621 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_get_diag'
623 INTEGER :: col, col_size, handle, i, &
624 nfullcols_total, nfullrows_total, row, &
626 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
629 CALL timeset(routinen, handle)
630 cpassert(omp_get_num_threads() == 1)
632 CALL dbcsr_get_info(matrix, nfullrows_total=nfullrows_total, nfullcols_total=nfullcols_total)
633 cpassert(nfullrows_total == nfullcols_total)
634 cpassert(nfullrows_total ==
SIZE(diag))
642 col_size=col_size, row_offset=row_offset)
644 cpassert(row_size == col_size)
646 diag(row_offset + i - 1) = block(i, i)
653 CALL timestop(handle)
663 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: diag
665 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_set_diag'
667 INTEGER :: col, col_size, handle, i, &
668 nfullcols_total, nfullrows_total, row, &
670 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
673 CALL timeset(routinen, handle)
674 cpassert(omp_get_num_threads() == 1)
676 CALL dbcsr_get_info(matrix, nfullrows_total=nfullrows_total, nfullcols_total=nfullcols_total)
677 cpassert(nfullrows_total == nfullcols_total)
678 cpassert(nfullrows_total ==
SIZE(diag))
687 col_size=col_size, row_offset=row_offset)
689 cpassert(row_size == col_size)
691 block(i, i) = diag(row_offset + i - 1)
698 CALL timestop(handle)
710 LOGICAL,
INTENT(IN),
OPTIONAL :: pos
711 REAL(kind=
dp) :: checksum
713 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_checksum'
715 INTEGER :: col_offset, col_size, handle, i, j, &
718 REAL(kind=
dp) :: position_factor
719 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
723 CALL timeset(routinen, handle)
724 cpassert(omp_get_num_threads() == 1)
727 IF (
PRESENT(pos))
THEN
738 row_offset=row_offset, col_offset=col_offset)
742 position_factor = log(real((row_offset + i - 1)*(col_offset + j - 1), kind=
dp))
743 checksum = checksum + block(i, j)*position_factor
747 checksum = checksum + sum(block**2)
754 CALL group%sum(checksum)
756 CALL timestop(handle)
767 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: variable_name
768 INTEGER,
INTENT(IN),
OPTIONAL :: unit_nr
770 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dbcsr_print'
772 CHARACTER(LEN=default_string_length) :: my_variable_name, name
773 INTEGER :: col_offset, col_size, handle, i, iw, j, nblkcols_total, nblkrows_total, &
774 nfullcols_total, nfullrows_total, row_offset, row_size
775 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
778 CALL timeset(routinen, handle)
779 cpassert(omp_get_num_threads() == 1)
782 IF (
PRESENT(unit_nr)) iw = unit_nr
784 my_variable_name =
'a'
785 IF (
PRESENT(variable_name)) my_variable_name = variable_name
789 nblkrows_total=nblkrows_total, nblkcols_total=nblkcols_total, &
790 nfullrows_total=nfullrows_total, nfullcols_total=nfullcols_total)
791 WRITE (iw, *)
"===", routinen,
"==="
792 WRITE (iw, *)
"Name:", name
797 WRITE (iw, *)
"Full size:", nfullrows_total,
"x", nfullcols_total
798 WRITE (iw, *)
"Blocked size:", nblkrows_total,
"x", nblkcols_total
806 row_offset=row_offset, col_offset=col_offset)
810 WRITE (iw,
'(A,I4,A,I4,A,E23.16,A)') trim(my_variable_name)//
'(', &
811 row_offset + i - 1,
',', col_offset + j - 1,
')=', block(i, j),
';'
819 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,...
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)
...
subroutine, public dbcsr_work_create(matrix, nblks_guess, sizedata_guess, n, work_mutable)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset, transposed)
...
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_dot_batch(matrix_a, matrix_b, trace, comm)
Evaluate several dot products in one OpenMP region; MPI reductions remain outside it.
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.