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

Last change on this file since 1233 was 1222, checked in by raasch, 11 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 10.5 KB
RevLine 
[1]1 PROGRAM palm
2
[1036]3!--------------------------------------------------------------------------------!
4! This file is part of PALM.
5!
6! PALM is free software: you can redistribute it and/or modify it under the terms
7! of the GNU General Public License as published by the Free Software Foundation,
8! either version 3 of the License, or (at your option) any later 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-2012  Leibniz University Hannover
18!--------------------------------------------------------------------------------!
19!
[484]20! Current revisions:
[1]21! -----------------
[77]22!
[1222]23!
[77]24! Former revisions:
25! -----------------
26! $Id: palm.f90 1222 2013-09-10 14:48:09Z kanani $
27!
[1222]28! 1221 2013-09-10 08:59:13Z raasch
29! +wall_flags_00, rflags_invers, rflags_s_inner in copyin statement
30!
[1213]31! 1212 2013-08-15 08:46:27Z raasch
32! +tri in copyin statement
33!
[1182]34! 1179 2013-06-14 05:57:58Z raasch
35! ref_state added to copyin-list
36!
[1114]37! 1113 2013-03-10 02:48:14Z raasch
38! openACC statements modified
39!
[1112]40! 1111 2013-03-08 23:54:10Z raasch
41! openACC statements updated
42!
[1093]43! 1092 2013-02-02 11:24:22Z raasch
44! unused variables removed
45!
[1037]46! 1036 2012-10-22 13:43:42Z raasch
47! code put under GPL (PALM 3.9)
48!
[1017]49! 1015 2012-09-27 09:23:24Z raasch
[863]50! Version number changed from 3.8 to 3.8a.
[1017]51! OpenACC statements added + code changes required for GPU optimization
[863]52!
[850]53! 849 2012-03-15 10:35:09Z raasch
54! write_particles renamed lpm_write_restart_file
55!
[760]56! 759 2011-09-15 13:58:31Z raasch
57! Splitting of parallel I/O, cpu measurement for write_3d_binary and opening
58! of unit 14 moved to here
59!
[496]60! 495 2010-03-02 00:40:15Z raasch
61! Particle data for restart runs are only written if write_binary=.T..
62!
[226]63! 215 2008-11-18 09:54:31Z raasch
64! Initialization of coupled runs modified for MPI-1 and moved to external
65! subroutine init_coupling
66!
[198]67! 197 2008-09-16 15:29:03Z raasch
68! Workaround for getting information about the coupling mode
69!
[110]70! 108 2007-08-24 15:10:38Z letzel
71! Get coupling mode from environment variable, change location of debug output
72!
[77]73! 75 2007-03-22 09:54:05Z raasch
[70]74! __vtk directives removed, write_particles is called only in case of particle
[75]75! advection switched on, open unit 9 for debug output,
76! setting of palm version moved from modules to here
[1]77!
[3]78! RCS Log replace by Id keyword, revision history cleaned up
79!
[1]80! Revision 1.10  2006/08/04 14:53:12  raasch
81! Distibution of run description header removed, call of header moved behind
82! init_3d_model
83!
84! Revision 1.2  2001/01/25 07:15:06  raasch
85! Program name changed to PALM, module test_variables removed.
86! Initialization of dvrp logging as well as exit of dvrp moved to new
87! subroutines init_dvrp_logging and close_dvrp (file init_dvrp.f90)
88!
89! Revision 1.1  1997/07/24 11:23:35  raasch
90! Initial revision
91!
92!
93! Description:
94! ------------
95! Large-Eddy Simulation (LES) model for the convective boundary layer,
96! optimized for use on parallel machines (implementation realized using the
97! Message Passing Interface (MPI)). The model can also be run on vector machines
98! (less well optimized) and workstations. Versions for the different types of
99! machines are controlled via cpp-directives.
100! Model runs are only feasible using the ksh-script mrun.
101!------------------------------------------------------------------------------!
102
103
104    USE arrays_3d
105    USE constants
[102]106    USE control_parameters
[1]107    USE cpulog
108    USE dvrp_variables
109    USE grid_variables
110    USE indices
111    USE interfaces
112    USE model_1d
113    USE particle_attributes
114    USE pegrid
115    USE spectrum
116    USE statistics
117
[1015]118#if defined( __openacc )
119    USE OPENACC
120#endif
121
[1]122    IMPLICIT NONE
123
124!
125!-- Local variables
126    CHARACTER (LEN=9) ::  time_to_string
[1092]127    INTEGER           ::  i
[1015]128#if defined( __openacc )
129    REAL, DIMENSION(100) ::  acc_dum
130#endif
[1]131
[1036]132    version = 'PALM 3.9'
[75]133
[1]134#if defined( __parallel )
135!
136!-- MPI initialisation. comm2d is preliminary set, because
137!-- it will be defined in init_pegrid but is used before in cpu_log.
138    CALL MPI_INIT( ierr )
139    CALL MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
[206]140    CALL MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
[1]141    comm_palm = MPI_COMM_WORLD
142    comm2d    = MPI_COMM_WORLD
143
144!
[206]145!-- Initialize PE topology in case of coupled runs
146    CALL init_coupling
[102]147#endif
148
[1015]149#if defined( __openacc )
[102]150!
[1015]151!-- Get the number of accelerator boards per node and assign the MPI processes
152!-- to these boards
[1092]153    PRINT*, '*** ACC_DEVICE_NVIDIA = ', ACC_DEVICE_NVIDIA
[1015]154    num_acc_per_node  = ACC_GET_NUM_DEVICES( ACC_DEVICE_NVIDIA )
[1092]155    IF ( numprocs == 1  .AND.  num_acc_per_node > 0 )  num_acc_per_node = 1
156    PRINT*, '*** myid = ', myid, ' num_acc_per_node = ', num_acc_per_node
[1015]157    acc_rank = MOD( myid, num_acc_per_node )
[1092]158!    STOP '****'
[1015]159    CALL ACC_SET_DEVICE_NUM ( acc_rank, ACC_DEVICE_NVIDIA )
160!
161!-- Test output (to be removed later)
162    WRITE (*,'(A,I4,A,I3,A,I3,A,I3)') '*** Connect MPI-Task ', myid,' to CPU ',&
163                                      acc_rank, ' Devices: ', num_acc_per_node,&
164                                      ' connected to:',                        &
165                                      ACC_GET_DEVICE_NUM( ACC_DEVICE_NVIDIA )
166#endif
[1092]167
[1015]168!
169!-- Ensure that OpenACC first attaches the GPU devices by copying a dummy data
170!-- region
171    !$acc data copyin( acc_dum )
172
173!
[1]174!-- Initialize measuring of the CPU-time remaining to the run
175    CALL local_tremain_ini
176
177!
178!-- Start of total CPU time measuring.
179    CALL cpu_log( log_point(1), 'total', 'start' )
180    CALL cpu_log( log_point(2), 'initialisation', 'start' )
181
182!
[206]183!-- Open a file for debug output
184    WRITE (myid_char,'(''_'',I4.4)')  myid
185    OPEN( 9, FILE='DEBUG'//TRIM( coupling_char )//myid_char, FORM='FORMATTED' )
186
187!
[1]188!-- Initialize dvrp logging. Also, one PE maybe split from the global
189!-- communicator for doing the dvrp output. In that case, the number of
190!-- PEs available for PALM is reduced by one and communicator comm_palm
191!-- is changed respectively.
192#if defined( __parallel )
193    CALL MPI_COMM_RANK( comm_palm, myid, ierr )
194!
[102]195!-- TEST OUTPUT (TO BE REMOVED)
196    WRITE(9,*) '*** coupling_mode = "', TRIM( coupling_mode ), '"'
197    CALL LOCAL_FLUSH( 9 )
[215]198    IF ( TRIM( coupling_mode ) /= 'uncoupled' )  THEN
199       PRINT*, '*** PE', myid, ' Global target PE:', target_id, &
200               TRIM( coupling_mode )
201    ENDIF
[102]202#endif
203
[108]204    CALL init_dvrp_logging
205
[102]206!
[108]207!-- Read control parameters from NAMELIST files and read environment-variables
208    CALL parin
209
210!
211!-- Determine processor topology and local array indices
212    CALL init_pegrid
213
214!
[1]215!-- Generate grid parameters
216    CALL init_grid
217
218!
219!-- Check control parameters and deduce further quantities
220    CALL check_parameters
221
[667]222
[1]223!
224!-- Initialize all necessary variables
225    CALL init_3d_model
226
227!
228!-- Output of program header
229    IF ( myid == 0 )  CALL header
230
231    CALL cpu_log( log_point(2), 'initialisation', 'stop' )
232
233!
234!-- Set start time in format hh:mm:ss
235    simulated_time_chr = time_to_string( simulated_time )
236
237!
238!-- If required, output of initial arrays
239    IF ( do2d_at_begin )  THEN
240       CALL data_output_2d( 'xy', 0 )
241       CALL data_output_2d( 'xz', 0 )
242       CALL data_output_2d( 'yz', 0 )
243    ENDIF
244    IF ( do3d_at_begin )  THEN
245       CALL data_output_3d( 0 )
246    ENDIF
247
248!
[1015]249!-- Declare and initialize variables in the accelerator memory with their
250!-- host values
[1113]251    !$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 )          &
[1212]252    !$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 )   &
[1015]253    !$acc       copyin( hom, qs, qsws, qswst, rif, rif_wall, shf, ts, tswst, us, usws, uswst, vsws, vswst, z0, z0h )      &
254    !$acc       copyin( fxm, fxp, fym, fyp, fwxm, fwxp, fwym, fwyp, nzb_diff_s_inner, nzb_diff_s_outer, nzb_diff_u )       &
255    !$acc       copyin( nzb_diff_v, nzb_s_inner, nzb_s_outer, nzb_u_inner )    &
256    !$acc       copyin( nzb_u_outer, nzb_v_inner, nzb_v_outer, nzb_w_inner )   &
[1221]257    !$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 )  &
258    !$acc       copyin( ngp_2dh, ngp_2dh_s_inner )  &
[1113]259    !$acc       copyin( weight_pres, weight_substep )
[1015]260!
[495]261!-- Integration of the model equations using timestep-scheme
[1]262    CALL time_integration
263
264!
[495]265!-- If required, write binary data for restart runs
266    IF ( write_binary(1:4) == 'true' )  THEN
[759]267
268       CALL cpu_log( log_point(22), 'write_3d_binary', 'start' )
269
270       CALL check_open( 14 )
271
272       DO  i = 0, io_blocks-1
273          IF ( i == io_group )  THEN
[1]274!
[759]275!--          Write flow field data
276             CALL write_3d_binary
277          ENDIF
278#if defined( __parallel )
279          CALL MPI_BARRIER( comm2d, ierr )
280#endif
281       ENDDO
282
283       CALL cpu_log( log_point(22), 'write_3d_binary', 'stop' )
284
[495]285!
286!--    If required, write particle data
[849]287       IF ( particle_advection )  CALL lpm_write_restart_file
[495]288    ENDIF
[1]289
290!
291!-- If required, repeat output of header including the required CPU-time
292    IF ( myid == 0 )  CALL header
293!
294!-- If required, final user-defined actions, and
295!-- last actions on the open files and close files. Unit 14 was opened
296!-- in write_3d_binary but it is closed here, to allow writing on this
297!-- unit in routine user_last_actions.
298    CALL cpu_log( log_point(4), 'last actions', 'start' )
[759]299    DO  i = 0, io_blocks-1
300       IF ( i == io_group )  THEN
301          CALL user_last_actions
302          IF ( write_binary(1:4) == 'true' )  CALL close_file( 14 )
303       ENDIF
304#if defined( __parallel )
305       CALL MPI_BARRIER( comm2d, ierr )
306#endif
307    ENDDO
[1]308    CALL close_file( 0 )
309    CALL close_dvrp
310    CALL cpu_log( log_point(4), 'last actions', 'stop' )
311
[102]312#if defined( __mpi2 )
[1]313!
[206]314!-- Test exchange via intercommunicator in case of a MPI-2 coupling
[102]315    IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
316       i = 12345 + myid
317       CALL MPI_SEND( i, 1, MPI_INTEGER, myid, 11, comm_inter, ierr )
318    ELSEIF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
319       CALL MPI_RECV( i, 1, MPI_INTEGER, myid, 11, comm_inter, status, ierr )
320       PRINT*, '### myid: ', myid, '   received from atmosphere:  i = ', i
321    ENDIF
322#endif
323
324!
[1015]325!-- Close the OpenACC dummy data region
326    !$acc end data
327    !$acc end data
328
329!
[1]330!-- Take final CPU-time for CPU-time analysis
331    CALL cpu_log( log_point(1), 'total', 'stop' )
332    CALL cpu_statistics
333
334#if defined( __parallel )
335    CALL MPI_FINALIZE( ierr )
336#endif
337
338 END PROGRAM palm
Note: See TracBrowser for help on using the repository browser.