Line data Source code
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: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief Type to store integrals for semi-empirical calculations
10 : !> \author Teodoro Laino [tlaino] - University of Zurich
11 : !> \date 05.2008
12 : ! **************************************************************************************************
13 : MODULE semi_empirical_store_int_types
14 :
15 : USE hfx_compression_methods, ONLY: hfx_decompress_first_cache,&
16 : hfx_flush_last_cache,&
17 : hfx_reset_cache_and_container
18 : USE hfx_types, ONLY: hfx_cache_type,&
19 : hfx_container_type,&
20 : hfx_init_container,&
21 : hfx_memory_type,&
22 : parse_memory_section
23 : USE input_section_types, ONLY: section_vals_get_subs_vals,&
24 : section_vals_type,&
25 : section_vals_val_get
26 : USE kinds, ONLY: dp
27 : USE memory_utilities, ONLY: reallocate
28 : #include "./base/base_uses.f90"
29 :
30 : IMPLICIT NONE
31 :
32 : PRIVATE
33 :
34 : ! *** Global parameters ***
35 :
36 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'semi_empirical_store_int_types'
37 :
38 : ! **************************************************************************************************
39 : !> \brief Semi-empirical store integrals type
40 : !> \author Teodoro Laino [tlaino] - University of Zurich
41 : !> \date 05.2008
42 : ! **************************************************************************************************
43 : TYPE semi_empirical_si_type
44 : LOGICAL :: filling_containers = .FALSE., compress = .FALSE.
45 : INTEGER :: nbuffer = -1
46 : REAL(KIND=dp), POINTER, DIMENSION(:) :: max_val_buffer => NULL(), uncompressed_container => NULL()
47 : TYPE(hfx_memory_type) :: memory_parameter = hfx_memory_type()
48 : TYPE(hfx_cache_type), DIMENSION(:), &
49 : POINTER :: integral_caches => NULL()
50 : TYPE(hfx_container_type), DIMENSION(:), &
51 : POINTER :: integral_containers => NULL()
52 : END TYPE semi_empirical_si_type
53 :
54 : PUBLIC :: semi_empirical_si_type, &
55 : semi_empirical_si_create, &
56 : semi_empirical_si_release, &
57 : semi_empirical_si_finalize, &
58 : semi_empirical_si_initialize
59 :
60 : CONTAINS
61 :
62 : ! **************************************************************************************************
63 : !> \brief Allocate semi-empirical store integrals type
64 : !> \param store_int_env ...
65 : !> \param se_section ...
66 : !> \param compression ...
67 : !> \date 05.2008
68 : !> \author Teodoro Laino [tlaino] - University of Zurich
69 : ! **************************************************************************************************
70 1000 : SUBROUTINE semi_empirical_si_create(store_int_env, se_section, compression)
71 : TYPE(semi_empirical_si_type), POINTER :: store_int_env
72 : TYPE(section_vals_type), POINTER :: se_section
73 : LOGICAL, INTENT(in), OPTIONAL :: compression
74 :
75 : INTEGER :: i
76 : TYPE(section_vals_type), POINTER :: se_mem_section
77 :
78 1000 : CPASSERT(.NOT. ASSOCIATED(store_int_env))
79 1000 : ALLOCATE (store_int_env)
80 1000 : store_int_env%filling_containers = .TRUE.
81 1000 : store_int_env%nbuffer = 0
82 : NULLIFY (store_int_env%max_val_buffer, store_int_env%uncompressed_container)
83 :
84 : ! Memory section
85 1000 : se_mem_section => section_vals_get_subs_vals(se_section, "MEMORY")
86 1000 : IF (PRESENT(compression)) THEN
87 0 : store_int_env%compress = compression
88 : ELSE
89 1000 : CALL section_vals_val_get(se_mem_section, "COMPRESS", l_val=store_int_env%compress)
90 : END IF
91 : CALL parse_memory_section(store_int_env%memory_parameter, se_mem_section, skip_disk=.TRUE., &
92 1000 : skip_in_core_forces=.TRUE.)
93 1000 : store_int_env%memory_parameter%ram_counter = 0
94 : ! If we don't compress there's no cache
95 1000 : IF (.NOT. store_int_env%compress) THEN
96 996 : store_int_env%memory_parameter%cache_size = 1
97 : END IF
98 :
99 : ! Disk Storage disabled for semi-empirical methods
100 1000 : IF (store_int_env%memory_parameter%do_disk_storage) THEN
101 0 : CPABORT("Disk storage for SEMIEMPIRICAL methods disabled! ")
102 : END IF
103 :
104 : ! Allocate containers/caches for integral storage if requested
105 1000 : IF (.NOT. store_int_env%memory_parameter%do_all_on_the_fly .AND. store_int_env%compress) THEN
106 260 : ALLOCATE (store_int_env%integral_containers(64))
107 4356 : ALLOCATE (store_int_env%integral_caches(64))
108 260 : DO i = 1, 64
109 256 : store_int_env%integral_caches(i)%element_counter = 1
110 262400 : store_int_env%integral_caches(i)%data = 0
111 262656 : ALLOCATE (store_int_env%integral_containers(i)%first)
112 256 : store_int_env%integral_containers(i)%first%prev => NULL()
113 256 : store_int_env%integral_containers(i)%first%next => NULL()
114 256 : store_int_env%integral_containers(i)%current => store_int_env%integral_containers(i)%first
115 262400 : store_int_env%integral_containers(i)%current%data = 0
116 260 : store_int_env%integral_containers(i)%element_counter = 1
117 : END DO
118 : END IF
119 1000 : END SUBROUTINE semi_empirical_si_create
120 :
121 : ! **************************************************************************************************
122 : !> \brief Deallocate the semi-empirical store integrals type
123 : !> \param store_int_env ...
124 : !> \date 05.2008
125 : !> \author Teodoro Laino [tlaino] - University of Zurich
126 : ! **************************************************************************************************
127 2000 : SUBROUTINE semi_empirical_si_release(store_int_env)
128 : TYPE(semi_empirical_si_type), POINTER :: store_int_env
129 :
130 : INTEGER :: i
131 :
132 2000 : IF (ASSOCIATED(store_int_env)) THEN
133 : ! Deallocate containers/caches
134 1000 : IF (.NOT. store_int_env%memory_parameter%do_all_on_the_fly) THEN
135 1000 : IF (store_int_env%compress) THEN
136 : ! Deallocate containers/caches
137 260 : DO i = 1, 64
138 : CALL hfx_init_container(store_int_env%integral_containers(i), &
139 : store_int_env%memory_parameter%actual_memory_usage, &
140 256 : .FALSE.)
141 260 : DEALLOCATE (store_int_env%integral_containers(i)%first)
142 : END DO
143 4 : IF (ASSOCIATED(store_int_env%max_val_buffer)) THEN
144 4 : DEALLOCATE (store_int_env%max_val_buffer)
145 : END IF
146 4 : DEALLOCATE (store_int_env%integral_containers)
147 4 : DEALLOCATE (store_int_env%integral_caches)
148 : ELSE
149 996 : IF (ASSOCIATED(store_int_env%uncompressed_container)) THEN
150 348 : DEALLOCATE (store_int_env%uncompressed_container)
151 : END IF
152 : END IF
153 : END IF
154 : ! Deallocate the full store_int_env
155 1000 : DEALLOCATE (store_int_env)
156 : END IF
157 :
158 2000 : END SUBROUTINE semi_empirical_si_release
159 :
160 : ! **************************************************************************************************
161 : !> \brief Deallocate the semi-empirical store integrals type
162 : !> \param store_int_env ...
163 : !> \param geometry_did_change ...
164 : !> \date 05.2008
165 : !> \author Teodoro Laino [tlaino] - University of Zurich
166 : ! **************************************************************************************************
167 41348 : SUBROUTINE semi_empirical_si_initialize(store_int_env, geometry_did_change)
168 : TYPE(semi_empirical_si_type), POINTER :: store_int_env
169 : LOGICAL, INTENT(IN) :: geometry_did_change
170 :
171 : INTEGER :: i
172 :
173 41348 : IF (ASSOCIATED(store_int_env)) THEN
174 41348 : IF (.NOT. store_int_env%memory_parameter%do_all_on_the_fly) THEN
175 41348 : IF (geometry_did_change) THEN
176 3716 : store_int_env%filling_containers = .TRUE.
177 3716 : store_int_env%nbuffer = 0
178 3716 : store_int_env%memory_parameter%ram_counter = HUGE(store_int_env%memory_parameter%ram_counter)
179 3716 : IF (store_int_env%compress) THEN
180 : ! Compress integrals
181 6 : CALL reallocate(store_int_env%max_val_buffer, 1, store_int_env%nbuffer)
182 : ! Clean containers
183 390 : DO i = 1, 64
184 : CALL hfx_init_container(store_int_env%integral_containers(i), &
185 : store_int_env%memory_parameter%actual_memory_usage, &
186 390 : .FALSE.)
187 : END DO
188 : ELSE
189 : ! Skip compression
190 3710 : CALL reallocate(store_int_env%uncompressed_container, 1, 0)
191 3710 : store_int_env%memory_parameter%actual_memory_usage = 1
192 : END IF
193 : ELSE
194 37632 : store_int_env%filling_containers = .FALSE.
195 37632 : store_int_env%nbuffer = 0
196 37632 : IF (store_int_env%compress) THEN
197 : ! Retrieve data into the cache
198 8710 : DO i = 1, 64
199 : CALL hfx_decompress_first_cache(i, store_int_env%integral_caches(i), &
200 : store_int_env%integral_containers(i), &
201 8710 : store_int_env%memory_parameter%actual_memory_usage, .FALSE.)
202 : END DO
203 : ELSE
204 37498 : store_int_env%memory_parameter%actual_memory_usage = 1
205 : END IF
206 : END IF
207 : END IF
208 : END IF
209 :
210 41348 : END SUBROUTINE semi_empirical_si_initialize
211 :
212 : ! **************************************************************************************************
213 : !> \brief Deallocate the semi-empirical store integrals type
214 : !> \param store_int_env ...
215 : !> \param geometry_did_change ...
216 : !> \date 05.2008
217 : !> \author Teodoro Laino [tlaino] - University of Zurich
218 : ! **************************************************************************************************
219 41348 : SUBROUTINE semi_empirical_si_finalize(store_int_env, geometry_did_change)
220 : TYPE(semi_empirical_si_type), POINTER :: store_int_env
221 : LOGICAL, INTENT(IN) :: geometry_did_change
222 :
223 : INTEGER :: i
224 :
225 41348 : IF (ASSOCIATED(store_int_env)) THEN
226 41348 : IF (.NOT. store_int_env%memory_parameter%do_all_on_the_fly) THEN
227 41348 : IF (geometry_did_change) THEN
228 3716 : IF (store_int_env%compress) THEN
229 : ! Flush last cache
230 390 : DO i = 1, 64
231 : CALL hfx_flush_last_cache(i, store_int_env%integral_caches(i), &
232 : store_int_env%integral_containers(i), &
233 390 : store_int_env%memory_parameter%actual_memory_usage, .FALSE.)
234 : END DO
235 : ! Reallocate this array with the proper size
236 6 : CALL reallocate(store_int_env%max_val_buffer, 1, store_int_env%nbuffer)
237 : ELSE
238 : ! Skip compression
239 : CALL reallocate(store_int_env%uncompressed_container, 1, &
240 3710 : store_int_env%memory_parameter%actual_memory_usage - 1)
241 : END IF
242 : END IF
243 41348 : IF (store_int_env%compress) THEN
244 : ! Reset caches and containers
245 9100 : DO i = 1, 64
246 : CALL hfx_reset_cache_and_container( &
247 : store_int_env%integral_caches(i), &
248 : store_int_env%integral_containers(i), store_int_env%memory_parameter%actual_memory_usage, &
249 9100 : .FALSE.)
250 : END DO
251 : END IF
252 : END IF
253 : END IF
254 :
255 41348 : END SUBROUTINE semi_empirical_si_finalize
256 :
257 0 : END MODULE semi_empirical_store_int_types
|