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

Last change on this file since 4446 was 4444, checked in by raasch, 4 years ago

bugfix: cpp-directives for serial mode added

  • Property svn:keywords set to Id
File size: 5.5 KB
Line 
1!> @file local_stop.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
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-2020 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: local_stop.f90 4444 2020-03-05 15:59:50Z raasch $
27! bugfix: misplaced cpp-directive moved
28!
29! 4360 2020-01-07 11:25:50Z suehring
30! Corrected "Former revisions" section
31!
32! 3655 2019-01-07 16:51:22Z knoop
33! Added an empty output string to stop keywords to clean up job protocol
34!
35! Revision 1.1  2002/12/19 15:46:23  raasch
36! Initial revision
37!
38!
39! Description:
40! ------------
41!> Stop program execution
42!------------------------------------------------------------------------------!
43 SUBROUTINE local_stop
44 
45#if defined( __parallel )
46
47    USE control_parameters,                                                    &
48        ONLY:  abort_mode, coupling_mode, coupling_mode_remote, dt_restart,    &
49               stop_dt, terminate_coupled, terminate_coupled_remote,           &
50               terminate_run, time_restart
51
52    USE pegrid
53
54    USE pmc_interface,                                                         &
55        ONLY:  nested_run
56
57
58    IF ( coupling_mode == 'uncoupled' )  THEN
59       IF ( nested_run )  THEN
60!
61!--       Workaround: If any of the nested model crashes, it aborts the whole
62!--       run with MPI_ABORT, regardless of the reason given by abort_mode
63          CALL MPI_ABORT( MPI_COMM_WORLD, 9999, ierr )
64       ELSE
65          IF ( abort_mode == 1 )  THEN
66             CALL MPI_FINALIZE( ierr )
67             STOP 1
68          ELSEIF ( abort_mode == 2 )  THEN
69             CALL MPI_ABORT( comm2d, 9999, ierr )
70          ELSEIF ( abort_mode == 3 )  THEN
71             CALL MPI_ABORT( MPI_COMM_WORLD, 9999, ierr )
72          ENDIF
73       ENDIF
74    ELSEIF ( coupling_mode(1:8) == 'vnested_' )  THEN
75
76       PRINT*, '+++ local_stop:'
77       PRINT*, '     model "', TRIM( coupling_mode ), '" terminated'
78!
79!--    Abort both coarse and fine grid
80       CALL MPI_ABORT( MPI_COMM_WORLD, 9999, ierr )
81    ELSE
82
83       SELECT CASE ( terminate_coupled_remote )
84
85          CASE ( 0 )
86             IF ( myid == 0 )  THEN
87                PRINT*, '+++ local_stop:'
88                PRINT*, '    local model "', TRIM( coupling_mode ), &
89                     '" stops now'
90             ENDIF
91!
92!--          Inform the remote model of the termination and its reason, provided
93!--          the remote model has not already been informed of another
94!--          termination reason (terminate_coupled > 0) before.
95             IF ( terminate_coupled == 0 )  THEN
96                terminate_coupled = 1
97                IF ( myid == 0 ) THEN
98                   CALL MPI_SENDRECV( &
99                        terminate_coupled,        1, MPI_INTEGER, target_id,  0, &
100                        terminate_coupled_remote, 1, MPI_INTEGER, target_id,  0, &
101                        comm_inter, status, ierr )
102                ENDIF
103                CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_REAL, 0, comm2d, ierr)
104             ENDIF
105             CALL MPI_FINALIZE( ierr )
106             STOP 1
107
108          CASE ( 1 )
109             IF ( myid == 0 )  THEN
110                PRINT*, '+++ local_stop:'
111                PRINT*, '    remote model "', TRIM( coupling_mode_remote ), &
112                     '" stopped'
113             ENDIF
114             CALL MPI_FINALIZE( ierr )
115             STOP 1
116
117          CASE ( 2 )
118             IF ( myid == 0 )  THEN
119                PRINT*, '+++ local_stop:'
120                PRINT*, '    remote model "', TRIM( coupling_mode_remote ), &
121                     '" terminated'
122                PRINT*, '    with stop_dt = .T.'
123             ENDIF
124             stop_dt = .TRUE.
125
126          CASE ( 3 )
127             IF ( myid == 0 )  THEN
128                PRINT*, '+++ local_stop:'
129                PRINT*, '    remote model "', TRIM( coupling_mode_remote ), &
130                     '" terminated'
131                PRINT*, '    with terminate_run = .T. (CPU-time limit)'
132             ENDIF
133             terminate_run = .TRUE.
134
135          CASE ( 4 )
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. (restart)'
141             ENDIF
142             terminate_run = .TRUE.
143             time_restart = time_restart + dt_restart
144
145          CASE ( 5 )
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. (single restart)'
151             ENDIF
152             terminate_run = .TRUE.
153             time_restart = 9999999.9_wp
154
155       END SELECT
156
157    ENDIF
158
159#else
160
161    STOP 1
162
163#endif
164
165 END SUBROUTINE local_stop   
Note: See TracBrowser for help on using the repository browser.