source: palm/trunk/SOURCE/local_stop.f90 @ 1834

Last change on this file since 1834 was 1818, checked in by maronga, 5 years ago

last commit documented / copyright update

  • Property svn:keywords set to Id
File size: 5.8 KB
Line 
1!> @file local_stop.f90
2!--------------------------------------------------------------------------------!
3! This file is part of PALM.
4!
5! PALM is free software: you can redistribute it and/or modify it under the terms
6! of the GNU General Public License as published by the Free Software Foundation,
7! either version 3 of the License, or (at your option) any later version.
8!
9! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
10! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12!
13! You should have received a copy of the GNU General Public License along with
14! PALM. If not, see <http://www.gnu.org/licenses/>.
15!
16! Copyright 1997-2016 Leibniz Universitaet Hannover
17!--------------------------------------------------------------------------------!
18!
19! Current revisions:
20! -----------------
21!
22!
23! Former revisions:
24! -----------------
25! $Id: local_stop.f90 1818 2016-04-06 15:53:27Z raasch $
26!
27! 1804 2016-04-05 16:30:18Z maronga
28! Removed code for parameter file check (__check)
29!
30! 1764 2016-02-28 12:45:19Z raasch
31! abort with MPI_COMM_WORLD added, nested runs always abort with MPI_ABORT
32!
33! 1682 2015-10-07 23:56:08Z knoop
34! Code annotations made doxygen readable
35!
36! 1353 2014-04-08 15:21:23Z heinze
37! REAL constants provided with KIND-attribute
38!
39! 1320 2014-03-20 08:40:49Z raasch
40! ONLY-attribute added to USE-statements,
41! revision history before 2012 removed
42!
43! 1036 2012-10-22 13:43:42Z raasch
44! code put under GPL (PALM 3.9)
45!
46! 809 2012-01-30 13:32:58Z maronga
47! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives
48!
49! 807 2012-01-25 11:53:51Z maronga
50! New cpp directive "__check" implemented which is used by check_namelist_files
51!
52! Revision 1.1  2002/12/19 15:46:23  raasch
53! Initial revision
54!
55!
56! Description:
57! ------------
58!> Stop program execution
59!------------------------------------------------------------------------------!
60 SUBROUTINE local_stop
61 
62
63    USE control_parameters,                                                    &
64        ONLY:  abort_mode, coupling_mode, coupling_mode_remote, dt_restart,    &
65               stop_dt, terminate_coupled, terminate_coupled_remote,           &
66               terminate_run, time_restart
67
68    USE pegrid
69
70    USE pmc_interface,                                                         &
71        ONLY:  nested_run
72
73#if defined( __parallel )
74    IF ( coupling_mode == 'uncoupled' )  THEN
75       IF ( nested_run )  THEN
76!
77!--       Workaround: If any of the nested model crashes, it aborts the whole
78!--       run with MPI_ABORT, regardless of the reason given by abort_mode
79          CALL MPI_ABORT( MPI_COMM_WORLD, 9999, ierr )
80       ELSE
81          IF ( abort_mode == 1 )  THEN
82             CALL MPI_FINALIZE( ierr )
83             STOP
84          ELSEIF ( abort_mode == 2 )  THEN
85             CALL MPI_ABORT( comm2d, 9999, ierr )
86          ELSEIF ( abort_mode == 3 )  THEN
87             CALL MPI_ABORT( MPI_COMM_WORLD, 9999, ierr )
88          ENDIF
89       ENDIF
90    ELSE
91
92       SELECT CASE ( terminate_coupled_remote )
93
94          CASE ( 0 )
95             IF ( myid == 0 )  THEN
96                PRINT*, '+++ local_stop:'
97                PRINT*, '    local model "', TRIM( coupling_mode ), &
98                     '" stops now'
99             ENDIF
100!
101!--          Inform the remote model of the termination and its reason, provided
102!--          the remote model has not already been informed of another
103!--          termination reason (terminate_coupled > 0) before.
104             IF ( terminate_coupled == 0 )  THEN
105                terminate_coupled = 1
106                IF ( myid == 0 ) THEN
107                   CALL MPI_SENDRECV( &
108                        terminate_coupled,        1, MPI_INTEGER, target_id,  0, &
109                        terminate_coupled_remote, 1, MPI_INTEGER, target_id,  0, &
110                        comm_inter, status, ierr )
111                ENDIF
112                CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_REAL, 0, comm2d, ierr)
113             ENDIF
114             CALL MPI_FINALIZE( ierr )
115             STOP
116
117          CASE ( 1 )
118             IF ( myid == 0 )  THEN
119                PRINT*, '+++ local_stop:'
120                PRINT*, '    remote model "', TRIM( coupling_mode_remote ), &
121                     '" stopped'
122             ENDIF
123             CALL MPI_FINALIZE( ierr )
124             STOP
125
126          CASE ( 2 )
127             IF ( myid == 0 )  THEN
128                PRINT*, '+++ local_stop:'
129                PRINT*, '    remote model "', TRIM( coupling_mode_remote ), &
130                     '" terminated'
131                PRINT*, '    with stop_dt = .T.'
132             ENDIF
133             stop_dt = .TRUE.
134
135          CASE ( 3 )
136             IF ( myid == 0 )  THEN
137                PRINT*, '+++ local_stop:'
138                PRINT*, '    remote model "', TRIM( coupling_mode_remote ), &
139                     '" terminated'
140                PRINT*, '    with terminate_run = .T. (CPU-time limit)'
141             ENDIF
142             terminate_run = .TRUE.
143
144          CASE ( 4 )
145             IF ( myid == 0 )  THEN
146                PRINT*, '+++ local_stop:'
147                PRINT*, '    remote model "', TRIM( coupling_mode_remote ), &
148                     '" terminated'
149                PRINT*, '    with terminate_run = .T. (restart)'
150             ENDIF
151             terminate_run = .TRUE.
152             time_restart = time_restart + dt_restart
153
154          CASE ( 5 )
155             IF ( myid == 0 )  THEN
156                PRINT*, '+++ local_stop:'
157                PRINT*, '    remote model "', TRIM( coupling_mode_remote ), &
158                     '" terminated'
159                PRINT*, '    with terminate_run = .T. (single restart)'
160             ENDIF
161             terminate_run = .TRUE.
162             time_restart = 9999999.9_wp
163
164       END SELECT
165
166    ENDIF
167
168#else
169
170    STOP
171
172#endif
173
174 END SUBROUTINE local_stop   
Note: See TracBrowser for help on using the repository browser.