29 #include "../base/base_uses.f90"
34 LOGICAL,
PRIVATE,
PARAMETER :: debug_this_module = .true.
35 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'cp_fm_pool_types'
37 PUBLIC :: cp_fm_pool_type, cp_fm_pool_p_type
43 fm_pools_create_fm_vect, &
44 fm_pools_give_back_fm_vect
58 INTEGER :: ref_count = -1
59 TYPE(cp_fm_struct_type),
POINTER :: el_struct => null()
60 TYPE(cp_sll_fm_type),
POINTER :: cache => null()
61 END TYPE cp_fm_pool_type
70 TYPE cp_fm_pool_p_type
71 TYPE(cp_fm_pool_type),
POINTER :: pool => null()
72 END TYPE cp_fm_pool_p_type
74 INTERFACE fm_pools_create_fm_vect
75 MODULE PROCEDURE fm_pools_create_fm_m1_p_type_pointer
76 MODULE PROCEDURE fm_pools_create_fm_m1_p_type_alloc
77 MODULE PROCEDURE fm_pools_create_fm_m1_array_pointer
78 MODULE PROCEDURE fm_pools_create_fm_m1_array_alloc
81 INTERFACE fm_pools_give_back_fm_vect
82 MODULE PROCEDURE fm_pools_give_back_fm_m1_p_type_pointer
83 MODULE PROCEDURE fm_pools_give_back_fm_m1_p_type_alloc
84 MODULE PROCEDURE fm_pools_give_back_fm_m1_array_pointer
85 MODULE PROCEDURE fm_pools_give_back_fm_m1_array_alloc
100 TYPE(cp_fm_pool_type),
POINTER :: pool
101 TYPE(cp_fm_struct_type),
TARGET :: el_struct
104 pool%el_struct => el_struct
118 TYPE(cp_fm_pool_type),
INTENT(INOUT) :: pool
120 cpassert(pool%ref_count > 0)
122 pool%ref_count = pool%ref_count + 1
132 SUBROUTINE fm_pool_flush_cache(pool)
133 TYPE(cp_fm_pool_type),
INTENT(IN) :: pool
135 TYPE(cp_fm_type),
POINTER :: el_att
136 TYPE(cp_sll_fm_type),
POINTER :: iterator
138 iterator => pool%cache
141 CALL cp_fm_release(el_att)
146 END SUBROUTINE fm_pool_flush_cache
156 TYPE(cp_fm_pool_type),
POINTER :: pool
158 IF (
ASSOCIATED(pool))
THEN
159 cpassert(pool%ref_count > 0)
160 pool%ref_count = pool%ref_count - 1
161 IF (pool%ref_count == 0)
THEN
163 CALL fm_pool_flush_cache(pool)
185 TYPE(cp_fm_pool_type),
INTENT(IN) :: pool
186 TYPE(cp_fm_type),
INTENT(OUT) :: element
187 CHARACTER(len=*),
INTENT(in),
OPTIONAL :: name
189 TYPE(cp_fm_type),
POINTER :: el
192 IF (
ASSOCIATED(pool%cache))
THEN
196 IF (
ASSOCIATED(el))
THEN
200 CALL cp_fm_create(element, matrix_struct=pool%el_struct)
203 IF (
PRESENT(name))
THEN
224 TYPE(cp_fm_pool_type),
INTENT(IN) :: pool
225 TYPE(cp_fm_type),
INTENT(INOUT) :: element
227 IF (.NOT.
ASSOCIATED(pool%el_struct, element%matrix_struct))
THEN
228 CALL cp_fm_release(element)
231 TYPE(cp_fm_type),
POINTER :: el
235 NULLIFY (element%matrix_struct, element%local_data, element%local_data_sp)
249 TYPE(cp_fm_pool_type),
INTENT(IN) :: pool
250 TYPE(cp_fm_struct_type),
POINTER :: res
252 res => pool%el_struct
265 SUBROUTINE fm_pools_copy(source_pools, target_pools)
266 TYPE(cp_fm_pool_p_type),
DIMENSION(:),
POINTER :: source_pools, target_pools
270 cpassert(
ASSOCIATED(source_pools))
271 ALLOCATE (target_pools(
SIZE(source_pools)))
272 DO i = 1,
SIZE(source_pools)
273 target_pools(i)%pool => source_pools(i)%pool
276 END SUBROUTINE fm_pools_copy
286 TYPE(cp_fm_pool_p_type),
DIMENSION(:),
POINTER :: pools
290 IF (
ASSOCIATED(pools))
THEN
291 DO i = 1,
SIZE(pools)
308 SUBROUTINE fm_pools_create_fm_m1_array_alloc (pools, elements, &
310 TYPE(cp_fm_pool_p_type),
DIMENSION(:),
INTENT(IN) :: pools
311 TYPE(cp_fm_type),
DIMENSION(:),
ALLOCATABLE :: elements
312 CHARACTER(len=*),
INTENT(in),
OPTIONAL :: name
315 TYPE(cp_fm_pool_type),
POINTER :: pool
319 ALLOCATE (elements(
SIZE(pools)))
320 DO i = 1,
SIZE(pools)
321 pool => pools(i)%pool
322 IF (
PRESENT(name))
THEN
324 name=name//
"-"//adjustl(cp_to_string(i)))
331 END SUBROUTINE fm_pools_create_fm_m1_array_alloc
344 SUBROUTINE fm_pools_give_back_fm_m1_array_alloc (pools, elements)
345 TYPE(cp_fm_pool_p_type),
DIMENSION(:),
INTENT(IN) :: pools
346 TYPE(cp_fm_type),
DIMENSION(:),
ALLOCATABLE :: elements
350 IF (
ALLOCATED (elements))
THEN
351 cpassert(
SIZE(pools) ==
SIZE(elements))
352 DO i = 1,
SIZE(pools)
356 DEALLOCATE (elements)
358 END SUBROUTINE fm_pools_give_back_fm_m1_array_alloc
368 SUBROUTINE fm_pools_create_fm_m1_array_pointer (pools, elements, &
370 TYPE(cp_fm_pool_p_type),
DIMENSION(:),
INTENT(IN) :: pools
371 TYPE(cp_fm_type),
DIMENSION(:),
POINTER :: elements
372 CHARACTER(len=*),
INTENT(in),
OPTIONAL :: name
375 TYPE(cp_fm_pool_type),
POINTER :: pool
379 ALLOCATE (elements(
SIZE(pools)))
380 DO i = 1,
SIZE(pools)
381 pool => pools(i)%pool
382 IF (
PRESENT(name))
THEN
384 name=name//
"-"//adjustl(cp_to_string(i)))
391 END SUBROUTINE fm_pools_create_fm_m1_array_pointer
404 SUBROUTINE fm_pools_give_back_fm_m1_array_pointer (pools, elements)
405 TYPE(cp_fm_pool_p_type),
DIMENSION(:),
INTENT(IN) :: pools
406 TYPE(cp_fm_type),
DIMENSION(:),
POINTER :: elements
410 IF (
ASSOCIATED (elements))
THEN
411 cpassert(
SIZE(pools) ==
SIZE(elements))
412 DO i = 1,
SIZE(pools)
416 DEALLOCATE (elements)
419 END SUBROUTINE fm_pools_give_back_fm_m1_array_pointer
429 SUBROUTINE fm_pools_create_fm_m1_p_type_alloc (pools, elements, &
431 TYPE(cp_fm_pool_p_type),
DIMENSION(:),
INTENT(IN) :: pools
432 TYPE(cp_fm_p_type),
DIMENSION(:),
ALLOCATABLE :: elements
433 CHARACTER(len=*),
INTENT(in),
OPTIONAL :: name
436 TYPE(cp_fm_pool_type),
POINTER :: pool
440 ALLOCATE (elements(
SIZE(pools)))
441 DO i = 1,
SIZE(pools)
442 pool => pools(i)%pool
443 ALLOCATE (elements(i)%matrix)
444 IF (
PRESENT(name))
THEN
446 name=name//
"-"//adjustl(cp_to_string(i)))
453 END SUBROUTINE fm_pools_create_fm_m1_p_type_alloc
466 SUBROUTINE fm_pools_give_back_fm_m1_p_type_alloc (pools, elements)
467 TYPE(cp_fm_pool_p_type),
DIMENSION(:),
INTENT(IN) :: pools
468 TYPE(cp_fm_p_type),
DIMENSION(:),
ALLOCATABLE :: elements
472 IF (
ALLOCATED (elements))
THEN
473 cpassert(
SIZE(pools) ==
SIZE(elements))
474 DO i = 1,
SIZE(pools)
477 DEALLOCATE (elements(i)%matrix)
479 DEALLOCATE (elements)
481 END SUBROUTINE fm_pools_give_back_fm_m1_p_type_alloc
491 SUBROUTINE fm_pools_create_fm_m1_p_type_pointer (pools, elements, &
493 TYPE(cp_fm_pool_p_type),
DIMENSION(:),
INTENT(IN) :: pools
494 TYPE(cp_fm_p_type),
DIMENSION(:),
POINTER :: elements
495 CHARACTER(len=*),
INTENT(in),
OPTIONAL :: name
498 TYPE(cp_fm_pool_type),
POINTER :: pool
502 ALLOCATE (elements(
SIZE(pools)))
503 DO i = 1,
SIZE(pools)
504 pool => pools(i)%pool
505 ALLOCATE (elements(i)%matrix)
506 IF (
PRESENT(name))
THEN
508 name=name//
"-"//adjustl(cp_to_string(i)))
515 END SUBROUTINE fm_pools_create_fm_m1_p_type_pointer
528 SUBROUTINE fm_pools_give_back_fm_m1_p_type_pointer (pools, elements)
529 TYPE(cp_fm_pool_p_type),
DIMENSION(:),
INTENT(IN) :: pools
530 TYPE(cp_fm_p_type),
DIMENSION(:),
POINTER :: elements
534 IF (
ASSOCIATED (elements))
THEN
535 cpassert(
SIZE(pools) ==
SIZE(elements))
536 DO i = 1,
SIZE(pools)
539 DEALLOCATE (elements(i)%matrix)
541 DEALLOCATE (elements)
544 END SUBROUTINE fm_pools_give_back_fm_m1_p_type_pointer
pool for for elements that are retained and released
subroutine, public fm_pool_create_fm(pool, element, name)
returns an element, allocating it if none is in the pool
subroutine, public fm_pool_create(pool, el_struct)
creates a pool of elements
subroutine, public fm_pool_release(pool)
releases the given pool (see cp2k/doc/ReferenceCounting.html)
subroutine, public fm_pool_give_back_fm(pool, element)
returns the element to the pool
subroutine, public fm_pool_retain(pool)
retains the pool (see cp2k/doc/ReferenceCounting.html)
subroutine, public fm_pools_dealloc(pools)
deallocate an array of pools (releasing each pool)
type(cp_fm_struct_type) function, pointer, public fm_pool_get_el_struct(pool)
returns the structure of the elements in this pool
represent the structure of a full matrix
subroutine, public cp_fm_struct_retain(fmstruct)
retains a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
subroutine, public cp_sll_fm_insert_el(sll, el)
insert an element at the beginning of the list
logical function, public cp_sll_fm_next(iterator, el_att)
returns true if the actual element is valid (i.e. iterator ont at end) moves the iterator to the next...
type(cp_fm_type) function, pointer, public cp_sll_fm_get_first_el(sll)
returns the first element stored in the list
subroutine, public cp_sll_fm_dealloc(sll)
deallocates the singly linked list starting at sll. Does not work if loops are present!
subroutine, public cp_sll_fm_rm_first_el(sll)
remove the first element of the linked list
various routines to log and control the output. The idea is that decisions about where to log should ...