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