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