25 module ensemble_manager_mod
31 use mpp_mod,
only : input_nml_file
32 use fms2_io_mod,
only : fms2_io_set_filename_appendix=>set_filename_appendix
33 #ifdef use_deprecated_io
34 use fms_io_mod,
only : fms_io_set_filename_appendix=>set_filename_appendix
41 integer,
parameter :: MAX_ENSEMBLE_SIZE = 100
44 integer,
allocatable,
dimension(:,:) :: ensemble_pelist
45 integer,
allocatable,
dimension(:,:) :: ensemble_pelist_ocean
46 integer,
allocatable,
dimension(:,:) :: ensemble_pelist_atmos
47 integer,
allocatable,
dimension(:,:) :: ensemble_pelist_land
48 integer,
allocatable,
dimension(:,:) :: ensemble_pelist_ice
49 integer,
allocatable,
dimension(:) :: ensemble_pelist_ocean_filter
50 integer,
allocatable,
dimension(:) :: ensemble_pelist_atmos_filter
51 integer,
allocatable,
dimension(:) :: ensemble_pelist_land_filter
52 integer,
allocatable,
dimension(:) :: ensemble_pelist_ice_filter
54 integer :: ensemble_size = 1
55 integer :: ensemble_id = 1
56 integer :: pe, total_npes_pm=0,ocean_npes_pm=0,atmos_npes_pm=0
57 integer :: land_npes_pm=0,ice_npes_pm=0
80 integer :: i, io_status, npes, ierr
82 namelist /ensemble_nml/ ensemble_size
84 read (input_nml_file, ensemble_nml, iostat=io_status)
87 if(ensemble_size < 1)
call mpp_error(fatal, &
88 'ensemble_manager_mod: ensemble_nml variable ensemble_size must be a positive integer')
89 if(ensemble_size > max_ensemble_size)
call mpp_error(fatal, &
90 'ensemble_manager_mod: ensemble_nml variable ensemble_size should be no larger than MAX_ENSEMBLE_SIZE, '// &
91 'change ensemble_size or increase MAX_ENSEMBLE_SIZE')
95 if (npes < ensemble_size)
then
96 call mpp_error(fatal,
'npes must be >= ensemble_size')
98 total_npes_pm = npes/ensemble_size
99 if (mod(npes, total_npes_pm) /= 0)
call mpp_error(fatal,
'ensemble_size must be divis by npes')
130 integer,
intent(inout) :: pelist(:,:)
131 character(len=*),
intent(in),
optional :: name
133 if (
size(pelist,1) < ensemble_size) &
134 call mpp_error(fatal,
'get_ensemble_pelist: size of pelist 1st index < ensemble_size')
136 if(
present(name))
then
139 if (
size(pelist,2) < ocean_npes_pm)&
140 call mpp_error(fatal,
'get_ensemble_pelist: size of pelist 2nd index < ocean_npes_pm')
142 pelist(1:ensemble_size,1:ocean_npes_pm) = &
143 ensemble_pelist_ocean(1:ensemble_size,1:ocean_npes_pm)
146 if (
size(pelist,2) < atmos_npes_pm)&
147 call mpp_error(fatal,
'get_ensemble_pelist: size of pelist 2nd index < atmos_npes_pm')
149 pelist(1:ensemble_size,1:atmos_npes_pm) = &
150 ensemble_pelist_atmos(1:ensemble_size,1:atmos_npes_pm)
153 if (
size(pelist,2) < land_npes_pm)&
154 call mpp_error(fatal,
'get_ensemble_pelist: size of pelist 2nd index < land_npes_pm')
156 pelist(1:ensemble_size,1:land_npes_pm) = &
157 ensemble_pelist_land(1:ensemble_size,1:land_npes_pm)
160 if (
size(pelist,2) < ice_npes_pm)&
161 call mpp_error(fatal,
'get_ensemble_pelist: size of pelist 2nd index < ice_npes_pm')
163 pelist(1:ensemble_size,1:ice_npes_pm) = &
164 ensemble_pelist_ice(1:ensemble_size,1:ice_npes_pm)
167 call mpp_error(fatal,
'get_ensemble_pelist: unknown argument name='//name)
170 if (
size(pelist,2) < total_npes_pm)&
171 call mpp_error(fatal,
'get_ensemble_pelist: size of pelist 2nd index < total_npes_pm')
173 pelist(1:ensemble_size,1:total_npes_pm) = &
174 ensemble_pelist(1:ensemble_size,1:total_npes_pm)
189 integer,
intent(inout) :: pelist(:)
190 character(len=*),
intent(in) :: name
194 if (
size(pelist) < ensemble_size * ocean_npes_pm)&
195 call mpp_error(fatal,
'get_ensemble_filter_pelist: size of pelist argument < ensemble_size * ocean_npes_pm')
197 pelist(1:ensemble_size*ocean_npes_pm) = &
198 ensemble_pelist_ocean_filter(1:ensemble_size*ocean_npes_pm)
201 if (
size(pelist) < ensemble_size * atmos_npes_pm)&
202 call mpp_error(fatal,
'get_ensemble_filter_pelist: size of pelist argument < ensemble_size * atmos_npes_pm')
204 pelist(1:ensemble_size*atmos_npes_pm) = &
205 ensemble_pelist_atmos_filter(1:ensemble_size*atmos_npes_pm)
208 if (
size(pelist) < ensemble_size * land_npes_pm)&
209 call mpp_error(fatal,
'get_ensemble_filter_pelist: size of pelist argument < ensemble_size * land_npes_pm')
211 pelist(1:ensemble_size*land_npes_pm) = &
212 ensemble_pelist_land_filter(1:ensemble_size*land_npes_pm)
215 if (
size(pelist) < ensemble_size * ice_npes_pm)&
216 call mpp_error(fatal,
'get_ensemble_filter_pelist: size of pelist argument < ensemble_size * ice_npes_pm')
218 pelist(1:ensemble_size*ice_npes_pm) = &
219 ensemble_pelist_ice_filter(1:ensemble_size*ice_npes_pm)
222 call mpp_error(fatal,
'get_ensemble_filter_pelist: unknown argument name='//name)
236 Atm_pelist, Ocean_pelist, Land_pelist, Ice_pelist)
237 logical,
intent(in) :: concurrent
238 integer,
intent(in) :: atmos_npes, ocean_npes
239 integer,
intent(in) :: land_npes, ice_npes
240 integer,
dimension(:),
intent(inout) :: atm_pelist, ocean_pelist
241 integer,
dimension(:),
intent(inout) :: land_pelist, ice_pelist
242 integer :: atmos_pe_start, atmos_pe_end, ocean_pe_start, ocean_pe_end
243 integer :: land_pe_start, land_pe_end, ice_pe_start, ice_pe_end
244 character(len=10) :: pelist_name, text
245 integer :: npes, n, m ,i
250 if(land_npes > atmos_npes)
call mpp_error(fatal,
'ensemble_manager_mod: land_npes > atmos_npes')
251 if(ice_npes > atmos_npes)
call mpp_error(fatal,
'ensemble_manager_mod: ice_npes > atmos_npes')
253 allocate(ensemble_pelist(ensemble_size,total_npes_pm))
254 allocate(ensemble_pelist_ocean(1:ensemble_size, 1:ocean_npes) )
255 allocate(ensemble_pelist_atmos(1:ensemble_size, 1:atmos_npes) )
256 allocate(ensemble_pelist_land(1:ensemble_size, 1:land_npes) )
257 allocate(ensemble_pelist_ice(1:ensemble_size, 1:ice_npes) )
263 if( concurrent .OR. atmos_npes+ocean_npes == npes )
then
264 ocean_pe_start = ensemble_size*atmos_npes
267 atmos_pe_end = atmos_pe_start + atmos_npes - 1
268 ocean_pe_end = ocean_pe_start + ocean_npes - 1
269 land_pe_end = land_pe_start + land_npes - 1
270 ice_pe_end = ice_pe_start + ice_npes - 1
271 ensemble_pelist_atmos(n, 1:atmos_npes) = (/(i,i=atmos_pe_start,atmos_pe_end)/)
272 ensemble_pelist_ocean(n, 1:ocean_npes) = (/(i,i=ocean_pe_start,ocean_pe_end)/)
273 ensemble_pelist_land(n, 1:land_npes) = (/(i,i=land_pe_start, land_pe_end)/)
274 ensemble_pelist_ice(n, 1:ice_npes) = (/(i,i=ice_pe_start, ice_pe_end)/)
275 ensemble_pelist(n, 1:atmos_npes) = ensemble_pelist_atmos(n, 1:atmos_npes)
276 if( concurrent .OR. atmos_npes+ocean_npes == npes ) &
277 ensemble_pelist(n, atmos_npes+1:npes) = ensemble_pelist_ocean(n, 1:ocean_npes)
278 if(any(ensemble_pelist(n,:) == pe)) ensemble_id = n
279 write(pelist_name,
'(a,i2.2)')
'_ens',n
281 atmos_pe_start = atmos_pe_end + 1
282 ocean_pe_start = ocean_pe_end + 1
283 land_pe_start = atmos_pe_start
284 ice_pe_start = atmos_pe_start
287 atm_pelist(:) = ensemble_pelist_atmos(ensemble_id,:)
288 ocean_pelist(:) = ensemble_pelist_ocean(ensemble_id,:)
289 land_pelist(:) = ensemble_pelist_land(ensemble_id,:)
290 ice_pelist(:) = ensemble_pelist_ice(ensemble_id,:)
341 write(pelist_name,
'(a,i2.2)')
'atm_ens',n
343 write(pelist_name,
'(a,i2.2)')
'ocn_ens',n
345 write(pelist_name,
'(a,i2.2)')
'lnd_ens',n
347 write(pelist_name,
'(a,i2.2)')
'ice_ens',n
351 write(pelist_name,
'(a,i2.2)')
'atm_ens',ensemble_id
353 write(pelist_name,
'(a,i2.2)')
'ocn_ens',ensemble_id
355 write(pelist_name,
'(a,i2.2)')
'lnd_ens',ensemble_id
357 write(pelist_name,
'(a,i2.2)')
'ice_ens',ensemble_id
361 ocean_npes_pm = ocean_npes
362 atmos_npes_pm = atmos_npes
363 land_npes_pm = land_npes
364 ice_npes_pm = ice_npes
367 allocate(ensemble_pelist_ocean_filter(ensemble_size * ocean_npes_pm))
368 allocate(ensemble_pelist_atmos_filter(ensemble_size * atmos_npes_pm))
369 allocate(ensemble_pelist_land_filter(ensemble_size * land_npes_pm))
370 allocate(ensemble_pelist_ice_filter(ensemble_size * ice_npes_pm))
373 i=(n-1)*ocean_npes_pm + m
374 ensemble_pelist_ocean_filter(i) = ensemble_pelist_ocean(n,m)
377 i=(n-1)*atmos_npes_pm + m
378 ensemble_pelist_atmos_filter(i) = ensemble_pelist_atmos(n,m)
381 i=(n-1)*land_npes_pm + m
382 ensemble_pelist_land_filter(i) = ensemble_pelist_land(n,m)
385 i=(n-1)*ice_npes_pm + m
386 ensemble_pelist_ice_filter(i) = ensemble_pelist_ice(n,m)
390 write(pelist_name,
'(a)')
'ocn_filter'
393 write(pelist_name,
'(a)')
'atm_filter'
396 write(pelist_name,
'(a)')
'lnd_filter'
399 write(pelist_name,
'(a)')
'ice_filter'
407 if (ensemble_size > 1)
then
408 write( text,
'(a,i2.2)' )
'ens_', ensemble_id
412 call fms2_io_set_filename_appendix(trim(text))
413 #ifdef use_deprecated_io
414 call fms_io_set_filename_appendix(trim(text))
421 end module ensemble_manager_mod
integer function, public get_ensemble_id()
Getter function for ensemble_id.
integer function, dimension(6), public get_ensemble_size()
Returns ensemble size integer array.
subroutine, public ensemble_pelist_setup(concurrent, atmos_npes, ocean_npes, land_npes, ice_npes, Atm_pelist, Ocean_pelist, Land_pelist, Ice_pelist)
Sets up pe list for an ensemble.
subroutine, public ensemble_manager_init()
Initializes ensemble_manager_mod.
subroutine, public get_ensemble_pelist(pelist, name)
Gets pe list for current ensemble or a given ensemble component.
subroutine, public get_ensemble_filter_pelist(pelist, name)
Gets filter pelist for a given ensemble component.
integer function, public check_nml_error(IOSTAT, NML_NAME)
Checks the iostat argument that is returned after reading a namelist and determines if the error code...
integer function stdout()
This function returns the current standard fortran unit numbers for output.
subroutine mpp_declare_pelist(pelist, name, commID)
Declare a pelist.
integer function stdlog()
This function returns the current standard fortran unit numbers for log messages. Log messages,...
integer function mpp_npes()
Returns processor count for current pelist.
integer function mpp_pe()
Returns processor ID.