(git:5a3db73)
Loading...
Searching...
No Matches
dbm_api.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: BSD-3-Clause !
6!--------------------------------------------------------------------------------------------------!
7
8MODULE dbm_api
9 USE iso_c_binding, ONLY: c_associated, c_bool, c_char, c_double, c_f_pointer, c_funloc, c_funptr, &
10 c_int, c_int64_t, c_null_char, c_null_ptr, c_ptr
11 USE kinds, ONLY: default_string_length, &
12 dp, &
13 int_8
14 USE message_passing, ONLY: mp_cart_type, &
16
17! Uncomment the following line to enable validation.
18!#define DBM_VALIDATE_AGAINST_DBCSR
19#define DBM_VALIDATE_NBLOCKS_MATCH .TRUE.
20#define DBM_VALIDATE_THRESHOLD 5e-10_dp
21
22#if defined(DBM_VALIDATE_AGAINST_DBCSR)
23 USE dbcsr_block_access, ONLY: dbcsr_get_block_p, &
24 dbcsr_put_block, &
25 dbcsr_reserve_blocks
26 USE dbcsr_dist_methods, ONLY: dbcsr_distribution_col_dist, &
27 dbcsr_distribution_hold, &
28 dbcsr_distribution_new, &
29 dbcsr_distribution_release, &
30 dbcsr_distribution_row_dist
31 USE dbcsr_dist_operations, ONLY: dbcsr_get_stored_coordinates
32 USE dbcsr_dist_util, ONLY: dbcsr_checksum
33 USE dbcsr_iterator_operations, ONLY: dbcsr_iterator_blocks_left, &
34 dbcsr_iterator_next_block, &
35 dbcsr_iterator_start, &
36 dbcsr_iterator_stop
37 USE dbcsr_methods, ONLY: dbcsr_col_block_sizes, &
38 dbcsr_get_num_blocks, &
39 dbcsr_get_nze, &
40 dbcsr_mp_release, &
41 dbcsr_release, &
42 dbcsr_row_block_sizes
43 USE dbcsr_mp_methods, ONLY: dbcsr_mp_new
44 USE dbcsr_multiply_api, ONLY: dbcsr_multiply
45 USE dbcsr_operations, ONLY: dbcsr_add, &
46 dbcsr_clear, &
47 dbcsr_copy, &
48 dbcsr_filter, &
49 dbcsr_get_info, &
50 dbcsr_maxabs, &
51 dbcsr_scale, &
52 dbcsr_zero
53 USE dbcsr_transformations, ONLY: dbcsr_redistribute
54 USE dbcsr_types, ONLY: dbcsr_distribution_obj, &
55 dbcsr_iterator, &
56 dbcsr_mp_obj, &
57 dbcsr_no_transpose, &
58 dbcsr_transpose, &
59 dbcsr_type, &
60 dbcsr_type_no_symmetry, &
61 dbcsr_type_real_8
62 USE dbcsr_work_operations, ONLY: dbcsr_create, &
63 dbcsr_finalize
64 USE dbcsr_data_methods, ONLY: dbcsr_scalar
65#endif
66
67#include "../base/base_uses.f90"
68
69 IMPLICIT NONE
70
71 PRIVATE
72
73 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'dbm_api'
74
75 PUBLIC :: dbm_distribution_obj
76 PUBLIC :: dbm_distribution_new
77 PUBLIC :: dbm_distribution_hold
82
83 PUBLIC :: dbm_iterator
84 PUBLIC :: dbm_iterator_start
85 PUBLIC :: dbm_iterator_stop
89
90 PUBLIC :: dbm_type
91 PUBLIC :: dbm_release
92 PUBLIC :: dbm_create
94 PUBLIC :: dbm_clear
95 PUBLIC :: dbm_scale
96 PUBLIC :: dbm_get_block_p
97 PUBLIC :: dbm_put_block
98 PUBLIC :: dbm_reserve_blocks
100 PUBLIC :: dbm_filter
101 PUBLIC :: dbm_finalize
102 PUBLIC :: dbm_multiply
103 PUBLIC :: dbm_redistribute
104 PUBLIC :: dbm_copy
105 PUBLIC :: dbm_add
106 PUBLIC :: dbm_maxabs
107 PUBLIC :: dbm_zero
108 PUBLIC :: dbm_checksum
109 PUBLIC :: dbm_get_name
110 PUBLIC :: dbm_get_distribution
111 PUBLIC :: dbm_get_num_blocks
112 PUBLIC :: dbm_get_nze
116 PUBLIC :: dbm_get_local_rows
117 PUBLIC :: dbm_get_local_cols
118
119 PUBLIC :: dbm_library_init
120 PUBLIC :: dbm_library_finalize
122
124 PRIVATE
125 TYPE(C_PTR) :: c_ptr = c_null_ptr
126#if defined(DBM_VALIDATE_AGAINST_DBCSR)
127 TYPE(dbcsr_distribution_obj) :: dbcsr
128#endif
129 END TYPE dbm_distribution_obj
130
132 PRIVATE
133 TYPE(C_PTR) :: c_ptr = c_null_ptr
134#if defined(DBM_VALIDATE_AGAINST_DBCSR)
135 TYPE(dbcsr_type) :: dbcsr
136#endif
137 END TYPE dbm_type
138
140 PRIVATE
141 TYPE(C_PTR) :: c_ptr = c_null_ptr
142 END TYPE dbm_iterator
143
144CONTAINS
145
146#if defined(DBM_VALIDATE_AGAINST_DBCSR)
147! **************************************************************************************************
148!> \brief Compates the given DBM matrix against its shadow DBCSR matrics.
149!> \param matrix ...
150!> \author Ole Schuett
151! **************************************************************************************************
152 SUBROUTINE validate(matrix)
153 TYPE(dbm_type), INTENT(IN) :: matrix
154
155 INTEGER :: col, col_size, col_size_dbcsr, i, j, &
156 num_blocks, num_blocks_dbcsr, &
157 num_blocks_diff, row, row_size, &
158 row_size_dbcsr
159 INTEGER, ALLOCATABLE, DIMENSION(:) :: local_cols, local_rows
160 LOGICAL :: transposed
161 REAL(dp) :: norm2, rel_diff
162 REAL(dp), DIMENSION(:, :), POINTER :: block, block_dbcsr
163 TYPE(C_PTR) :: block_c
164 TYPE(dbcsr_iterator) :: iter
165 INTERFACE
166 SUBROUTINE dbm_get_block_p_c(matrix, row, col, block, row_size, col_size) &
167 BIND(C, name="dbm_get_block_p")
168 IMPORT :: c_ptr, c_int
169 TYPE(C_PTR), VALUE :: matrix
170 INTEGER(kind=C_INT), VALUE :: row
171 INTEGER(kind=C_INT), VALUE :: col
172 TYPE(C_PTR) :: block
173 INTEGER(kind=C_INT) :: row_size
174 INTEGER(kind=C_INT) :: col_size
175 END SUBROUTINE dbm_get_block_p_c
176 END INTERFACE
177
178 ! Call some getters to run their validation code.
179 CALL dbm_get_local_rows(matrix, local_rows)
180 CALL dbm_get_local_cols(matrix, local_cols)
181
182 num_blocks_dbcsr = dbcsr_get_num_blocks(matrix%dbcsr)
183 num_blocks = dbm_get_num_blocks(matrix)
184 num_blocks_diff = abs(num_blocks - num_blocks_dbcsr)
185 IF (num_blocks_diff /= 0) THEN
186 WRITE (*, *) "num_blocks mismatch dbcsr:", num_blocks_dbcsr, "new:", num_blocks
187 IF (dbm_validate_nblocks_match) THEN
188 cpabort("num_blocks mismatch")
189 END IF
190 END IF
191
192 IF (dbm_validate_nblocks_match) THEN
193 cpassert(dbm_get_nze(matrix) == dbcsr_get_nze(matrix%dbcsr))
194 END IF
195
196 ! check all dbcsr blocks
197 norm2 = 0.0_dp
198 CALL dbcsr_iterator_start(iter, matrix%dbcsr)
199 DO WHILE (dbcsr_iterator_blocks_left(iter))
200 CALL dbcsr_iterator_next_block(iter, row=row, column=col, block=block_dbcsr, &
201 transposed=transposed, &
202 row_size=row_size_dbcsr, col_size=col_size_dbcsr)
203 cpassert(.NOT. transposed)
204 CALL dbm_get_block_p_c(matrix=matrix%c_ptr, row=row - 1, col=col - 1, &
205 block=block_c, row_size=row_size, col_size=col_size)
206
207 cpassert(row_size == row_size_dbcsr .AND. col_size == col_size_dbcsr)
208 IF (SIZE(block_dbcsr) == 0) THEN
209 cycle
210 END IF
211 IF (.NOT. c_associated(block_c)) THEN
212 cpassert(maxval(abs(block_dbcsr)) < dbm_validate_threshold)
213 cycle
214 END IF
215
216 CALL c_f_pointer(block_c, block, shape=[row_size, col_size])
217 DO i = 1, row_size
218 DO j = 1, col_size
219 rel_diff = abs(block(i, j) - block_dbcsr(i, j))/max(1.0_dp, abs(block_dbcsr(i, j)))
220 IF (rel_diff > dbm_validate_threshold) THEN
221 WRITE (*, *) "row:", row, "col:", col, "i:", i, "j:", j, "rel_diff:", rel_diff
222 WRITE (*, *) "values dbcsr:", block_dbcsr(i, j), "new:", block(i, j)
223 cpabort("block value mismatch")
224 END IF
225 END DO
226 END DO
227 norm2 = norm2 + sum(block**2)
228 block_dbcsr(:, :) = block(:, :) ! quench numerical noise
229 END DO
230 CALL dbcsr_iterator_stop(iter)
231
232 ! Can not call dbcsr_get_block_p because it's INTENT(INOUT) :-(
233
234 !! At least check that the norm (=checksum) of excesive blocks is small.
235 !TODO: sum norm2 across all mpi ranks.
236 !TODO: re-add INTERFACE to dbm_checksum_c, which got removed by prettify.
237 !rel_diff = ABS(dbm_checksum_c(matrix%c_ptr) - norm2)/MAX(1.0_dp, norm2)
238 !IF (rel_diff > DBM_VALIDATE_THRESHOLD) THEN
239 ! WRITE (*, *) "num_blocks dbcsr:", num_blocks_dbcsr, "new:", num_blocks
240 ! WRITE (*, *) "norm2: ", norm2
241 ! WRITE (*, *) "relative residual norm diff: ", rel_diff
242 ! CPABORT("residual norm diff")
243 !END IF
244 END SUBROUTINE validate
245
246#else
247
248! **************************************************************************************************
249!> \brief Dummy for when DBM_VALIDATE_AGAINST_DBCSR is not defined.
250!> \param matrix ...
251! **************************************************************************************************
252 SUBROUTINE validate(matrix)
253 TYPE(dbm_type), INTENT(IN) :: matrix
254
255 mark_used(matrix)
256 END SUBROUTINE validate
257#endif
258
259! **************************************************************************************************
260!> \brief Creates a new matrix from given template, reusing dist and row/col_block_sizes.
261!> \param matrix ...
262!> \param name ...
263!> \param template ...
264!> \author Ole Schuett
265! **************************************************************************************************
266 SUBROUTINE dbm_create_from_template(matrix, name, template)
267 TYPE(dbm_type), INTENT(INOUT) :: matrix
268 CHARACTER(len=*), INTENT(IN) :: name
269 TYPE(dbm_type), INTENT(IN) :: template
270
271 INTEGER, CONTIGUOUS, DIMENSION(:), POINTER :: col_block_sizes, row_block_sizes
272
273 ! Store pointers in intermediate variables to workaround a CCE error.
274 row_block_sizes => dbm_get_row_block_sizes(template)
275 col_block_sizes => dbm_get_col_block_sizes(template)
276
277 CALL dbm_create(matrix, &
278 name=name, &
279 dist=dbm_get_distribution(template), &
280 row_block_sizes=row_block_sizes, &
281 col_block_sizes=col_block_sizes)
282
283 END SUBROUTINE dbm_create_from_template
284
285! **************************************************************************************************
286!> \brief Creates a new matrix.
287!> \param matrix ...
288!> \param name ...
289!> \param dist ...
290!> \param row_block_sizes ...
291!> \param col_block_sizes ...
292!> \author Ole Schuett
293! **************************************************************************************************
294 SUBROUTINE dbm_create(matrix, name, dist, row_block_sizes, col_block_sizes)
295 TYPE(dbm_type), INTENT(INOUT) :: matrix
296 CHARACTER(len=*), INTENT(IN) :: name
297 TYPE(dbm_distribution_obj), INTENT(IN) :: dist
298 INTEGER, CONTIGUOUS, DIMENSION(:), INTENT(IN), &
299 POINTER :: row_block_sizes, col_block_sizes
300
301 INTERFACE
302 SUBROUTINE dbm_create_c(matrix, dist, name, nrows, ncols, row_sizes, col_sizes) &
303 BIND(C, name="dbm_create")
304 IMPORT :: c_ptr, c_char, c_int
305 TYPE(c_ptr) :: matrix
306 TYPE(c_ptr), VALUE :: dist
307 CHARACTER(kind=C_CHAR), DIMENSION(*) :: name
308 INTEGER(kind=C_INT), VALUE :: nrows
309 INTEGER(kind=C_INT), VALUE :: ncols
310 INTEGER(kind=C_INT), DIMENSION(*) :: row_sizes
311 INTEGER(kind=C_INT), DIMENSION(*) :: col_sizes
312 END SUBROUTINE dbm_create_c
313 END INTERFACE
314
315 cpassert(.NOT. c_associated(matrix%c_ptr))
316 CALL dbm_create_c(matrix=matrix%c_ptr, &
317 dist=dist%c_ptr, &
318 name=trim(name)//c_null_char, &
319 nrows=SIZE(row_block_sizes), &
320 ncols=SIZE(col_block_sizes), &
321 row_sizes=row_block_sizes, &
322 col_sizes=col_block_sizes)
323 cpassert(c_associated(matrix%c_ptr))
324
325#if defined(DBM_VALIDATE_AGAINST_DBCSR)
326 CALL dbcsr_create(matrix%dbcsr, name=name, dist=dist%dbcsr, &
327 matrix_type=dbcsr_type_no_symmetry, &
328 row_blk_size=row_block_sizes, col_blk_size=col_block_sizes, &
329 data_type=dbcsr_type_real_8)
330
331 CALL validate(matrix)
332#endif
333 END SUBROUTINE dbm_create
334
335! **************************************************************************************************
336!> \brief Needed to be called for DBCSR after blocks where inserted. For DBM it's a no-opt.
337!> \param matrix ...
338!> \author Ole Schuett
339! **************************************************************************************************
340 SUBROUTINE dbm_finalize(matrix)
341 TYPE(dbm_type), INTENT(INOUT) :: matrix
342
343 mark_used(matrix) ! New implementation does not need finalize.
344
345#if defined(DBM_VALIDATE_AGAINST_DBCSR)
346 CALL dbcsr_finalize(matrix%dbcsr)
347#endif
348 END SUBROUTINE dbm_finalize
349
350! **************************************************************************************************
351!> \brief Releases a matrix and all its ressources.
352!> \param matrix ...
353!> \author Ole Schuett
354! **************************************************************************************************
355 SUBROUTINE dbm_release(matrix)
356 TYPE(dbm_type), INTENT(INOUT) :: matrix
357
358 INTERFACE
359 SUBROUTINE dbm_release_c(matrix) &
360 BIND(C, name="dbm_release")
361 IMPORT :: c_ptr
362 TYPE(c_ptr), VALUE :: matrix
363 END SUBROUTINE dbm_release_c
364 END INTERFACE
365
366 CALL dbm_release_c(matrix=matrix%c_ptr)
367 matrix%c_ptr = c_null_ptr
368
369#if defined(DBM_VALIDATE_AGAINST_DBCSR)
370 CALL dbcsr_release(matrix%dbcsr)
371#endif
372 END SUBROUTINE dbm_release
373
374! **************************************************************************************************
375!> \brief Copies content of matrix_b into matrix_a.
376!> Matrices must have the same row/col block sizes and distribution.
377!> \param matrix_a ...
378!> \param matrix_b ...
379!> \author Ole Schuett
380! **************************************************************************************************
381 SUBROUTINE dbm_copy(matrix_a, matrix_b)
382 TYPE(dbm_type), INTENT(INOUT) :: matrix_a
383 TYPE(dbm_type), INTENT(IN) :: matrix_b
384
385 CHARACTER(LEN=*), PARAMETER :: routinen = 'dbm_copy'
386
387 INTEGER :: handle
388 INTERFACE
389 SUBROUTINE dbm_copy_c(matrix_a, matrix_b) &
390 BIND(C, name="dbm_copy")
391 IMPORT :: c_ptr
392 TYPE(c_ptr), VALUE :: matrix_a
393 TYPE(c_ptr), VALUE :: matrix_b
394 END SUBROUTINE dbm_copy_c
395 END INTERFACE
396
397 CALL timeset(routinen, handle)
398 CALL dbm_copy_c(matrix_a=matrix_a%c_ptr, matrix_b=matrix_b%c_ptr)
399
400#if defined(DBM_VALIDATE_AGAINST_DBCSR)
401 CALL dbcsr_copy(matrix_a%dbcsr, matrix_b%dbcsr)
402 CALL validate(matrix_a)
403#endif
404 CALL timestop(handle)
405 END SUBROUTINE dbm_copy
406
407! **************************************************************************************************
408!> \brief Copies content of matrix_b into matrix_a. Matrices may have different distributions.
409!> \param matrix ...
410!> \param redist ...
411!> \author Ole Schuett
412! **************************************************************************************************
413 SUBROUTINE dbm_redistribute(matrix, redist)
414 TYPE(dbm_type), INTENT(IN) :: matrix
415 TYPE(dbm_type), INTENT(INOUT) :: redist
416
417 CHARACTER(LEN=*), PARAMETER :: routinen = 'dbm_redistribute'
418
419 INTEGER :: handle
420 INTERFACE
421 SUBROUTINE dbm_redistribute_c(matrix, redist) &
422 BIND(C, name="dbm_redistribute")
423 IMPORT :: c_ptr
424 TYPE(c_ptr), VALUE :: matrix
425 TYPE(c_ptr), VALUE :: redist
426 END SUBROUTINE dbm_redistribute_c
427 END INTERFACE
428
429 CALL timeset(routinen, handle)
430 CALL dbm_redistribute_c(matrix=matrix%c_ptr, redist=redist%c_ptr)
431
432#if defined(DBM_VALIDATE_AGAINST_DBCSR)
433 CALL dbcsr_redistribute(matrix%dbcsr, redist%dbcsr)
434 CALL validate(redist)
435#endif
436 CALL timestop(handle)
437 END SUBROUTINE dbm_redistribute
438
439! **************************************************************************************************
440!> \brief Looks up a block from given matrics. This routine is thread-safe.
441!> If the block is not found then a null pointer is returned.
442!> \param matrix ...
443!> \param row ...
444!> \param col ...
445!> \param block ...
446!> \param row_size ...
447!> \param col_size ...
448!> \author Ole Schuett
449! **************************************************************************************************
450 SUBROUTINE dbm_get_block_p(matrix, row, col, block, row_size, col_size)
451 TYPE(dbm_type), INTENT(INOUT) :: matrix
452 INTEGER, INTENT(IN) :: row, col
453 REAL(dp), DIMENSION(:, :), INTENT(OUT), POINTER :: block
454 INTEGER, INTENT(OUT), OPTIONAL :: row_size, col_size
455
456 INTEGER :: my_col_size, my_row_size
457 TYPE(c_ptr) :: block_c
458 INTERFACE
459 SUBROUTINE dbm_get_block_p_c(matrix, row, col, block, row_size, col_size) &
460 BIND(C, name="dbm_get_block_p")
461 IMPORT :: c_ptr, c_int
462 TYPE(c_ptr), VALUE :: matrix
463 INTEGER(kind=C_INT), VALUE :: row
464 INTEGER(kind=C_INT), VALUE :: col
465 TYPE(c_ptr) :: block
466 INTEGER(kind=C_INT) :: row_size
467 INTEGER(kind=C_INT) :: col_size
468 END SUBROUTINE dbm_get_block_p_c
469 END INTERFACE
470
471 CALL dbm_get_block_p_c(matrix=matrix%c_ptr, row=row - 1, col=col - 1, &
472 block=block_c, row_size=my_row_size, col_size=my_col_size)
473 IF (c_associated(block_c)) THEN
474 CALL c_f_pointer(block_c, block, shape=[my_row_size, my_col_size])
475 ELSE
476 NULLIFY (block) ! block not found
477 END IF
478 IF (PRESENT(row_size)) row_size = my_row_size
479 IF (PRESENT(col_size)) col_size = my_col_size
480 END SUBROUTINE dbm_get_block_p
481
482! **************************************************************************************************
483!> \brief Adds a block to given matrix. This routine is thread-safe.
484!> If block already exist then it gets overwritten (or summed).
485!> \param matrix ...
486!> \param row ...
487!> \param col ...
488!> \param block ...
489!> \param summation ...
490!> \author Ole Schuett
491! **************************************************************************************************
492 SUBROUTINE dbm_put_block(matrix, row, col, block, summation)
493 TYPE(dbm_type), INTENT(INOUT) :: matrix
494 INTEGER, INTENT(IN) :: row, col
495 REAL(dp), CONTIGUOUS, DIMENSION(:, :), INTENT(IN) :: block
496 LOGICAL, INTENT(IN), OPTIONAL :: summation
497
498 LOGICAL :: my_summation
499 INTERFACE
500 SUBROUTINE dbm_put_block_c(matrix, row, col, summation, block) &
501 BIND(C, name="dbm_put_block")
502 IMPORT :: c_ptr, c_int, c_bool, c_double
503 TYPE(c_ptr), VALUE :: matrix
504 INTEGER(kind=C_INT), VALUE :: row
505 INTEGER(kind=C_INT), VALUE :: col
506 LOGICAL(kind=C_BOOL), VALUE :: summation
507 REAL(kind=c_double), DIMENSION(*) :: block
508 END SUBROUTINE dbm_put_block_c
509 END INTERFACE
510
511 my_summation = .false.
512 IF (PRESENT(summation)) my_summation = summation
513
514 CALL dbm_put_block_c(matrix=matrix%c_ptr, &
515 row=row - 1, col=col - 1, &
516 summation=LOGICAL(my_summation, C_BOOL), &
517 block=block)
518
519#if defined(DBM_VALIDATE_AGAINST_DBCSR)
520 CALL dbcsr_put_block(matrix%dbcsr, row, col, block, summation=summation)
521 ! Can not call validate(matrix) because the dbcsr matrix needs to be finalized first.
522#endif
523 END SUBROUTINE dbm_put_block
524
525! **************************************************************************************************
526!> \brief Remove all blocks from given matrix, but does not release the underlying memory.
527!> \param matrix ...
528!> \author Ole Schuett
529! **************************************************************************************************
530 SUBROUTINE dbm_clear(matrix)
531 TYPE(dbm_type), INTENT(INOUT) :: matrix
532
533 INTERFACE
534 SUBROUTINE dbm_clear_c(matrix) &
535 BIND(C, name="dbm_clear")
536 IMPORT :: c_ptr
537 TYPE(c_ptr), VALUE :: matrix
538 END SUBROUTINE dbm_clear_c
539 END INTERFACE
540
541 CALL dbm_clear_c(matrix=matrix%c_ptr)
542
543#if defined(DBM_VALIDATE_AGAINST_DBCSR)
544 CALL dbcsr_clear(matrix%dbcsr)
545 CALL validate(matrix)
546#endif
547 END SUBROUTINE dbm_clear
548
549! **************************************************************************************************
550!> \brief Removes all blocks from the given matrix whose block norm is below the given threshold.
551!> Blocks of size zero are always kept.
552!> \param matrix ...
553!> \param eps ...
554!> \author Ole Schuett
555! **************************************************************************************************
556 SUBROUTINE dbm_filter(matrix, eps)
557 TYPE(dbm_type), INTENT(INOUT) :: matrix
558 REAL(dp), INTENT(IN) :: eps
559
560 CHARACTER(LEN=*), PARAMETER :: routinen = 'dbm_filter'
561
562 INTEGER :: handle
563 INTERFACE
564 SUBROUTINE dbm_filter_c(matrix, eps) &
565 BIND(C, name="dbm_filter")
566 IMPORT :: c_ptr, c_double
567 TYPE(c_ptr), VALUE :: matrix
568 REAL(kind=c_double), VALUE :: eps
569 END SUBROUTINE dbm_filter_c
570 END INTERFACE
571
572 CALL timeset(routinen, handle)
573 CALL validate(matrix)
574 CALL dbm_filter_c(matrix=matrix%c_ptr, eps=eps)
575
576#if defined(DBM_VALIDATE_AGAINST_DBCSR)
577 CALL dbcsr_filter(matrix%dbcsr, eps)
578 CALL validate(matrix)
579#endif
580 CALL timestop(handle)
581 END SUBROUTINE dbm_filter
582
583! **************************************************************************************************
584!> \brief Adds given list of blocks efficiently. The blocks will be filled with zeros.
585!> \param matrix ...
586!> \param rows ...
587!> \param cols ...
588!> \author Ole Schuett
589! **************************************************************************************************
590 SUBROUTINE dbm_reserve_blocks(matrix, rows, cols)
591 TYPE(dbm_type), INTENT(INOUT) :: matrix
592 INTEGER, DIMENSION(:), INTENT(IN) :: rows, cols
593
594 CHARACTER(LEN=*), PARAMETER :: routinen = 'dbm_reserve_blocks'
595
596 INTEGER :: handle
597 INTEGER(kind=C_INT), DIMENSION(SIZE(rows)) :: cols_c, rows_c
598 INTERFACE
599 SUBROUTINE dbm_reserve_blocks_c(matrix, nblocks, rows, cols) &
600 BIND(C, name="dbm_reserve_blocks")
601 IMPORT :: c_ptr, c_int
602 TYPE(c_ptr), VALUE :: matrix
603 INTEGER(kind=C_INT), VALUE :: nblocks
604 INTEGER(kind=C_INT), DIMENSION(*) :: rows
605 INTEGER(kind=C_INT), DIMENSION(*) :: cols
606 END SUBROUTINE dbm_reserve_blocks_c
607 END INTERFACE
608
609 CALL timeset(routinen, handle)
610 cpassert(SIZE(rows) == SIZE(cols))
611 rows_c = rows - 1
612 cols_c = cols - 1
613
614 CALL dbm_reserve_blocks_c(matrix=matrix%c_ptr, &
615 nblocks=SIZE(rows), &
616 rows=rows_c, &
617 cols=cols_c)
618
619#if defined(DBM_VALIDATE_AGAINST_DBCSR)
620 CALL dbcsr_reserve_blocks(matrix%dbcsr, rows, cols)
621 CALL validate(matrix)
622#endif
623 CALL timestop(handle)
624 END SUBROUTINE dbm_reserve_blocks
625
626! **************************************************************************************************
627!> \brief Reserves template blocks in a matrix sharing the distribution object.
628!> Block sizes may differ. Existing values are preserved, new blocks zeroed.
629!> Call outside an OpenMP parallel region.
630!> \param matrix Target matrix
631!> \param template Source block structure
632! **************************************************************************************************
633 SUBROUTINE dbm_reserve_blocks_template(matrix, template)
634 TYPE(dbm_type), INTENT(INOUT) :: matrix
635 TYPE(dbm_type), INTENT(IN) :: template
636
637 CHARACTER(LEN=*), PARAMETER :: routinen = 'dbm_reserve_blocks_template'
638
639 INTEGER :: handle
640#if defined(DBM_VALIDATE_AGAINST_DBCSR)
641 INTEGER :: iblock, nblocks
642 INTEGER, ALLOCATABLE, DIMENSION(:) :: rows, cols
643 TYPE(dbm_iterator) :: iter
644#endif
645 INTERFACE
646 SUBROUTINE dbm_reserve_blocks_template_c(matrix, template) &
647 BIND(C, name="dbm_reserve_blocks_template")
648 IMPORT :: c_ptr
649 TYPE(c_ptr), VALUE :: matrix, template
650 END SUBROUTINE dbm_reserve_blocks_template_c
651 END INTERFACE
652
653 CALL timeset(routinen, handle)
654 CALL dbm_reserve_blocks_template_c(matrix%c_ptr, template%c_ptr)
655#if defined(DBM_VALIDATE_AGAINST_DBCSR)
656!$OMP PARALLEL DEFAULT(NONE) SHARED(matrix,template) PRIVATE(iter,nblocks,iblock,rows,cols)
657 CALL dbm_iterator_start(iter, template)
658 nblocks = dbm_iterator_num_blocks(iter)
659 ALLOCATE (rows(nblocks), cols(nblocks))
660 DO iblock = 1, nblocks
661 CALL dbm_iterator_next_block(iter, row=rows(iblock), column=cols(iblock))
662 END DO
663 CALL dbm_iterator_stop(iter)
664 CALL dbcsr_reserve_blocks(matrix%dbcsr, rows, cols)
665 DEALLOCATE (rows, cols)
666!$OMP END PARALLEL
667 CALL validate(matrix)
668#endif
669 CALL timestop(handle)
670 END SUBROUTINE dbm_reserve_blocks_template
671
672! **************************************************************************************************
673!> \brief Multiplies all entries in the given matrix by the given factor alpha.
674!> \param matrix ...
675!> \param alpha ...
676!> \author Ole Schuett
677! **************************************************************************************************
678 SUBROUTINE dbm_scale(matrix, alpha)
679 TYPE(dbm_type), INTENT(INOUT) :: matrix
680 REAL(dp), INTENT(IN) :: alpha
681
682 CHARACTER(LEN=*), PARAMETER :: routinen = 'dbm_scale'
683
684 INTEGER :: handle
685 INTERFACE
686 SUBROUTINE dbm_scale_c(matrix, alpha) &
687 BIND(C, name="dbm_scale")
688 IMPORT :: c_ptr, c_double
689 TYPE(c_ptr), VALUE :: matrix
690 REAL(kind=c_double), VALUE :: alpha
691 END SUBROUTINE dbm_scale_c
692 END INTERFACE
693
694 CALL timeset(routinen, handle)
695 CALL dbm_scale_c(matrix=matrix%c_ptr, alpha=alpha)
696
697#if defined(DBM_VALIDATE_AGAINST_DBCSR)
698 CALL dbcsr_scale(matrix%dbcsr, alpha)
699 CALL validate(matrix)
700#endif
701 CALL timestop(handle)
702 END SUBROUTINE dbm_scale
703
704! **************************************************************************************************
705!> \brief Sets all blocks in the given matrix to zero.
706!> \param matrix ...
707!> \author Ole Schuett
708! **************************************************************************************************
709 SUBROUTINE dbm_zero(matrix)
710 TYPE(dbm_type), INTENT(INOUT) :: matrix
711
712 CHARACTER(LEN=*), PARAMETER :: routinen = 'dbm_zero'
713
714 INTEGER :: handle
715 INTERFACE
716 SUBROUTINE dbm_zero_c(matrix) &
717 BIND(C, name="dbm_zero")
718 IMPORT :: c_ptr
719 TYPE(c_ptr), VALUE :: matrix
720 END SUBROUTINE dbm_zero_c
721 END INTERFACE
722
723 CALL timeset(routinen, handle)
724 CALL dbm_zero_c(matrix=matrix%c_ptr)
725
726#if defined(DBM_VALIDATE_AGAINST_DBCSR)
727 CALL dbcsr_zero(matrix%dbcsr)
728 CALL validate(matrix)
729#endif
730 CALL timestop(handle)
731 END SUBROUTINE dbm_zero
732
733! **************************************************************************************************
734!> \brief Adds matrix_b to matrix_a.
735!> \param matrix_a ...
736!> \param matrix_b ...
737!> \author Ole Schuett
738! **************************************************************************************************
739 SUBROUTINE dbm_add(matrix_a, matrix_b)
740 TYPE(dbm_type), INTENT(INOUT) :: matrix_a
741 TYPE(dbm_type), INTENT(IN) :: matrix_b
742
743 CHARACTER(LEN=*), PARAMETER :: routinen = 'dbm_add'
744
745 INTEGER :: handle
746 INTERFACE
747 SUBROUTINE dbm_add_c(matrix_a, matrix_b) &
748 BIND(C, name="dbm_add")
749 IMPORT :: c_ptr, c_double
750 TYPE(c_ptr), VALUE :: matrix_a
751 TYPE(c_ptr), VALUE :: matrix_b
752 END SUBROUTINE dbm_add_c
753 END INTERFACE
754
755 CALL timeset(routinen, handle)
756 CALL validate(matrix_a)
757 CALL validate(matrix_b)
758 CALL dbm_add_c(matrix_a=matrix_a%c_ptr, matrix_b=matrix_b%c_ptr)
759
760#if defined(DBM_VALIDATE_AGAINST_DBCSR)
761 CALL dbcsr_add(matrix_a%dbcsr, matrix_b%dbcsr)
762 CALL validate(matrix_a)
763#endif
764 CALL timestop(handle)
765 END SUBROUTINE dbm_add
766
767! **************************************************************************************************
768!> \brief Computes matrix product: matrix_c = alpha * matrix_a * matrix_b + beta * matrix_c.
769!> \param transa ...
770!> \param transb ...
771!> \param alpha ...
772!> \param matrix_a ...
773!> \param matrix_b ...
774!> \param beta ...
775!> \param matrix_c ...
776!> \param retain_sparsity ...
777!> \param filter_eps ...
778!> \param flop ...
779!> \author Ole Schuett
780! **************************************************************************************************
781 SUBROUTINE dbm_multiply(transa, transb, &
782 alpha, matrix_a, matrix_b, beta, matrix_c, &
783 retain_sparsity, filter_eps, flop)
784 LOGICAL, INTENT(IN) :: transa, transb
785 REAL(kind=dp), INTENT(IN) :: alpha
786 TYPE(dbm_type), INTENT(IN) :: matrix_a, matrix_b
787 REAL(kind=dp), INTENT(IN) :: beta
788 TYPE(dbm_type), INTENT(INOUT) :: matrix_c
789 LOGICAL, INTENT(IN), OPTIONAL :: retain_sparsity
790 REAL(kind=dp), INTENT(IN), OPTIONAL :: filter_eps
791 INTEGER(int_8), INTENT(OUT), OPTIONAL :: flop
792
793 CHARACTER(LEN=*), PARAMETER :: routinen = 'dbm_multiply'
794
795 CHARACTER(LEN=1) :: transa_char, transb_char
796 INTEGER :: handle
797 INTEGER(int_8) :: flop_dbcsr, my_flop
798 LOGICAL :: my_retain_sparsity
799 REAL(kind=dp) :: my_filter_eps
800 INTERFACE
801 SUBROUTINE dbm_multiply_c(transa, transb, alpha, &
802 matrix_a, matrix_b, &
803 beta, matrix_c, &
804 retain_sparsity, filter_eps, flop) &
805 BIND(C, name="dbm_multiply")
806 IMPORT :: c_ptr, c_double, c_bool, c_int64_t
807 LOGICAL(kind=C_BOOL), VALUE :: transa
808 LOGICAL(kind=C_BOOL), VALUE :: transb
809 REAL(kind=c_double), VALUE :: alpha
810 TYPE(c_ptr), VALUE :: matrix_a
811 TYPE(c_ptr), VALUE :: matrix_b
812 REAL(kind=c_double), VALUE :: beta
813 TYPE(c_ptr), VALUE :: matrix_c
814 LOGICAL(kind=C_BOOL), VALUE :: retain_sparsity
815 REAL(kind=c_double), VALUE :: filter_eps
816 INTEGER(kind=C_INT64_T) :: flop
817 END SUBROUTINE dbm_multiply_c
818 END INTERFACE
819
820 CALL timeset(routinen, handle)
821
822 IF (PRESENT(retain_sparsity)) THEN
823 my_retain_sparsity = retain_sparsity
824 ELSE
825 my_retain_sparsity = .false.
826 END IF
827
828 IF (PRESENT(filter_eps)) THEN
829 my_filter_eps = filter_eps
830 ELSE
831 my_filter_eps = 0.0_dp
832 END IF
833
834 CALL validate(matrix_a)
835 CALL validate(matrix_b)
836 CALL validate(matrix_c)
837 CALL dbm_multiply_c(transa=LOGICAL(transa, C_BOOL), &
838 transb=logical(transb, c_bool), &
839 alpha=alpha, &
840 matrix_a=matrix_a%c_ptr, &
841 matrix_b=matrix_b%c_ptr, &
842 beta=beta, &
843 matrix_c=matrix_c%c_ptr, &
844 retain_sparsity=LOGICAL(my_retain_sparsity, C_BOOL), &
845 filter_eps=my_filter_eps, &
846 flop=my_flop)
847
848 IF (PRESENT(flop)) THEN
849 flop = my_flop
850 END IF
851
852#if defined(DBM_VALIDATE_AGAINST_DBCSR)
853 IF (transa) THEN
854 transa_char = dbcsr_transpose
855 ELSE
856 transa_char = dbcsr_no_transpose
857 END IF
858 IF (transb) THEN
859 transb_char = dbcsr_transpose
860 ELSE
861 transb_char = dbcsr_no_transpose
862 END IF
863 CALL dbcsr_multiply(transa=transa_char, transb=transb_char, &
864 alpha=alpha, matrix_a=matrix_a%dbcsr, &
865 matrix_b=matrix_b%dbcsr, beta=beta, matrix_c=matrix_c%dbcsr, &
866 retain_sparsity=retain_sparsity, filter_eps=filter_eps, flop=flop_dbcsr)
867 cpassert(my_flop == flop_dbcsr)
868 CALL validate(matrix_c)
869#else
870 ! Can not use preprocessor's ifdefs before INTERFACE because it confuses prettify.
871 mark_used(transa_char)
872 mark_used(transb_char)
873 mark_used(flop_dbcsr)
874#endif
875 CALL timestop(handle)
876 END SUBROUTINE dbm_multiply
877
878! **************************************************************************************************
879!> \brief Creates an iterator for the blocks of the given matrix. The iteration order is not stable.
880!> \param iterator ...
881!> \param matrix ...
882!> \author Ole Schuett
883! **************************************************************************************************
884 SUBROUTINE dbm_iterator_start(iterator, matrix)
885 TYPE(dbm_iterator), INTENT(OUT) :: iterator
886 TYPE(dbm_type), INTENT(IN) :: matrix
887
888 INTERFACE
889 SUBROUTINE dbm_iterator_start_c(iterator, matrix) &
890 BIND(C, name="dbm_iterator_start")
891 IMPORT :: c_ptr
892 TYPE(c_ptr) :: iterator
893 TYPE(c_ptr), VALUE :: matrix
894 END SUBROUTINE dbm_iterator_start_c
895 END INTERFACE
896
897 cpassert(.NOT. c_associated(iterator%c_ptr))
898 CALL dbm_iterator_start_c(iterator=iterator%c_ptr, matrix=matrix%c_ptr)
899 cpassert(c_associated(iterator%c_ptr))
900 CALL validate(matrix)
901 END SUBROUTINE dbm_iterator_start
902
903! **************************************************************************************************
904!> \brief Returns number of blocks the iterator will provide to calling thread.
905!> \param iterator ...
906!> \return ...
907!> \author Ole Schuett
908! **************************************************************************************************
909 FUNCTION dbm_iterator_num_blocks(iterator) RESULT(num_blocks)
910 TYPE(dbm_iterator), INTENT(IN) :: iterator
911 INTEGER :: num_blocks
912
913 INTERFACE
914 FUNCTION dbm_iterator_num_blocks_c(iterator) &
915 BIND(C, name="dbm_iterator_num_blocks")
916 IMPORT :: c_ptr, c_int
917 TYPE(c_ptr), VALUE :: iterator
918 INTEGER(kind=C_INT) :: dbm_iterator_num_blocks_c
919 END FUNCTION dbm_iterator_num_blocks_c
920 END INTERFACE
921
922 num_blocks = dbm_iterator_num_blocks_c(iterator%c_ptr)
923 END FUNCTION dbm_iterator_num_blocks
924
925! **************************************************************************************************
926!> \brief Tests whether the given iterator has any block left.
927!> \param iterator ...
928!> \return ...
929!> \author Ole Schuett
930! **************************************************************************************************
931 FUNCTION dbm_iterator_blocks_left(iterator) RESULT(blocks_left)
932 TYPE(dbm_iterator), INTENT(IN) :: iterator
933 LOGICAL :: blocks_left
934
935 INTERFACE
936 FUNCTION dbm_iterator_blocks_left_c(iterator) &
937 BIND(C, name="dbm_iterator_blocks_left")
938 IMPORT :: c_ptr, c_bool
939 TYPE(c_ptr), VALUE :: iterator
940 LOGICAL(C_BOOL) :: dbm_iterator_blocks_left_c
941 END FUNCTION dbm_iterator_blocks_left_c
942 END INTERFACE
943
944 blocks_left = dbm_iterator_blocks_left_c(iterator%c_ptr)
945 END FUNCTION dbm_iterator_blocks_left
946
947! **************************************************************************************************
948!> \brief Returns the next block from the given iterator.
949!> \param iterator ...
950!> \param row ...
951!> \param column ...
952!> \param block ...
953!> \param row_size ...
954!> \param col_size ...
955!> \author Ole Schuett
956! **************************************************************************************************
957 SUBROUTINE dbm_iterator_next_block(iterator, row, column, block, row_size, col_size)
958 TYPE(dbm_iterator), INTENT(INOUT) :: iterator
959 INTEGER, INTENT(OUT) :: row, column
960 REAL(dp), DIMENSION(:, :), INTENT(OUT), OPTIONAL, &
961 POINTER :: block
962 INTEGER, INTENT(OUT), OPTIONAL :: row_size, col_size
963
964 INTEGER :: col0, my_col_size, my_row_size, row0
965 TYPE(c_ptr) :: block_c
966 INTERFACE
967 SUBROUTINE dbm_iterator_next_block_c(iterator, row, col, block, row_size, col_size) &
968 BIND(C, name="dbm_iterator_next_block")
969 IMPORT :: c_ptr, c_int
970 TYPE(c_ptr), VALUE :: iterator
971 INTEGER(kind=C_INT) :: row
972 INTEGER(kind=C_INT) :: col
973 TYPE(c_ptr) :: block
974 INTEGER(kind=C_INT) :: row_size
975 INTEGER(kind=C_INT) :: col_size
976 END SUBROUTINE dbm_iterator_next_block_c
977 END INTERFACE
978
979 CALL dbm_iterator_next_block_c(iterator%c_ptr, row=row0, col=col0, block=block_c, &
980 row_size=my_row_size, col_size=my_col_size)
981
982 cpassert(c_associated(block_c))
983 IF (PRESENT(block)) CALL c_f_pointer(block_c, block, shape=[my_row_size, my_col_size])
984 row = row0 + 1
985 column = col0 + 1
986 IF (PRESENT(row_size)) row_size = my_row_size
987 IF (PRESENT(col_size)) col_size = my_col_size
988 END SUBROUTINE dbm_iterator_next_block
989
990! **************************************************************************************************
991!> \brief Releases the given iterator.
992!> \param iterator ...
993!> \author Ole Schuett
994! **************************************************************************************************
995 SUBROUTINE dbm_iterator_stop(iterator)
996 TYPE(dbm_iterator), INTENT(INOUT) :: iterator
997
998 INTERFACE
999 SUBROUTINE dbm_iterator_stop_c(iterator) &
1000 BIND(C, name="dbm_iterator_stop")
1001 IMPORT :: c_ptr
1002 TYPE(c_ptr), VALUE :: iterator
1003 END SUBROUTINE dbm_iterator_stop_c
1004 END INTERFACE
1005
1006 CALL dbm_iterator_stop_c(iterator%c_ptr)
1007 iterator%c_ptr = c_null_ptr
1008 END SUBROUTINE dbm_iterator_stop
1009
1010! **************************************************************************************************
1011!> \brief Computes a checksum of the given matrix.
1012!> \param matrix ...
1013!> \return ...
1014!> \author Ole Schuett
1015! **************************************************************************************************
1016 FUNCTION dbm_checksum(matrix) RESULT(res)
1017 TYPE(dbm_type), INTENT(IN) :: matrix
1018 REAL(kind=dp) :: res
1019
1020 INTERFACE
1021 FUNCTION dbm_checksum_c(matrix) &
1022 BIND(C, name="dbm_checksum")
1023 IMPORT :: c_ptr, c_double
1024 TYPE(c_ptr), VALUE :: matrix
1025 REAL(c_double) :: dbm_checksum_c
1026 END FUNCTION dbm_checksum_c
1027 END INTERFACE
1028
1029 CALL validate(matrix)
1030 res = dbm_checksum_c(matrix%c_ptr)
1031
1032#if defined(DBM_VALIDATE_AGAINST_DBCSR)
1033 cpassert(abs(res - dbcsr_checksum(matrix%dbcsr))/max(1.0_dp, abs(res)) < dbm_validate_threshold)
1034#endif
1035 END FUNCTION dbm_checksum
1036
1037! **************************************************************************************************
1038!> \brief Returns the absolute value of the larges element of the entire given matrix.
1039!> \param matrix ...
1040!> \return ...
1041!> \author Ole Schuett
1042! **************************************************************************************************
1043 FUNCTION dbm_maxabs(matrix) RESULT(res)
1044 TYPE(dbm_type), INTENT(INOUT) :: matrix
1045 REAL(kind=dp) :: res
1046
1047 INTERFACE
1048 FUNCTION dbm_maxabs_c(matrix) &
1049 BIND(C, name="dbm_maxabs")
1050 IMPORT :: c_ptr, c_double
1051 TYPE(c_ptr), VALUE :: matrix
1052 REAL(c_double) :: dbm_maxabs_c
1053 END FUNCTION dbm_maxabs_c
1054 END INTERFACE
1055
1056 CALL validate(matrix)
1057 res = dbm_maxabs_c(matrix%c_ptr)
1058
1059#if defined(DBM_VALIDATE_AGAINST_DBCSR)
1060 cpassert(abs(res - dbcsr_maxabs(matrix%dbcsr))/max(1.0_dp, abs(res)) < dbm_validate_threshold)
1061#endif
1062 END FUNCTION dbm_maxabs
1063
1064! **************************************************************************************************
1065!> \brief Returns the name of the matrix of the given matrix.
1066!> \param matrix ...
1067!> \return ...
1068!> \author Ole Schuett
1069! **************************************************************************************************
1070 FUNCTION dbm_get_name(matrix) RESULT(res)
1071 TYPE(dbm_type), INTENT(IN) :: matrix
1072 CHARACTER(len=default_string_length) :: res
1073
1074 CHARACTER(LEN=1, KIND=C_CHAR), DIMENSION(:), &
1075 POINTER :: name_f
1076 INTEGER :: i
1077 TYPE(c_ptr) :: name_c
1078 INTERFACE
1079 FUNCTION dbm_get_name_c(matrix) BIND(C, name="dbm_get_name")
1080 IMPORT :: c_ptr
1081 TYPE(c_ptr), VALUE :: matrix
1082 TYPE(c_ptr) :: dbm_get_name_c
1083 END FUNCTION dbm_get_name_c
1084 END INTERFACE
1085
1086 name_c = dbm_get_name_c(matrix%c_ptr)
1087
1088 CALL c_f_pointer(name_c, name_f, shape=[default_string_length])
1089
1090 res = ""
1091 DO i = 1, default_string_length
1092 IF (name_f(i) == c_null_char) EXIT
1093 res(i:i) = name_f(i)
1094 END DO
1095
1096 END FUNCTION dbm_get_name
1097
1098! **************************************************************************************************
1099!> \brief Returns the number of local Non-Zero Elements of the given matrix.
1100!> \param matrix ...
1101!> \return ...
1102!> \author Ole Schuett
1103! **************************************************************************************************
1104 PURE FUNCTION dbm_get_nze(matrix) RESULT(res)
1105 TYPE(dbm_type), INTENT(IN) :: matrix
1106 INTEGER :: res
1107
1108 INTERFACE
1109 PURE FUNCTION dbm_get_nze_c(matrix) &
1110 BIND(C, name="dbm_get_nze")
1111 IMPORT :: c_ptr, c_int
1112 TYPE(c_ptr), VALUE, INTENT(IN) :: matrix
1113 INTEGER(C_INT) :: dbm_get_nze_c
1114 END FUNCTION dbm_get_nze_c
1115 END INTERFACE
1116
1117 res = dbm_get_nze_c(matrix%c_ptr)
1118
1119 END FUNCTION dbm_get_nze
1120
1121! **************************************************************************************************
1122!> \brief Returns the number of local blocks of the given matrix.
1123!> \param matrix ...
1124!> \return ...
1125!> \author Ole Schuett
1126! **************************************************************************************************
1127 PURE FUNCTION dbm_get_num_blocks(matrix) RESULT(res)
1128 TYPE(dbm_type), INTENT(IN) :: matrix
1129 INTEGER :: res
1130
1131 INTERFACE
1132 PURE FUNCTION dbm_get_num_blocks_c(matrix) &
1133 BIND(C, name="dbm_get_num_blocks")
1134 IMPORT :: c_ptr, c_int
1135 TYPE(c_ptr), VALUE, INTENT(IN) :: matrix
1136 INTEGER(C_INT) :: dbm_get_num_blocks_c
1137 END FUNCTION dbm_get_num_blocks_c
1138 END INTERFACE
1139
1140 res = dbm_get_num_blocks_c(matrix%c_ptr)
1141
1142 END FUNCTION dbm_get_num_blocks
1143
1144! **************************************************************************************************
1145!> \brief Returns the row block sizes of the given matrix.
1146!> \param matrix ...
1147!> \return ...
1148!> \author Ole Schuett
1149! **************************************************************************************************
1150 FUNCTION dbm_get_row_block_sizes(matrix) RESULT(res)
1151 TYPE(dbm_type), INTENT(IN) :: matrix
1152 INTEGER, CONTIGUOUS, DIMENSION(:), POINTER :: res
1153
1154 INTEGER :: nrows
1155 TYPE(c_ptr) :: row_sizes
1156 INTERFACE
1157 SUBROUTINE dbm_get_row_sizes_c(matrix, nrows, row_sizes) &
1158 BIND(C, name="dbm_get_row_sizes")
1159 IMPORT :: c_ptr, c_int
1160 TYPE(c_ptr), VALUE :: matrix
1161 INTEGER(C_INT) :: nrows
1162 TYPE(c_ptr) :: row_sizes
1163 END SUBROUTINE dbm_get_row_sizes_c
1164 END INTERFACE
1165
1166 CALL dbm_get_row_sizes_c(matrix%c_ptr, nrows, row_sizes)
1167 CALL c_f_pointer(row_sizes, res, shape=[nrows])
1168 ! TODO: maybe return an ALLOCATABLE
1169 END FUNCTION dbm_get_row_block_sizes
1170
1171! **************************************************************************************************
1172!> \brief Returns the column block sizes of the given matrix.
1173!> \param matrix ...
1174!> \return ...
1175!> \author Ole Schuett
1176! **************************************************************************************************
1177 FUNCTION dbm_get_col_block_sizes(matrix) RESULT(res)
1178 TYPE(dbm_type), INTENT(IN) :: matrix
1179 INTEGER, CONTIGUOUS, DIMENSION(:), POINTER :: res
1180
1181 INTEGER :: ncols
1182 TYPE(c_ptr) :: col_sizes
1183 INTERFACE
1184 SUBROUTINE dbm_get_col_sizes_c(matrix, ncols, col_sizes) &
1185 BIND(C, name="dbm_get_col_sizes")
1186 IMPORT :: c_ptr, c_int
1187 TYPE(c_ptr), VALUE :: matrix
1188 INTEGER(C_INT) :: ncols
1189 TYPE(c_ptr) :: col_sizes
1190 END SUBROUTINE dbm_get_col_sizes_c
1191 END INTERFACE
1192
1193 CALL dbm_get_col_sizes_c(matrix%c_ptr, ncols, col_sizes)
1194 CALL c_f_pointer(col_sizes, res, shape=[ncols])
1195 ! TODO: maybe return an ALLOCATABLE
1196 END FUNCTION dbm_get_col_block_sizes
1197
1198! **************************************************************************************************
1199!> \brief Returns the local row block sizes of the given matrix.
1200!> \param matrix ...
1201!> \param local_rows ...
1202!> \return ...
1203!> \author Ole Schuett
1204! **************************************************************************************************
1205 SUBROUTINE dbm_get_local_rows(matrix, local_rows)
1206 TYPE(dbm_type), INTENT(IN) :: matrix
1207 INTEGER, ALLOCATABLE, DIMENSION(:) :: local_rows
1208
1209 INTEGER :: nlocal_rows
1210 INTEGER, DIMENSION(:), POINTER :: local_rows_dbcsr, local_rows_ptr
1211 TYPE(c_ptr) :: local_rows_c
1212 INTERFACE
1213 SUBROUTINE dbm_get_local_rows_c(matrix, nlocal_rows, local_rows) &
1214 BIND(C, name="dbm_get_local_rows")
1215 IMPORT :: c_ptr, c_int
1216 TYPE(c_ptr), VALUE :: matrix
1217 INTEGER(C_INT) :: nlocal_rows
1218 TYPE(c_ptr) :: local_rows
1219 END SUBROUTINE dbm_get_local_rows_c
1220 END INTERFACE
1221
1222 CALL dbm_get_local_rows_c(matrix%c_ptr, nlocal_rows, local_rows_c)
1223 CALL c_f_pointer(local_rows_c, local_rows_ptr, shape=[nlocal_rows])
1224 ALLOCATE (local_rows(nlocal_rows))
1225 local_rows(:) = local_rows_ptr(:) + 1
1226
1227#if defined(DBM_VALIDATE_AGAINST_DBCSR)
1228 CALL dbcsr_get_info(matrix%dbcsr, local_rows=local_rows_dbcsr)
1229 cpassert(all(local_rows == local_rows_dbcsr))
1230#else
1231 mark_used(local_rows_dbcsr)
1232#endif
1233 END SUBROUTINE dbm_get_local_rows
1234
1235! **************************************************************************************************
1236!> \brief Returns the local column block sizes of the given matrix.
1237!> \param matrix ...
1238!> \param local_cols ...
1239!> \return ...
1240!> \author Ole Schuett
1241! **************************************************************************************************
1242 SUBROUTINE dbm_get_local_cols(matrix, local_cols)
1243 TYPE(dbm_type), INTENT(IN) :: matrix
1244 INTEGER, ALLOCATABLE, DIMENSION(:) :: local_cols
1245
1246 INTEGER :: nlocal_cols
1247 INTEGER, DIMENSION(:), POINTER :: local_cols_dbcsr, local_cols_ptr
1248 TYPE(c_ptr) :: local_cols_c
1249 INTERFACE
1250 SUBROUTINE dbm_get_local_cols_c(matrix, nlocal_cols, local_cols) &
1251 BIND(C, name="dbm_get_local_cols")
1252 IMPORT :: c_ptr, c_int
1253 TYPE(c_ptr), VALUE :: matrix
1254 INTEGER(C_INT) :: nlocal_cols
1255 TYPE(c_ptr) :: local_cols
1256 END SUBROUTINE dbm_get_local_cols_c
1257 END INTERFACE
1258
1259 CALL dbm_get_local_cols_c(matrix%c_ptr, nlocal_cols, local_cols_c)
1260 CALL c_f_pointer(local_cols_c, local_cols_ptr, shape=[nlocal_cols])
1261 ALLOCATE (local_cols(nlocal_cols))
1262 local_cols(:) = local_cols_ptr(:) + 1
1263
1264#if defined(DBM_VALIDATE_AGAINST_DBCSR)
1265 CALL dbcsr_get_info(matrix%dbcsr, local_cols=local_cols_dbcsr)
1266 cpassert(all(local_cols == local_cols_dbcsr))
1267#else
1268 mark_used(local_cols_dbcsr)
1269#endif
1270 END SUBROUTINE dbm_get_local_cols
1271
1272! **************************************************************************************************
1273!> \brief Returns the MPI rank on which the given block should be stored.
1274!> \param matrix ...
1275!> \param row ...
1276!> \param column ...
1277!> \param processor ...
1278!> \author Ole Schuett
1279! **************************************************************************************************
1280 SUBROUTINE dbm_get_stored_coordinates(matrix, row, column, processor)
1281 TYPE(dbm_type), INTENT(IN) :: matrix
1282 INTEGER, INTENT(IN) :: row, column
1283 INTEGER, INTENT(OUT) :: processor
1284
1285 INTEGER :: processor_dbcsr
1286 INTERFACE
1287 PURE FUNCTION dbm_get_stored_coordinates_c(matrix, row, col) &
1288 BIND(C, name="dbm_get_stored_coordinates")
1289 IMPORT :: c_ptr, c_int
1290 TYPE(c_ptr), VALUE, INTENT(IN) :: matrix
1291 INTEGER(C_INT), VALUE, INTENT(IN) :: row
1292 INTEGER(C_INT), VALUE, INTENT(IN) :: col
1293 INTEGER(C_INT) :: dbm_get_stored_coordinates_c
1294 END FUNCTION dbm_get_stored_coordinates_c
1295 END INTERFACE
1296
1297 processor = dbm_get_stored_coordinates_c(matrix%c_ptr, row=row - 1, col=column - 1)
1298
1299#if defined(DBM_VALIDATE_AGAINST_DBCSR)
1300 CALL dbcsr_get_stored_coordinates(matrix%dbcsr, row, column, processor_dbcsr)
1301 cpassert(processor == processor_dbcsr)
1302#else
1303 mark_used(processor_dbcsr)
1304#endif
1305 END SUBROUTINE dbm_get_stored_coordinates
1306
1307! **************************************************************************************************
1308!> \brief Returns the distribution of the given matrix.
1309!> \param matrix ...
1310!> \return ...
1311!> \author Ole Schuett
1312! **************************************************************************************************
1313 FUNCTION dbm_get_distribution(matrix) RESULT(res)
1314 TYPE(dbm_type), INTENT(IN) :: matrix
1315 TYPE(dbm_distribution_obj) :: res
1316
1317 INTERFACE
1318 FUNCTION dbm_get_distribution_c(matrix) BIND(C, name="dbm_get_distribution")
1319 IMPORT :: c_ptr
1320 TYPE(c_ptr), VALUE :: matrix
1321 TYPE(c_ptr) :: dbm_get_distribution_c
1322 END FUNCTION dbm_get_distribution_c
1323 END INTERFACE
1324
1325 res%c_ptr = dbm_get_distribution_c(matrix%c_ptr)
1326
1327#if defined(DBM_VALIDATE_AGAINST_DBCSR)
1328 CALL dbcsr_get_info(matrix%dbcsr, distribution=res%dbcsr)
1329#endif
1330
1331 END FUNCTION dbm_get_distribution
1332
1333! **************************************************************************************************
1334!> \brief Returns whether two handles refer to the same distribution object.
1335!> \param dist_a ...
1336!> \param dist_b ...
1337!> \return ...
1338! **************************************************************************************************
1339 PURE FUNCTION dbm_distribution_is_same(dist_a, dist_b) RESULT(res)
1340 TYPE(dbm_distribution_obj), INTENT(IN) :: dist_a, dist_b
1341 LOGICAL :: res
1342
1343 res = c_associated(dist_a%c_ptr, dist_b%c_ptr)
1344 END FUNCTION dbm_distribution_is_same
1345
1346! **************************************************************************************************
1347!> \brief Creates a new two dimensional distribution.
1348!> \param dist ...
1349!> \param mp_comm ...
1350!> \param row_dist_block ...
1351!> \param col_dist_block ...
1352!> \author Ole Schuett
1353! **************************************************************************************************
1354 SUBROUTINE dbm_distribution_new(dist, mp_comm, row_dist_block, col_dist_block)
1355 TYPE(dbm_distribution_obj), INTENT(OUT) :: dist
1356
1357 CLASS(mp_comm_type), INTENT(IN) :: mp_comm
1358 INTEGER, CONTIGUOUS, DIMENSION(:), INTENT(IN), &
1359 POINTER :: row_dist_block, col_dist_block
1360
1361 INTERFACE
1362 SUBROUTINE dbm_distribution_new_c(dist, fortran_comm, nrows, ncols, row_dist, col_dist) &
1363 BIND(C, name="dbm_distribution_new")
1364 IMPORT :: c_ptr, c_char, c_int
1365 TYPE(c_ptr) :: dist
1366 INTEGER(kind=C_INT), VALUE :: fortran_comm
1367 INTEGER(kind=C_INT), VALUE :: nrows
1368 INTEGER(kind=C_INT), VALUE :: ncols
1369 INTEGER(kind=C_INT), DIMENSION(*) :: row_dist
1370 INTEGER(kind=C_INT), DIMENSION(*) :: col_dist
1371 END SUBROUTINE dbm_distribution_new_c
1372 END INTERFACE
1373
1374 cpassert(.NOT. c_associated(dist%c_ptr))
1375 CALL dbm_distribution_new_c(dist=dist%c_ptr, &
1376 fortran_comm=mp_comm%get_handle(), &
1377 nrows=SIZE(row_dist_block), &
1378 ncols=SIZE(col_dist_block), &
1379 row_dist=row_dist_block, &
1380 col_dist=col_dist_block)
1381 cpassert(c_associated(dist%c_ptr))
1382
1383#if defined(DBM_VALIDATE_AGAINST_DBCSR)
1384 CALL dbcsr_distribution_new_wrapper(dist, mp_comm, row_dist_block, col_dist_block)
1385#endif
1386 END SUBROUTINE dbm_distribution_new
1387
1388! **************************************************************************************************
1389!> \brief Helper for creating a new DBCSR distribution. Only needed for DBM_VALIDATE_AGAINST_DBCSR.
1390!> \param dist ...
1391!> \param mp_comm ...
1392!> \param row_dist_block ...
1393!> \param col_dist_block ...
1394!> \author Ole Schuett
1395! **************************************************************************************************
1396 SUBROUTINE dbcsr_distribution_new_wrapper(dist, mp_comm, row_dist_block, col_dist_block)
1397 TYPE(dbm_distribution_obj), INTENT(INOUT) :: dist
1398 TYPE(mp_cart_type), INTENT(IN) :: mp_comm
1399 INTEGER, CONTIGUOUS, DIMENSION(:), INTENT(IN), &
1400 POINTER :: row_dist_block, col_dist_block
1401
1402#if defined(DBM_VALIDATE_AGAINST_DBCSR)
1403 INTEGER :: mynode, numnodes, pcol, prow
1404 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: pgrid
1405 INTEGER, DIMENSION(2) :: coord, mycoord, npdims
1406 TYPE(dbcsr_mp_obj) :: mp_env
1407
1408 ! Create a dbcsr mp environment from communicator
1409 CALL mp_comm%get_info_cart(npdims, mycoord)
1410 CALL mp_comm%get_size(numnodes)
1411 CALL mp_comm%get_rank(mynode)
1412 ALLOCATE (pgrid(0:npdims(1) - 1, 0:npdims(2) - 1))
1413 DO prow = 0, npdims(1) - 1
1414 DO pcol = 0, npdims(2) - 1
1415 coord = [prow, pcol]
1416 CALL mp_comm%rank_cart(coord, pgrid(prow, pcol))
1417 END DO
1418 END DO
1419 cpassert(mynode == pgrid(mycoord(1), mycoord(2)))
1420
1421 CALL dbcsr_mp_new(mp_env, mp_comm%get_handle(), pgrid, mynode, numnodes, mycoord(1), mycoord(2))
1422 CALL dbcsr_distribution_new(dist=dist%dbcsr, mp_env=mp_env, &
1423 row_dist_block=row_dist_block, col_dist_block=col_dist_block)
1424 CALL dbcsr_mp_release(mp_env)
1425#else
1426 mark_used(dist)
1427 mark_used(mp_comm)
1428 mark_used(row_dist_block)
1429 mark_used(col_dist_block)
1430#endif
1431 END SUBROUTINE dbcsr_distribution_new_wrapper
1432
1433! **************************************************************************************************
1434!> \brief Increases the reference counter of the given distribution.
1435!> \param dist ...
1436!> \author Ole Schuett
1437! **************************************************************************************************
1438 SUBROUTINE dbm_distribution_hold(dist)
1439 TYPE(dbm_distribution_obj) :: dist
1440
1441 INTERFACE
1442 SUBROUTINE dbm_distribution_hold_c(dist) &
1443 BIND(C, name="dbm_distribution_hold")
1444 IMPORT :: c_ptr
1445 TYPE(c_ptr), VALUE :: dist
1446 END SUBROUTINE dbm_distribution_hold_c
1447 END INTERFACE
1448
1449 CALL dbm_distribution_hold_c(dist%c_ptr)
1450
1451#if defined(DBM_VALIDATE_AGAINST_DBCSR)
1452 CALL dbcsr_distribution_hold(dist%dbcsr)
1453#endif
1454 END SUBROUTINE dbm_distribution_hold
1455
1456! **************************************************************************************************
1457!> \brief Decreases the reference counter of the given distribution.
1458!> \param dist ...
1459!> \author Ole Schuett
1460! **************************************************************************************************
1462 TYPE(dbm_distribution_obj) :: dist
1463
1464 INTERFACE
1465 SUBROUTINE dbm_distribution_release_c(dist) &
1466 BIND(C, name="dbm_distribution_release")
1467 IMPORT :: c_ptr
1468 TYPE(c_ptr), VALUE :: dist
1469 END SUBROUTINE dbm_distribution_release_c
1470 END INTERFACE
1471
1472 CALL dbm_distribution_release_c(dist%c_ptr)
1473
1474#if defined(DBM_VALIDATE_AGAINST_DBCSR)
1475 CALL dbcsr_distribution_release(dist%dbcsr)
1476#endif
1477 END SUBROUTINE dbm_distribution_release
1478
1479! **************************************************************************************************
1480!> \brief Returns the rows of the given distribution.
1481!> \param dist ...
1482!> \return ...
1483!> \author Ole Schuett
1484! **************************************************************************************************
1485 FUNCTION dbm_distribution_row_dist(dist) RESULT(res)
1486 TYPE(dbm_distribution_obj), INTENT(IN) :: dist
1487 INTEGER, CONTIGUOUS, DIMENSION(:), POINTER :: res
1488
1489 INTEGER :: nrows
1490 TYPE(c_ptr) :: row_dist
1491 INTERFACE
1492 SUBROUTINE dbm_distribution_row_dist_c(dist, nrows, row_dist) &
1493 BIND(C, name="dbm_distribution_row_dist")
1494 IMPORT :: c_ptr, c_int
1495 TYPE(c_ptr), VALUE :: dist
1496 INTEGER(C_INT) :: nrows
1497 TYPE(c_ptr) :: row_dist
1498 END SUBROUTINE dbm_distribution_row_dist_c
1499 END INTERFACE
1500
1501 CALL dbm_distribution_row_dist_c(dist%c_ptr, nrows, row_dist)
1502 CALL c_f_pointer(row_dist, res, shape=[nrows])
1503
1504#if defined(DBM_VALIDATE_AGAINST_DBCSR)
1505 cpassert(all(res == dbcsr_distribution_row_dist(dist%dbcsr)))
1506#endif
1507 END FUNCTION dbm_distribution_row_dist
1508
1509! **************************************************************************************************
1510!> \brief Returns the columns of the given distribution.
1511!> \param dist ...
1512!> \return ...
1513!> \author Ole Schuett
1514! **************************************************************************************************
1515 FUNCTION dbm_distribution_col_dist(dist) RESULT(res)
1516 TYPE(dbm_distribution_obj), INTENT(IN) :: dist
1517 INTEGER, CONTIGUOUS, DIMENSION(:), POINTER :: res
1518
1519 INTEGER :: ncols
1520 TYPE(c_ptr) :: col_dist
1521 INTERFACE
1522 SUBROUTINE dbm_distribution_col_dist_c(dist, ncols, col_dist) &
1523 BIND(C, name="dbm_distribution_col_dist")
1524 IMPORT :: c_ptr, c_int
1525 TYPE(c_ptr), VALUE :: dist
1526 INTEGER(C_INT) :: ncols
1527 TYPE(c_ptr) :: col_dist
1528 END SUBROUTINE dbm_distribution_col_dist_c
1529 END INTERFACE
1530
1531 CALL dbm_distribution_col_dist_c(dist%c_ptr, ncols, col_dist)
1532 CALL c_f_pointer(col_dist, res, shape=[ncols])
1533
1534#if defined(DBM_VALIDATE_AGAINST_DBCSR)
1535 cpassert(all(res == dbcsr_distribution_col_dist(dist%dbcsr)))
1536#endif
1537 END FUNCTION dbm_distribution_col_dist
1538
1539! **************************************************************************************************
1540!> \brief Initialize DBM library
1541!> \author Ole Schuett
1542! **************************************************************************************************
1543 SUBROUTINE dbm_library_init()
1544 INTERFACE
1545 SUBROUTINE dbm_library_init_c() BIND(C, name="dbm_library_init")
1546 END SUBROUTINE dbm_library_init_c
1547 END INTERFACE
1548
1549 CALL dbm_library_init_c()
1550
1551 END SUBROUTINE dbm_library_init
1552
1553! **************************************************************************************************
1554!> \brief Finalize DBM library
1555!> \author Ole Schuett
1556! **************************************************************************************************
1558 INTERFACE
1559 SUBROUTINE dbm_library_finalize_c() BIND(C, name="dbm_library_finalize")
1560 END SUBROUTINE dbm_library_finalize_c
1561 END INTERFACE
1562
1563 CALL dbm_library_finalize_c()
1564
1565 END SUBROUTINE dbm_library_finalize
1566
1567! **************************************************************************************************
1568!> \brief Print DBM library statistics
1569!> \param mpi_comm ...
1570!> \param output_unit ...
1571!> \author Ole Schuett
1572! **************************************************************************************************
1573 SUBROUTINE dbm_library_print_stats(mpi_comm, output_unit)
1574 TYPE(mp_comm_type), INTENT(IN) :: mpi_comm
1575 INTEGER, INTENT(IN) :: output_unit
1576
1577 INTERFACE
1578 SUBROUTINE dbm_library_print_stats_c(mpi_comm, print_func, output_unit) &
1579 BIND(C, name="dbm_library_print_stats")
1580 IMPORT :: c_funptr, c_int
1581 INTEGER(KIND=C_INT), VALUE :: mpi_comm
1582 TYPE(c_funptr), VALUE :: print_func
1583 INTEGER(KIND=C_INT), VALUE :: output_unit
1584 END SUBROUTINE dbm_library_print_stats_c
1585 END INTERFACE
1586
1587 ! Since Fortran units groups can't be used from C, we pass a function pointer instead.
1588 CALL dbm_library_print_stats_c(mpi_comm=mpi_comm%get_handle(), &
1589 print_func=c_funloc(print_func), &
1590 output_unit=output_unit)
1591
1592 END SUBROUTINE dbm_library_print_stats
1593
1594! **************************************************************************************************
1595!> \brief Callback to write to a Fortran output unit (called by C-side).
1596!> \param msg to be printed.
1597!> \param msglen number of characters excluding the terminating character.
1598!> \param output_unit used for output.
1599!> \author Ole Schuett and Hans Pabst
1600! **************************************************************************************************
1601 SUBROUTINE print_func(msg, msglen, output_unit) BIND(C, name="dbm_api_print_func")
1602 CHARACTER(KIND=C_CHAR), INTENT(IN) :: msg(*)
1603 INTEGER(KIND=C_INT), INTENT(IN), VALUE :: msglen, output_unit
1604
1605 IF (output_unit <= 0) RETURN ! Omit to print the message.
1606 WRITE (output_unit, fmt="(100A)", advance="NO") msg(1:msglen)
1607 END SUBROUTINE print_func
1608END MODULE dbm_api
subroutine, public dbm_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, retain_sparsity, filter_eps, flop)
Computes matrix product: matrix_c = alpha * matrix_a * matrix_b + beta * matrix_c.
Definition dbm_api.F:784
subroutine, public dbm_redistribute(matrix, redist)
Copies content of matrix_b into matrix_a. Matrices may have different distributions.
Definition dbm_api.F:414
subroutine, public dbm_zero(matrix)
Sets all blocks in the given matrix to zero.
Definition dbm_api.F:710
subroutine, public dbm_clear(matrix)
Remove all blocks from given matrix, but does not release the underlying memory.
Definition dbm_api.F:531
real(kind=dp) function, public dbm_maxabs(matrix)
Returns the absolute value of the larges element of the entire given matrix.
Definition dbm_api.F:1044
subroutine, public dbm_create_from_template(matrix, name, template)
Creates a new matrix from given template, reusing dist and row/col_block_sizes.
Definition dbm_api.F:267
subroutine validate(matrix)
Dummy for when DBM_VALIDATE_AGAINST_DBCSR is not defined.
Definition dbm_api.F:253
pure integer function, public dbm_get_nze(matrix)
Returns the number of local Non-Zero Elements of the given matrix.
Definition dbm_api.F:1105
subroutine, public dbm_get_local_cols(matrix, local_cols)
Returns the local column block sizes of the given matrix.
Definition dbm_api.F:1243
subroutine, public dbm_scale(matrix, alpha)
Multiplies all entries in the given matrix by the given factor alpha.
Definition dbm_api.F:679
subroutine, public dbm_distribution_release(dist)
Decreases the reference counter of the given distribution.
Definition dbm_api.F:1462
subroutine, public dbm_library_init()
Initialize DBM library.
Definition dbm_api.F:1544
subroutine, public dbm_iterator_next_block(iterator, row, column, block, row_size, col_size)
Returns the next block from the given iterator.
Definition dbm_api.F:958
subroutine, public dbm_filter(matrix, eps)
Removes all blocks from the given matrix whose block norm is below the given threshold....
Definition dbm_api.F:557
integer function, public dbm_iterator_num_blocks(iterator)
Returns number of blocks the iterator will provide to calling thread.
Definition dbm_api.F:910
subroutine, public dbm_get_stored_coordinates(matrix, row, column, processor)
Returns the MPI rank on which the given block should be stored.
Definition dbm_api.F:1281
type(dbm_distribution_obj) function, public dbm_get_distribution(matrix)
Returns the distribution of the given matrix.
Definition dbm_api.F:1314
subroutine, public dbm_create(matrix, name, dist, row_block_sizes, col_block_sizes)
Creates a new matrix.
Definition dbm_api.F:295
integer function, dimension(:), pointer, contiguous, public dbm_get_row_block_sizes(matrix)
Returns the row block sizes of the given matrix.
Definition dbm_api.F:1151
logical function, public dbm_iterator_blocks_left(iterator)
Tests whether the given iterator has any block left.
Definition dbm_api.F:932
integer function, dimension(:), pointer, contiguous, public dbm_distribution_col_dist(dist)
Returns the columns of the given distribution.
Definition dbm_api.F:1516
subroutine, public dbm_reserve_blocks(matrix, rows, cols)
Adds given list of blocks efficiently. The blocks will be filled with zeros.
Definition dbm_api.F:591
subroutine, public dbm_library_finalize()
Finalize DBM library.
Definition dbm_api.F:1558
subroutine, public dbm_iterator_stop(iterator)
Releases the given iterator.
Definition dbm_api.F:996
subroutine, public dbm_get_local_rows(matrix, local_rows)
Returns the local row block sizes of the given matrix.
Definition dbm_api.F:1206
subroutine, public dbm_put_block(matrix, row, col, block, summation)
Adds a block to given matrix. This routine is thread-safe. If block already exist then it gets overwr...
Definition dbm_api.F:493
character(len=default_string_length) function, public dbm_get_name(matrix)
Returns the name of the matrix of the given matrix.
Definition dbm_api.F:1071
real(kind=dp) function, public dbm_checksum(matrix)
Computes a checksum of the given matrix.
Definition dbm_api.F:1017
subroutine, public dbm_add(matrix_a, matrix_b)
Adds matrix_b to matrix_a.
Definition dbm_api.F:740
subroutine, public dbm_finalize(matrix)
Needed to be called for DBCSR after blocks where inserted. For DBM it's a no-opt.
Definition dbm_api.F:341
subroutine, public dbm_iterator_start(iterator, matrix)
Creates an iterator for the blocks of the given matrix. The iteration order is not stable.
Definition dbm_api.F:885
pure integer function, public dbm_get_num_blocks(matrix)
Returns the number of local blocks of the given matrix.
Definition dbm_api.F:1128
subroutine, public dbm_library_print_stats(mpi_comm, output_unit)
Print DBM library statistics.
Definition dbm_api.F:1574
subroutine, public dbm_copy(matrix_a, matrix_b)
Copies content of matrix_b into matrix_a. Matrices must have the same row/col block sizes and distrib...
Definition dbm_api.F:382
subroutine, public dbm_distribution_hold(dist)
Increases the reference counter of the given distribution.
Definition dbm_api.F:1439
subroutine, public dbm_reserve_blocks_template(matrix, template)
Reserves template blocks in a matrix sharing the distribution object. Block sizes may differ....
Definition dbm_api.F:634
subroutine, public dbm_release(matrix)
Releases a matrix and all its ressources.
Definition dbm_api.F:356
integer function, dimension(:), pointer, contiguous, public dbm_get_col_block_sizes(matrix)
Returns the column block sizes of the given matrix.
Definition dbm_api.F:1178
pure logical function, public dbm_distribution_is_same(dist_a, dist_b)
Returns whether two handles refer to the same distribution object.
Definition dbm_api.F:1340
integer function, dimension(:), pointer, contiguous, public dbm_distribution_row_dist(dist)
Returns the rows of the given distribution.
Definition dbm_api.F:1486
subroutine, public dbm_distribution_new(dist, mp_comm, row_dist_block, col_dist_block)
Creates a new two dimensional distribution.
Definition dbm_api.F:1355
subroutine, public dbm_get_block_p(matrix, row, col, block, row_size, col_size)
Looks up a block from given matrics. This routine is thread-safe. If the block is not found then a nu...
Definition dbm_api.F:451
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public int_8
Definition kinds.F:54
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
Interface to the message passing library MPI.