SCALE-RM
scale-rm_init.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
11 !-------------------------------------------------------------------------------
12 program scalerm_init
13  !-----------------------------------------------------------------------------
14  !
15  !++ used modules
16  !
17  use scale_precision
18  use scale_io
19  use scale_prof
20 
21  use scale_prc, only: &
23  prc_mpistart, &
24  prc_abort, &
25  prc_mpifinish, &
26  prc_mpisplit, &
31  use scale_fpm, only: &
32  fpm_init
33  use mod_rm_prep, only: &
34  rm_prep
35  use mod_rm_driver, only: &
36  rm_driver
37  !-----------------------------------------------------------------------------
38  implicit none
39  !-----------------------------------------------------------------------------
40  !
41  !++ included parameters
42  !
43  !-----------------------------------------------------------------------------
44  !
45  !++ parameters & variables
46  !
47  !=============================================================================
48 
49  logical :: EXECUTE_PREPROCESS = .true. ! execute preprocess tools?
50  logical :: EXECUTE_MODEL = .false. ! execute main model?
51  integer :: NUM_BULKJOB = 1 ! number of bulk jobs
52  integer :: NUM_DOMAIN = 1 ! number of domains
53  integer :: NUM_FAIL_TOLERANCE = 1 ! tolerance number of failure processes
54  integer :: FREQ_FAIL_CHECK = 0 ! FPM polling frequency per DT (0: no polling)
55  integer :: PRC_DOMAINS(prc_domain_nlim) = 0 ! number of total process in each domain
56  character(len=H_LONG) :: CONF_FILES (prc_domain_nlim) = "" ! name of configulation files
57  logical :: ABORT_ALL_JOBS = .false. ! abort all jobs or not?
58  logical :: LOG_SPLIT = .false. ! log-output for mpi splitting?
59  logical :: COLOR_REORDER = .true. ! coloring reorder for mpi splitting?
60  logical :: FAILURE_PRC_MANAGE = .false. ! use failure process management?
61 
62  namelist / param_launcher / &
63 ! EXECUTE_PREPROCESS, &
64 ! EXECUTE_MODEL, &
65  num_bulkjob, &
66  num_domain, &
67  num_fail_tolerance, &
68  freq_fail_check, &
69  prc_domains, &
70  conf_files, &
71  abort_all_jobs, &
72  log_split, &
73  color_reorder, &
74  failure_prc_manage
75 
76  integer :: universal_comm ! universal communicator
77  integer :: universal_nprocs ! number of procs in universal communicator
78  logical :: universal_master ! master process in universal communicator?
79  character(len=H_LONG) :: universal_cnf_fname ! config file for launcher
80 
81  integer :: global_comm ! communicator for each member
82  integer :: global_nprocs ! number of procs in global communicator
83  integer :: PRC_BULKJOB(prc_domain_nlim) = 0 ! = global_nprocs
84  character(len=H_LONG) :: dummy1 (prc_domain_nlim) = ""
85  integer :: intercomm_parent_null ! NULL inter communicator with parent
86  integer :: intercomm_child_null ! NULL inter communicator with child
87  character(len=H_LONG) :: bulk_prefix ! dirname of each member
88 
89  logical :: use_fpm = .false. ! switch for fpm module
90 
91  integer :: local_comm ! assigned local communicator
92  integer :: intercomm_parent ! inter communicator with parent
93  integer :: intercomm_child ! inter communicator with child
94  character(len=H_LONG) :: local_cnf_fname ! config file for local domain
95 
96  integer :: fid, ierr
97  !-----------------------------------------------------------
98 
99  ! start MPI
100  call prc_mpistart( universal_comm ) ! [OUT]
101 
102  call prc_universal_setup( universal_comm, & ! [IN]
103  universal_nprocs, & ! [OUT]
104  universal_master ) ! [OUT]
105 
106  if( universal_master ) write(*,*) '*** Start Launch System for SCALE-RM'
107 
108  !--- read launcher config
109 
110  universal_cnf_fname = io_arg_getfname( universal_master )
111 
112  fid = io_cnf_open( universal_cnf_fname, & ! [IN]
113  universal_master ) ! [IN]
114 
115  ! set default
116  conf_files(1) = universal_cnf_fname
117 
118  ! read namelist
119  rewind(fid)
120  read(fid,nml=param_launcher,iostat=ierr)
121  if ( ierr < 0 ) then !--- missing
122  ! keep default setting (no members, no nesting)
123  elseif( ierr > 0 ) then !--- fatal error
124  if( universal_master ) write(*,*) 'xxx Not appropriate names in namelist PARAM_LAUNCHER. Check!'
125  call prc_abort
126  endif
127 
128  close(fid)
129  freq_fail_check = 0 ! force 0, coz no time integrations
130 
131  if ( execute_preprocess &
132  .OR. execute_model ) then
133  if( universal_master ) write(*,*) "*** Execute preprocess? : ", execute_preprocess
134  if( universal_master ) write(*,*) "*** Execute model? : ", execute_model
135  else
136  if( universal_master ) write(*,*) 'xxx No execution. please check PARAM_LAUNCHER. STOP'
137  call prc_abort
138  endif
139 
140  !--- split for bulk jobs
141 
142  if ( mod(universal_nprocs,num_bulkjob) /= 0 ) then !--- fatal error
143  if( universal_master ) write(*,*) 'xxx Total Num of Processes must be divisible by NUM_BULKJOB. Check!'
144  if( universal_master ) write(*,*) 'xxx Total Num of Processes = ', universal_nprocs
145  if( universal_master ) write(*,*) 'xxx NUM_BULKJOB = ', num_bulkjob
146  call prc_abort
147  endif
148 
149  global_nprocs = universal_nprocs / num_bulkjob
150  prc_bulkjob(1:num_bulkjob) = global_nprocs
151  if ( num_bulkjob > 1 ) then
152  if( universal_master ) write(*,'(1x,A,I5)') "*** TOTAL BULK JOB NUMBER = ", num_bulkjob
153  if( universal_master ) write(*,'(1x,A,I5)') "*** PROCESS NUM of EACH JOB = ", global_nprocs
154 
155  if ( failure_prc_manage ) then
156  if( universal_master ) write(*,'(1x,A)') "*** Available: Failure Process Management"
157  use_fpm = .true. !--- available only in bulk job
158  if ( num_fail_tolerance <= 0 ) then !--- fatal error
159  if( universal_master ) write(*,*) 'xxx Num of Failure Processes must be positive number. Check!'
160  if( universal_master ) write(*,*) 'xxx NUM_FAIL_TOLERANCE = ', num_fail_tolerance
161  call prc_abort
162  endif
163 
164  if ( num_fail_tolerance > num_bulkjob ) then !--- fatal error
165  write(*,*) 'xxx NUM_FAIL_TOLERANCE is bigger than NUM_BLUKJOB number'
166  write(*,*) ' set to be: NUM_FAIL_TOLERANCE <= NUM_BLUKJOB'
167  call prc_abort
168  endif
169  endif
170  endif
171 
172  ! communicator split for bulk/ensemble
173  call prc_mpisplit( universal_comm, & ! [IN]
174  num_bulkjob, & ! [IN]
175  prc_bulkjob(:), & ! [IN]
176  dummy1(:), & ! [IN] dummy
177  log_split, & ! [IN]
178  .true., & ! [IN] flag bulk_split
179  .false., & ! [IN] no reordering
180  global_comm, & ! [OUT]
181  intercomm_parent_null, & ! [OUT] null
182  intercomm_child_null, & ! [OUT] null
183  bulk_prefix ) ! [OUT] dir name instead of file name
184 
185  call prc_global_setup( abort_all_jobs, & ! [IN]
186  global_comm ) ! [IN]
187 
188  !--- split for nesting
189 
190  if ( num_domain > 1 ) then
191  if( universal_master ) write(*,'(1x,A,I5)') "*** TOTAL DOMAIN NUMBER = ", num_domain
192  if( universal_master ) write(*,'(1x,A,L5)') "*** Flag of ABORT ALL JOBS = ", abort_all_jobs
193  endif
194 
195  ! communicator split for nesting domains
196  call prc_mpisplit( global_comm, & ! [IN]
197  num_domain, & ! [IN]
198  prc_domains(:), & ! [IN]
199  conf_files(:), & ! [IN]
200  log_split, & ! [IN]
201  .false., & ! [IN] flag bulk_split
202  color_reorder, & ! [IN]
203  local_comm, & ! [OUT]
204  intercomm_parent, & ! [OUT]
205  intercomm_child, & ! [OUT]
206  local_cnf_fname ) ! [OUT]
207 
208  !--- initialize FPM module & error handler
209  call fpm_init( num_fail_tolerance, & ! [IN]
210  freq_fail_check, & ! [IN]
211  universal_comm, & ! [IN]
212  global_comm, & ! [IN]
213  local_comm, & ! [IN]
214  num_bulkjob, & ! [IN]
215  prc_global_root, & ! [IN]
216  use_fpm ) ! [IN]
217 
218  call prc_errhandler_setup( use_fpm, universal_master )
219 
220 
221  !--- start main routine
222 
223  if ( num_bulkjob > 1 ) then
224  local_cnf_fname = trim(bulk_prefix)//"/"//trim(local_cnf_fname)
225  endif
226 
227  if ( execute_preprocess ) then
228  call rm_prep( local_comm, & ! [IN]
229  intercomm_parent_null, & ! [IN]
230  intercomm_child_null, & ! [IN]
231  local_cnf_fname ) ! [IN]
232  endif
233 
234  if ( execute_model ) then
235  call rm_driver( local_comm, & ! [IN]
236  intercomm_parent, & ! [IN]
237  intercomm_child, & ! [IN]
238  local_cnf_fname ) ! [IN]
239  endif
240 
241  ! stop MPI
242  call prc_mpifinish
243 
244  if( universal_master ) write(*,*) '*** End Launch System for SCALE-RM'
245 
246  stop
247 end program scalerm_init
integer, parameter, public prc_domain_nlim
max depth of domains
Definition: scale_prc.F90:66
subroutine, public rm_prep(comm_world, intercomm_parent, intercomm_child, cnf_fname)
Setup.
Definition: mod_rm_prep.F90:59
subroutine, public prc_mpistart(comm)
Start MPI.
Definition: scale_prc.F90:121
subroutine, public prc_mpisplit(ORG_COMM, NUM_DOMAIN, PRC_DOMAINS, CONF_FILES, LOG_SPLIT, bulk_split, color_reorder, INTRA_COMM, inter_parent, inter_child, fname_local)
MPI Communicator Split.
Definition: scale_prc.F90:416
integer function, public io_cnf_open(fname, is_master)
open config file
Definition: scale_io.F90:392
subroutine, public prc_global_setup(abortall, comm)
setup MPI in global communicator
Definition: scale_prc.F90:184
module SCALE-RM (a main routine of regional model)
subroutine, public prc_universal_setup(comm, nprocs, ismaster)
setup MPI in universal communicator
Definition: scale_prc.F90:146
module PROCESS
Definition: scale_prc.F90:11
subroutine, public rm_driver(comm_world, intercomm_parent, intercomm_child, cnf_fname)
Setup.
program scalerm_init
Program SCALE-RM (a launcher of main routine)
subroutine, public prc_abort
Abort Process.
Definition: scale_prc.F90:338
character(len=h_long) function, public io_arg_getfname(is_master, allow_noconf)
get config filename from argument
Definition: scale_io.F90:360
module FPM
Definition: scale_fpm.F90:10
module profiler
Definition: scale_prof.F90:11
subroutine, public prc_errhandler_setup(use_fpm, master)
Setup MPI error handler.
Definition: scale_prc.F90:301
subroutine, public prc_mpifinish
Stop MPI peacefully.
Definition: scale_prc.F90:354
module PRECISION
subroutine, public fpm_init(max_failure, polling_freq, universal_comm, global_comm, local_comm, num_member, global_root, use_fpm)
Initialize FPM.
Definition: scale_fpm.F90:79
module SCALE-RM prep
Definition: mod_rm_prep.F90:14
module STDIO
Definition: scale_io.F90:10
integer, dimension(prc_domain_nlim+1), public prc_global_root
root processes in global members
Definition: scale_prc.F90:84