Octopus
restart.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!! Copyright (C) 2014 M. Oliveira
3!! Copyright (C) 2021 S. Ohlmann
4!! Copyright (C) 2025 M. Lueders
5!!
6!! This program is free software; you can redistribute it and/or modify
7!! it under the terms of the GNU General Public License as published by
8!! the Free Software Foundation; either version 2, or (at your option)
9!! any later version.
10!!
11!! This program is distributed in the hope that it will be useful,
12!! but WITHOUT ANY WARRANTY; without even the implied warranty of
13!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14!! GNU General Public License for more details.
15!!
16!! You should have received a copy of the GNU General Public License
17!! along with this program; if not, write to the Free Software
18!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19!! 02110-1301, USA.
20!!
21
22#include "global.h"
23
24module restart_oct_m
25 use batch_oct_m
27 use debug_oct_m
28 use global_oct_m
29 use index_oct_m
30 use io_oct_m
32 use loct_oct_m
33 use mesh_oct_m
36 use mpi_oct_m
39 use parser_oct_m
42 use space_oct_m
43 use string_oct_m
46
47 implicit none
48
49 private
50 public :: &
52 restart_t, &
53 clean_stop, &
56
57
59 integer, parameter :: RESTART_N_DATA_TYPES = 14
60
61 integer, parameter, public :: &
62 RESTART_UNDEFINED = -1, &
63 restart_all = 0, &
64 restart_gs = 1, &
65 restart_unocc = 2, &
66 restart_td = 3, &
67 restart_em_resp = 4, &
69 restart_kdotp = 6, &
71 restart_vdw = 8, &
72 restart_casida = 9, &
73 restart_oct = 10, &
74 restart_partition = 11, &
75 restart_proj = 12, &
76 restart_iteration = 13, &
78
80 private
81 character(len=20) :: tag
82 character(len=MAX_PATH_LEN) :: basedir
83 character(len=MAX_PATH_LEN) :: dir
84 integer :: flags
85 end type restart_data_t
86
87
88 integer, parameter, public :: &
89 RESTART_TYPE_DUMP = 1, &
91
93 integer, parameter, public :: &
94 RESTART_FLAG_STATES = 1, &
95 restart_flag_rho = 2, &
97 restart_flag_mix = 8, &
98 restart_flag_skip = 16, &
100
104 private
105 character(len=20) :: tag
106 character(len=MAX_PATH_LEN) :: dir
107 ! !! These will be appended to the basedir
108 integer :: default_flags = 0
109 end type restart_basic_data_t
110
111 character(len=4), parameter :: type_string(2) = (/ "DUMP", "LOAD"/)
112
113
120 !
121 type restart_basic_t
122 private
123 type(namespace_t), pointer, public :: namespace
124 integer :: data_type = restart_undefined
125 integer :: type = restart_undefined
126 logical :: skip_
127 character(len=MAX_PATH_LEN) :: dir_
128 character(len=MAX_PATH_LEN) :: pwd
129 ! !! from or dumped to. It can be either dir or a subdirectory of dir.
130 ! !! pwd is set by restart_basic_open_dir()/restart_basic_close_dir()
131 character(len=MAX_PATH_LEN), public :: basedir
132 integer :: flags
133 type(mpi_grp_t) , public :: mpi_grp
134 logical :: initialized = .false.
135 contains
136 !note: the generic name 'init' here is introduced to be able to combine the two functions (restart_basic_init and restart_init)
137 ! with a common name, despite having a different signature (optional arguments in restart_init)
138 procedure, private :: restart_basic_init
139 generic :: init => restart_basic_init
140 procedure :: end => restart_basic_end
141 procedure :: open => restart_basic_open
142 procedure :: close => restart_basic_close
143 procedure :: open_dir => restart_basic_open_dir
144 procedure :: close_dir => restart_basic_close_dir
145 procedure :: mkdir => restart_basic_mkdir
146 procedure :: dir => restart_basic_dir
147 procedure :: rm => restart_basic_rm
148 procedure :: read => restart_basic_read
149 procedure :: write => restart_basic_write
150 procedure :: get_data_type => restart_basic_get_data_type
151 procedure :: get_info => restart_basic_get_info
152 procedure :: do_i_write => restart_basic_do_i_write
153 procedure :: skip => restart_basic_skip
154 procedure :: has_flag => restart_basic_has_flag
155 end type
157 type, extends(restart_basic_t) :: restart_t
158 private
159 type(multicomm_t), pointer :: mc
160 logical :: has_mesh
161 ! !! and mesh functions cannot be written or read.
162 integer(int64), allocatable :: map(:)
163 ! !! used in the current calculations.
164 integer, public :: file_format_states
165
166 contains
167 !note: the generic name 'init' here is introduced to be able to combine the two functions (restart_basic_init and restart_init)
168 ! with a common name, despite having a different signature (optional arguments in restart_init)
169 procedure, private :: restart_init
170 generic :: init => restart_init
171 procedure :: end => restart_end
172 procedure :: has_map => restart_has_map
175 procedure, private :: drestart_read_mesh_function, zrestart_read_mesh_function
176 generic :: read_mesh_function => drestart_read_mesh_function, zrestart_read_mesh_function
193 procedure :: get_info => restart_get_info
194
195 end type restart_t
196
201 type(restart_basic_data_t), parameter :: basic_info(restart_undefined:restart_n_data_types)= [&
202 restart_basic_data_t("Undefined", ""), &
204 restart_basic_data_t("Ground-state", gs_dir), &
205 restart_basic_data_t("Unoccupied states", gs_dir), &
206 restart_basic_data_t("Time-dependent", td_dir), &
207 restart_basic_data_t("EM Resp.", em_resp_dir), &
208 restart_basic_data_t("EM Resp. FD", em_resp_fd_dir), &
210 restart_basic_data_t("Vib. Modes", vib_modes_dir), &
212 restart_basic_data_t("Casida", casida_dir), &
213 restart_basic_data_t("Optimal Control", oct_dir), &
215 restart_basic_data_t("GS for TDOutput", gs_dir), &
216 restart_basic_data_t("Iteration counter", iteration_dir), &
217 restart_basic_data_t("Custom data", "") &
221 ! from signals.c
224 subroutine block_signals()
225 implicit none
226 end subroutine block_signals
231 subroutine unblock_signals()
232 implicit none
233 end subroutine unblock_signals
234 end interface
236contains
239 function clean_stop(comm)
240 type(mpi_comm), intent(in) :: comm
241 logical :: clean_stop
243 logical :: file_exists
245 push_sub(clean_stop)
247 clean_stop = .false.
249 if (mpi_world%is_root()) then
250 inquire(file='stop', exist=file_exists)
251 if (file_exists) then
252 call loct_rm('stop')
253 clean_stop = .true.
254 end if
255 end if
256
257#ifdef HAVE_MPI
258 ! make sure all nodes agree on whether this condition occurred
259 call mpi_bcast(clean_stop, 1, mpi_logical, 0, comm)
260#endif
261
262 if (clean_stop) then
263 message(1) = 'Clean STOP'
265 end if
267 pop_sub(clean_stop)
268 end function clean_stop
271 subroutine restart_basic_init(restart, namespace, data_type, type, ierr, dir)
272 class(restart_basic_t), intent(out) :: restart
273 type(namespace_t), target, intent(in) :: namespace
274 integer, intent(in) :: data_type
275 integer, intent(in) :: type
277 integer, intent(out) :: ierr
278 character(len=*), optional, intent(in) :: dir
281 character(len=MAX_PATH_LEN) :: basedir, dirname
282 integer :: iline, n_cols, idata_type, i
283 character(len=MAX_PATH_LEN) :: default_basedir
284 character(len=20) :: tag
285 type(block_t) :: blk
286 logical :: restart_write, dir_exists
287 character(len=MAX_NAMESPACE_LEN) :: namespace_prefix
289
290 push_sub(restart_basic_init)
291
292 ! Some initializations
293 restart%type = type
294
295 namespace_prefix = trim(namespace%get())
297 default_basedir = trim(io_workdir())//'/restart/'
298 restart%basedir = default_basedir
299 restart%skip_ = .false.
300 restart%data_type = data_type
301 if(data_type>0 .and. data_type<=restart_n_data_types) then
302 restart%flags = basic_info(data_type)%default_flags
303 else
304 restart%flags = 0
305 end if
306
307 if (data_type < restart_undefined .and. data_type > restart_n_data_types) then
308 message(1) = "Illegal data_type in restart_init"
309 call messages_fatal(1, namespace=namespace)
310 end if
311 restart%namespace => namespace
312
313 ierr = 0
314
315 ! Read input
316 call messages_obsolete_variable(namespace, 'RestartFileFormat', 'RestartOptions')
317 call messages_obsolete_variable(namespace, 'TmpDir', 'RestartOptions')
318 call messages_obsolete_variable(namespace, 'RestartDir', 'RestartOptions')
319 call messages_obsolete_variable(namespace, 'MeshPartitionRead', 'RestartOptions')
320 call messages_obsolete_variable(namespace, 'MeshPartitionWrite', 'RestartOptions')
321 call messages_obsolete_variable(namespace, 'MeshPartitionDir', 'RestartOptions')
322
323 !%Variable RestartOptions
324 !%Type block
325 !%Section Execution::IO
326 !%Description
327 !% <tt>Octopus</tt> usually stores binary information, such as the wavefunctions, to be used
328 !% in subsequent calculations. The most common example is the ground-state states
329 !% that are used to start a time-dependent calculation. This variable allows to control
330 !% where this information is written to or read from. The format of this block is the following:
331 !% for each line, the first column indicates the type of data, the second column indicates
332 !% the path to the directory that should be used to read and write that restart information, and the
333 !% third column, which is optional, allows one to set some flags to modify the way how the data
334 !% is read or written. For example, if you are running a time-dependent calculation, you can
335 !% indicate where <tt>Octopus</tt> can find the ground-state information in the following way:
336 !%
337 !% <tt>%RestartOptions
338 !% <br>&nbsp;&nbsp;restart_gs | "gs_restart"
339 !% <br>&nbsp;&nbsp;restart_td | "td_restart"
340 !% <br>%</tt>
341 !%
342 !% The second line of the above example also tells <tt>Octopus</tt> that the time-dependent restart data
343 !% should be read from and written to the "td_restart" directory.
344 !%
345 !% In case you want to change the path of all the restart directories, you can use the <tt>restart_all</tt> option.
346 !% When using the <tt>restart_all</tt> option, it is still possible to have a different restart directory for specific
347 !% data types. For example, when including the following block in your input file:
348 !%
349 !% <tt>%RestartOptions
350 !% <br>&nbsp;&nbsp;restart_all | "my_restart"
351 !% <br>&nbsp;&nbsp;restart_td&nbsp; | "td_restart"
352 !% <br>%</tt>
353 !%
354 !% the time-dependent restart information will be stored in the "td_restart" directory, while all the remaining
355 !% restart information will be stored in the "my_restart" directory.
356 !%
357 !% By default, the name of the "restart_all" directory is set to "restart".
358 !%
359 !%
360 !% For multisystem calculations, the namespace of each system is inserted between the `restart top` folder and the specific
361 !% directory for each data type. When specifying a folder for a given system, the corresponding namespace is added
362 !% automatically to the folder name, unless the flag `restart_literal` is added.
363 !%
364 !% Some <tt>CalculationMode</tt>s also take into account specific flags set in the third column of the <tt>RestartOptions</tt>
365 !% block. These are used to determine if some specific part of the restart data is to be taken into account
366 !% or not when reading the restart information. For example, when restarting a ground-state calculation, one can
367 !% set the <tt>restart_rho</tt> flags, so that the density used is not built from the saved wavefunctions, but is
368 !% instead read from the restart directory. In this case, the block should look like this:
369 !%
370 !% <tt>%RestartOptions
371 !% <br>&nbsp;&nbsp;restart_gs | "restart" | restart_rho
372 !% <br>%</tt>
373 !%
374 !% A list of available flags is given below, but note that the code might ignore some of them, which will happen if they
375 !% are not available for that particular calculation, or might assume some of them always present, which will happen
376 !% in case they are mandatory.
377 !%
378 !% Finally, note that all the restart information of a given data type is always stored in a subdirectory of the
379 !% specified path. The name of this subdirectory is fixed and cannot be changed. For example, ground-state information
380 !% will always be stored in a subdirectory named "gs". This makes it safe in most situations to use the same path for
381 !% all the data types. The name of these subdirectories is indicated in the description of the data types below.
382 !%
383 !% Currently, the available restart data types and flags are the following:
384 !%Option restart_all 0
385 !% (data type)
386 !% Option to globally change the path of all the restart information.
387 !%Option restart_gs 1
388 !% (data type)
389 !% The data resulting from a ground-state calculation.
390 !% This information is stored under the "gs" subdirectory.
391 !%Option restart_unocc 2
392 !% (data type)
393 !% The data resulting from an unoccupied states calculation. This information also corresponds to a ground state and
394 !% can be used as such, so it is stored under the same subdirectory as the one of restart_gs.
395 !%Option restart_td 3
396 !% (data type)
397 !% The data resulting from a real-time time-dependent calculation.
398 !% This information is stored under the "td" subdirectory.
399 !%Option restart_em_resp 4
400 !% (data type)
401 !% The data resulting from the calculation of the electromagnetic response using the Sternheimer approach.
402 !% This information is stored under the "em_resp" subdirectory.
403 !%Option restart_em_resp_fd 5
404 !% (data type)
405 !% The data resulting from the calculation of the electromagnetic response using finite-differences.
406 !% This information is stored under the "em_resp_fd" subdirectory.
407 !%Option restart_kdotp 6
408 !% (data type)
409 !% The data resulting from the calculation of effective masses by k.p perturbation theory.
410 !% This information is stored under the "kdotp" subdirectory.
411 !%Option restart_vib_modes 7
412 !% (data type)
413 !% The data resulting from the calculation of vibrational modes.
414 !% This information is stored under the "vib_modes" subdirectory.
415 !%Option restart_vdw 8
416 !% (data type)
417 !% The data resulting from the calculation of van der Waals coefficients.
418 !% This information is stored under the "vdw" subdirectory.
419 !%Option restart_casida 9
420 !% (data type)
421 !% The data resulting from a Casida calculation.
422 !% This information is stored under the "casida" subdirectory.
423 !%Option restart_oct 10
424 !% (data type)
425 !% The data for optimal control calculations.
426 !% This information is stored under the "opt-control" subdirectory.
427 !%Option restart_partition 11
428 !% (data type)
429 !% The data for the mesh partitioning.
430 !% This information is stored under the "partition" subdirectory.
431 !%Option restart_proj 12
432 !% (data type)
433 !% The ground-state to be used with the td_occup and populations options of <tt>TDOutput</tt>.
434 !% This information should be a ground state, so the "gs" subdirectory is used.
435 !%Option restart_states 1
436 !% (flag)
437 !% Read the electronic states. (not yet implemented)
438 !%Option restart_rho 2
439 !% (flag)
440 !% Read the electronic density.
441 !%Option restart_vhxc 4
442 !% (flag)
443 !% Read the Hartree and XC potentials.
444 !%Option restart_mix 8
445 !% (flag)
446 !% Read the SCF mixing information.
447 !%Option restart_skip 16
448 !% (flag)
449 !% This flag allows to selectively skip the reading and writing of specific restart information.
450 !%Option restart_literal 32
451 !% (flag)
452 !% Treat the given path literally, i.e. do not insert the namespace. This is useful for ensembles
453 !% if a given replica should read from a specific restart folder.
454 !%End
455 if (parse_block(namespace, 'RestartOptions', blk) == 0) then
456
457
458 do iline = 1, parse_block_n(blk)
459 n_cols = parse_block_cols(blk,iline-1)
460
461 call parse_block_integer(blk, iline-1, 0, idata_type)
462 if (idata_type < 0 .or. idata_type > restart_n_data_types) then
463 call messages_input_error(namespace, 'RestartOptions', "Invalid data type", row=iline-1, column=0)
464 end if
465 if (data_type == 0) then
466 call parse_block_string(blk, iline-1, 1, default_basedir)
467 end if
468
469 if (idata_type == data_type .or. idata_type == 0) then
470 call parse_block_string(blk, iline-1, 1, restart%basedir)
471 if (n_cols > 2) call parse_block_integer(blk, iline-1, 2, restart%flags)
472
473 namespace_prefix = parse_get_full_name(namespace, 'RestartOptions')
474 namespace_prefix = namespace_prefix(1:len_trim(namespace_prefix)-len_trim('.RestartOptions'))
475
476 if (len_trim(namespace_prefix) == 0 .or. trim(namespace%get()) == trim(namespace_prefix)) then
477 namespace_prefix = trim(namespace%get())
478 end if
479
480 if (bitand(restart%flags, restart_flag_literal) > 0) then
481 namespace_prefix = ""
482 end if
483
484 end if
485
486
487 end do
488 call parse_block_end(blk)
489
490 end if
491
492 basedir = restart%basedir
493 call add_last_slash(basedir)
494
495 do i=1, len(namespace_prefix)
496 if (namespace_prefix(i:i) == '.') namespace_prefix(i:i) = '/'
497 end do
498
499 ! append namespace and ensure a single trailing slash
500 basedir = trim(basedir)//trim(namespace_prefix)
501 call add_last_slash(basedir)
502 dirname = trim(basic_info(restart%data_type)%dir)
503
504 call mpi_grp_init(restart%mpi_grp, mpi_comm_undefined)
505
506 select case (restart%type)
507 case (restart_type_dump)
508 !%Variable RestartWrite
509 !%Type logical
510 !%Default true
511 !%Section Execution::IO
512 !%Description
513 !% If this variable is set to no, restart information is not
514 !% written. Note that some run modes will ignore this
515 !% option and write some restart information anyway.
516 !%End
517
518 call parse_variable(namespace, 'RestartWrite', .true., restart_write)
519 restart%skip_ = .not. restart_write
520
521 if (restart%skip_) then
522 message(1) = 'Restart information will not be written.'
523 call messages_info(1, namespace=namespace)
524 end if
525
526 case (restart_type_load)
527 ! This is set to true as an error condition, checked by assertions in some routines.
528 restart%skip_ = .false.
529
530 case default
531 message(1) = "Unknown restart type in restart_init"
532 call messages_fatal(1, namespace=namespace)
533 end select
534
535
536 ! If the restart data type is not defined, the directories should be set explicitly
537 if (restart%data_type == restart_undefined) then
538 assert(present(dir))
539 basedir = trim(dir)
540 dirname = ""
541 end if
542
543 ! Set final path
544 restart%dir_ = trim(basedir)//trim(dirname)
545 ! Remove any trailing "/" from the path (all the routines from this module should add the trailing "/" when needed)
546 if (index(restart%dir_, '/', .true.) == len_trim(restart%dir_)) then
547 restart%dir_ = restart%dir_(1:len_trim(restart%dir_)-1)
548 end if
549
550 ! Set initial path to the working directory
551 restart%pwd = restart%dir_
552
553 ! Check if the directory already exists and create it if necessary
554 if (restart%mpi_grp%is_root()) then
555 dir_exists = io_dir_exists(restart%pwd)
556 if (restart%type == restart_type_dump .and. .not. dir_exists) then
557 call io_mkdir(restart%pwd, namespace, parents=.true.)
558 end if
559 end if
560 if (restart%mpi_grp%size > 1) then
561 call restart%mpi_grp%bcast(dir_exists, 1, mpi_logical, 0)
562 end if
563
564 if (restart%data_type == restart_undefined) then
565 tag = "Some "
566 else
567 tag = trim(basic_info(data_type)%tag)
568 end if
569
570 select case (restart%type)
571 case (restart_type_dump)
572 if (.not. restart%skip_) then
573 message(1) = "Info: "//trim(tag)//" restart information will be written to '"//trim(restart%pwd)//"'."
574 call messages_info(1, namespace=namespace)
575 end if
576
577 case (restart_type_load)
578 if (.not. dir_exists) then
579 ierr = 1
580 restart%skip_ = .true.
581
582 message(1) = "Info: Could not find '"//trim(restart%pwd)//"' directory for restart."
583 message(2) = "Info: No restart information will be read."
584 call messages_info(2, namespace=namespace)
585 else
586 message(1) = "Info: "//trim(tag)//" restart information will be read from '"//trim(restart%pwd)//"'."
587 call messages_info(1, namespace=namespace)
588 end if
589
590 end select
591
592 restart%initialized = .true.
593
594 pop_sub(restart_basic_init)
595 end subroutine restart_basic_init
596
597 function restart_basic_do_i_write(restart) result(res)
598 class(restart_basic_t), intent(in) :: restart
599 logical :: res
600
601 res = restart%mpi_grp%is_root()
602
603 end function restart_basic_do_i_write
604
605 ! ---------------------------------------------------------
611 subroutine restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
612 class(restart_t), intent(out) :: restart
613 type(namespace_t), target, intent(in) :: namespace
614 integer, intent(in) :: data_type
615 integer, intent(in) :: type
617 type(multicomm_t), target, intent(in) :: mc
618 integer, intent(out) :: ierr
619 class(mesh_t), optional, intent(in) :: mesh
621 character(len=*), optional, intent(in) :: dir
623 logical, optional, intent(in) :: exact
625
626 logical :: grid_changed, grid_reordered, exact_, with_changed_grid
627 integer :: default_format
628
629 push_sub(restart_init)
630
631 ierr = 0
632
633 call restart_basic_init(restart, namespace, data_type, type, ierr, dir)
634 ! At this point, ierr == 1 indicates that the folder did not exist for RESTART_TYPE_LOAD.
635 ! In this case, also restart%skip_ has been set.
636
637 restart%has_mesh = present(mesh)
638 restart%mc => mc
639 call mpi_grp_init(restart%mpi_grp, mc%master_comm)
640
641 ! Sanity checks
642 if (present(exact) .and. .not. present(mesh)) then
643 message(1) = "Error in restart_init: the 'exact' optional argument requires a mesh."
644 call messages_fatal(1, namespace=namespace)
645 end if
646
647 exact_ = optional_default(exact, .false.)
648
649 restart%has_mesh = present(mesh)
650 restart%mc => mc
651
652 if(present(mesh)) then
653 !%Variable RestartFileFormatStates
654 !%Type integer
655 !%Section Execution::IO
656 !%Description
657 !% File format used for writing and reading the restart files for the states.
658 !% Default is adios2 if support is available, otherwise obf.
659 !% Restart files for linear response calculations always use obf.
660 !%Option obf 1
661 !% obf is the Octopus binary format, for which there is one file for
662 !% each state.
663 !%Option adios2 2
664 !% For large systems, especially with many k points, having one file per state can
665 !% be problematic for the file system. This option selects a format based on the
666 !% ADIOS2 library which needs to be available. The library handles IO efficiently
667 !% including aggregation and makes the restart IO much faster. However, it does
668 !% not support all features that the default obf format supports. Moreover, it
669 !% might use more memory for internal aggregation. In case of out-of-memory issues,
670 !% you might need to rerun on more nodes.
671 !%End
672#ifdef HAVE_ADIOS2
673 default_format = option__restartfileformatstates__adios2
674#else
675 default_format = option__restartfileformatstates__obf
676#endif
677 call parse_variable(namespace, 'RestartFileFormatStates', default_format, restart%file_format_states)
678 if (.not. varinfo_valid_option('RestartFileFormatStates', restart%file_format_states)) then
679 call messages_input_error(namespace, 'RestartFileFormatStates')
680 end if
681
682 if (restart%file_format_states == option__restartfileformatstates__adios2) then
683 ! the ADIOS2 format requires the exact same mesh for restarting
684 exact_ = .true.
685#ifndef HAVE_ADIOS2
686 message(1) = "Error: adios2 restart file format requested, but not compiled against ADIOS2 library."
687 call messages_fatal(1)
688#endif
689 end if
690
691 !%Variable RestartWithChangedGrid
692 !%Type logical
693 !%Default false
694 !%Section Execution::IO
695 !%Description
696 !% Use restart data even when the grid has changed. Normally, this is not needed, but can be enabled.
697 !%End
698 call parse_variable(namespace, 'RestartWithChangedGrid', .false., with_changed_grid)
699
700 select case (restart%type)
701 case (restart_type_dump)
702 if (.not. restart%skip_) then
703 ! Dump the grid information. The main parameters of the grid should not change
704 ! during the calculation, so we should only need to dump it once.
705 call index_dump(mesh%idx, mesh%np_part_global, restart%pwd, restart%mpi_grp, &
706 restart%namespace, ierr)
707 if (ierr /= 0) then
708 message(1) = "Unable to write index map to '"//trim(restart%pwd)//"'."
709 call messages_fatal(1, namespace=namespace)
710 end if
711
712 call mesh_write_fingerprint(mesh, restart%pwd, "grid", restart%mpi_grp, namespace, ierr)
713 if (ierr /= 0) then
714 message(1) = "Unable to write mesh fingerprint to '"//trim(restart%pwd)//"/grid'."
715 call messages_fatal(1, namespace=namespace)
716 end if
717 end if
718
719 case (restart_type_load)
720 if(.not. restart%skip_) then
721 call mesh_check_dump_compatibility(mesh, restart%pwd, "grid", global_namespace, &
722 restart%mpi_grp, grid_changed, grid_reordered, restart%map, ierr)
723
724 ! Check whether an error occurred. In this case we cannot read.
725 if (ierr /= 0) then
726 if (ierr == 1) then
727 message(1) = "Unable to check mesh compatibility: unable to read mesh fingerprint"
728 message(2) = "in '"//trim(restart%pwd)//"'."
729 else if (ierr > 1) then
730 message(1) = "Mesh from current calculation is not compatible with mesh found in"
731 message(2) = "'"//trim(restart%pwd)//"'."
732 end if
733 message(3) = "No restart information will be read."
734 call messages_warning(3, namespace=namespace)
735 ierr = 1
736 end if
737
738 ! Print some warnings in case the mesh is compatible, but changed.
739 if (grid_changed) then
740 if (grid_reordered) then
741 message(1) = "Info: Octopus is attempting to restart from a mesh with a different order of points."
742 else
743 message(1) = "Info: Octopus is attempting to restart from a different mesh."
744 end if
745 if (with_changed_grid) then
746 call messages_info(1, namespace=namespace)
747 else
748 message(2) = "This is disabled. To enable this, set RestartWithChangedGrid=True."
749 call messages_warning(2, namespace=namespace)
750 ierr = 1
751 end if
752 end if
753
754 if (exact_) then
755 restart%skip_ = grid_changed .and. .not. grid_reordered
756 if (restart%skip_) then
757 message(1) = "This calculation requires the exact same mesh to restart."
758 message(2) = "No restart information will be read from '"//trim(restart%pwd)//"'."
759 call messages_warning(2, namespace=namespace)
760 ierr = 1
761 end if
762 else
763 restart%skip_ = .false.
764 end if
765 end if
766 end select
767
768 ! Make sure all the processes have finished reading/writing all the grid information,
769 ! as there might be some subsequent calls to this function where that information will
770 ! be written/read to/from the same directory.
771 if (restart%mpi_grp%size > 1) then
772 call restart%mpi_grp%barrier()
773 end if
774
775 end if
776
777 pop_sub(restart_init)
778 end subroutine restart_init
779
780
781 subroutine restart_basic_end(restart)
782 class(restart_basic_t), intent(inout) :: restart
783
784 push_sub(restart_basic_end)
785
786 restart%type = 0
787 restart%data_type = 0
788 restart%skip_ = .true.
789
790 pop_sub(restart_basic_end)
791
792 end subroutine restart_basic_end
793
794 ! ---------------------------------------------------------
795 subroutine restart_end(restart)
796 class(restart_t), intent(inout) :: restart
797
798 push_sub(restart_end)
799
800 if (restart%mpi_grp%is_root() .and. .not. restart%skip_) then
801 select case (restart%type)
802 case (restart_type_load)
803 message(1) = "Info: Finished reading information "//trim(basic_info(restart%type)%tag)//" from '"//trim(restart%dir_)//"'."
804 call io_rm(trim(restart%pwd)//"/loading")
805 case (restart_type_dump)
806 call io_rm(trim(restart%pwd)//"/dumping")
807 message(1) = "Info: Finished writing information "//trim(basic_info(restart%type)%tag)//" to '"//trim(restart%dir_)//"'."
808 end select
809 call messages_info(1, namespace=restart%namespace)
810 end if
811
812 safe_deallocate_a(restart%map)
813 restart%has_mesh = .false.
814 nullify(restart%mc)
815
816 call restart_basic_end(restart)
817
818 pop_sub(restart_end)
819 end subroutine restart_end
820
821
822 ! ---------------------------------------------------------
829 function restart_basic_dir(restart)
830 class(restart_basic_t), intent(in) :: restart
831 character(len=MAX_PATH_LEN) :: restart_basic_dir
832
833 push_sub(restart_basic_dir)
834
835 restart_basic_dir = io_workpath(restart%pwd)
836
837 pop_sub(restart_basic_dir)
838 end function restart_basic_dir
839
840
841 ! ---------------------------------------------------------
844 subroutine restart_basic_open_dir(restart, dirname, ierr)
845 class(restart_basic_t), intent(inout) :: restart
846 character(len=*), intent(in) :: dirname
847 integer, intent(out) :: ierr
848
849 push_sub(restart_basic_open_dir)
850
851 assert(.not. restart%skip_)
852
853 ierr = 0
854
855 select case (restart%type)
856 case (restart_type_dump)
857 call restart_basic_mkdir(restart, dirname)
858 case (restart_type_load)
859 if (.not. loct_dir_exists(trim(restart%dir_)//"/"//trim(dirname))) then
860 ierr = 1
861 end if
862 end select
863
864 if (ierr == 0) then
865 if (index(dirname, '/', .true.) == len_trim(dirname)) then
866 restart%pwd = trim(restart%dir_)//"/"//dirname(1:len_trim(dirname)-1)
867 else
868 restart%pwd = trim(restart%dir_)//"/"//trim(dirname)
869 end if
870 end if
871
873 end subroutine restart_basic_open_dir
874
875
876 ! ---------------------------------------------------------
878 subroutine restart_basic_close_dir(restart)
879 class(restart_basic_t), intent(inout) :: restart
880
882
883 assert(.not. restart%skip_)
884
885 restart%pwd = restart%dir_
886
888 end subroutine restart_basic_close_dir
889
891 ! ---------------------------------------------------------
893 subroutine restart_basic_mkdir(restart, dirname)
894 class(restart_basic_t), intent(in) :: restart
895 character(len=*), intent(in) :: dirname
896
897 push_sub(restart_basic_mkdir)
898
899 assert(.not. restart%skip_)
900
901 assert(restart%type == restart_type_dump)
902
903 call io_mkdir(trim(restart%pwd)//"/"//trim(dirname), parents=.true.)
904
905 pop_sub(restart_basic_mkdir)
906 end subroutine restart_basic_mkdir
907
908
909 ! ---------------------------------------------------------
911 subroutine restart_basic_rm(restart, name)
912 class(restart_basic_t), intent(in) :: restart
913 character(len=*), intent(in) :: name
914
915 assert(.not. restart%skip_)
916 assert(restart%type == restart_type_dump)
917
918 push_sub(restart_basic_rm)
919
920 call io_rm(trim(restart%pwd)//"/"//trim(name))
921
922 pop_sub(restart_basic_rm)
923 end subroutine restart_basic_rm
925
926 ! ---------------------------------------------------------
933 function restart_basic_open(restart, filename, status, position, silent)
934 class(restart_basic_t), intent(in) :: restart
935 character(len=*), intent(in) :: filename
936 character(len=*), optional, intent(in) :: status
937 character(len=*), optional, intent(in) :: position
938 logical, optional, intent(in) :: silent
939 integer :: restart_basic_open
940
941 logical :: die
942 character(len=20) :: action, status_
943
944 push_sub(restart_basic_open)
945
946 assert(restart%initialized)
947 assert(.not. restart%skip_)
948
949 select case (restart%type)
950 case (restart_type_dump)
951 status_ = 'unknown'
952 action = 'write'
953 die = .true.
954
955 case (restart_type_load)
956 status_ = 'old'
957 action = 'read'
958 die = .false.
959
960 case default
961 message(1) = "Error in restart_basic_open: illegal restart type"
962 call messages_fatal(1)
963 end select
964
965 if (present(status)) status_ = status
966
967 restart_basic_open = io_open(trim(restart%pwd)//"/"//trim(filename), &
968 action=trim(action), status=trim(status_), &
969 die=die, position=position, form="formatted", grp=restart%mpi_grp)
970
971 if (restart_basic_open == -1 .and. .not. optional_default(silent, .false.)) then
972 message(1) = "Unable to open file '"//trim(restart%pwd)//"/"//trim(filename)//"'."
974 end if
975
976 pop_sub(restart_basic_open)
977 end function restart_basic_open
978
979
980 ! ---------------------------------------------------------
981 subroutine restart_basic_write(restart, iunit, lines, nlines, ierr)
982 class(restart_basic_t), intent(in) :: restart
983 integer, intent(in) :: iunit
984 character(len=*), intent(in) :: lines(:)
985 integer, intent(in) :: nlines
986 integer, intent(out) :: ierr
987
988 integer :: iline
989
990 push_sub(restart_basic_write)
991
992 if (iunit /= -1) then
993 ierr = 0
994 if (restart%mpi_grp%is_root()) then
995 do iline = 1, nlines
996 write(iunit,"(a)") trim(lines(iline))
997 end do
998 end if
999 else
1000 ierr = 1
1001 end if
1002
1003 pop_sub(restart_basic_write)
1004 end subroutine restart_basic_write
1005
1007 ! ---------------------------------------------------------
1008 subroutine restart_basic_read(restart, iunit, lines, nlines, ierr)
1009 class(restart_basic_t), intent(in) :: restart
1010 integer, intent(in) :: iunit
1011 character(len=*), intent(out) :: lines(:)
1012 integer, intent(in) :: nlines
1013 integer, intent(out) :: ierr
1014
1015 push_sub(restart_basic_read)
1016
1017 call iopar_read(restart%mpi_grp, iunit, lines, nlines, ierr)
1018
1019 pop_sub(restart_basic_read)
1020 end subroutine restart_basic_read
1021
1022
1023 ! ---------------------------------------------------------
1025 subroutine restart_basic_close(restart, iunit)
1026 class(restart_basic_t), intent(in) :: restart
1027 integer, intent(inout) :: iunit
1029 push_sub(restart_basic_close)
1030
1031 if (iunit /= -1) call io_close(iunit, restart%mpi_grp)
1032
1033 call restart%mpi_grp%barrier()
1034
1035 pop_sub(restart_basic_close)
1036 end subroutine restart_basic_close
1037
1038
1039 ! ---------------------------------------------------------
1044 logical pure function restart_basic_skip(restart)
1045 class(restart_basic_t), intent(in) :: restart
1046
1047 restart_basic_skip = restart%skip_ .or. restart%has_flag(restart_flag_skip)
1048
1049 end function restart_basic_skip
1050
1051
1052 ! ---------------------------------------------------------
1054 logical pure function restart_basic_has_flag(restart, flag)
1055 class(restart_basic_t), intent(in) :: restart
1056 integer, intent(in) :: flag
1057
1058 restart_basic_has_flag = bitand(restart%flags, flag) /= 0
1059
1060 end function restart_basic_has_flag
1061
1062
1063 ! ---------------------------------------------------------
1065 logical pure function restart_has_map(restart)
1066 class(restart_t), intent(in) :: restart
1067
1068 restart_has_map = allocated(restart%map)
1069
1070 end function restart_has_map
1071
1072
1074 integer pure function restart_basic_get_data_type(restart)
1075 class(restart_basic_t), intent(in) :: restart
1077 restart_basic_get_data_type = restart%data_type
1078 end function restart_basic_get_data_type
1079
1080 function restart_basic_get_info(restart) result(info)
1081 class(restart_basic_t), intent(in) :: restart
1082
1083 character(:), allocatable :: info
1084
1085 info = "restart_basic "//trim(basic_info(restart%data_type)%tag)//" "//type_string(restart%type)
1086
1087 end function restart_basic_get_info
1088
1089 function restart_get_info(restart) result(info)
1090 class(restart_t), intent(in) :: restart
1091
1092 character(:), allocatable :: info
1093
1094 info = "restart "//trim(basic_info(restart%data_type)%tag)//" "//type_string(restart%type)
1095
1096 end function restart_get_info
1097
1098#include "undef.F90"
1099#include "real.F90"
1100#include "restart_inc.F90"
1101
1102#include "undef.F90"
1103#include "complex.F90"
1104#include "restart_inc.F90"
1105
1106end module restart_oct_m
1107
1108
1109!! Local Variables:
1110!! mode: f90
1111!! coding: utf-8
1112!! End:
block signals while writing the restart files
Definition: restart.F90:318
unblock signals when writing restart is finished
Definition: restart.F90:325
This module implements batches of mesh functions.
Definition: batch.F90:135
This module handles the calculation mode.
character(len= *), parameter, public em_resp_fd_dir
Definition: global.F90:272
character(len= *), parameter, public gs_dir
Definition: global.F90:268
character(len= *), parameter, public iteration_dir
Definition: global.F90:280
character(len= *), parameter, public casida_dir
Definition: global.F90:276
character(len= *), parameter, public vib_modes_dir
Definition: global.F90:274
character(len= *), parameter, public partition_dir
Definition: global.F90:279
character(len= *), parameter, public kdotp_dir
Definition: global.F90:273
character(len= *), parameter, public em_resp_dir
Definition: global.F90:271
character(len= *), parameter, public td_dir
Definition: global.F90:269
character(len= *), parameter, public vdw_dir
Definition: global.F90:275
character(len= *), parameter, public oct_dir
Definition: global.F90:277
This module implements the index, used for the mesh points.
Definition: index.F90:124
subroutine, public index_dump(idx, np, dir, mpi_grp, namespace, ierr)
Definition: index.F90:311
Definition: io.F90:116
subroutine, public io_close(iunit, grp)
Definition: io.F90:467
subroutine, public iopar_read(grp, iunit, lines, n_lines, ierr)
Definition: io.F90:588
character(len=max_path_len) function, public io_workpath(path, namespace)
construct path name from given name and namespace
Definition: io.F90:318
subroutine, public io_rm(fname, namespace)
Definition: io.F90:392
character(len=max_path_len) function, public io_workdir()
construct working directory
Definition: io.F90:286
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:361
logical function, public io_dir_exists(dir, namespace)
Returns true if a dir with name 'dir' exists.
Definition: io.F90:579
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:402
System information (time, memory, sysname)
Definition: loct.F90:117
subroutine, public loct_rm(name)
Definition: loct.F90:318
logical function, public loct_dir_exists(dirname)
Definition: loct.F90:349
This module defines functions over batches of mesh functions.
Definition: mesh_batch.F90:118
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
subroutine, public mesh_check_dump_compatibility(mesh, dir, filename, namespace, mpi_grp, grid_changed, grid_reordered, map, ierr)
Definition: mesh.F90:596
subroutine, public mesh_write_fingerprint(mesh, dir, filename, mpi_grp, namespace, ierr)
Definition: mesh.F90:460
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:524
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:999
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:161
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:409
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:690
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:593
type(mpi_comm), parameter, public mpi_comm_undefined
used to indicate a communicator has not been initialized
Definition: mpi.F90:138
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:272
subroutine mpi_grp_init(grp, comm)
Initialize MPI group instance.
Definition: mpi.F90:341
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:147
type(namespace_t), public global_namespace
Definition: namespace.F90:135
Some general things and nomenclature:
Definition: par_vec.F90:173
character(len=:) function, allocatable, public parse_get_full_name(namespace, varname)
Given a namespace and a variable name, this function will iterate over all namespace ancestors contai...
Definition: parser.F90:773
subroutine, public parse_block_string(blk, l, c, res, convert_to_c)
Definition: parser.F90:810
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:615
subroutine zrestart_write_binary3_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2386
subroutine drestart_write_binary1_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1718
subroutine drestart_read_binary3(restart, filename, np, ff, ierr)
Definition: restart.F90:1664
logical pure function restart_has_map(restart)
Returns true if the restart was from a different order of mesh points.
Definition: restart.F90:1161
integer, parameter, public restart_partition
Definition: restart.F90:156
integer, parameter, public restart_custom
Definition: restart.F90:156
subroutine drestart_write_binary5(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1566
subroutine restart_basic_end(restart)
Definition: restart.F90:877
subroutine restart_basic_open_dir(restart, dirname, ierr)
Change the restart directory to dirname, where "dirname" is a subdirectory of the base restart direct...
Definition: restart.F90:940
subroutine restart_basic_mkdir(restart, dirname)
Make directory "dirname" inside the current restart directory.
Definition: restart.F90:989
subroutine zrestart_write_mesh_function(restart, filename, mesh, ff, ierr, root)
Definition: restart.F90:1903
integer, parameter, public restart_all
Definition: restart.F90:156
subroutine restart_basic_close(restart, iunit)
Close a file previously opened with restart_basic_open.
Definition: restart.F90:1121
subroutine drestart_read_binary1(restart, filename, np, ff, ierr)
Definition: restart.F90:1608
subroutine restart_basic_close_dir(restart)
Change back to the base directory. To be called after restart_basic_open_dir.
Definition: restart.F90:974
subroutine zrestart_write_binary1(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2080
integer, parameter, public restart_casida
Definition: restart.F90:156
subroutine zrestart_write_binary5_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2400
logical function, public clean_stop(comm)
returns true if a file named stop exists
Definition: restart.F90:335
subroutine zrestart_read_binary5_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:2455
integer, parameter, public restart_kdotp
Definition: restart.F90:156
subroutine zrestart_read_binary3(restart, filename, np, ff, ierr)
Definition: restart.F90:2304
integer, parameter, public restart_oct
Definition: restart.F90:156
subroutine drestart_read_binary3_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:1802
type(restart_basic_data_t), dimension(restart_undefined:restart_n_data_types), parameter basic_info
Information about the components for a given system.
Definition: restart.F90:296
subroutine zrestart_read_binary3_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:2442
subroutine drestart_read_binary2(restart, filename, np, ff, ierr)
Definition: restart.F90:1636
integer, parameter, public restart_gs
Definition: restart.F90:156
subroutine zrestart_read_binary1_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:2414
integer, parameter, public restart_iteration
Definition: restart.F90:156
subroutine drestart_write_binary3(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1524
integer, parameter, public restart_flag_mix
Definition: restart.F90:188
subroutine drestart_write_binary3_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1746
subroutine zrestart_write_binary1_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2358
subroutine restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
Initializes a specific restart object.
Definition: restart.F90:707
integer function restart_basic_open(restart, filename, status, position, silent)
Open file "filename" found inside the current restart directory. Depending on the type of restart,...
Definition: restart.F90:1029
integer, parameter, public restart_flag_skip
Definition: restart.F90:188
integer, parameter, public restart_em_resp_fd
Definition: restart.F90:156
subroutine drestart_read_binary2_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:1788
subroutine drestart_write_binary5_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1760
subroutine restart_basic_rm(restart, name)
Remove directory or file "name" that is located inside the current restart directory.
Definition: restart.F90:1007
subroutine restart_end(restart)
Definition: restart.F90:891
integer, parameter, public restart_proj
Definition: restart.F90:156
subroutine zrestart_read_binary1(restart, filename, np, ff, ierr)
Definition: restart.F90:2248
integer, parameter, public restart_flag_rho
Definition: restart.F90:188
integer, parameter, public restart_em_resp
Definition: restart.F90:156
integer, parameter, public restart_vib_modes
Definition: restart.F90:156
subroutine drestart_write_binary1(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1440
subroutine drestart_read_binary1_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:1774
subroutine zrestart_write_binary5(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2206
integer, parameter, public restart_flag_vhxc
Definition: restart.F90:188
logical pure function restart_basic_has_flag(restart, flag)
Returns true if...
Definition: restart.F90:1150
subroutine restart_basic_write(restart, iunit, lines, nlines, ierr)
Definition: restart.F90:1077
integer, parameter, public restart_flag_literal
Definition: restart.F90:188
subroutine drestart_read_binary5_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:1815
subroutine drestart_write_binary2(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1482
subroutine drestart_read_binary5(restart, filename, np, ff, ierr)
Definition: restart.F90:1691
character(len=max_path_len) function restart_basic_dir(restart)
Returns the name of the directory containing the restart information. The use of this function should...
Definition: restart.F90:925
subroutine zrestart_write_binary2_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2372
character(len=4), dimension(2), parameter type_string
Definition: restart.F90:206
subroutine drestart_write_mesh_function(restart, filename, mesh, ff, ierr, root)
Definition: restart.F90:1263
logical pure function restart_basic_skip(restart)
Returns true if the restart information should neither be read nor written. This might happen because...
Definition: restart.F90:1140
integer, parameter, public restart_td
Definition: restart.F90:156
integer, parameter, public restart_type_load
Definition: restart.F90:183
character(:) function, allocatable restart_basic_get_info(restart)
Definition: restart.F90:1176
subroutine restart_basic_read(restart, iunit, lines, nlines, ierr)
Definition: restart.F90:1104
subroutine zrestart_read_binary2(restart, filename, np, ff, ierr)
Definition: restart.F90:2276
integer pure function restart_basic_get_data_type(restart)
Returns the data type of the restart.
Definition: restart.F90:1170
integer, parameter, public restart_vdw
Definition: restart.F90:156
subroutine zrestart_read_binary5(restart, filename, np, ff, ierr)
Definition: restart.F90:2331
subroutine zrestart_write_binary2(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2122
integer, parameter, public restart_unocc
Definition: restart.F90:156
subroutine zrestart_write_binary3(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2164
subroutine zrestart_read_binary2_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:2428
logical function restart_basic_do_i_write(restart)
Definition: restart.F90:693
character(:) function, allocatable restart_get_info(restart)
Definition: restart.F90:1185
subroutine restart_basic_init(restart, namespace, data_type, type, ierr, dir)
Definition: restart.F90:367
subroutine drestart_write_binary2_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1732
subroutine, public add_last_slash(str)
Adds a '/' in the end of the string, only if it missing. Useful for directories.
Definition: string.F90:163
This module defines the unit system, used for input and output.
Describes mesh distribution to nodes.
Definition: mesh.F90:187
Stores all communicators and groups.
Definition: multicomm.F90:208
restart_basic_data_t stores global information about a specific component we want to save....
Definition: restart.F90:198
restart_basic_t stores the basic information about a restart object.
Definition: restart.F90:216
int true(void)