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

Last change on this file since 1832 was 1818, checked in by maronga, 9 years ago

last commit documented / copyright update

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