source: palm/trunk/SOURCE/check_for_restart.f90 @ 236

Last change on this file since 236 was 226, checked in by raasch, 16 years ago

preparations for the next release

  • Property svn:keywords set to Id
File size: 5.2 KB
RevLine 
[1]1 SUBROUTINE check_for_restart
2
3!------------------------------------------------------------------------------!
4! Actual revisions:
5! -----------------
[226]6!
[1]7!
8! Former revisions:
9! -----------------
[3]10! $Id: check_for_restart.f90 226 2009-02-02 07:39:34Z letzel $
[110]11!
[226]12! 222 2009-01-12 16:04:16Z letzel
13! Implementation of an MPI-1 coupling: replaced myid with target_id
14! Bugfix for nonparallel execution
15!
[110]16! 108 2007-08-24 15:10:38Z letzel
17! modifications to terminate coupled runs
18!
[3]19! RCS Log replace by Id keyword, revision history cleaned up
20!
[1]21! Revision 1.11  2007/02/11 12:55:13  raasch
22! Informative output to the job protocol
23!
24! Revision 1.1  1998/03/18 20:06:51  raasch
25! Initial revision
26!
27!
28! Description:
29! ------------
30! Set stop flag, if restart is neccessary because of expiring cpu-time or
31! if it is forced by user
32!------------------------------------------------------------------------------!
33
34    USE pegrid
35    USE control_parameters
36
37    IMPLICIT NONE
38
39
40    LOGICAL :: terminate_run_l
41    REAL ::  remaining_time
42
43
44!
45!-- Check remaining CPU-time
46    CALL local_tremain( remaining_time )
47
48!
49!-- If necessary set a flag to stop the model run
50    terminate_run_l = .FALSE.
51    IF ( remaining_time <= termination_time_needed  .AND. &
52         write_binary(1:4) == 'true' )  THEN
53
54       terminate_run_l = .TRUE.
55    ENDIF
56
57#if defined( __parallel )
58!
59!-- Make a logical OR for all processes. Stop the model run if at least
60!-- one processor has reached the time limit.
61    CALL MPI_ALLREDUCE( terminate_run_l, terminate_run, 1, MPI_LOGICAL, &
62                        MPI_LOR, comm2d, ierr )
63#else
64    terminate_run = terminate_run_l
65#endif
66
67!
68!-- Output that job will be terminated
69    IF ( terminate_run  .AND.  myid == 0 )  THEN
[206]70       PRINT*, '*** WARNING: run will be terminated because it is running', &
71                    ' out of job cpu limit'
[1]72       PRINT*, '             remaining time:         ', remaining_time, ' s'
[206]73       PRINT*, '             termination time needed:', &
74                             termination_time_needed, ' s'
[1]75    ENDIF
76
77!
[108]78!-- In case of coupled runs inform the remote model of the termination
79!-- and its reason, provided the remote model has not already been
80!-- informed of another termination reason (terminate_coupled > 0) before,
81!-- or vice versa (terminate_coupled_remote > 0).
[110]82    IF ( terminate_run .AND. TRIM( coupling_mode ) /= 'uncoupled'  .AND. &
83         terminate_coupled == 0  .AND.  terminate_coupled_remote == 0 )  THEN
84
[108]85       terminate_coupled = 3
[222]86#if defined( __parallel )
[206]87       CALL MPI_SENDRECV( terminate_coupled,        1, MPI_INTEGER,          &
88                          target_id, 0,                                      &
89                          terminate_coupled_remote, 1, MPI_INTEGER,          &
90                          target_id, 0,                                      &
[110]91                          comm_inter, status, ierr )
[222]92#endif
[108]93    ENDIF
94
95!
[1]96!-- Set the stop flag also, if restart is forced by user
97    IF ( time_restart /= 9999999.9  .AND.  time_restart < simulated_time ) &
98    THEN
99!
100!--    Restart is not neccessary, if the end time of the run (given by
101!--    the user) has been reached
102       IF ( simulated_time < end_time )  THEN
103          terminate_run = .TRUE.
104!
105!--       Increment restart time, if forced by user, otherwise set restart
106!--       time to default (no user restart)
107          IF ( dt_restart /= 9999999.9 )  THEN
108             time_restart = time_restart + dt_restart
109          ELSE
110             time_restart = 9999999.9
111          ENDIF
112
113          IF ( myid == 0 )  THEN
[110]114             PRINT*, '*** INFORMATIVE: run will be terminated due to user ', &
115                                       'settings of'
[1]116             PRINT*, '                 restart_time / dt_restart'
[206]117             PRINT*, '                 new restart time is: ', time_restart, &
118                                       ' s'
[1]119          ENDIF
[108]120!
121!--       In case of coupled runs inform the remote model of the termination
122!--       and its reason, provided the remote model has not already been
123!--       informed of another termination reason (terminate_coupled > 0) before,
124!--       or vice versa (terminate_coupled_remote > 0).
[206]125          IF ( coupling_mode /= 'uncoupled' .AND. terminate_coupled == 0  &
126               .AND.  terminate_coupled_remote == 0 )  THEN
[110]127
[108]128             IF ( dt_restart /= 9999999.9 )  THEN
129                terminate_coupled = 4
130             ELSE
131                terminate_coupled = 5
132             ENDIF
[222]133#if defined( __parallel )
[206]134             CALL MPI_SENDRECV( terminate_coupled,        1, MPI_INTEGER,    &
135                                target_id,  0,                               &
136                                terminate_coupled_remote, 1, MPI_INTEGER,    &
137                                target_id,  0,                               &
138                                comm_inter, status, ierr )
[222]139#endif
[108]140          ENDIF
141       ELSE
[1]142          time_restart = 9999999.9
143       ENDIF
144    ENDIF
145
146!
147!-- If the run is stopped, set a flag file which is necessary to initiate
148!-- the start of a continuation run
149    IF ( terminate_run  .AND.  myid == 0 )  THEN
150
151       OPEN ( 90, FILE='CONTINUE_RUN', FORM='FORMATTED' )
152       WRITE ( 90, '(A)' )  TRIM( run_description_header )
153       CLOSE ( 90 )
154
155    ENDIF
156
157
158 END SUBROUTINE check_for_restart
Note: See TracBrowser for help on using the repository browser.