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

Last change on this file since 1986 was 1977, checked in by maronga, 8 years ago

last commit documented

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