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

Last change on this file since 2000 was 2000, checked in by knoop, 5 years ago

Forced header and separation lines into 80 columns

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