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