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 integer, parameter, public :: &
108 RESTART_UNDEFINED = -1, &
109 restart_all = 0, &
110 restart_gs = 1, &
111 restart_unocc = 2, &
112 restart_td = 3, &
113 restart_em_resp = 4, &
114 restart_em_resp_fd = 5, &
115 restart_kdotp = 6, &
117 restart_vdw = 8, &
118 restart_casida = 9, &
119 restart_oct = 10, &
120 restart_partition = 11, &
121 restart_proj = 12
122
123 integer, parameter :: RESTART_N_DATA_TYPES = 12
124
125 type restart_t
126 private
127 integer :: data_type = restart_undefined
128 integer :: type = restart_undefined
129 logical :: skip
130 character(len=MAX_PATH_LEN) :: dir
131 character(len=MAX_PATH_LEN) :: pwd
133 type(namespace_t), pointer, public :: namespace
134 type(mpi_grp_t) :: mpi_grp
135 type(multicomm_t), pointer :: mc
136 logical :: has_mesh
137 integer(int64), allocatable :: map(:)
138 contains
139 procedure :: get_data_type => restart_get_data_type
140 end type restart_t
141
142
143 type restart_data_t
144 private
145 character(len=20) :: tag
146 character(len=MAX_PATH_LEN) :: basedir
147 character(len=MAX_PATH_LEN) :: dir
148 integer :: flags
149 end type restart_data_t
150
151
152 integer, parameter, public :: &
153 RESTART_TYPE_DUMP = 1, &
155
156 integer, parameter, public :: &
157 RESTART_FLAG_STATES = 1, &
158 restart_flag_rho = 2, &
159 restart_flag_vhxc = 4, &
160 restart_flag_mix = 8, &
162
163 type(restart_data_t) :: info(RESTART_N_DATA_TYPES)
164
165
167 interface restart_block_signals
168 subroutine block_signals()
169 implicit none
170 end subroutine block_signals
171 end interface restart_block_signals
172
174 subroutine unblock_signals()
175 implicit none
176 end subroutine unblock_signals
177 end interface
178
179contains
182 function clean_stop(comm)
183 type(MPI_Comm), intent(in) :: comm
184
185 logical :: clean_stop, file_exists
187 push_sub(clean_stop)
188
189 clean_stop = .false.
190
191 if (mpi_grp_is_root(mpi_world)) then
192 inquire(file='stop', exist=file_exists)
193 if (file_exists) then
194 call loct_rm('stop')
195 clean_stop = .true.
196 end if
197 end if
198
199#ifdef HAVE_MPI
200 ! make sure all nodes agree on whether this condition occurred
201 call mpi_bcast(clean_stop, 1, mpi_logical, 0, comm, mpi_err)
202#endif
203
204 if (clean_stop) then
205 message(1) = 'Clean STOP'
206 call messages_warning(1)
207 end if
208
209 pop_sub(clean_stop)
210 end function clean_stop
211
212
213 ! ---------------------------------------------------------
214 subroutine restart_module_init(namespace)
215 type(namespace_t), intent(in) :: namespace
217 logical :: set(restart_n_data_types)
218 integer :: iline, n_cols, data_type
219 character(len=MAX_PATH_LEN) :: default_basedir
220 type(block_t) :: blk
224 ! Each data type should have a tag
225 info(restart_gs)%tag = "Ground-state"
226 info(restart_unocc)%tag = "Unoccupied states"
227 info(restart_td)%tag = "Time-dependent"
228 info(restart_em_resp)%tag = "EM Resp."
229 info(restart_em_resp_fd)%tag = "EM Resp. FD"
230 info(restart_kdotp)%tag = "KdotP"
231 info(restart_vib_modes)%tag = "Vib. Modes"
232 info(restart_vdw)%tag = "VdW"
233 info(restart_casida)%tag = "Casida"
234 info(restart_oct)%tag = "Optimal Control"
235 info(restart_proj)%tag = "GS for TDOutput"
236 info(restart_partition)%tag = "Mesh Partition"
237
238 ! Default flags and directories (flags not yet used)
239 info(:)%basedir = 'restart'
240 info(:)%flags = 0
242
243 info(restart_gs)%dir = gs_dir
244 info(restart_unocc)%dir = gs_dir
245 info(restart_td)%dir = td_dir
246 info(restart_em_resp)%dir = em_resp_dir
248 info(restart_kdotp)%dir = kdotp_dir
250 info(restart_vdw)%dir = vdw_dir
251 info(restart_casida)%dir = casida_dir
252 info(restart_oct)%dir = oct_dir
253 info(restart_proj)%dir = gs_dir
255
256 ! Read input
257 call messages_obsolete_variable(namespace, 'RestartFileFormat', 'RestartOptions')
258 call messages_obsolete_variable(namespace, 'TmpDir', 'RestartOptions')
259 call messages_obsolete_variable(namespace, 'RestartDir', 'RestartOptions')
260 call messages_obsolete_variable(namespace, 'MeshPartitionRead', 'RestartOptions')
261 call messages_obsolete_variable(namespace, 'MeshPartitionWrite', 'RestartOptions')
262 call messages_obsolete_variable(namespace, 'MeshPartitionDir', 'RestartOptions')
263
264 !%Variable RestartOptions
265 !%Type block
266 !%Section Execution::IO
267 !%Description
268 !% <tt>Octopus</tt> usually stores binary information, such as the wavefunctions, to be used
269 !% in subsequent calculations. The most common example is the ground-state states
270 !% that are used to start a time-dependent calculation. This variable allows to control
271 !% where this information is written to or read from. The format of this block is the following:
272 !% for each line, the first column indicates the type of data, the second column indicates
273 !% the path to the directory that should be used to read and write that restart information, and the
274 !% third column, which is optional, allows one to set some flags to modify the way how the data
275 !% is read or written. For example, if you are running a time-dependent calculation, you can
276 !% indicate where <tt>Octopus</tt> can find the ground-state information in the following way:
277 !%
278 !% <tt>%RestartOptions
279 !% <br>&nbsp;&nbsp;restart_gs | "gs_restart"
280 !% <br>&nbsp;&nbsp;restart_td | "td_restart"
281 !% <br>%</tt>
282 !%
283 !% The second line of the above example also tells <tt>Octopus</tt> that the time-dependent restart data
284 !% should be read from and written to the "td_restart" directory.
285 !%
286 !% In case you want to change the path of all the restart directories, you can use the <tt>restart_all</tt> option.
287 !% When using the <tt>restart_all</tt> option, it is still possible to have a different restart directory for specific
288 !% data types. For example, when including the following block in your input file:
289 !%
290 !% <tt>%RestartOptions
291 !% <br>&nbsp;&nbsp;restart_all | "my_restart"
292 !% <br>&nbsp;&nbsp;restart_td&nbsp; | "td_restart"
293 !% <br>%</tt>
294 !%
295 !% the time-dependent restart information will be stored in the "td_restart" directory, while all the remaining
296 !% restart information will be stored in the "my_restart" directory.
297 !%
298 !% By default, the name of the "restart_all" directory is set to "restart".
299 !%
300 !% Some <tt>CalculationMode</tt>s also take into account specific flags set in the third column of the <tt>RestartOptions</tt>
301 !% block. These are used to determine if some specific part of the restart data is to be taken into account
302 !% or not when reading the restart information. For example, when restarting a ground-state calculation, one can
303 !% set the <tt>restart_rho</tt> flags, so that the density used is not built from the saved wavefunctions, but is
304 !% instead read from the restart directory. In this case, the block should look like this:
305 !%
306 !% <tt>%RestartOptions
307 !% <br>&nbsp;&nbsp;restart_gs | "restart" | restart_rho
308 !% <br>%</tt>
309 !%
310 !% A list of available flags is given below, but note that the code might ignore some of them, which will happen if they
311 !% are not available for that particular calculation, or might assume some of them always present, which will happen
312 !% in case they are mandatory.
313 !%
314 !% Finally, note that all the restart information of a given data type is always stored in a subdirectory of the
315 !% specified path. The name of this subdirectory is fixed and cannot be changed. For example, ground-state information
316 !% will always be stored in a subdirectory named "gs". This makes it safe in most situations to use the same path for
317 !% all the data types. The name of these subdirectories is indicated in the description of the data types below.
318 !%
319 !% Currently, the available restart data types and flags are the following:
320 !%Option restart_all 0
321 !% (data type)
322 !% Option to globally change the path of all the restart information.
323 !%Option restart_gs 1
324 !% (data type)
325 !% The data resulting from a ground-state calculation.
326 !% This information is stored under the "gs" subdirectory.
327 !%Option restart_unocc 2
328 !% (data type)
329 !% The data resulting from an unoccupied states calculation. This information also corresponds to a ground state and
330 !% can be used as such, so it is stored under the same subdirectory as the one of restart_gs.
331 !%Option restart_td 3
332 !% (data type)
333 !% The data resulting from a real-time time-dependent calculation.
334 !% This information is stored under the "td" subdirectory.
335 !%Option restart_em_resp 4
336 !% (data type)
337 !% The data resulting from the calculation of the electromagnetic response using the Sternheimer approach.
338 !% This information is stored under the "em_resp" subdirectory.
339 !%Option restart_em_resp_fd 5
340 !% (data type)
341 !% The data resulting from the calculation of the electromagnetic response using finite-differences.
342 !% This information is stored under the "em_resp_fd" subdirectory.
343 !%Option restart_kdotp 6
344 !% (data type)
345 !% The data resulting from the calculation of effective masses by k.p perturbation theory.
346 !% This information is stored under the "kdotp" subdirectory.
347 !%Option restart_vib_modes 7
348 !% (data type)
349 !% The data resulting from the calculation of vibrational modes.
350 !% This information is stored under the "vib_modes" subdirectory.
351 !%Option restart_vdw 8
352 !% (data type)
353 !% The data resulting from the calculation of van der Waals coefficients.
354 !% This information is stored under the "vdw" subdirectory.
355 !%Option restart_casida 9
356 !% (data type)
357 !% The data resulting from a Casida calculation.
358 !% This information is stored under the "casida" subdirectory.
359 !%Option restart_oct 10
360 !% (data type)
361 !% The data for optimal control calculations.
362 !% This information is stored under the "opt-control" subdirectory.
363 !%Option restart_partition 11
364 !% (data type)
365 !% The data for the mesh partitioning.
366 !% This information is stored under the "partition" subdirectory.
367 !%Option restart_proj 12
368 !% (data type)
369 !% The ground-state to be used with the td_occup and populations options of <tt>TDOutput</tt>.
370 !% This information should be a ground state, so the "gs" subdirectory is used.
371 !%Option restart_states 1
372 !% (flag)
373 !% Read the electronic states. (not yet implemented)
374 !%Option restart_rho 2
375 !% (flag)
376 !% Read the electronic density.
377 !%Option restart_vhxc 4
378 !% (flag)
379 !% Read the Hartree and XC potentials.
380 !%Option restart_mix 8
381 !% (flag)
382 !% Read the SCF mixing information.
383 !%Option restart_skip 16
384 !% (flag)
385 !% This flag allows to selectively skip the reading and writting of specific restart information.
386 !%End
387 set = .false.
388 if (parse_block(namespace, 'RestartOptions', blk) == 0) then
389
390 default_basedir = 'restart'
391
392 do iline = 1, parse_block_n(blk)
393 n_cols = parse_block_cols(blk,iline-1)
394
395 call parse_block_integer(blk, iline-1, 0, data_type)
396 if (data_type < 0 .or. data_type > restart_n_data_types) then
397 call messages_input_error(namespace, 'RestartOptions', "Invalid data type", row=iline-1, column=0)
398 end if
399 if (data_type == 0) then
400 call parse_block_string(blk, iline-1, 1, default_basedir)
401 else
402 set(data_type) = .true.
403 call parse_block_string(blk, iline-1, 1, info(data_type)%basedir)
404
405 if (n_cols > 2) call parse_block_integer(blk, iline-1, 2, info(data_type)%flags)
406 end if
407
408 end do
409 call parse_block_end(blk)
410
411 where (.not. set)
412 info(:)%basedir = default_basedir
413 end where
414 end if
415
416 pop_sub(restart_module_init)
417 end subroutine restart_module_init
418
419
420 ! ---------------------------------------------------------
422 subroutine restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
423 type(restart_t), intent(out) :: restart
424 type(namespace_t), target, intent(in) :: namespace
425 integer, intent(in) :: data_type
426 integer, intent(in) :: type
428 type(multicomm_t), target, intent(in) :: mc
429 integer, intent(out) :: ierr
430 class(mesh_t), optional, intent(in) :: mesh
432 character(len=*), optional, intent(in) :: dir
434 logical, optional, intent(in) :: exact
436
437 logical :: grid_changed, grid_reordered, restart_write, dir_exists
438 character(len=20) :: tag
439 character(len=MAX_PATH_LEN) :: basedir, dirname
440
441 push_sub(restart_init)
442
443 ierr = 0
444
445 ! Sanity checks
446 if (present(exact) .and. .not. present(mesh)) then
447 message(1) = "Error in restart_init: the 'exact' optional argument requires a mesh."
448 call messages_fatal(1, namespace=namespace)
449 end if
450
451 restart%has_mesh = present(mesh)
452
453 ! Some initializations
454 restart%type = type
455 restart%mc => mc
456 call mpi_grp_init(restart%mpi_grp, mc%master_comm)
457 if (data_type < restart_undefined .and. data_type > restart_n_data_types) then
458 message(1) = "Illegal data_type in restart_init"
459 call messages_fatal(1, namespace=namespace)
460 end if
461 restart%data_type = data_type
462 restart%namespace => namespace
463
464 select case (restart%type)
465 case (restart_type_dump)
466 !%Variable RestartWrite
467 !%Type logical
468 !%Default true
469 !%Section Execution::IO
470 !%Description
471 !% If this variable is set to no, restart information is not
472 !% written. Note that some run modes will ignore this
473 !% option and write some restart information anyway.
474 !%End
475
476 call parse_variable(namespace, 'RestartWrite', .true., restart_write)
477 restart%skip = .not. restart_write
478
479 if (restart%skip) then
480 message(1) = 'Restart information will not be written.'
481 call messages_warning(1, namespace=namespace)
482 end if
483
484 case (restart_type_load)
485 ! This is set to true as an error condition, checked by assertions in some routines.
486 restart%skip = .false.
487
488 case default
489 message(1) = "Unknown restart type in restart_init"
490 call messages_fatal(1, namespace=namespace)
491 end select
492
493
494 ! If the restart data type is not defined, the directories should be set explicitly
495 if (restart%data_type == restart_undefined) then
496 assert(present(dir))
497 basedir = dir
498 dirname = ""
499 else
500 basedir = info(restart%data_type)%basedir
501 if (index(basedir, '/', .true.) /= len_trim(basedir)) then
502 basedir = trim(basedir)//"/"
503 end if
504 dirname = info(restart%data_type)%dir
505 end if
506
507 ! Set final path
508 restart%dir = trim(basedir)//trim(dirname)
509 ! Remove any trailing "/" from the path (all the routines from this module should add the trailing "/" when needed)
510 if (index(restart%dir, '/', .true.) == len_trim(restart%dir)) then
511 restart%dir = restart%dir(1:len_trim(restart%dir)-1)
512 end if
513
514 ! Set initial path to the working directory
515 restart%pwd = restart%dir
516 ! Check if the directory already exists and create it if necessary
517 if (mpi_grp_is_root(restart%mpi_grp)) then
518 dir_exists = io_dir_exists(trim(restart%pwd), namespace)
519 if (restart%type == restart_type_dump .and. .not. dir_exists) then
520 call io_mkdir(trim(restart%pwd), namespace, parents=.true.)
521 end if
522 end if
523 if (restart%mpi_grp%size > 1) then
524 call restart%mpi_grp%bcast(dir_exists, 1, mpi_logical, 0)
525 end if
526
527 if (restart%data_type == restart_undefined) then
528 tag = "Some "
529 else
530 tag = info(data_type)%tag
531 end if
532
533 select case (restart%type)
534 case (restart_type_dump)
535 if (.not. restart%skip) then
536 message(1) = "Info: "//trim(tag)//" restart information will be written to '"//trim(restart%pwd)//"'."
537 call messages_info(1, namespace=namespace)
538
539 ! Dump the grid information. The main parameters of the grid should not change
540 ! during the calculation, so we should only need to dump it once.
541 if (present(mesh)) then
542 call index_dump(mesh%idx, mesh%np_part_global, restart%pwd, restart%mpi_grp, &
543 restart%namespace, ierr)
544 if (ierr /= 0) then
545 message(1) = "Unable to write index map to '"//trim(restart%pwd)//"'."
546 call messages_fatal(1, namespace=namespace)
547 end if
548
549 call mesh_write_fingerprint(mesh, restart%pwd, "grid", restart%mpi_grp, namespace, ierr)
550 if (ierr /= 0) then
551 message(1) = "Unable to write mesh fingerprint to '"//trim(restart%pwd)//"/grid'."
552 call messages_fatal(1, namespace=namespace)
553 end if
554 end if
555
556 end if
557
558 case (restart_type_load)
559 if (.not. dir_exists) then
560 ierr = 1
561 restart%skip = .true.
562
563 message(1) = "Info: Could not find '"//trim(restart%pwd)//"' directory for restart."
564 message(2) = "Info: No restart information will be read."
565 call messages_info(2, namespace=namespace)
566
567 else
568 message(1) = "Info: "//trim(tag)//" restart information will be read from '"//trim(restart%pwd)//"'."
569 call messages_info(1, namespace=namespace)
570
571 if (present(mesh)) then
572 call mesh_check_dump_compatibility(mesh, restart%pwd, "grid", restart%namespace, &
573 restart%mpi_grp, grid_changed, grid_reordered, restart%map, ierr)
574
575 ! Check whether an error occurred. In this case we cannot read.
576 if (ierr /= 0) then
577 if (ierr == -1) then
578 message(1) = "Unable to check mesh compatibility: unable to read mesh fingerprint"
579 message(2) = "in '"//trim(restart%pwd)//"'."
580 else if (ierr > 0) then
581 message(1) = "Mesh from current calculation is not compatible with mesh found in"
582 message(2) = "'"//trim(restart%pwd)//"'."
583 end if
584 message(3) = "No restart information will be read."
585 call messages_warning(3, namespace=namespace)
586 ierr = 1
587 end if
588
589 ! Print some warnings in case the mesh is compatible, but changed.
590 if (grid_changed) then
591 if (grid_reordered) then
592 message(1) = "Info: Octopus is attempting to restart from a mesh with a different order of points."
593 else
594 message(1) = "Info: Octopus is attempting to restart from a different mesh."
595 end if
596 call messages_info(1, namespace=namespace)
597 end if
598
599 if (present(exact)) then
600 restart%skip = grid_changed .and. .not. grid_reordered .and. exact
601 if (restart%skip) then
602 message(1) = "This calculation requires the exact same mesh to restart."
603 message(2) = "No restart information will be read from '"//trim(restart%pwd)//"'."
604 call messages_warning(2, namespace=namespace)
605 ierr = 1
606 end if
607 else
608 restart%skip = .false.
609 end if
610 end if
611 end if
612
613 end select
614
615
616 ! Make sure all the processes have finished reading/writing all the grid information,
617 ! as there might be some subsequent calls to this function where that information will
618 ! be written/read to/from the same directory.
619 if (restart%mpi_grp%size > 1) then
620 call restart%mpi_grp%barrier()
621 end if
622
623 pop_sub(restart_init)
624 end subroutine restart_init
625
626
627 ! ---------------------------------------------------------
628 subroutine restart_end(restart)
629 type(restart_t), intent(inout) :: restart
630
631 push_sub(restart_end)
632
633 if (mpi_grp_is_root(restart%mpi_grp) .and. .not. restart%skip) then
634 select case (restart%type)
635 case (restart_type_load)
636 message(1) = "Info: Finished reading information from '"//trim(restart%dir)//"'."
637 call io_rm(trim(restart%pwd)//"/loading", restart%namespace)
638 case (restart_type_dump)
639 call io_rm(trim(restart%pwd)//"/dumping", restart%namespace)
640 message(1) = "Info: Finished writing information to '"//trim(restart%dir)//"'."
641 end select
642 call messages_info(1, namespace=restart%namespace)
643 end if
644
645 restart%type = 0
646 restart%data_type = 0
647 restart%skip = .true.
648 safe_deallocate_a(restart%map)
649 restart%has_mesh = .false.
650 nullify(restart%mc)
651
652 pop_sub(restart_end)
653 end subroutine restart_end
654
655
656 ! ---------------------------------------------------------
663 function restart_dir(restart)
664 type(restart_t), intent(in) :: restart
665 character(len=MAX_PATH_LEN) :: restart_dir
666
667 push_sub(restart_dir)
668
669 restart_dir = io_workpath(restart%pwd, restart%namespace)
670
671 pop_sub(restart_dir)
672 end function restart_dir
673
674
675 ! ---------------------------------------------------------
678 subroutine restart_open_dir(restart, dirname, ierr)
679 type(restart_t), intent(inout) :: restart
680 character(len=*), intent(in) :: dirname
681 integer, intent(out) :: ierr
682
683 push_sub(restart_open_dir)
684
685 assert(.not. restart%skip)
686
687 ierr = 0
688
689 select case (restart%type)
690 case (restart_type_dump)
691 call restart_mkdir(restart, dirname)
692 case (restart_type_load)
693 if (.not. loct_dir_exists(trim(restart%dir)//"/"//trim(dirname))) then
694 ierr = 1
695 end if
696 end select
697
698 if (ierr == 0) then
699 if (index(dirname, '/', .true.) == len_trim(dirname)) then
700 restart%pwd = trim(restart%dir)//"/"//dirname(1:len_trim(dirname)-1)
701 else
702 restart%pwd = trim(restart%dir)//"/"//trim(dirname)
703 end if
704 end if
705
706 pop_sub(restart_open_dir)
707 end subroutine restart_open_dir
708
709
710 ! ---------------------------------------------------------
712 subroutine restart_close_dir(restart)
713 type(restart_t), intent(inout) :: restart
714
715 push_sub(restart_close_dir)
716
717 assert(.not. restart%skip)
718
719 restart%pwd = restart%dir
720
722 end subroutine restart_close_dir
723
724
725 ! ---------------------------------------------------------
727 subroutine restart_mkdir(restart, dirname)
728 type(restart_t), intent(in) :: restart
729 character(len=*), intent(in) :: dirname
730
731 push_sub(restart_mkdir)
732
733 assert(.not. restart%skip)
734
735 assert(restart%type == restart_type_dump)
736
737 call io_mkdir(trim(restart%pwd)//"/"//trim(dirname), restart%namespace, parents=.true.)
738
739 pop_sub(restart_mkdir)
740 end subroutine restart_mkdir
741
742
743 ! ---------------------------------------------------------
745 subroutine restart_rm(restart, name)
746 type(restart_t), intent(in) :: restart
747 character(len=*), intent(in) :: name
748
749 assert(.not. restart%skip)
750 assert(restart%type == restart_type_dump)
751
752 push_sub(restart_rm)
753
754 call io_rm(trim(restart%pwd)//"/"//trim(name), restart%namespace)
755
756 pop_sub(restart_rm)
757 end subroutine restart_rm
758
759
760 ! ---------------------------------------------------------
767 function restart_open(restart, filename, status, position, silent)
768 type(restart_t), intent(in) :: restart
769 character(len=*), intent(in) :: filename
770 character(len=*), optional, intent(in) :: status
771 character(len=*), optional, intent(in) :: position
772 logical, optional, intent(in) :: silent
773 integer :: restart_open
774
775 logical :: die
776 character(len=20) :: action, status_
777
778 push_sub(restart_open)
779
780 assert(.not. restart%skip)
781
782 select case (restart%type)
783 case (restart_type_dump)
784 status_ = 'unknown'
785 action = 'write'
786 die = .true.
787
788 case (restart_type_load)
789 status_ = 'old'
790 action = 'read'
791 die = .false.
792
793 case default
794 message(1) = "Error in restart_open: illegal restart type"
795 call messages_fatal(1)
796 end select
797
798 if (present(status)) status_ = status
799
800 restart_open = io_open(trim(restart%pwd)//"/"//trim(filename), restart%namespace, &
801 action=trim(action), status=trim(status_), &
802 die=die, position=position, form="formatted", grp=restart%mpi_grp)
803
804 if (restart_open < 0 .and. .not. optional_default(silent, .false.)) then
805 message(1) = "Unable to open file '"//trim(restart%pwd)//"/"//trim(filename)//"'."
806 call messages_warning(1)
807 end if
808
809 pop_sub(restart_open)
810 end function restart_open
811
812
813 ! ---------------------------------------------------------
814 subroutine restart_write(restart, iunit, lines, nlines, ierr)
815 type(restart_t), intent(in) :: restart
816 integer, intent(in) :: iunit
817 character(len=*), intent(in) :: lines(:)
818 integer, intent(in) :: nlines
819 integer, intent(out) :: ierr
821 integer :: iline
822
823 push_sub(restart_write)
824
825 if (iunit > 0) then
826 ierr = 0
827 if (mpi_grp_is_root(restart%mpi_grp)) then
828 do iline = 1, nlines
829 write(iunit,"(a)") trim(lines(iline))
830 end do
831 end if
832 else
833 ierr = 1
834 end if
835
836 pop_sub(restart_write)
837 end subroutine restart_write
839
840 ! ---------------------------------------------------------
841 subroutine restart_read(restart, iunit, lines, nlines, ierr)
842 type(restart_t), intent(in) :: restart
843 integer, intent(in) :: iunit
844 character(len=*), intent(out) :: lines(:)
845 integer, intent(in) :: nlines
846 integer, intent(out) :: ierr
847
848 push_sub(restart_read)
849
850 call iopar_read(restart%mpi_grp, iunit, lines, nlines, ierr)
851
852 pop_sub(restart_read)
853 end subroutine restart_read
854
855
856 ! ---------------------------------------------------------
858 subroutine restart_close(restart, iunit)
859 type(restart_t), intent(in) :: restart
860 integer, intent(inout) :: iunit
861
862 push_sub(restart_close)
863
864 if (iunit > 0) call io_close(iunit, restart%mpi_grp)
865
866 pop_sub(restart_close)
867 end subroutine restart_close
868
869
870 ! ---------------------------------------------------------
875 logical pure function restart_skip(restart)
876 type(restart_t), intent(in) :: restart
877
878 restart_skip = restart%skip .or. restart_has_flag(restart, restart_flag_skip)
879
880 end function restart_skip
881
882
883 ! ---------------------------------------------------------
885 logical pure function restart_has_flag(restart, flag)
886 type(restart_t), intent(in) :: restart
887 integer, intent(in) :: flag
888
889 restart_has_flag = bitand(info(restart%data_type)%flags, flag) /= 0
890
891 end function restart_has_flag
892
893
894 ! ---------------------------------------------------------
896 logical pure function restart_has_map(restart)
897 type(restart_t), intent(in) :: restart
898
899 restart_has_map = allocated(restart%map)
900
901 end function restart_has_map
902
903
904 ! ---------------------------------------------------------
906 logical pure function restart_are_basedirs_equal(type1, type2)
907 integer, intent(in) :: type1
908 integer, intent(in) :: type2
909
910 restart_are_basedirs_equal = trim(info(type1)%basedir) == trim(info(type2)%basedir)
911
912 end function restart_are_basedirs_equal
913
915 integer pure function restart_get_data_type(restart)
916 class(restart_t), intent(in) :: restart
917
918 restart_get_data_type = restart%data_type
919 end function restart_get_data_type
920
921
922#include "undef.F90"
923#include "real.F90"
924#include "restart_inc.F90"
925
926#include "undef.F90"
927#include "complex.F90"
928#include "restart_inc.F90"
929
930end module restart_oct_m
931
932
933!! Local Variables:
934!! mode: f90
935!! coding: utf-8
936!! 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
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
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:624
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:2210
subroutine drestart_write_binary1_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1541
subroutine drestart_read_binary3(restart, filename, np, ff, ierr)
Definition: restart.F90:1487
integer, parameter, public restart_partition
Definition: restart.F90:200
subroutine, public restart_module_init(namespace)
Definition: restart.F90:308
subroutine drestart_write_binary5(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1389
subroutine, public restart_read(restart, iunit, lines, nlines, ierr)
Definition: restart.F90:935
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:757
integer, parameter, public restart_all
Definition: restart.F90:200
subroutine drestart_read_binary1(restart, filename, np, ff, ierr)
Definition: restart.F90:1431
subroutine zrestart_write_mesh_function(restart, space, filename, mesh, ff, ierr, root)
Definition: restart.F90:1726
subroutine zrestart_write_binary1(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1904
integer, parameter, public restart_casida
Definition: restart.F90:200
subroutine zrestart_write_binary5_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2224
subroutine, public restart_close(restart, iunit)
Close a file previously opened with restart_open.
Definition: restart.F90:952
logical function, public clean_stop(comm)
returns true if a file named stop exists
Definition: restart.F90:276
subroutine zrestart_read_binary5_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:2279
integer, parameter, public restart_kdotp
Definition: restart.F90:200
subroutine zrestart_read_binary3(restart, filename, np, ff, ierr)
Definition: restart.F90:2128
integer, parameter, public restart_oct
Definition: restart.F90:200
subroutine drestart_read_binary3_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:1625
subroutine, public restart_rm(restart, name)
Remove directory or file "name" that is located inside the current restart directory.
Definition: restart.F90:839
subroutine, public restart_mkdir(restart, dirname)
Make directory "dirname" inside the current restart directory.
Definition: restart.F90:821
integer pure function restart_get_data_type(restart)
Returns the data type of the restart.
Definition: restart.F90:1009
subroutine zrestart_read_binary3_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:2266
subroutine drestart_read_binary2(restart, filename, np, ff, ierr)
Definition: restart.F90:1459
integer, parameter, public restart_gs
Definition: restart.F90:200
subroutine zrestart_read_binary1_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:2238
type(restart_data_t), dimension(restart_n_data_types) info
Definition: restart.F90:256
subroutine drestart_write_binary3(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1347
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:1166
integer, parameter, public restart_flag_mix
Definition: restart.F90:249
subroutine drestart_write_binary3_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1569
subroutine zrestart_write_binary1_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2182
integer, parameter, public restart_flag_skip
Definition: restart.F90:249
integer, parameter, public restart_em_resp_fd
Definition: restart.F90:200
subroutine drestart_read_binary2_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:1611
subroutine drestart_write_binary5_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1583
subroutine, public restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
Initializes a restart object.
Definition: restart.F90:516
integer, parameter, public restart_proj
Definition: restart.F90:200
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:1807
subroutine zrestart_read_binary1(restart, filename, np, ff, ierr)
Definition: restart.F90:2072
integer, parameter, public restart_flag_rho
Definition: restart.F90:249
integer, parameter, public restart_em_resp
Definition: restart.F90:200
subroutine, public restart_write(restart, iunit, lines, nlines, ierr)
Definition: restart.F90:908
integer, parameter, public restart_vib_modes
Definition: restart.F90:200
subroutine drestart_write_binary1(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1263
subroutine drestart_read_binary1_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:1597
subroutine zrestart_write_binary5(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2030
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:969
integer, parameter, public restart_flag_vhxc
Definition: restart.F90:249
logical pure function, public restart_has_map(restart)
Returns true if the restart was from a different order of mesh points.
Definition: restart.F90:990
subroutine drestart_read_binary5_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:1638
subroutine drestart_write_binary2(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1305
subroutine drestart_read_binary5(restart, filename, np, ff, ierr)
Definition: restart.F90:1514
subroutine zrestart_write_binary2_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:2196
logical pure function, public restart_has_flag(restart, flag)
Returns true if...
Definition: restart.F90:979
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:861
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:772
integer, parameter, public restart_td
Definition: restart.F90:200
integer, parameter, public restart_type_load
Definition: restart.F90:245
subroutine zrestart_read_binary2(restart, filename, np, ff, ierr)
Definition: restart.F90:2100
integer, parameter, public restart_vdw
Definition: restart.F90:200
subroutine zrestart_read_binary5(restart, filename, np, ff, ierr)
Definition: restart.F90:2155
subroutine zrestart_write_binary2(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1946
subroutine drestart_write_mesh_function(restart, space, filename, mesh, ff, ierr, root)
Definition: restart.F90:1085
integer, parameter, public restart_unocc
Definition: restart.F90:200
subroutine zrestart_write_binary3(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1988
logical pure function, public restart_are_basedirs_equal(type1, type2)
Returns true if...
Definition: restart.F90:1000
subroutine zrestart_read_binary2_int32(restart, filename, np, ff, ierr)
Definition: restart.F90:2252
subroutine, public restart_end(restart)
Definition: restart.F90:722
subroutine, public restart_close_dir(restart)
Change back to the base directory. To be called after restart_open_dir.
Definition: restart.F90:806
subroutine drestart_write_binary2_int32(restart, filename, np, ff, ierr, root)
Definition: restart.F90:1555
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)