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

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

last commit documented

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