source: palm/trunk/SOURCE/palm.f90 @ 2118

Last change on this file since 2118 was 2118, checked in by raasch, 7 years ago

all OpenACC directives and related parts removed from the code

  • Property svn:keywords set to Id
File size: 15.2 KB
Line 
1!> @file palm.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-2017 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22! OpenACC directives and related code removed
23!
24! Former revisions:
25! -----------------
26! $Id: palm.f90 2118 2017-01-17 16:38:49Z raasch $
27!
28! 2011 2016-09-19 17:29:57Z kanani
29! Flag urban_surface is now defined in module control_parameters.
30!
31! 2007 2016-08-24 15:47:17Z kanani
32! Temporarily added CALL for writing of restart data for urban surface model
33!
34! 2000 2016-08-20 18:09:15Z knoop
35! Forced header and separation lines into 80 columns
36!
37! 1976 2016-07-27 13:28:04Z maronga
38! Added call to radiation_last_actions for binary output of land surface model
39! data
40!
41! 1972 2016-07-26 07:52:02Z maronga
42! Added call to lsm_last_actions for binary output of land surface model data
43!
44! 1960 2016-07-12 16:34:24Z suehring
45! Separate humidity and passive scalar
46!
47! 1834 2016-04-07 14:34:20Z raasch
48! Initial version of purely vertical nesting introduced.
49!
50! 1833 2016-04-07 14:23:03Z raasch
51! required user interface version changed
52!
53! 1808 2016-04-05 19:44:00Z raasch
54! routine local_flush replaced by FORTRAN statement
55!
56! 1783 2016-03-06 18:36:17Z raasch
57! required user interface version changed
58!
59! 1781 2016-03-03 15:12:23Z raasch
60! pmc initialization moved from time_integration to here
61!
62! 1779 2016-03-03 08:01:28Z raasch
63! setting of nest_domain and coupling_char moved to the pmci
64!
65! 1764 2016-02-28 12:45:19Z raasch
66! cpp-statements for nesting removed, communicator settings cleaned up
67!
68! 1762 2016-02-25 12:31:13Z hellstea
69! Introduction of nested domain feature
70!
71! 1747 2016-02-08 12:25:53Z raasch
72! OpenACC-adjustment for new surface layer parameterization
73!
74! 1682 2015-10-07 23:56:08Z knoop
75! Code annotations made doxygen readable
76!
77! 1668 2015-09-23 13:45:36Z raasch
78! warning replaced by abort in case of failed user interface check
79!
80! 1666 2015-09-23 07:31:10Z raasch
81! check for user's interface version added
82!
83! 1482 2014-10-18 12:34:45Z raasch
84! adjustments for using CUDA-aware OpenMPI
85!
86! 1468 2014-09-24 14:06:57Z maronga
87! Adapted for use on up to 6-digit processor cores
88!
89! 1402 2014-05-09 14:25:13Z raasch
90! location messages added
91!
92! 1374 2014-04-25 12:55:07Z raasch
93! bugfix: various modules added
94!
95! 1320 2014-03-20 08:40:49Z raasch
96! ONLY-attribute added to USE-statements,
97! kind-parameters added to all INTEGER and REAL declaration statements,
98! kinds are defined in new module kinds,
99! old module precision_kind is removed,
100! revision history before 2012 removed,
101! comment fields (!:) to be used for variable explanations added to
102! all variable declaration statements
103!
104! 1318 2014-03-17 13:35:16Z raasch
105! module interfaces removed
106!
107! 1241 2013-10-30 11:36:58Z heinze
108! initialization of nuding and large scale forcing from external file
109!
110! 1221 2013-09-10 08:59:13Z raasch
111! +wall_flags_00, rflags_invers, rflags_s_inner in copyin statement
112!
113! 1212 2013-08-15 08:46:27Z raasch
114! +tri in copyin statement
115!
116! 1179 2013-06-14 05:57:58Z raasch
117! ref_state added to copyin-list
118!
119! 1113 2013-03-10 02:48:14Z raasch
120! openACC statements modified
121!
122! 1111 2013-03-08 23:54:10Z raasch
123! openACC statements updated
124!
125! 1092 2013-02-02 11:24:22Z raasch
126! unused variables removed
127!
128! 1036 2012-10-22 13:43:42Z raasch
129! code put under GPL (PALM 3.9)
130!
131! 1015 2012-09-27 09:23:24Z raasch
132! Version number changed from 3.8 to 3.8a.
133! OpenACC statements added + code changes required for GPU optimization
134!
135! 849 2012-03-15 10:35:09Z raasch
136! write_particles renamed lpm_write_restart_file
137!
138! Revision 1.1  1997/07/24 11:23:35  raasch
139! Initial revision
140!
141!
142! Description:
143! ------------
144!> Large-Eddy Simulation (LES) model for the convective boundary layer,
145!> optimized for use on parallel machines (implementation realized using the
146!> Message Passing Interface (MPI)). The model can also be run on vector machines
147!> (less well optimized) and workstations. Versions for the different types of
148!> machines are controlled via cpp-directives.
149!> Model runs are only feasible using the ksh-script mrun.
150!>
151!> @todo create routine last_actions instead of calling lsm_last_actions etc.
152!> @todo eventually move CALL usm_write_restart_data to suitable location
153!------------------------------------------------------------------------------!
154 PROGRAM palm
155 
156
157    USE arrays_3d
158
159    USE control_parameters,                                                    &
160        ONLY:  constant_diffusion, coupling_char, coupling_mode,               &
161               do2d_at_begin, do3d_at_begin, humidity, io_blocks, io_group,    &
162               large_scale_forcing, message_string, nest_domain, neutral,      &
163               nudging, passive_scalar, simulated_time, simulated_time_chr,    &
164               urban_surface,                                                  &
165               user_interface_current_revision,                                &
166               user_interface_required_revision, version, wall_heatflux,       &
167               write_binary
168
169    USE cpulog,                                                                &
170        ONLY:  cpu_log, log_point, cpu_statistics
171
172    USE grid_variables,                                                        &
173        ONLY:  fxm, fxp, fym, fyp, fwxm, fwxp, fwym, fwyp, wall_e_x, wall_e_y, &
174               wall_u, wall_v, wall_w_x, wall_w_y
175
176    USE indices,                                                               &
177        ONLY:  nbgp, ngp_2dh, ngp_2dh_s_inner, nzb_diff_s_inner, nzb_diff_s_outer,   &
178               nzb_diff_u, nzb_diff_v, nzb_s_inner, nzb_s_outer, nzb_u_inner,  &
179               nzb_u_outer, nzb_v_inner, nzb_v_outer, nzb_w_inner,             &
180               nzb_w_outer, rflags_invers, rflags_s_inner, wall_flags_0,       &
181               wall_flags_00
182
183    USE kinds
184
185    USE land_surface_model_mod,                                                &
186        ONLY:  land_surface, lsm_last_actions
187
188    USE ls_forcing_mod,                                                        &
189        ONLY:  init_ls_forcing
190
191    USE nudge_mod,                                                             &
192        ONLY:  init_nudge
193
194    USE particle_attributes,                                                   &
195        ONLY:  particle_advection
196
197    USE pegrid
198
199    USE pmc_interface,                                                         &
200        ONLY:  cpl_id, nested_run, pmci_child_initialize, pmci_init,           &
201               pmci_modelconfiguration, pmci_parent_initialize
202
203    USE radiation_model_mod,                                                   &
204        ONLY:  radiation, radiation_last_actions
205
206    USE statistics,                                                            &
207        ONLY:  hom, rmask, weight_pres, weight_substep
208
209    USE surface_layer_fluxes_mod,                                              &
210        ONLY:  pt1, qv1, uv_total
211       
212    USE urban_surface_mod,                                                     &
213        ONLY:  usm_write_restart_data       
214
215    IMPLICIT NONE
216
217!
218!-- Local variables
219    CHARACTER(LEN=9)  ::  time_to_string  !<
220    CHARACTER(LEN=10) ::  env_string      !< to store string of environment var
221    INTEGER(iwp)      ::  env_stat        !< to hold status of GET_ENV
222    INTEGER(iwp)      ::  i               !<
223    INTEGER(iwp)      ::  myid_openmpi    !< OpenMPI local rank for CUDA aware MPI
224
225    version = 'PALM 4.0'
226    user_interface_required_revision = 'r1819'
227
228#if defined( __parallel )
229!
230!-- MPI initialisation. comm2d is preliminary set, because
231!-- it will be defined in init_pegrid but is used before in cpu_log.
232    CALL MPI_INIT( ierr )
233
234!
235!-- Initialize the coupling for nested-domain runs
236!-- comm_palm is the communicator which includes all PEs (MPI processes)
237!-- available for this (nested) model. If it is not a nested run, comm_palm
238!-- is returned as MPI_COMM_WORLD
239    CALL pmci_init( comm_palm )
240    comm2d = comm_palm
241!
242!-- Get the (preliminary) number of MPI processes and the local PE-id (in case
243!-- of a further communicator splitting in init_coupling, these numbers will
244!-- be changed in init_pegrid).
245    IF ( nested_run )  THEN
246
247       CALL MPI_COMM_SIZE( comm_palm, numprocs, ierr )
248       CALL MPI_COMM_RANK( comm_palm, myid, ierr )
249
250    ELSE
251
252       CALL MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
253       CALL MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
254!
255!--    Initialize PE topology in case of coupled atmosphere-ocean runs (comm_palm
256!--    will be splitted in init_coupling)
257       CALL init_coupling
258    ENDIF
259#endif
260
261!
262!-- Initialize measuring of the CPU-time remaining to the run
263    CALL local_tremain_ini
264
265!
266!-- Start of total CPU time measuring.
267    CALL cpu_log( log_point(1), 'total', 'start' )
268    CALL cpu_log( log_point(2), 'initialisation', 'start' )
269
270!
271!-- Open a file for debug output
272    WRITE (myid_char,'(''_'',I6.6)')  myid
273    OPEN( 9, FILE='DEBUG'//TRIM( coupling_char )//myid_char, FORM='FORMATTED' )
274
275!
276!-- Initialize dvrp logging. Also, one PE maybe split from the global
277!-- communicator for doing the dvrp output. In that case, the number of
278!-- PEs available for PALM is reduced by one and communicator comm_palm
279!-- is changed respectively.
280#if defined( __parallel )
281    CALL MPI_COMM_RANK( comm_palm, myid, ierr )
282!
283!-- TEST OUTPUT (TO BE REMOVED)
284    WRITE(9,*) '*** coupling_mode = "', TRIM( coupling_mode ), '"'
285    FLUSH( 9 )
286    IF ( TRIM( coupling_mode ) /= 'uncoupled' )  THEN
287       PRINT*, '*** PE', myid, ' Global target PE:', target_id, &
288               TRIM( coupling_mode )
289    ENDIF
290#endif
291
292    CALL init_dvrp_logging
293
294!
295!-- Read control parameters from NAMELIST files and read environment-variables
296    CALL parin
297
298!
299!-- Check for the user's interface version
300    IF ( user_interface_current_revision /= user_interface_required_revision )  &
301    THEN
302       message_string = 'current user-interface revision "' //                  &
303                        TRIM( user_interface_current_revision ) // '" does ' // &
304                        'not match the required revision ' //                   &
305                        TRIM( user_interface_required_revision )
306        CALL message( 'palm', 'PA0169', 1, 2, 0, 6, 0 )
307    ENDIF
308
309!
310!-- Determine processor topology and local array indices
311    CALL init_pegrid
312
313!
314!-- Generate grid parameters
315    CALL init_grid
316
317!
318!-- Initialize nudging if required
319    IF ( nudging )  THEN
320       CALL init_nudge
321    ENDIF
322
323!
324!-- Initialize reading of large scale forcing from external file - if required
325    IF ( large_scale_forcing )  THEN
326       CALL init_ls_forcing
327    ENDIF
328
329!
330!-- Check control parameters and deduce further quantities
331    CALL check_parameters
332
333!
334!-- Initialize all necessary variables
335    CALL init_3d_model
336
337!
338!-- Coupling protocol setup for nested-domain runs
339    IF ( nested_run )  THEN
340       CALL pmci_modelconfiguration
341!
342!--    Receive and interpolate initial data on children.
343!--    Child initialization must be made first if the model is both child and
344!--    parent
345       CALL pmci_child_initialize
346!
347!--    Send initial condition data from parent to children
348       CALL pmci_parent_initialize
349!
350!--    Exchange_horiz is needed after the nest initialization
351       IF ( nest_domain )  THEN
352          CALL exchange_horiz( u, nbgp )
353          CALL exchange_horiz( v, nbgp )
354          CALL exchange_horiz( w, nbgp )
355          IF ( .NOT. neutral )  THEN
356             CALL exchange_horiz( pt, nbgp )
357          ENDIF
358          IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e, nbgp )
359          IF ( humidity       )  CALL exchange_horiz( q, nbgp )
360          IF ( passive_scalar )  CALL exchange_horiz( s, nbgp )
361       ENDIF
362
363    ENDIF
364
365!
366!-- Output of program header
367    IF ( myid == 0 )  CALL header
368
369    CALL cpu_log( log_point(2), 'initialisation', 'stop' )
370
371!
372!-- Set start time in format hh:mm:ss
373    simulated_time_chr = time_to_string( simulated_time )
374
375!
376!-- If required, output of initial arrays
377    IF ( do2d_at_begin )  THEN
378       CALL data_output_2d( 'xy', 0 )
379       CALL data_output_2d( 'xz', 0 )
380       CALL data_output_2d( 'yz', 0 )
381    ENDIF
382
383    IF ( do3d_at_begin )  THEN
384       CALL data_output_3d( 0 )
385    ENDIF
386
387!
388!-- Integration of the model equations using timestep-scheme
389    CALL time_integration
390
391!
392!-- If required, write binary data for restart runs
393    IF ( write_binary(1:4) == 'true' )  THEN
394
395       CALL cpu_log( log_point(22), 'write_3d_binary', 'start' )
396
397       CALL location_message( 'writing restart data', .FALSE. )
398
399       CALL check_open( 14 )
400
401       DO  i = 0, io_blocks-1
402          IF ( i == io_group )  THEN
403!
404!--          Write flow field data
405             CALL write_3d_binary
406          ENDIF
407#if defined( __parallel )
408          CALL MPI_BARRIER( comm2d, ierr )
409#endif
410       ENDDO
411
412       CALL location_message( 'finished', .TRUE. )
413
414       CALL cpu_log( log_point(22), 'write_3d_binary', 'stop' )
415
416!
417!--    If required, write particle data
418       IF ( particle_advection )  CALL lpm_write_restart_file
419!
420!--    If required, write urban surface data
421       IF (urban_surface)  CALL usm_write_restart_data
422       
423    ENDIF
424
425!
426!-- If required, repeat output of header including the required CPU-time
427    IF ( myid == 0 )  CALL header
428!
429!-- If required, final land surface and user-defined actions, and
430!-- last actions on the open files and close files. Unit 14 was opened
431!-- in write_3d_binary but it is closed here, to allow writing on this
432!-- unit in routine user_last_actions.
433    CALL cpu_log( log_point(4), 'last actions', 'start' )
434    DO  i = 0, io_blocks-1
435       IF ( i == io_group )  THEN
436          IF ( land_surface )  THEN
437             CALL lsm_last_actions
438          ENDIF
439          IF ( radiation )  THEN
440             CALL radiation_last_actions
441          ENDIF
442          CALL user_last_actions
443          IF ( write_binary(1:4) == 'true' )  CALL close_file( 14 )
444       ENDIF
445#if defined( __parallel )
446       CALL MPI_BARRIER( comm2d, ierr )
447#endif
448    ENDDO
449    CALL close_file( 0 )
450    CALL close_dvrp
451    CALL cpu_log( log_point(4), 'last actions', 'stop' )
452
453#if defined( __mpi2 )
454!
455!-- Test exchange via intercommunicator in case of a MPI-2 coupling
456    IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
457       i = 12345 + myid
458       CALL MPI_SEND( i, 1, MPI_INTEGER, myid, 11, comm_inter, ierr )
459    ELSEIF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
460       CALL MPI_RECV( i, 1, MPI_INTEGER, myid, 11, comm_inter, status, ierr )
461       PRINT*, '### myid: ', myid, '   received from atmosphere:  i = ', i
462    ENDIF
463#endif
464
465!
466!-- Take final CPU-time for CPU-time analysis
467    CALL cpu_log( log_point(1), 'total', 'stop' )
468    CALL cpu_statistics
469
470#if defined( __parallel )
471    CALL MPI_FINALIZE( ierr )
472#endif
473
474 END PROGRAM palm
Note: See TracBrowser for help on using the repository browser.