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

Last change on this file since 4644 was 4539, checked in by raasch, 4 years ago

checks added, if index limits in header are exceeded (restart_data_mpi_io_mod), bugfix in rrd_mpi_io_int_2d, location and log_point names added/modified, cpu time per grid point and timestep does not included initialization and spinup any more (cpulog_mod)

  • Property svn:keywords set to Id
File size: 16.3 KB
Line 
1! !> @file palm.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
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-2020 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: palm.f90 4539 2020-05-18 14:05:17Z pavelkrc $
27! log point name changed
28!
29! 4535 2020-05-15 12:07:23Z raasch
30! bugfix for restart data format query
31!
32! 4496 2020-04-15 08:37:26Z raasch
33! bugfix: coupling character added to restart output filename
34!
35! 4495 2020-04-13 20:11:20Z raasch
36! restart data handling with MPI-IO added
37!
38! 4457 2020-03-11 14:20:43Z raasch
39! use statement for exchange horiz added
40!
41! 4444 2020-03-05 15:59:50Z raasch
42! bugfix: cpp-directives for serial mode added
43!
44! 4414 2020-02-19 20:16:04Z suehring
45! Call to module_interface_init_numerics
46!
47! 4400 2020-02-10 20:32:41Z suehring
48! Add interface to initialize data output with dom
49!
50! 4360 2020-01-07 11:25:50Z suehring
51! implement new palm_date_time_mod
52!
53! 4094 2019-07-12 09:24:21Z gronemeier
54! Corrected "Former revisions" section
55!
56! 4039 2019-06-18 10:32:41Z suehring
57! Rename subroutines in module for diagnostic quantities
58!
59! 4017 2019-06-06 12:16:46Z schwenkel
60! new module for calculation and output of diagnostic quantities added
61!
62! 3885 2019-04-11 11:29:34Z kanani
63! Changes related to global restructuring of location messages and introduction
64! of additional debug messages
65!
66! 3761 2019-02-25 15:31:42Z raasch
67! unused variable removed
68!
69! 3719 2019-02-06 13:10:18Z kanani
70! Included cpu measurement for wall/soil spinup
71!
72! 3703 2019-01-29 16:43:53Z knoop
73! Some interface calls moved to module_interface + cleanup
74!
75! 3648 2019-01-02 16:35:46Z suehring
76! Rename subroutines for surface-data output
77!
78! Revision 1.1  1997/07/24 11:23:35  raasch
79! Initial revision
80!
81!
82! Description:
83! ------------
84!> Large-Eddy Simulation (LES) model for atmospheric and oceanic boundary-layer
85!> flows
86!> see the PALM homepage https://palm-model.org for further information
87!------------------------------------------------------------------------------!
88 PROGRAM palm
89 
90
91    USE arrays_3d
92
93#if defined( __parallel )
94    USE bulk_cloud_model_mod,                                                  &
95        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
96#endif
97
98    USE control_parameters,                                                    &
99        ONLY:  coupling_char, do2d_at_begin, do3d_at_begin, io_blocks,         &
100               io_group, message_string, restart_data_format_output, runnr, simulated_time_chr, spinup,   &
101               time_since_reference_point, user_interface_current_revision,    &
102               user_interface_required_revision, version, write_binary
103
104#if defined( __parallel )
105    USE control_parameters,                                                    &
106        ONLY:  child_domain, constant_diffusion, humidity,                     &
107               initializing_actions, neutral, passive_scalar
108#endif
109
110    USE cpulog,                                                                &
111        ONLY:  cpu_log, log_point, cpu_statistics
112
113#if defined( __parallel )
114    USE cpulog,                                                                &
115        ONLY:  log_point_s
116#endif
117
118    USE diagnostic_output_quantities_mod,                                      &
119        ONLY:  doq_calculate
120
121#if defined( __parallel )
122    USE exchange_horiz_mod,                                                    &
123        ONLY:  exchange_horiz
124
125    USE indices,                                                               &
126        ONLY:  nbgp
127#endif
128
129    USE kinds
130
131    USE module_interface,                                                      &
132        ONLY:  module_interface_init_numerics,                                 &
133               module_interface_init_output,                                   &
134               module_interface_last_actions
135
136
137    USE multi_agent_system_mod,                                                &
138        ONLY:  agents_active, mas_last_actions
139
140    USE netcdf_data_input_mod,                                                 &
141        ONLY:  netcdf_data_input_inquire_file, netcdf_data_input_init,         &
142               netcdf_data_input_surface_data, netcdf_data_input_topo
143
144    USE pegrid
145
146#if defined( __parallel )
147    USE pmc_particle_interface,                                                &
148        ONLY: pmcp_g_alloc_win
149
150    USE pmc_interface,                                                         &
151        ONLY:  nested_run, pmci_child_initialize, pmci_init,                   &
152               pmci_modelconfiguration, pmci_parent_initialize
153#endif
154
155    USE restart_data_mpi_io_mod,                                               &
156        ONLY:  rd_mpi_io_close, rd_mpi_io_open
157
158    USE surface_data_output_mod,                                               &
159        ONLY:  surface_data_output_last_action
160
161    USE write_restart_data_mod,                                                &
162        ONLY:  wrd_global, wrd_local
163
164#if defined( __parallel )  &&  defined( _OPENACC )
165    USE openacc
166#endif
167
168
169    IMPLICIT NONE
170
171!
172!-- Local variables
173    CHARACTER(LEN=9) ::  time_to_string  !<
174    INTEGER(iwp)     ::  i               !< loop counter for blocked I/O
175#if defined( __parallel) && defined( _OPENACC )
176    INTEGER(iwp)     :: local_comm       !< local communicator (shared memory)
177    INTEGER(iwp)     :: local_num_procs  !< local number of processes
178    INTEGER(iwp)     :: local_id         !< local id
179    INTEGER(acc_device_kind) :: device_type !< device type for OpenACC
180    INTEGER(iwp)     ::  num_devices     !< number of devices visible to OpenACC
181    INTEGER(iwp)     ::  my_device       !< device used by this process
182#endif
183
184    version = 'PALM 6.0'
185    user_interface_required_revision = 'r4495'
186
187#if defined( __parallel )
188!
189!-- MPI initialisation. comm2d is preliminary set, because
190!-- it will be defined in init_pegrid but is used before in cpu_log.
191    CALL MPI_INIT( ierr )
192
193!
194!-- Initialize the coupling for nested-domain runs
195!-- comm_palm is the communicator which includes all PEs (MPI processes)
196!-- available for this (nested) model. If it is not a nested run, comm_palm
197!-- is returned as MPI_COMM_WORLD
198    CALL cpu_log( log_point_s(70), 'pmci_init', 'start' )
199    CALL pmci_init( comm_palm )
200    CALL cpu_log( log_point_s(70), 'pmci_init', 'stop' )
201    comm2d = comm_palm
202!
203!-- Get the (preliminary) number of MPI processes and the local PE-id (in case
204!-- of a further communicator splitting in init_coupling, these numbers will
205!-- be changed in init_pegrid).
206    IF ( nested_run )  THEN
207
208       CALL MPI_COMM_SIZE( comm_palm, numprocs, ierr )
209       CALL MPI_COMM_RANK( comm_palm, myid, ierr )
210
211    ELSE
212
213       CALL MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
214       CALL MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
215!
216!--    Initialize PE topology in case of coupled atmosphere-ocean runs (comm_palm
217!--    will be splitted in init_coupling)
218       CALL init_coupling
219    ENDIF
220
221#ifdef _OPENACC
222!
223!-- Select OpenACC device to use in this process. For this find out how many
224!-- neighbors there are running on the same node and which id this process is.
225    IF ( nested_run )  THEN
226       CALL MPI_COMM_SPLIT_TYPE( comm_palm, MPI_COMM_TYPE_SHARED, 0,           &
227                                 MPI_INFO_NULL, local_comm, ierr )
228    ELSE
229       CALL MPI_COMM_SPLIT_TYPE( MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0,      &
230                                 MPI_INFO_NULL, local_comm, ierr )
231    ENDIF
232    CALL MPI_COMM_SIZE( local_comm, local_num_procs, ierr )
233    CALL MPI_COMM_RANK( local_comm, local_id, ierr )
234
235!
236!-- This loop including the barrier is a workaround for PGI compiler versions
237!-- up to and including 18.4. Later releases are able to select their GPUs in
238!-- parallel, without running into spurious errors.
239    DO i = 0, local_num_procs-1
240       CALL MPI_BARRIER( local_comm, ierr )
241
242       IF ( i == local_id )  THEN
243          device_type = acc_get_device_type()
244          num_devices = acc_get_num_devices( device_type )
245          my_device = MOD( local_id, num_devices )
246          CALL acc_set_device_num( my_device, device_type )
247       ENDIF
248    ENDDO
249
250    CALL MPI_COMM_FREE( local_comm, ierr )
251#endif
252#endif
253
254!
255!-- Initialize measuring of the CPU-time remaining to the run
256    CALL local_tremain_ini
257
258!
259!-- Start of total CPU time measuring.
260    CALL cpu_log( log_point(1), 'total', 'start' )
261    CALL cpu_log( log_point(2), 'initialisation', 'start' )
262
263!
264!-- Open a file for debug output
265    WRITE (myid_char,'(''_'',I6.6)')  myid
266    OPEN( 9, FILE='DEBUG'//TRIM( coupling_char )//myid_char, FORM='FORMATTED' )
267
268!
269!-- Initialize dvrp logging. Also, one PE maybe split from the global
270!-- communicator for doing the dvrp output. In that case, the number of
271!-- PEs available for PALM is reduced by one and communicator comm_palm
272!-- is changed respectively.
273#if defined( __parallel )
274    CALL MPI_COMM_RANK( comm_palm, myid, ierr )
275#endif
276
277!
278!-- Read control parameters from NAMELIST files and read environment-variables
279    CALL parin
280
281!
282!-- Check for the user's interface version
283    IF ( user_interface_current_revision /= user_interface_required_revision )  &
284    THEN
285       message_string = 'current user-interface revision "' //                  &
286                        TRIM( user_interface_current_revision ) // '" does ' // &
287                        'not match the required revision ' //                   &
288                        TRIM( user_interface_required_revision )
289        CALL message( 'palm', 'PA0169', 1, 2, 0, 6, 0 )
290    ENDIF
291
292!
293!-- Determine processor topology and local array indices
294    CALL init_pegrid
295!
296!-- Check if input file according to input-data standard exists
297    CALL netcdf_data_input_inquire_file
298!
299!-- Read topography input data if required. This is required before the
300!-- numerical grid is finally created in init_grid
301    CALL netcdf_data_input_topo 
302!
303!-- Generate grid parameters, initialize generic topography and further process
304!-- topography information if required
305    CALL init_grid
306!
307!-- Initialize boundary conditions and numerics such as the multigrid solver or
308!-- the advection routine
309    CALL module_interface_init_numerics
310!
311!-- Read global attributes if available. 
312    CALL netcdf_data_input_init 
313!
314!-- Read surface classification data, e.g. vegetation and soil types, water
315!-- surfaces, etc., if available. Some of these data is required before
316!-- check parameters is invoked.     
317    CALL netcdf_data_input_surface_data
318!
319!-- Check control parameters and deduce further quantities
320    CALL check_parameters
321
322    CALL init_3d_model
323
324    CALL module_interface_init_output
325
326#if defined( __parallel )
327!
328!-- Coupling protocol setup for nested-domain runs
329    IF ( nested_run )  THEN
330       CALL pmci_modelconfiguration
331!
332!--    Receive and interpolate initial data on children.
333!--    Child initialization must be made first if the model is both child and
334!--    parent if necessary
335       IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
336          CALL pmci_child_initialize
337!
338!--       Send initial condition data from parent to children
339          CALL pmci_parent_initialize
340!
341!--       Exchange_horiz is needed after the nest initialization
342          IF ( child_domain )  THEN
343             CALL exchange_horiz( u, nbgp )
344             CALL exchange_horiz( v, nbgp )
345             CALL exchange_horiz( w, nbgp )
346             IF ( .NOT. neutral )  THEN
347                CALL exchange_horiz( pt, nbgp )
348             ENDIF
349             IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e, nbgp )
350             IF ( humidity )  THEN
351                CALL exchange_horiz( q, nbgp )
352                IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
353                  CALL exchange_horiz( qc, nbgp )
354                  CALL exchange_horiz( nc, nbgp )
355                ENDIF
356                IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
357                   CALL exchange_horiz( qr, nbgp ) 
358                   CALL exchange_horiz( nr, nbgp )
359                ENDIF
360             ENDIF
361             IF ( passive_scalar )  CALL exchange_horiz( s, nbgp )
362          ENDIF
363       ENDIF
364
365       CALL pmcp_g_alloc_win                    ! Must be called after pmci_child_initialize and pmci_parent_initialize
366    ENDIF
367#endif
368
369!
370!-- Output of program header
371    IF ( myid == 0 )  CALL header
372
373    CALL cpu_log( log_point(2), 'initialisation', 'stop' )
374
375!
376!-- Integration of the non-atmospheric equations (land surface model, urban
377!-- surface model)
378    IF ( spinup )  THEN
379       CALL cpu_log( log_point(41), 'wall/soil spinup', 'start' )
380       CALL time_integration_spinup
381       CALL cpu_log( log_point(41), 'wall/soil spinup', 'stop' )
382    ENDIF
383
384!
385!-- Set start time in format hh:mm:ss
386    simulated_time_chr = time_to_string( time_since_reference_point )
387
388!
389!-- If required, output of initial arrays
390    IF ( do2d_at_begin )  THEN
391       CALL doq_calculate    !TODO, will be called twice
392
393       CALL data_output_2d( 'xy', 0 )
394       CALL data_output_2d( 'xz', 0 )
395       CALL data_output_2d( 'yz', 0 )
396    ENDIF
397
398    IF ( do3d_at_begin )  THEN
399       CALL doq_calculate    !TODO, will be called twice
400
401       CALL data_output_3d( 0 )
402    ENDIF
403
404!
405!-- Integration of the model equations using timestep-scheme
406    CALL time_integration
407
408!
409!-- If required, write binary data for restart runs
410    IF ( write_binary )  THEN
411
412       CALL cpu_log( log_point(22), 'write-restart-data', 'start' )
413
414       CALL location_message( 'writing restart data', 'start' )
415
416       IF ( TRIM( restart_data_format_output ) == 'fortran_binary' )  THEN
417
418          DO  i = 0, io_blocks-1
419             IF ( i == io_group )  THEN
420
421!
422!--             Open binary file
423                CALL check_open( 14 )
424!
425!--             Write control parameters and other global variables for restart.
426                IF ( myid == 0 )  CALL wrd_global
427!
428!--             Write processor specific flow field data for restart runs
429                CALL wrd_local
430!
431!--             Close binary file
432                CALL close_file( 14 )
433
434             ENDIF
435#if defined( __parallel )
436             CALL MPI_BARRIER( comm2d, ierr )
437#endif
438          ENDDO
439
440       ELSEIF ( restart_data_format_output(1:3) == 'mpi' )  THEN
441!
442!--       Open MPI-IO restart file
443          CALL rd_mpi_io_open( 'write', 'BINOUT' // TRIM( coupling_char ) )
444!
445!--       Write control parameters and other global variables for restart.
446          CALL wrd_global
447!
448!--       Write processor specific flow field data for restart runs
449          CALL wrd_local
450!
451!--       Close restart File
452          CALL rd_mpi_io_close
453
454       ENDIF
455
456       CALL location_message( 'writing restart data', 'finished' )
457
458       CALL cpu_log( log_point(22), 'write-restart-data', 'stop' )
459       
460    ENDIF
461!
462!-- Last actions for surface output, for instantaneous and time-averaged data
463    CALL surface_data_output_last_action( 0 )
464    CALL surface_data_output_last_action( 1 )
465
466!
467!-- If required, repeat output of header including the required CPU-time
468    IF ( myid == 0 )  CALL header
469!
470!-- Perform module specific last actions
471    CALL cpu_log( log_point(4), 'last actions', 'start' )
472
473    IF ( myid == 0 .AND. agents_active ) CALL mas_last_actions ! ToDo: move to module_interface
474
475    CALL module_interface_last_actions
476
477    CALL cpu_log( log_point(4), 'last actions', 'stop' )
478
479!
480!-- Close files
481    CALL close_file( 0 )
482
483!
484!-- Write run number to file (used by palmrun to create unified cycle numbers
485!-- for output files
486    IF ( myid == 0  .AND.  runnr > 0 )  THEN
487       OPEN( 90, FILE='RUN_NUMBER', FORM='FORMATTED' )
488       WRITE( 90, '(I4)' )  runnr
489       CLOSE( 90 )
490    ENDIF
491
492!
493!-- Take final CPU-time for CPU-time analysis
494    CALL cpu_log( log_point(1), 'total', 'stop' )
495    CALL cpu_statistics
496
497#if defined( __parallel )
498    CALL MPI_FINALIZE( ierr )
499#endif
500
501 END PROGRAM palm
Note: See TracBrowser for help on using the repository browser.