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