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