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

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

last commit documented

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