Branch data Line data Source code
1 : : !!****m* ABINIT/m_gwls_TimingLog
2 : : !! NAME
3 : : !! m_gwls_TimingLog
4 : : !!
5 : : !! FUNCTION
6 : : !! .
7 : : !!
8 : : !! COPYRIGHT
9 : : !! Copyright (C) 2009-2026 ABINIT group (JLJ, BR, MC)
10 : : !! This file is distributed under the terms of the
11 : : !! GNU General Public License, see ~abinit/COPYING
12 : : !! or http://www.gnu.org/copyleft/gpl.txt .
13 : : !!
14 : : !! SOURCE
15 : :
16 : : #if defined HAVE_CONFIG_H
17 : : #include "config.h"
18 : : #endif
19 : :
20 : : #include "abi_common.h"
21 : :
22 : :
23 : : module m_gwls_TimingLog
24 : : !----------------------------------------------------------------------------------------------------
25 : : ! This module will control the opening, writing and closing of a log file which will contain
26 : : ! timing information. By making this a module, which can be called from anywhere, existing
27 : : ! routines can easily write to this log without modifying their arguments.
28 : : !----------------------------------------------------------------------------------------------------
29 : : ! local modules
30 : : use m_gwls_utility
31 : :
32 : : ! Abinit modules
33 : : use m_abicore
34 : : use defs_basis
35 : :
36 : : use m_io_tools, only : get_unit
37 : :
38 : : implicit none
39 : : private
40 : : !!***
41 : :
42 : : ! Global quantities
43 : : integer, public :: io_unit_timing_log
44 : :
45 : : character(128) :: timing_log_filename = "Timing_Log.dat"
46 : :
47 : : logical :: head_node_timing
48 : : !!***
49 : :
50 : : public :: close_timing_log, setup_timing_log
51 : : public :: write_block_lanczos_timing_log
52 : : public :: write_text_block_in_Timing_log
53 : : public :: write_timing_log
54 : : !!***
55 : :
56 : : contains
57 : :
58 : :
59 : : !!****f* m_hamiltonian/setup_timing_log
60 : : !! NAME
61 : : !! setup_timing_log
62 : : !!
63 : : !! FUNCTION
64 : : !! .
65 : : !!
66 : : !! INPUTS
67 : : !!
68 : : !! OUTPUT
69 : : !!
70 : : !! SOURCE
71 : :
72 : 181 : subroutine setup_timing_log()
73 : : !--------------------------------------------------------------------------------
74 : : ! This routine opens the timing log file.
75 : : !--------------------------------------------------------------------------------
76 : : use m_gwls_hamiltonian, only: mpi_enreg
77 : :
78 : :
79 : : logical :: file_exists
80 : : integer :: i
81 : :
82 : : ! *************************************************************************
83 : :
84 : :
85 : 8 : head_node_timing = (mpi_enreg%me == 0)
86 : :
87 : :
88 [ + + ]: 8 : if (head_node_timing) then
89 : 5 : inquire(file=timing_log_filename,exist=file_exists)
90 : :
91 : 5 : i = 0
92 [ + + ]: 11 : do while (file_exists)
93 : 6 : i = i+1
94 : 6 : write (timing_log_filename,'(A,I0,A)') "Timing_Log_",i,".dat"
95 : 11 : inquire(file=timing_log_filename,exist=file_exists)
96 : : end do
97 : :
98 : :
99 : 5 : io_unit_timing_log = get_unit()
100 : 5 : open(io_unit_timing_log,file=timing_log_filename,status=files_status_new)
101 : 5 : write(io_unit_timing_log,10) ''
102 : 5 : write(io_unit_timing_log,10) '#============================================================================================'
103 : 5 : write(io_unit_timing_log,10) '# This file contains timing information for various routines from gw_sternheimer.'
104 : 5 : write(io_unit_timing_log,10) '# The purpose of this information is to establish which parts of the computation'
105 : 5 : write(io_unit_timing_log,10) '# are time consuming.'
106 : 5 : write(io_unit_timing_log,10) '#============================================================================================'
107 : 5 : write(io_unit_timing_log,10) '# computation time (seconds) '
108 : 5 : write(io_unit_timing_log,10) '#============================================================================================'
109 : 5 : write(io_unit_timing_log,10) '#'
110 : 5 : flush(io_unit_timing_log)
111 : : end if
112 : :
113 : : 10 format(A)
114 : :
115 : :
116 : 8 : end subroutine setup_timing_log
117 : : !!***
118 : :
119 : : !!****f* m_hamiltonian/close_timing_log
120 : : !! NAME
121 : : !! close_timing_log
122 : : !!
123 : : !! FUNCTION
124 : : !! .
125 : : !!
126 : : !! INPUTS
127 : : !!
128 : : !! OUTPUT
129 : : !!
130 : : !! SOURCE
131 : :
132 : 8 : subroutine close_timing_log()
133 : : !--------------------------------------------------------------------------------
134 : : ! This routine closes the timing log file.
135 : : !--------------------------------------------------------------------------------
136 : : ! *************************************************************************
137 : :
138 [ + + ]: 8 : if (head_node_timing) close(io_unit_timing_log)
139 : :
140 : 8 : end subroutine close_timing_log
141 : : !!***
142 : :
143 : : !!****f* m_hamiltonian/write_text_block_in_Timing_log
144 : : !! NAME
145 : : !! write_text_block_in_Timing_log
146 : : !!
147 : : !! FUNCTION
148 : : !! .
149 : : !!
150 : : !! INPUTS
151 : : !!
152 : : !! OUTPUT
153 : : !!
154 : : !! SOURCE
155 : :
156 : 95 : subroutine write_text_block_in_Timing_log(string)
157 : : !--------------------------------------------------------------------------------
158 : : ! This routine opens the timing log file.
159 : : !--------------------------------------------------------------------------------
160 : :
161 : : character(256):: string
162 : : ! *************************************************************************
163 : :
164 [ + + ]: 95 : if (head_node_timing) then
165 : 53 : write(io_unit_timing_log,10) trim(string)
166 : 53 : flush(io_unit_timing_log)
167 : : end if
168 : :
169 : : 10 format(A)
170 : :
171 : 95 : end subroutine write_text_block_in_Timing_log
172 : : !!***
173 : :
174 : : !!****f* m_hamiltonian/write_timing_log
175 : : !! NAME
176 : : !! write_timing_log
177 : : !!
178 : : !! FUNCTION
179 : : !! .
180 : : !!
181 : : !! INPUTS
182 : : !!
183 : : !! OUTPUT
184 : : !!
185 : : !! SOURCE
186 : :
187 : 162 : subroutine write_timing_log(string,time)
188 : : !--------------------------------------------------------------------------------
189 : : ! This routine opens the timing log file.
190 : : !--------------------------------------------------------------------------------
191 : :
192 : : character(256):: string
193 : : real(dp) :: time
194 : : ! *************************************************************************
195 : :
196 [ + + ]: 162 : if (head_node_timing) then
197 : 90 : write(io_unit_timing_log,20) trim(string),time
198 : 90 : flush(io_unit_timing_log)
199 : : end if
200 : :
201 : :
202 : : 20 format(A,ES12.4)
203 : :
204 : 162 : end subroutine write_timing_log
205 : : !!***
206 : :
207 : :
208 : :
209 : : !!****f* m_hamiltonian/write_block_lanczos_timing_log
210 : : !! NAME
211 : : !! write_block_lanczos_timing_log
212 : : !!
213 : : !! FUNCTION
214 : : !! .
215 : : !!
216 : : !! INPUTS
217 : : !!
218 : : !! OUTPUT
219 : : !!
220 : : !! SOURCE
221 : :
222 : 173 : subroutine write_block_lanczos_timing_log(list_time,ntime)
223 : : !--------------------------------------------------------------------------------
224 : : ! This routine writes the timing for the block lanczos routine.
225 : : !--------------------------------------------------------------------------------
226 : : use m_gwls_hamiltonian, only: mpi_enreg
227 : :
228 : :
229 : : integer , intent(in) :: ntime
230 : : real(dp), intent(in) :: list_time(ntime)
231 : :
232 : : logical :: file_exists
233 : :
234 : : integer, save :: icounter = 0
235 : :
236 : : integer :: io_unit
237 : :
238 : : character(128) :: block_lanczos_log_filename = "block_lanczos_timing.log"
239 : :
240 : : logical :: head_node
241 : :
242 : : ! *************************************************************************
243 : :
244 : 173 : head_node = (mpi_enreg%me == 0)
245 [ + + ]: 173 : if (head_node) then
246 : :
247 : 113 : inquire(file=block_lanczos_log_filename,exist=file_exists)
248 : :
249 : 113 : io_unit = get_unit()
250 : :
251 [ + + ]: 113 : if (.not. file_exists) then
252 : 2 : open(io_unit,file=block_lanczos_log_filename,status=files_status_new)
253 : 2 : write(io_unit,10) ''
254 : 2 : write(io_unit,10) '#==============================================================================================='
255 : 2 : write(io_unit,10) '# This file contains timing information for the block Lanczos algorithm. '
256 : 2 : write(io_unit,10) '# The purpose of this information is to establish which parts of the computation'
257 : 2 : write(io_unit,10) '# are time consuming.'
258 : 2 : write(io_unit,10) '#==============================================================================================='
259 : 2 : write(io_unit,10) '# computation time (seconds) '
260 : 2 : write(io_unit,10) '#==============================================================================================='
261 : 2 : write(io_unit,10) '#'
262 : : else
263 : 111 : open(io_unit,file=block_lanczos_log_filename,position='append',status=files_status_old)
264 : : end if
265 : :
266 : :
267 : 113 : icounter = icounter + 1
268 : 113 : write(io_unit,10) ''
269 : 113 : write(io_unit,10) '#=========================='
270 : 113 : write(io_unit,15) '# Call number ', icounter
271 : 113 : write(io_unit,10) '#=========================='
272 : 113 : write(io_unit,10) ''
273 : :
274 : 113 : write(io_unit,20) ' Apply Matrix Function :', list_time(1)
275 : 113 : write(io_unit,20) ' Compute Alpha :', list_time(2)
276 : 113 : write(io_unit,20) ' Update residual array (1-ZGEMM):', list_time(3)
277 : 113 : write(io_unit,20) ' Update residual array (2-ZGEMM):', list_time(4)
278 : 113 : write(io_unit,20) ' Orthogonalize :', list_time(5)
279 : 113 : write(io_unit,20) ' Extract QR factorization :', list_time(6)
280 : 113 : write(io_unit,10) '-------------------------------------------------------'
281 [ + + ]: 791 : write(io_unit,20) ' Sum of the above :', sum(list_time(1:6))
282 : 113 : write(io_unit,20) ' TOTAL ROUTINE TIME :', list_time(7)
283 : :
284 : :
285 : 113 : close(io_unit)
286 : :
287 : : end if
288 : :
289 : : 10 format(A)
290 : : 15 format(A,I5)
291 : : 20 format(A,ES10.2)
292 : :
293 : 173 : end subroutine write_block_lanczos_timing_log
294 : : !!***
295 : :
296 : : end module m_gwls_TimingLog
297 : : !!***
|