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!!
5!! This program is free software; you can redistribute it and/or modify
6!! it under the terms of the GNU General Public License as published by
7!! the Free Software Foundation; either version 2, or (at your option)
8!! any later version.
9!!
10!! This program is distributed in the hope that it will be useful,
11!! but WITHOUT ANY WARRANTY; without even the implied warranty of
12!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13!! GNU General Public License for more details.
14!!
15!! You should have received a copy of the GNU General Public License
16!! along with this program; if not, write to the Free Software
17!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18!! 02110-1301, USA.
19!!
20
21#include "global.h"
22
23module restart_oct_m
24 use batch_oct_m
26 use debug_oct_m
27 use global_oct_m
28 use index_oct_m
29 use io_oct_m
31 use loct_oct_m
32 use mesh_oct_m
35 use mpi_oct_m
38 use parser_oct_m
41 use space_oct_m
43
44 implicit none
45
46 private
47 public :: &
48 restart_t, &
49 clean_stop, &
57 restart_rm, &
74
75 interface drestart_write_binary
79 end interface drestart_write_binary
80
81 interface zrestart_write_binary
85 end interface zrestart_write_binary
86
87 interface drestart_read_binary
91 end interface drestart_read_binary
92
93 interface zrestart_read_binary
97 end interface zrestart_read_binary
98
101 end interface restart_read_mesh_function
102
105 end interface restart_write_mesh_function
106
107 type restart_t
108 private
109 integer :: data_type
110 integer :: type
111 logical :: skip
112 character(len=MAX_PATH_LEN) :: dir
113 character(len=MAX_PATH_LEN) :: pwd
115 type(namespace_t), pointer, public :: namespace
116 type(mpi_grp_t) :: mpi_grp
117 type(multicomm_t), pointer :: mc
118 logical :: has_mesh
119 integer(int64), allocatable :: map(:)
120 end type restart_t
121
122
123 type restart_data_t
124 private
125 character(len=20) :: tag
126 character(len=MAX_PATH_LEN) :: basedir
127 character(len=MAX_PATH_LEN) :: dir
128 integer :: flags
129 end type restart_data_t
130
131
132 integer, parameter, public :: &
133 RESTART_TYPE_DUMP = 1, &
135
136 integer, parameter, public :: &
137 RESTART_UNDEFINED = -1, &
138 restart_all = 0, &
139 restart_gs = 1, &
140 restart_unocc = 2, &
141 restart_td = 3, &
142 restart_em_resp = 4, &
143 restart_em_resp_fd = 5, &
144 restart_kdotp = 6, &
145 restart_vib_modes = 7, &
146 restart_vdw = 8, &
147 restart_casida = 9, &
148 restart_oct = 10, &
149 restart_partition = 11, &
150 restart_proj = 12
151
152 integer, parameter :: RESTART_N_DATA_TYPES = 12
153
154 integer, parameter, public :: &
155 RESTART_FLAG_STATES = 1, &
156 restart_flag_rho = 2, &
157 restart_flag_vhxc = 4, &
158 restart_flag_mix = 8, &
160
161 type(restart_data_t) :: info(RESTART_N_DATA_TYPES)
162
163
165 interface restart_block_signals
166 subroutine block_signals()
167 implicit none
168 end subroutine block_signals
169 end interface restart_block_signals
170
172 subroutine unblock_signals()
173 implicit none
174 end subroutine unblock_signals
175 end interface
176
177contains
178
180 function clean_stop(comm)
181 type(MPI_Comm), intent(in) :: comm
182
183 logical :: clean_stop, file_exists
184
185 push_sub(clean_stop)
187 clean_stop = .false.
188
189 if (mpi_grp_is_root(mpi_world)) then
190 inquire(file='stop', exist=file_exists)
191 if (file_exists) then
192 call loct_rm('stop')
193 clean_stop = .true.
194 end if
195 end if
197#ifdef HAVE_MPI
198 ! make sure all nodes agree on whether this condition occurred
199 call mpi_bcast(clean_stop, 1, mpi_logical, 0, comm, mpi_err)
200#endif
201
202 if (clean_stop) then
203 message(1) = 'Clean STOP'
205 end if
207 pop_sub(clean_stop)
208 end function clean_stop
211 ! ---------------------------------------------------------
212 subroutine restart_module_init(namespace)
213 type(namespace_t), intent(in) :: namespace
214
215 logical :: set(restart_n_data_types)
216 integer :: iline, n_cols, data_type
217 character(len=MAX_PATH_LEN) :: default_basedir
218 type(block_t) :: blk
222 ! Each data type should have a tag
223 info(restart_gs)%tag = "Ground-state"
224 info(restart_unocc)%tag = "Unoccupied states"
225 info(restart_td)%tag = "Time-dependent"
226 info(restart_em_resp)%tag = "EM Resp."
227 info(restart_em_resp_fd)%tag = "EM Resp. FD"
228 info(restart_kdotp)%tag = "KdotP"
229 info(restart_vib_modes)%tag = "Vib. Modes"
230 info(restart_vdw)%tag = "VdW"
231 info(restart_casida)%tag = "Casida"
232 info(restart_oct)%tag = "Optimal Control"
233 info(restart_proj)%tag = "GS for TDOutput"
234 info(restart_partition)%tag = "Mesh Partition"
235
236 ! Default flags and directories (flags not yet used)
237 info(:)%basedir = 'restart'
238 info(:)%flags = 0
240
241 info(restart_gs)%dir = gs_dir
242 info(restart_unocc)%dir = gs_dir
243 info(restart_td)%dir = td_dir
244 info(restart_em_resp)%dir = em_resp_dir
246 info(restart_kdotp)%dir = kdotp_dir
248 info(restart_vdw)%dir = vdw_dir
249 info(restart_casida)%dir = casida_dir
250 info(restart_oct)%dir = oct_dir
251 info(restart_proj)%dir = gs_dir
253
254 ! Read input
255 call messages_obsolete_variable(namespace, 'RestartFileFormat', 'RestartOptions')
256 call messages_obsolete_variable(namespace, 'TmpDir', 'RestartOptions')
257 call messages_obsolete_variable(namespace, 'RestartDir', 'RestartOptions')
258 call messages_obsolete_variable(namespace, 'MeshPartitionRead', 'RestartOptions')
259 call messages_obsolete_variable(namespace, 'MeshPartitionWrite', 'RestartOptions')
260 call messages_obsolete_variable(namespace, 'MeshPartitionDir', 'RestartOptions')
261
262 !%Variable RestartOptions
263 !%Type block
264 !%Section Execution::IO
265 !%Description
266 !% <tt>Octopus</tt> usually stores binary information, such as the wavefunctions, to be used
267 !% in subsequent calculations. The most common example is the ground-state states
268 !% that are used to start a time-dependent calculation. This variable allows to control
269 !% where this information is written to or read from. The format of this block is the following:
270 !% for each line, the first column indicates the type of data, the second column indicates
271 !% the path to the directory that should be used to read and write that restart information, and the
272 !% third column, which is optional, allows one to set some flags to modify the way how the data
273 !% is read or written. For example, if you are running a time-dependent calculation, you can
274 !% indicate where <tt>Octopus</tt> can find the ground-state information in the following way:
275 !%
276 !% <tt>%RestartOptions
277 !% <br>&nbsp;&nbsp;restart_gs | "gs_restart"
278 !% <br>&nbsp;&nbsp;restart_td | "td_restart"
279 !% <br>%</tt>
280 !%
281 !% The second line of the above example also tells <tt>Octopus</tt> that the time-dependent restart data
282 !% should be read from and written to the "td_restart" directory.
283 !%
284 !% In case you want to change the path of all the restart directories, you can use the <tt>restart_all</tt> option.
285 !% When using the <tt>restart_all</tt> option, it is still possible to have a different restart directory for specific
286 !% data types. For example, when including the following block in your input file:
287 !%
288 !% <tt>%RestartOptions
289 !% <br>&nbsp;&nbsp;restart_all | "my_restart"
290 !% <br>&nbsp;&nbsp;restart_td&nbsp; | "td_restart"
291 !% <br>%</tt>
292 !%
293 !% the time-dependent restart information will be stored in the "td_restart" directory, while all the remaining
294 !% restart information will be stored in the "my_restart" directory.
295 !%
296 !% By default, the name of the "restart_all" directory is set to "restart".
297 !%
298 !% Some <tt>CalculationMode</tt>s also take into account specific flags set in the third column of the <tt>RestartOptions</tt>
299 !% block. These are used to determine if some specific part of the restart data is to be taken into account
300 !% or not when reading the restart information. For example, when restarting a ground-state calculation, one can
301 !% set the <tt>restart_rho</tt> flags, so that the density used is not built from the saved wavefunctions, but is
302 !% instead read from the restart directory. In this case, the block should look like this:
303 !%
304 !% <tt>%RestartOptions
305 !% <br>&nbsp;&nbsp;restart_gs | "restart" | restart_rho
306 !% <br>%</tt>
307 !%
308 !% A list of available flags is given below, but note that the code might ignore some of them, which will happen if they
309 !% are not available for that particular calculation, or might assume some of them always present, which will happen
310 !% in case they are mandatory.
311 !%
312 !% Finally, note that all the restart information of a given data type is always stored in a subdirectory of the
313 !% specified path. The name of this subdirectory is fixed and cannot be changed. For example, ground-state information
314 !% will always be stored in a subdirectory named "gs". This makes it safe in most situations to use the same path for
315 !% all the data types. The name of these subdirectories is indicated in the description of the data types below.
316 !%
317 !% Currently, the available restart data types and flags are the following:
318 !%Option restart_all 0
319 !% (data type)
320 !% Option to globally change the path of all the restart information.
321 !%Option restart_gs 1
322 !% (data type)
323 !% The data resulting from a ground-state calculation.
324 !% This information is stored under the "gs" subdirectory.
325 !%Option restart_unocc 2
326 !% (data type)
327 !% The data resulting from an unoccupied states calculation. This information also corresponds to a ground state and
328 !% can be used as such, so it is stored under the same subdirectory as the one of restart_gs.
329 !%Option restart_td 3
330 !% (data type)
331 !% The data resulting from a real-time time-dependent calculation.
332 !% This information is stored under the "td" subdirectory.
333 !%Option restart_em_resp 4
334 !% (data type)
335 !% The data resulting from the calculation of the electromagnetic response using the Sternheimer approach.
336 !% This information is stored under the "em_resp" subdirectory.
337 !%Option restart_em_resp_fd 5
338 !% (data type)
339 !% The data resulting from the calculation of the electromagnetic response using finite-differences.
340 !% This information is stored under the "em_resp_fd" subdirectory.
341 !%Option restart_kdotp 6
342 !% (data type)
343 !% The data resulting from the calculation of effective masses by k.p perturbation theory.
344 !% This information is stored under the "kdotp" subdirectory.
345 !%Option restart_vib_modes 7
346 !% (data type)
347 !% The data resulting from the calculation of vibrational modes.
348 !% This information is stored under the "vib_modes" subdirectory.
349 !%Option restart_vdw 8
350 !% (data type)
351 !% The data resulting from the calculation of van der Waals coefficients.
352 !% This information is stored under the "vdw" subdirectory.
353 !%Option restart_casida 9
354 !% (data type)
355 !% The data resulting from a Casida calculation.
356 !% This information is stored under the "casida" subdirectory.
357 !%Option restart_oct 10
358 !% (data type)
359 !% The data for optimal control calculations.
360 !% This information is stored under the "opt-control" subdirectory.
361 !%Option restart_partition 11
362 !% (data type)
363 !% The data for the mesh partitioning.
364 !% This information is stored under the "partition" subdirectory.
365 !%Option restart_proj 12
366 !% (data type)
367 !% The ground-state to be used with the td_occup and populations options of <tt>TDOutput</tt>.
368 !% This information should be a ground state, so the "gs" subdirectory is used.
369 !%Option restart_states 1
370 !% (flag)
371 !% Read the electronic states. (not yet implemented)
372 !%Option restart_rho 2
373 !% (flag)
374 !% Read the electronic density.
375 !%Option restart_vhxc 4
376 !% (flag)
377 !% Read the Hartree and XC potentials.
378 !%Option restart_mix 8
379 !% (flag)
380 !% Read the SCF mixing information.
381 !%Option restart_skip 16
382 !% (flag)
383 !% This flag allows to selectively skip the reading and writting of specific restart information.
384 !%End
385 set = .false.
386 if (parse_block(namespace, 'RestartOptions', blk) == 0) then
387
388 default_basedir = 'restart'
389
390 do iline = 1, parse_block_n(blk)
391 n_cols = parse_block_cols(blk,iline-1)
392
393 call parse_block_integer(blk, iline-1, 0, data_type)
394 if (data_type < 0 .or. data_type > restart_n_data_types) then
395 call messages_input_error(namespace, 'RestartOptions', "Invalid data type", row=iline-1, column=0)
396 end if
397 if (data_type == 0) then
398 call parse_block_string(blk, iline-1, 1, default_basedir)
399 else
400 set(data_type) = .true.
401 call parse_block_string(blk, iline-1, 1, info(data_type)%basedir)
402
403 if (n_cols > 2) call parse_block_integer(blk, iline-1, 2, info(data_type)%flags)
404 end if
405
406 end do
407 call parse_block_end(blk)
408
409 where (.not. set)
410 info(:)%basedir = default_basedir
411 end where
412 end if
413
414 pop_sub(restart_module_init)
415 end subroutine restart_module_init
416
417
418 ! ---------------------------------------------------------
420 subroutine restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
421 type(restart_t), intent(out) :: restart
422 type(namespace_t), target, intent(in) :: namespace
423 integer, intent(in) :: data_type
424 integer, intent(in) :: type
426 type(multicomm_t), target, intent(in) :: mc
427 integer, intent(out) :: ierr
428 class(mesh_t), optional, intent(in) :: mesh
430 character(len=*), optional, intent(in) :: dir
432 logical, optional, intent(in) :: exact
434
435 logical :: grid_changed, grid_reordered, restart_write, dir_exists
436 character(len=20) :: tag
437 character(len=MAX_PATH_LEN) :: basedir, dirname
438
439 push_sub(restart_init)
440
441 ierr = 0
442
443 ! Sanity checks
444 if (present(exact) .and. .not. present(mesh)) then
445 message(1) = "Error in restart_init: the 'exact' optional argument requires a mesh."
446 call messages_fatal(1, namespace=namespace)
447 end if
448
449 restart%has_mesh = present(mesh)
450
451 ! Some initializations
452 restart%type = type
453 restart%mc => mc
454 call mpi_grp_init(restart%mpi_grp, mc%master_comm)
455 if (data_type < restart_undefined .and. data_type > restart_n_data_types) then
456 message(1) = "Illegal data_type in restart_init"
457 call messages_fatal(1, namespace=namespace)
458 end if
459 restart%data_type = data_type
460 restart%namespace => namespace
461
462 select case (restart%type)
463 case (restart_type_dump)
464 !%Variable RestartWrite
465 !%Type logical
466 !%Default true
467 !%Section Execution::IO
468 !%Description
469 !% If this variable is set to no, restart information is not
470 !% written. Note that some run modes will ignore this
471 !% option and write some restart information anyway.
472 !%End
473
474 call parse_variable(namespace, 'RestartWrite', .true., restart_write)
475 restart%skip = .not. restart_write
476
477 if (restart%skip) then
478 message(1) = 'Restart information will not be written.'
479 call messages_warning(1, namespace=namespace)
480 end if
481
482 case (restart_type_load)
483 ! This is set to true as an error condition, checked by assertions in some routines.
484 restart%skip = .false.
485
486 case default
487 message(1) = "Unknown restart type in restart_init"
488 call messages_fatal(1, namespace=namespace)
489 end select
490
491
492 ! If the restart data type is not defined, the directories should be set explicitly
493 if (restart%data_type == restart_undefined) then
494 assert(present(dir))
495 basedir = dir
496 dirname = ""
497 else
498 basedir = info(restart%data_type)%basedir
499 if (index(basedir, '/', .true.) /= len_trim(basedir)) then
500 basedir = trim(basedir)//"/"
501 end if
502 dirname = info(restart%data_type)%dir
503 end if
504
505 ! Set final path
506 restart%dir = trim(basedir)//trim(dirname)
507 ! Remove any trailing "/" from the path (all the routines from this module should add the trailing "/" when needed)
508 if (index(restart%dir, '/', .true.) == len_trim(restart%dir)) then
509 restart%dir = restart%dir(1:len_trim(restart%dir)-1)
510 end if
511
512 ! Set initial path to the working directory
513 restart%pwd = restart%dir
514 ! Check if the directory already exists and create it if necessary
515 if (mpi_grp_is_root(restart%mpi_grp)) then
516 dir_exists = io_dir_exists(trim(restart%pwd), namespace)
517 if (restart%type == restart_type_dump .and. .not. dir_exists) then
518 call io_mkdir(trim(restart%pwd), namespace, parents=.true.)
519 end if
520 end if
521 if (restart%mpi_grp%size > 1) then
522 call restart%mpi_grp%bcast(dir_exists, 1, mpi_logical, 0)
523 end if
524
525 if (restart%data_type == restart_undefined) then
526 tag = "Some "
527 else
528 tag = info(data_type)%tag
529 end if
530
531 select case (restart%type)
532 case (restart_type_dump)
533 if (.not. restart%skip) then
534 message(1) = "Info: "//trim(tag)//" restart information will be written to '"//trim(restart%pwd)//"'."
535 call messages_info(1, namespace=namespace)
536
537 ! Dump the grid information. The main parameters of the grid should not change
538 ! during the calculation, so we should only need to dump it once.
539 if (present(mesh)) then
540 call index_dump(mesh%idx, mesh%np_part_global, restart%pwd, restart%mpi_grp, &
541 restart%namespace, ierr)
542 if (ierr /= 0) then
543 message(1) = "Unable to write index map to '"//trim(restart%pwd)//"'."
544 call messages_fatal(1, namespace=namespace)
545 end if
546
547 call mesh_write_fingerprint(mesh, restart%pwd, "grid", restart%mpi_grp, namespace, ierr)
548 if (ierr /= 0) then
549 message(1) = "Unable to write mesh fingerprint to '"//trim(restart%pwd)//"/grid'."
550 call messages_fatal(1, namespace=namespace)
551 end if
552 end if
553
554 end if
555
556 case (restart_type_load)
557 if (.not. dir_exists) then
558 ierr = 1
559 restart%skip = .true.
560
561 message(1) = "Info: Could not find '"//trim(restart%pwd)//"' directory for restart."
562 message(2) = "Info: No restart information will be read."
563 call messages_info(2, namespace=namespace)
564
565 else
566 message(1) = "Info: "//trim(tag)//" restart information will be read from '"//trim(restart%pwd)//"'."
567 call messages_info(1, namespace=namespace)
568
569 if (present(mesh)) then
570 call mesh_check_dump_compatibility(mesh, restart%pwd, "grid", restart%namespace, &
571 restart%mpi_grp, grid_changed, grid_reordered, restart%map, ierr)
572
573 ! Check whether an error occurred. In this case we cannot read.
574 if (ierr /= 0) then
575 if (ierr == -1) then
576 message(1) = "Unable to check mesh compatibility: unable to read mesh fingerprint"
577 message(2) = "in '"//trim(restart%pwd)//"'."
578 else if (ierr > 0) then
579 message(1) = "Mesh from current calculation is not compatible with mesh found in"
580 message(2) = "'"//trim(restart%pwd)//"'."
581 end if
582 message(3) = "No restart information will be read."
583 call messages_warning(3, namespace=namespace)
584 ierr = 1
585 end if
586
587 ! Print some warnings in case the mesh is compatible, but changed.
588 if (grid_changed) then
589 if (grid_reordered) then
590 message(1) = "Info: Octopus is attempting to restart from a mesh with a different order of points."
591 else
592 message(1) = "Info: Octopus is attempting to restart from a different mesh."
593 end if
594 call messages_info(1, namespace=namespace)
595 end if
596
597 if (present(exact)) then
598 restart%skip = grid_changed .and. .not. grid_reordered .and. exact
599 if (restart%skip) then
600 message(1) = "This calculation requires the exact same mesh to restart."
601 message(2) = "No restart information will be read from '"//trim(restart%pwd)//"'."
602 call messages_warning(2, namespace=namespace)
603 ierr = 1
604 end if
605 else
606 restart%skip = .false.
607 end if
608 end if
609 end if
610
611 end select
612
613
614 ! Make sure all the processes have finished reading/writing all the grid information,
615 ! as there might be some subsequent calls to this function where that information will
616 ! be written/read to/from the same directory.
617 if (restart%mpi_grp%size > 1) then
618 call restart%mpi_grp%barrier()
619 end if
620
621 pop_sub(restart_init)
622 end subroutine restart_init
623
624
625 ! ---------------------------------------------------------
626 subroutine restart_end(restart)
627 type(restart_t), intent(inout) :: restart
628
629 push_sub(restart_end)
630
631 if (mpi_grp_is_root(restart%mpi_grp) .and. .not. restart%skip) then
632 select case (restart%type)
633 case (restart_type_load)
634 message(1) = "Info: Finished reading information from '"//trim(restart%dir)//"'."
635 call io_rm(trim(restart%pwd)//"/loading", restart%namespace)
636 case (restart_type_dump)
637 call io_rm(trim(restart%pwd)//"/dumping", restart%namespace)
638 message(1) = "Info: Finished writing information to '"//trim(restart%dir)//"'."
639 end select
640 call messages_info(1, namespace=restart%namespace)
641 end if
642
643 restart%type = 0
644 restart%data_type = 0
645 restart%skip = .true.
646 safe_deallocate_a(restart%map)
647 restart%has_mesh = .false.
648 nullify(restart%mc)
649
650 pop_sub(restart_end)
651 end subroutine restart_end
652
653
654 ! ---------------------------------------------------------
661 function restart_dir(restart)
662 type(restart_t), intent(in) :: restart
663 character(len=MAX_PATH_LEN) :: restart_dir
664
665 push_sub(restart_dir)
666
667 restart_dir = io_workpath(restart%pwd, restart%namespace)
668
669 pop_sub(restart_dir)
670 end function restart_dir
671
672
673 ! ---------------------------------------------------------
676 subroutine restart_open_dir(restart, dirname, ierr)
677 type(restart_t), intent(inout) :: restart
678 character(len=*), intent(in) :: dirname
679 integer, intent(out) :: ierr
680
681 push_sub(restart_open_dir)
682
683 assert(.not. restart%skip)
684
685 ierr = 0
686
687 select case (restart%type)
688 case (restart_type_dump)
689 call restart_mkdir(restart, dirname)
690 case (restart_type_load)
691 if (.not. loct_dir_exists(trim(restart%dir)//"/"//trim(dirname))) then
692 ierr = 1
693 end if
694 end select
695
696 if (ierr == 0) then
697 if (index(dirname, '/', .true.) == len_trim(dirname)) then
698 restart%pwd = trim(restart%dir)//"/"//dirname(1:len_trim(dirname)-1)
699 else
700 restart%pwd = trim(restart%dir)//"/"//trim(dirname)
701 end if
702 end if
703
704 pop_sub(restart_open_dir)
705 end subroutine restart_open_dir
706
707
708 ! ---------------------------------------------------------
710 subroutine restart_close_dir(restart)
711 type(restart_t), intent(inout) :: restart
712
713 push_sub(restart_close_dir)
714
715 assert(.not. restart%skip)
716
717 restart%pwd = restart%dir
718
720 end subroutine restart_close_dir
721
722
723 ! ---------------------------------------------------------
725 subroutine restart_mkdir(restart, dirname)
726 type(restart_t), intent(in) :: restart
727 character(len=*), intent(in) :: dirname
728
729 push_sub(restart_mkdir)
730
731 assert(.not. restart%skip)
732
733 assert(restart%type == restart_type_dump)
734
735 call io_mkdir(trim(restart%pwd)//"/"//trim(dirname), restart%namespace, parents=.true.)
736
737 pop_sub(restart_mkdir)
738 end subroutine restart_mkdir
739
740
741 ! ---------------------------------------------------------
743 subroutine restart_rm(restart, name)
744 type(restart_t), intent(in) :: restart
745 character(len=*), intent(in) :: name
746
747 assert(.not. restart%skip)
748 assert(restart%type == restart_type_dump)
749
750 push_sub(restart_rm)
751
752 call io_rm(trim(restart%pwd)//"/"//trim(name), restart%namespace)
753
754 pop_sub(restart_rm)
755 end subroutine restart_rm
756
757
758 ! ---------------------------------------------------------
765 function restart_open(restart, filename, status, position, silent)
766 type(restart_t), intent(in) :: restart
767 character(len=*), intent(in) :: filename
768 character(len=*), optional, intent(in) :: status
769 character(len=*), optional, intent(in) :: position
770 logical, optional, intent(in) :: silent
771 integer :: restart_open
772
773 logical :: die
774 character(len=20) :: action, status_
775
776 push_sub(restart_open)
777
778 assert(.not. restart%skip)
779
780 select case (restart%type)
781 case (restart_type_dump)
782 status_ = 'unknown'
783 action = 'write'
784 die = .true.
785
786 case (restart_type_load)
787 status_ = 'old'
788 action = 'read'
789 die = .false.
790
791 case default
792 message(1) = "Error in restart_open: illegal restart type"
793 call messages_fatal(1)
794 end select
795
796 if (present(status)) status_ = status
797
798 restart_open = io_open(trim(restart%pwd)//"/"//trim(filename), restart%namespace, &
799 action=trim(action), status=trim(status_), &
800 die=die, position=position, form="formatted", grp=restart%mpi_grp)
801
802 if (restart_open < 0 .and. .not. optional_default(silent, .false.)) then
803 message(1) = "Unable to open file '"//trim(restart%pwd)//"/"//trim(filename)//"'."
804 call messages_warning(1)
805 end if
806
807 pop_sub(restart_open)
808 end function restart_open
809
810
811 ! ---------------------------------------------------------
812 subroutine restart_write(restart, iunit, lines, nlines, ierr)
813 type(restart_t), intent(in) :: restart
814 integer, intent(in) :: iunit
815 character(len=*), intent(in) :: lines(:)
816 integer, intent(in) :: nlines
817 integer, intent(out) :: ierr
819 integer :: iline
820
821 push_sub(restart_write)
822
823 if (iunit > 0) then
824 ierr = 0
825 if (mpi_grp_is_root(restart%mpi_grp)) then
826 do iline = 1, nlines
827 write(iunit,"(a)") trim(lines(iline))
828 end do
829 end if
830 else
831 ierr = 1
832 end if
833
834 pop_sub(restart_write)
835 end subroutine restart_write
837
838 ! ---------------------------------------------------------
839 subroutine restart_read(restart, iunit, lines, nlines, ierr)
840 type(restart_t), intent(in) :: restart
841 integer, intent(in) :: iunit
842 character(len=*), intent(out) :: lines(:)
843 integer, intent(in) :: nlines
844 integer, intent(out) :: ierr
845
846 push_sub(restart_read)
847
848 call iopar_read(restart%mpi_grp, iunit, lines, nlines, ierr)
849
850 pop_sub(restart_read)
851 end subroutine restart_read
852
853
854 ! ---------------------------------------------------------
856 subroutine restart_close(restart, iunit)
857 type(restart_t), intent(in) :: restart
858 integer, intent(inout) :: iunit
859
860 push_sub(restart_close)
861
862 if (iunit > 0) call io_close(iunit, restart%mpi_grp)
863
864 pop_sub(restart_close)
865 end subroutine restart_close
866
867
868 ! ---------------------------------------------------------
873 logical pure function restart_skip(restart)
874 type(restart_t), intent(in) :: restart
875
876 restart_skip = restart%skip .or. restart_has_flag(restart, restart_flag_skip)
877
878 end function restart_skip
879
880
881 ! ---------------------------------------------------------
883 logical pure function restart_has_flag(restart, flag)
884 type(restart_t), intent(in) :: restart
885 integer, intent(in) :: flag
886
887 restart_has_flag = bitand(info(restart%data_type)%flags, flag) /= 0
888
889 end function restart_has_flag
890
891
892 ! ---------------------------------------------------------
894 logical pure function restart_has_map(restart)
895 type(restart_t), intent(in) :: restart
896
897 restart_has_map = allocated(restart%map)
898
899 end function restart_has_map
900
901
902 ! ---------------------------------------------------------
904 logical pure function restart_are_basedirs_equal(type1, type2)
905 integer, intent(in) :: type1
906 integer, intent(in) :: type2
907
908 restart_are_basedirs_equal = trim(info(type1)%basedir) == trim(info(type2)%basedir)
909
910 end function restart_are_basedirs_equal
911
912
913#include "undef.F90"
914#include "real.F90"
915#include "restart_inc.F90"
916
917#include "undef.F90"
918#include "complex.F90"
919#include "restart_inc.F90"
920
921end module restart_oct_m
922
923
924!! Local Variables:
925!! mode: f90
926!! coding: utf-8
927!! End:
This module implements batches of mesh functions.
Definition: batch.F90:133
This module handles the calculation mode.
character(len= *), parameter, public em_resp_fd_dir
Definition: global.F90:253
character(len= *), parameter, public gs_dir
Definition: global.F90:249
character(len= *), parameter, public casida_dir
Definition: global.F90:257
character(len= *), parameter, public vib_modes_dir
Definition: global.F90:255
character(len= *), parameter, public partition_dir
Definition: global.F90:260
character(len= *), parameter, public kdotp_dir
Definition: global.F90:254
character(len= *), parameter, public em_resp_dir
Definition: global.F90:252
character(len= *), parameter, public td_dir
Definition: global.F90:250
character(len= *), parameter, public vdw_dir
Definition: global.F90:256
character(len= *), parameter, public oct_dir
Definition: global.F90:258
This module implements the index, used for the mesh points.
Definition: index.F90:122
subroutine, public index_dump(idx, np, dir, mpi_grp, namespace, ierr)
Definition: index.F90:309
Definition: io.F90:114
subroutine, public io_close(iunit, grp)
Definition: io.F90:468
subroutine, public iopar_read(grp, iunit, lines, n_lines, ierr)
Definition: io.F90:621
character(len=max_path_len) function, public io_workpath(path, namespace)
Definition: io.F90:313
subroutine, public io_rm(fname, namespace)
Definition: io.F90:385
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:354
logical function, public io_dir_exists(dir, namespace)
Returns true if a dir with name 'dir' exists.
Definition: io.F90:612
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:395
logical function, public loct_dir_exists(dirname)
Definition: loct.F90:333
This module defines functions over batches of mesh functions.
Definition: mesh_batch.F90:116
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:118
subroutine, public mesh_check_dump_compatibility(mesh, dir, filename, namespace, mpi_grp, grid_changed, grid_reordered, map, ierr)
Definition: mesh.F90:590
subroutine, public mesh_write_fingerprint(mesh, dir, filename, mpi_grp, namespace, ierr)
Definition: mesh.F90:454
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:543
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:1057
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
Definition: messages.F90:624
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:160
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:420
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:723
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
Definition: mpi.F90:430
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:266
subroutine mpi_grp_init(grp, comm)
Initialize MPI group instance.
Definition: mpi.F90:346
integer, public mpi_err
used to store return values of mpi calls
Definition: mpi.F90:269
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:145
Some general things and nomenclature:
Definition: par_vec.F90:171
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:618
subroutine zrestart_write_binary3_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2201
subroutine drestart_write_binary1_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1532
subroutine drestart_read_binary3(restart, filename, np, ff, ierr)
Definition: restart.F90:1478
integer, parameter, public restart_partition
Definition: restart.F90:229
subroutine, public restart_module_init(namespace)
Definition: restart.F90:306
subroutine drestart_write_binary5(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1380
subroutine, public restart_read(restart, iunit, lines, nlines, ierr)
Definition: restart.F90:933
character(len=max_path_len) function, public restart_dir(restart)
Returns the name of the directory containing the restart information. The use of this function should...
Definition: restart.F90:755
integer, parameter, public restart_all
Definition: restart.F90:229
subroutine drestart_read_binary1(restart, filename, np, ff, ierr)
Definition: restart.F90:1422
subroutine zrestart_write_mesh_function(restart, space, filename, mesh, ff, ierr, root)
Definition: restart.F90:1717
subroutine zrestart_write_binary1(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1895
integer, parameter, public restart_casida
Definition: restart.F90:229
subroutine zrestart_write_binary5_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2215
subroutine, public restart_close(restart, iunit)
Close a file previously opened with restart_open.
Definition: restart.F90:950
logical function, public clean_stop(comm)
returns true if a file named stop exists
Definition: restart.F90:274
subroutine zrestart_read_binary5_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:2270
integer, parameter, public restart_kdotp
Definition: restart.F90:229
subroutine zrestart_read_binary3(restart, filename, np, ff, ierr)
Definition: restart.F90:2119
integer, parameter, public restart_oct
Definition: restart.F90:229
subroutine drestart_read_binary3_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:1616
subroutine, public restart_rm(restart, name)
Remove directory or file "name" that is located inside the current restart directory.
Definition: restart.F90:837
subroutine, public restart_mkdir(restart, dirname)
Make directory "dirname" inside the current restart directory.
Definition: restart.F90:819
subroutine zrestart_read_binary3_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:2257
subroutine drestart_read_binary2(restart, filename, np, ff, ierr)
Definition: restart.F90:1450
integer, parameter, public restart_gs
Definition: restart.F90:229
subroutine zrestart_read_binary1_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:2229
type(restart_data_t), dimension(restart_n_data_types) info
Definition: restart.F90:254
subroutine drestart_write_binary3(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1338
subroutine drestart_read_mesh_function(restart, space, filename, mesh, ff, ierr)
In domain parallel case each process reads a part of the file. At the end all the processes have the ...
Definition: restart.F90:1157
integer, parameter, public restart_flag_mix
Definition: restart.F90:247
subroutine drestart_write_binary3_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1560
subroutine zrestart_write_binary1_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2173
integer, parameter, public restart_flag_skip
Definition: restart.F90:247
integer, parameter, public restart_em_resp_fd
Definition: restart.F90:229
subroutine drestart_read_binary2_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:1602
subroutine drestart_write_binary5_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1574
subroutine, public restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
Initializes a restart object.
Definition: restart.F90:514
integer, parameter, public restart_proj
Definition: restart.F90:229
subroutine zrestart_read_mesh_function(restart, space, filename, mesh, ff, ierr)
In domain parallel case each process reads a part of the file. At the end all the processes have the ...
Definition: restart.F90:1798
subroutine zrestart_read_binary1(restart, filename, np, ff, ierr)
Definition: restart.F90:2063
integer, parameter, public restart_flag_rho
Definition: restart.F90:247
integer, parameter, public restart_em_resp
Definition: restart.F90:229
subroutine, public restart_write(restart, iunit, lines, nlines, ierr)
Definition: restart.F90:906
integer, parameter, public restart_vib_modes
Definition: restart.F90:229
subroutine drestart_write_binary1(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1254
subroutine drestart_read_binary1_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:1588
subroutine zrestart_write_binary5(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2021
logical pure function, public restart_skip(restart)
Returns true if the restart information should neither be read nor written. This might happen because...
Definition: restart.F90:967
integer, parameter, public restart_flag_vhxc
Definition: restart.F90:247
logical pure function, public restart_has_map(restart)
Returns true if the restart was from a different order of mesh points.
Definition: restart.F90:988
subroutine drestart_read_binary5_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:1629
subroutine drestart_write_binary2(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1296
subroutine drestart_read_binary5(restart, filename, np, ff, ierr)
Definition: restart.F90:1505
subroutine zrestart_write_binary2_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2187
logical pure function, public restart_has_flag(restart, flag)
Returns true if...
Definition: restart.F90:977
integer function, public restart_open(restart, filename, status, position, silent)
Open file "filename" found inside the current restart directory. Depending on the type of restart,...
Definition: restart.F90:859
subroutine, public restart_open_dir(restart, dirname, ierr)
Change the restart directory to dirname, where "dirname" is a subdirectory of the base restart direct...
Definition: restart.F90:770
integer, parameter, public restart_td
Definition: restart.F90:229
integer, parameter, public restart_type_load
Definition: restart.F90:225
subroutine zrestart_read_binary2(restart, filename, np, ff, ierr)
Definition: restart.F90:2091
integer, parameter, public restart_vdw
Definition: restart.F90:229
subroutine zrestart_read_binary5(restart, filename, np, ff, ierr)
Definition: restart.F90:2146
subroutine zrestart_write_binary2(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1937
subroutine drestart_write_mesh_function(restart, space, filename, mesh, ff, ierr, root)
Definition: restart.F90:1076
integer, parameter, public restart_unocc
Definition: restart.F90:229
subroutine zrestart_write_binary3(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1979
logical pure function, public restart_are_basedirs_equal(type1, type2)
Returns true if...
Definition: restart.F90:998
subroutine zrestart_read_binary2_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:2243
subroutine, public restart_end(restart)
Definition: restart.F90:720
subroutine, public restart_close_dir(restart)
Change back to the base directory. To be called after restart_open_dir.
Definition: restart.F90:804
subroutine drestart_write_binary2_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1546
This module defines the unit system, used for input and output.
Describes mesh distribution to nodes.
Definition: mesh.F90:186
Stores all communicators and groups.
Definition: multicomm.F90:206
int true(void)