SCALE-RM
scale-rm.f90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
11 !-------------------------------------------------------------------------------
13  !-----------------------------------------------------------------------------
14  !
15  !++ used modules
16  !
17  use gtool_file, only: &
19  use scale_precision
20  use scale_stdio
21  use scale_prof
22 
23  use scale_process, only: &
25  prc_mpistart, &
26  prc_mpistop, &
27  prc_mpifinish, &
28  prc_mpisplit, &
31  use mod_rm_prep, only: &
33  use mod_rm_driver, only: &
34  scalerm
35  !-----------------------------------------------------------------------------
36  implicit none
37  !-----------------------------------------------------------------------------
38  !
39  !++ included parameters
40  !
41  !-----------------------------------------------------------------------------
42  !
43  !++ parameters & variables
44  !
45  !=============================================================================
46 
47  logical :: execute_preprocess = .false. ! execute preprocess tools?
48  logical :: execute_model = .true. ! execute main model?
49  integer :: num_bulkjob = 1 ! number of bulk jobs
50  integer :: num_domain = 1 ! number of domains
51  integer :: prc_domains(prc_domain_nlim) = 0 ! number of total process in each domain
52  character(len=H_LONG) :: conf_files (prc_domain_nlim) = "" ! name of configulation files
53  logical :: abort_all_jobs = .false. ! abort all jobs or not?
54  logical :: log_split = .false. ! log-output for mpi splitting?
55  logical :: color_reorder = .true. ! coloring reorder for mpi splitting?
56 
57  namelist / param_launcher / &
58  execute_preprocess, &
59  execute_model, &
60  num_bulkjob, &
61  num_domain, &
62  prc_domains, &
63  conf_files, &
64  abort_all_jobs, &
65  log_split, &
66  color_reorder
67 
68  integer :: universal_comm ! universal communicator
69  integer :: universal_nprocs ! number of procs in universal communicator
70  logical :: universal_master ! master process in universal communicator?
71  character(len=H_LONG) :: universal_cnf_fname ! config file for launcher
72 
73  integer :: global_comm ! communicator for each member
74  integer :: global_nprocs ! number of procs in global communicator
75  integer :: prc_bulkjob(prc_domain_nlim) = 0 ! = global_nprocs
76  character(len=H_LONG) :: dummy1 (prc_domain_nlim) = ""
77  integer :: intercomm_parent_null ! NULL inter communicator with parent
78  integer :: intercomm_child_null ! NULL inter communicator with child
79  character(len=H_LONG) :: bulk_prefix ! dirname of each member
80 
81  integer :: local_comm ! assigned local communicator
82  integer :: intercomm_parent ! inter communicator with parent
83  integer :: intercomm_child ! inter communicator with child
84  character(len=H_LONG) :: local_cnf_fname ! config file for local domain
85 
86  integer :: fid, ierr
87  !-----------------------------------------------------------
88 
89  ! start MPI
90  call prc_mpistart( universal_comm ) ! [OUT]
91 
92  call prc_universal_setup( universal_comm, & ! [IN]
93  universal_nprocs, & ! [OUT]
94  universal_master ) ! [OUT]
95 
96  if( universal_master ) write(*,*) '*** Start Launch System for SCALE-RM'
97 
98  !--- read launcher config
99 
100  universal_cnf_fname = io_arg_getfname( universal_master )
101 
102  fid = io_cnf_open( universal_cnf_fname, & ! [IN]
103  universal_master ) ! [IN]
104 
105  ! set default
106  conf_files(1) = universal_cnf_fname
107 
108  ! read namelist
109  rewind(fid)
110  read(fid,nml=param_launcher,iostat=ierr)
111  if ( ierr < 0 ) then !--- missing
112  ! keep default setting (no members, no nesting)
113  elseif( ierr > 0 ) then !--- fatal error
114  if( universal_master ) write(*,*) 'xxx Not appropriate names in namelist PARAM_LAUNCHER. Check!'
115  call prc_mpistop
116  endif
117 
118  close(fid)
119 
120  if ( execute_preprocess &
121  .OR. execute_model ) then
122  if( universal_master ) write(*,*) "*** Execute preprocess? : ", execute_preprocess
123  if( universal_master ) write(*,*) "*** Execute model? : ", execute_model
124  else
125  if( universal_master ) write(*,*) 'xxx No execution. please check PARAM_LAUNCHER. STOP'
126  call prc_mpistop
127  endif
128 
129  !--- split for bulk jobs
130 
131  if ( mod(universal_nprocs,num_bulkjob) /= 0 ) then !--- fatal error
132  if( universal_master ) write(*,*) 'xxx Total Num of Processes must be divisible by NUM_BULKJOB. Check!'
133  if( universal_master ) write(*,*) 'xxx Total Num of Processes = ', universal_nprocs
134  if( universal_master ) write(*,*) 'xxx NUM_BULKJOB = ', num_bulkjob
135  call prc_mpistop
136  endif
137 
138  global_nprocs = universal_nprocs / num_bulkjob
139  prc_bulkjob(1:num_bulkjob) = global_nprocs
140  if ( num_bulkjob > 1 ) then
141  if( universal_master ) write(*,'(1x,A,I5)') "*** TOTAL BULK JOB NUMBER = ", num_bulkjob
142  if( universal_master ) write(*,'(1x,A,I5)') "*** PROCESS NUM of EACH JOB = ", global_nprocs
143  endif
144 
145  ! communicator split for bulk/ensemble
146  call prc_mpisplit( universal_comm, & ! [IN]
147  num_bulkjob, & ! [IN]
148  prc_bulkjob(:), & ! [IN]
149  dummy1(:), & ! [IN] dummy
150  log_split, & ! [IN]
151  .true., & ! [IN] flag bulk_split
152  .false., & ! [IN] no reordering
153  global_comm, & ! [OUT]
154  intercomm_parent_null, & ! [OUT] null
155  intercomm_child_null, & ! [OUT] null
156  bulk_prefix ) ! [OUT] dir name instead of file name
157 
158  call prc_global_setup( abort_all_jobs, & ! [IN]
159  global_comm ) ! [IN]
160 
161  !--- split for nesting
162 
163  if ( num_domain > 1 ) then
164  if( universal_master ) write(*,'(1x,A,I5)') "*** TOTAL DOMAIN NUMBER = ", num_domain
165  if( universal_master ) write(*,'(1x,A,L5)') "*** Flag of ABORT ALL JOBS = ", abort_all_jobs
166  endif
167 
168  ! communicator split for nesting domains
169  call prc_mpisplit( global_comm, & ! [IN]
170  num_domain, & ! [IN]
171  prc_domains(:), & ! [IN]
172  conf_files(:), & ! [IN]
173  log_split, & ! [IN]
174  .false., & ! [IN] flag bulk_split
175  color_reorder, & ! [IN]
176  local_comm, & ! [OUT]
177  intercomm_parent, & ! [OUT]
178  intercomm_child, & ! [OUT]
179  local_cnf_fname ) ! [OUT]
180 
181  !--- start main routine
182 
183  if ( num_bulkjob > 1 ) then
184  local_cnf_fname = trim(bulk_prefix)//"/"//trim(local_cnf_fname)
185  endif
186 
187  if ( execute_preprocess ) then
188  call scalerm_prep( local_comm, & ! [IN]
189  intercomm_parent_null, & ! [IN]
190  intercomm_child_null, & ! [IN]
191  local_cnf_fname ) ! [IN]
192  endif
193 
194  if ( execute_model ) then
195  call scalerm ( local_comm, & ! [IN]
196  intercomm_parent, & ! [IN]
197  intercomm_child, & ! [IN]
198  local_cnf_fname ) ! [IN]
199  endif
200 
201  ! stop MPI
202  call prc_mpifinish
203 
204  if( universal_master ) write(*,*) '*** End Launch System for SCALE-RM'
205 
206  stop
207 end program scalerm_launcher
module GTOOL_FILE
Definition: gtool_file.f90:17
subroutine, public prc_mpistop
Abort MPI.
subroutine, public scalerm(comm_world, intercomm_parent, intercomm_child, cnf_fname)
Setup.
module STDIO
Definition: scale_stdio.F90:12
subroutine, public prc_universal_setup(comm, nprocs, ismaster)
setup MPI in universal communicator
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.
character(len=h_long) function, public io_arg_getfname(is_master)
get config filename from argument
subroutine, public filecloseall
module SCALE-RM (a main routine of regional model)
program scalerm_launcher
Program SCALE-RM (a launcher of main routine)
Definition: scale-rm.f90:12
module PROCESS
subroutine, public prc_global_setup(abortall, comm)
setup MPI in global communicator
subroutine, public scalerm_prep(comm_world, intercomm_parent, intercomm_child, cnf_fname)
Setup.
Definition: mod_rm_prep.f90:67
subroutine, public prc_mpistart(comm)
Start MPI.
module profiler
Definition: scale_prof.F90:10
module PRECISION
integer, parameter, public prc_domain_nlim
max depth of domains
module SCALE-RM prep
Definition: mod_rm_prep.f90:18
subroutine, public prc_mpifinish
Stop MPI peacefully.
integer function, public io_cnf_open(fname, is_master)
open config file