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

Last change on this file since 2000 was 2000, checked in by knoop, 8 years ago

Forced header and separation lines into 80 columns

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