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

Last change on this file since 1682 was 1682, checked in by knoop, 9 years ago

Code annotations made doxygen readable

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