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

Last change on this file since 2008 was 2008, checked in by kanani, 8 years ago

last commit documented

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