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

Last change on this file since 1765 was 1765, checked in by raasch, 5 years ago

last commit documented

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