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

Last change on this file since 1951 was 1933, checked in by hellstea, 8 years ago

last commit documented

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