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

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

openacc adjustments and bugfixes

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