Octopus
run.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!! Copyright (C) 2020 M. Oliveira
3!!
4!! This program is free software; you can redistribute it and/or modify
5!! it under the terms of the GNU General Public License as published by
6!! the Free Software Foundation; either version 2, or (at your option)
7!! any later version.
8!!
9!! This program is distributed in the hope that it will be useful,
10!! but WITHOUT ANY WARRANTY; without even the implied warranty of
11!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12!! GNU General Public License for more details.
13!!
14!! You should have received a copy of the GNU General Public License
15!! along with this program; if not, write to the Free Software
16!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17!! 02110-1301, USA.
18!!
19
20#include "global.h"
21
24module run_oct_m
25 use accel_oct_m
27 use casida_oct_m
28 use debug_oct_m
33 use fft_oct_m
35 use global_oct_m
40 use io_oct_m
41 use lasers_oct_m
44 use mpi_oct_m
51 use parser_oct_m
57 use kdotp_oct_m
59 use pulpo_oct_m
63 use system_oct_m
64 use td_oct_m
65#ifdef HAVE_APP_TESTS
66 use test_oct_m
67#endif
70 use unocc_oct_m
72 use vdw_oct_m
73
74 implicit none
75
76 private
77 public :: &
78 run
79
80 integer, parameter :: LR = 1, fd = 2
81
82contains
83
84 ! ---------------------------------------------------------
86 integer function get_resp_method(namespace)
87 type(namespace_t), intent(in) :: namespace
88
89 push_sub(get_resp_method)
90
91 !%Variable ResponseMethod
92 !%Type integer
93 !%Default sternheimer
94 !%Section Linear Response
95 !%Description
96 !% Some response properties can be calculated either via
97 !% Sternheimer linear response or by using finite
98 !% differences. You can use this variable to select how you want
99 !% them to be calculated, it applies to <tt>em_resp</tt> and <tt>vib_modes</tt>
100 !% calculation modes. By default, the Sternheimer linear-response
101 !% technique is used.
102 !%Option sternheimer 1
103 !% The linear response is obtained by solving a self-consistent
104 !% Sternheimer equation for the variation of the orbitals. This
105 !% is the recommended method.
106 !%Option finite_differences 2
107 !% Properties are calculated as a finite-differences derivative of
108 !% the energy obtained by several ground-state calculations. This
109 !% method, slow and limited only to static response, is kept
110 !% mainly because it is simple and useful for testing purposes.
111 !%End
112
113 call parse_variable(namespace, 'ResponseMethod', lr, get_resp_method)
114
115 if (.not. varinfo_valid_option('ResponseMethod', get_resp_method)) then
116 call messages_input_error(namespace, 'ResponseMethod')
117 end if
118
119 pop_sub(get_resp_method)
120 end function get_resp_method
121
122 ! ---------------------------------------------------------
126 subroutine run(namespace, calc_mode_id)
127 type(namespace_t), intent(in) :: namespace
128 integer, intent(in) :: calc_mode_id
129
130 type(partner_list_t) :: partners
131 class(system_t), pointer :: systems
132 type(system_factory_t) :: system_factory
133 type(interactions_factory_t) :: interactions_factory
134 logical :: from_scratch
135 integer :: iunit_out
136 type(partner_iterator_t) :: iter
137 type(system_list_t) :: flat_list
138 class(interaction_partner_t), pointer :: partner
139 real(real64) :: largest_dt, largest_allowed_time
140
141 push_sub(run)
142
143 call messages_print_with_emphasis(msg="Calculation Mode", namespace=namespace)
144 call messages_print_var_option("CalculationMode", calc_mode_id, namespace=namespace)
145 call messages_print_with_emphasis(namespace=namespace)
146
147 call calc_mode_parallel_strategy_init(calc_mode_id)
148
149 if (calc_mode_id == option__calculationmode__recipe) then
150 call pulpo_print()
151 pop_sub(run)
152 return
153 end if
154
155 call unit_system_init(namespace)
156
157 call accel_init(mpi_world, namespace)
159 ! initialize FFTs
160 call fft_all_init(namespace)
161
162 if (calc_mode_id == option__calculationmode__test) then
163#ifdef HAVE_APP_TESTS
164 call test_run(namespace, mpi_world)
165 call fft_all_end()
167 pop_sub(run)
168 return
169#else
170 call messages_not_implemented("CalculationMode = test (build with OCTOPUS_APP_TESTS=ON)", namespace=namespace)
171#endif
172 end if
173
174 ! Create systems
175 if (parse_is_defined(namespace, "Systems")) then
176 ! We are running in multi-system mode
177 systems => system_factory%create(namespace, system_multisystem, calc_mode_id, mpi_world)
178 else
179 ! Fall back to old behaviour
180 systems => electrons_t(namespace, mpi_world, calc_mode_id)
181 end if
182
183 ! Create list of partners
184 select type (systems)
185 class is (multisystem_basic_t)
186 ! Systems are also partners
187 partners = systems%list
188 ! Add external potentials to partners list
189 call load_external_potentials(partners, namespace)
190
191 call load_external_waves(partners, namespace)
192
193 ! Add lasers to the partner list
194 call load_lasers(partners, namespace)
195
196 type is (electrons_t)
197 call partners%add(systems)
198 end select
199
200 ! Ultrasoft/PAW pseudopotentials (generalized overlap) are supported for the
201 ! run modes whose ingredients are implemented and verified: ground state
202 ! (energy, forces, stress), real-time TDDFT, unoccupied states (generalized
203 ! eigensolver), geometry optimization (ion positions and, via the stress,
204 ! cell degrees of freedom; collinear spin only), Casida linear response and
205 ! finite-difference vibrational modes (energy + forces). Every other mode
206 ! (em_resp, kdotp, vdw, optimal control, Sternheimer vib_modes, ...) would
207 ! silently use unimplemented augmentation/overlap contributions and is fenced
208 ! off here.
209 select type (systems)
210 type is (electrons_t)
211 if (systems%hm%ep%requires_generalized_overlap) then
212 select case (calc_mode_id)
213 case (option__calculationmode__gs, option__calculationmode__td, &
214 option__calculationmode__unocc, option__calculationmode__casida)
215 ! supported for ultrasoft/PAW
216 case (option__calculationmode__go)
217 ! Geometry optimization drives the ions with the forces.
218 case (option__calculationmode__vib_modes)
219 ! Only the finite-difference backend is correct for ultrasoft/PAW
220 if (get_resp_method(namespace) /= fd) then
222 "Sternheimer vib_modes (ResponseMethod = lr) with ultrasoft/PAW; "//&
223 "use ResponseMethod = finite_differences", namespace=namespace)
224 end if
225 case default
227 "CalculationMode other than GS, TD, UNOCC, GO, Casida or "//&
228 "(finite-difference) vib_modes with ultrasoft/PAW generalized overlap", &
229 namespace=namespace)
230 end select
231 end if
232 end select
233
234 ! Initialize algorithms (currently only propagators are supported)
235 select type (systems)
236 class is (multisystem_basic_t)
237 select case (calc_mode_id)
238 case (option__calculationmode__gs)
239 call systems%new_algorithm(minimizer_factory_t(systems%namespace))
240 case (option__calculationmode__td)
241 call systems%new_algorithm(propagator_factory_t(systems%namespace))
242 end select
243 end select
244
245
246 ! Check whether the final propagation time would lead to an infinite loop, and stop the code if necessary.
247 ! See issue: https://gitlab.com/octopus-code/octopus/-/issues/1226
248 !
249 ! The deadlock currently appears when systems have different timesteps, and one system could do a
250 !
251 ! 2 4 6 8 10 propagation time=11
252 ! system1 (dt=2): * * * * * |
253 ! system2 (dt=4): * * |
254 !
255 ! As system2 is not allowed to do to timestep 12, it is stuck at 8. System1 will try to get to 10, but is stuck at a barrier, as
256 ! system2 is behind, and keeps waiting for system2.
257 !
258 ! We can only allow propagations up to the largest time, the fastest system (largest dt)
259 ! can reach within the given propagation time. If one of the slower systems could perform
260 ! an extra step within the propagation time, we need to stop the calculation, before the
261 ! propagation, to prevent wasting CPU time in the deadlock.
262 !
263 ! TODO: Fix the framework, so that this infinite loop can be avoided in the first place.
264
265 if(calc_mode_id == option__calculationmode__td) then
266
267 select type (sys => systems)
268 type is (multisystem_basic_t)
269
270 largest_dt = m_zero
271 largest_allowed_time = m_zero
272
273 call sys%get_flat_list(flat_list)
274
275 call iter%start(flat_list)
276 do while (iter%has_next())
277 select type (subsystem => iter%get_next())
278 class is (system_t)
279 select type (subalgorithm => subsystem%algo)
280 class is (propagator_t)
281 largest_dt = max(largest_dt, subalgorithm%dt)
282 end select
283 end select
284 end do
285
286 select type(prop => systems%algo)
287 class is (propagator_t)
288 largest_allowed_time = floor(prop%final_time / largest_dt)* largest_dt
289 class default
290 assert(.false.)
291 end select
292
293 call iter%start(flat_list)
294 do while (iter%has_next())
295 select type(subsystem => iter%get_next())
296 class is (system_t)
297 select type (subalgorithm => subsystem%algo)
298 class is (propagator_t)
299 if( floor(subalgorithm%final_time/subalgorithm%dt) * subalgorithm%dt > largest_allowed_time ) then
300 write(message(1), *) "Incommensurate propagation time: The calculation would run into a deadlock, as a system with"
301 write(message(2), *) "a smaller timestep would attempt a timestep beyond the last step" &
302 // " of a system with a larger time step."
303 write(message(3), *) "Please, adjust the TDPropagationTime and/or the TDTimeStep variables of the systems."
304 write(message(4), *) ""
305 write(message(5), *) "With the current timesteps, the TDPropagationTime should be ", largest_allowed_time
306 call messages_fatal(5, namespace=namespace)
307 end if
308 end select
309 end select
310 end do
311
312 end select
313
314 end if
315
316 ![create_interactions] !doxygen marker. Dont delete
317 ! Create and initialize interactions
318 !
319 ! This function is called recursively for all subsystems of systems.
320 ! If systems is a multisystem_basic_t container, the partners list contains all subsystems.
321 call systems%create_interactions(interactions_factory, partners)
322 ![create_interactions]
323
324 select type (systems)
325 class is (multisystem_basic_t)
326 ! Write the interaction graph as a DOT graph for debug
327 if ((debug%interaction_graph .or. debug%interaction_graph_full) .and. mpi_world%is_root()) then
328 iunit_out = io_open('debug/interaction_graph.dot', systems%namespace, action='write')
329 write(iunit_out, '(a)') 'digraph {'
330 call systems%write_interaction_graph(iunit_out, debug%interaction_graph_full)
331 write(iunit_out, '(a)') '}'
332 call io_close(iunit_out)
333 end if
334 end select
335
336 if (.not. systems%process_is_slave()) then
337 call messages_write('Info: Octopus initialization completed.', new_line = .true.)
338 call messages_write('Info: Starting calculation mode.')
339 call messages_info(namespace=namespace)
340
341 !%Variable FromScratch
342 !%Type logical
343 !%Default false
344 !%Section Execution
345 !%Description
346 !% When this variable is set to true, <tt>Octopus</tt> will perform a
347 !% calculation from the beginning, without looking for restart
348 !% information.
349 !% NOTE: If available, mesh partitioning information will be used for
350 !% initializing the calculation regardless of the set value for this variable.
351 !%End
352 call parse_variable(namespace, 'FromScratch', .false., from_scratch)
353
354 call profiling_in("CALC_MODE")
355
356 select case (calc_mode_id)
357 case (option__calculationmode__gs)
358 select type (systems)
359 class is (multisystem_basic_t)
360 call multisystem_run(systems, from_scratch)
361 type is (electrons_t)
362 call systems%ground_state_run(from_scratch)
363 end select
364 case (option__calculationmode__unocc)
365 call unocc_run(systems, from_scratch)
366 case (option__calculationmode__td)
367 select type (systems)
368 class is (multisystem_basic_t)
369 call multisystem_run(systems, from_scratch)
370 type is (electrons_t)
371 call time_dependent_run(systems, from_scratch)
372 end select
373 case (option__calculationmode__go)
374 call geom_opt_run(systems, from_scratch)
375 case (option__calculationmode__opt_control)
376 call opt_control_run(systems)
377 case (option__calculationmode__em_resp)
378 select case (get_resp_method(namespace))
379 case (fd)
380 call static_pol_run(systems, from_scratch)
381 case (lr)
382 call em_resp_run(systems, from_scratch)
383 end select
384 case (option__calculationmode__casida)
385 call casida_run(systems, from_scratch)
386 case (option__calculationmode__vdw)
387 call vdw_run(systems, from_scratch)
388 case (option__calculationmode__vib_modes)
389 select case (get_resp_method(namespace))
390 case (fd)
391 call phonons_run(systems)
392 case (lr)
393 call phonons_lr_run(systems, from_scratch)
394 end select
395 case (option__calculationmode__one_shot)
396 message(1) = "CalculationMode = one_shot is obsolete. Please use gs with MaximumIter = 0."
397 call messages_fatal(1, namespace=namespace)
398 case (option__calculationmode__kdotp)
399 call kdotp_lr_run(systems, from_scratch)
400 case (option__calculationmode__dummy)
401 case (option__calculationmode__invert_ks)
402 call invert_ks_run(systems)
403 case (option__calculationmode__recipe)
404 assert(.false.) !this is handled before, if we get here, it is an error
405 end select
406
407 call profiling_out("CALC_MODE")
408 end if
409
410 select type (systems)
411 class is (multisystem_basic_t)
412 !Deallocate the external potentials
413 call iter%start(partners)
414 do while (iter%has_next())
415 select type(ptr => iter%get_next())
416 class is(external_potential_t)
417 partner => ptr
418 safe_deallocate_p(partner)
419 class is(external_waves_t)
420 partner => ptr
421 safe_deallocate_p(partner)
422 class is(lasers_t)
423 partner => ptr
424 safe_deallocate_p(partner)
425 end select
426 end do
427 end select
428
429 ! Finalize systems
430 safe_deallocate_p(systems)
431
432 call fft_all_end()
433
435
437
438 pop_sub(run)
439
440 end subroutine run
441
443 subroutine calc_mode_parallel_strategy_init(calc_mode_id)
444 integer, intent(in) :: calc_mode_id
445
447
448 select case (calc_mode_id)
449 case (option__calculationmode__gs, option__calculationmode__go, option__calculationmode__unocc)
450 call calc_mode_par%set_parallelization(p_strategy_states, default = .false.)
451#ifdef HAVE_SCALAPACK
452 call calc_mode_par%set_scalapack_compat()
453#endif
454
455 case (option__calculationmode__td)
456 call calc_mode_par%set_parallelization(p_strategy_states, default = .true.)
457
458 case (option__calculationmode__casida)
459 ! Pure 'other' parallelization is a bad idea. Trying to solve the Poisson equation separately on each node
460 ! consumes excessive memory and time (easily more than is available). In principle, the line below would setup
461 ! joint domain/other parallelization, but 'other' parallelization takes precedence, especially since
462 ! multicomm_init does not know the actual problem size and uses a fictitious value of 10000, making it
463 ! impossible to choose joint parallelization wisely, and generally resulting in a choice of only one domain
464 ! group. FIXME! --DAS
465
466 ! With the recent improvements, the 'other' parallelization over electron-hole
467 ! pairs works quite well now. For smaller matrices, a combination
468 ! seems to give the fastest run times. For larger matrices (more than a few
469 ! thousand entries per dimension), CasidaDistributedMatrix is needed for
470 ! the Casida matrix to fit into memory; this takes the cores from the
471 ! 'other' strategy. For very large matrices (more than 100000), it is
472 ! advisable to use only the 'other' strategy because the diagonalization
473 ! uses most of the computation time.
474 ! Thus you may want to enable this or a combination of other and domain to get
475 ! better performance - STO
476 call calc_mode_par%set_parallelization(p_strategy_other, default = .false.) ! enabled, but not default
477 call calc_mode_par%unset_parallelization(p_strategy_kpoints) ! disabled. FIXME: could be implemented.
478
479 end select
480
482
484
485end module run_oct_m
486
487!! Local Variables:
488!! mode: f90
489!! coding: utf-8
490!! End:
double floor(double __x) __attribute__((__nothrow__
subroutine, public accel_init(base_grp, namespace)
Definition: accel.F90:411
subroutine, public accel_end(namespace)
Definition: accel.F90:673
This module handles the calculation mode.
integer, parameter, public p_strategy_kpoints
parallelization in k-points
integer, parameter, public p_strategy_other
something else like e-h pairs
type(calc_mode_par_t), public calc_mode_par
Singleton instance of parallel calculation mode.
integer, parameter, public p_strategy_states
parallelization in states
This module implements the Casida equations for excited states.
Definition: casida.F90:117
subroutine, public casida_run(system, from_scratch)
Definition: casida.F90:296
type(debug_t), save, public debug
Definition: debug.F90:133
subroutine, public em_resp_run(system, from_scratch)
Definition: em_resp.F90:211
subroutine, public load_external_potentials(external_potentials, namespace)
subroutine, public load_external_waves(partners, namespace)
Fast Fourier Transform module. This module provides a single interface that works with different FFT ...
Definition: fft.F90:97
subroutine, public fft_all_init(namespace)
initialize the table
Definition: fft.F90:280
subroutine, public fft_all_end()
delete all plans
Definition: fft.F90:406
subroutine, public geom_opt_run(system, from_scratch)
Definition: geom_opt.F90:222
real(real64), parameter, public m_zero
Definition: global.F90:173
This module defines classes and functions for interaction partners.
subroutine, public invert_ks_run(system)
Definition: invert_ks.F90:126
Definition: io.F90:93
subroutine, public io_close(iunit, grp)
Definition: io.F90:444
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:379
subroutine, public kdotp_lr_run(system, from_scratch)
Definition: kdotp.F90:164
subroutine, public load_lasers(partners, namespace)
Definition: lasers.F90:1215
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:878
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1048
character(len=512), private msg
Definition: messages.F90:143
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:138
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:386
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:671
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:570
This module implements the factory for ground state algorithm.
subroutine, public mpi_debug_statistics()
Definition: mpi_debug.F90:198
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:317
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:124
This module implements the basic mulsisystem class, a container system for other systems.
This module implements the multisystem debug functionality.
subroutine, public multisystem_run(systems, from_scratch)
type(namespace_t), public global_namespace
Definition: namespace.F90:112
This module contains the main procedure ("opt_control_run") that is used when optimal control runs ar...
Definition: opt_control.F90:95
subroutine, public opt_control_run(system)
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:440
subroutine, public phonons_run(system)
Definition: phonons_fd.F90:131
subroutine, public phonons_lr_run(system, from_scratch)
Definition: phonons_lr.F90:150
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:672
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:604
This module implements the factory for propagators.
This module implements the basic propagator framework.
Definition: propagator.F90:96
subroutine, public pulpo_print()
Definition: pulpo.F90:109
top level module for all calculation modes
Definition: run.F90:96
integer function get_resp_method(namespace)
query input file for the response mode.
Definition: run.F90:159
integer, parameter fd
Definition: run.F90:152
subroutine calc_mode_parallel_strategy_init(calc_mode_id)
Calculation mode initialization (parallelization strategy)
Definition: run.F90:516
subroutine, public run(namespace, calc_mode_id)
main routine to run all calculations: This routine parses the input file, sets up the systems and int...
Definition: run.F90:199
subroutine, public static_pol_run(system, from_scratch)
Definition: static_pol.F90:138
integer, parameter, public system_multisystem
container system. (multisystem_basic_oct_m::multisystem_basic_t)
This module implements the abstract system type.
Definition: system.F90:97
Definition: td.F90:93
subroutine, public time_dependent_run(electrons, from_scratch)
This module defines the unit system, used for input and output.
subroutine, public unit_system_init(namespace)
subroutine, public unocc_run(system, from_scratch)
Definition: unocc.F90:138
subroutine, public vdw_run(system, from_scratch)
Definition: vdw.F90:131
Class describing the electron system.
Definition: electrons.F90:202
This class defines the factory for minimizers.
Container class for lists of system_oct_m::system_t.
This class defines the factory for propagators.
Abstract class implementing propagators.
Definition: propagator.F90:121
Abstract class for systems.
Definition: system.F90:152
int true(void)