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

Last change on this file since 1858 was 1834, checked in by raasch, 9 years ago

last commit documented

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