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

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

further modularization of land surface model (2D/3D output and restart data)

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