203 class(DistributedSimType) :: this
204
205 character(len=LENMEMPATH) :: simnam_mempath, hpc_mempath
206 character(len=LENMODELNAME) :: model_name
207 type(CharacterStringType), dimension(:), contiguous, pointer :: mnames
208 type(CharacterStringType), dimension(:), contiguous, pointer :: mnames_hpc
209 integer(I4B), dimension(:), contiguous, pointer :: mranks_hpc
210 integer(I4B) :: i, model_idx
211 integer(I4B) :: target_rank
212 integer(I4B), dimension(:), allocatable :: rank_used
213 type(CharacterStringType), dimension(:), contiguous, pointer :: hpc_names
214 character(len=LINELENGTH) :: hpc_filename
215
216
217 this%model_ranks = -1
218
219
220 simnam_mempath = create_mem_path('SIM', 'NAM', idm_context)
221 hpc_mempath = create_mem_path('UTL', 'HPC', idm_context)
222 call mem_setptr(mnames, 'MNAME', simnam_mempath)
223 call mem_setptr(mnames_hpc, 'MNAME', hpc_mempath)
224 call mem_setptr(mranks_hpc, 'MRANK', hpc_mempath)
225 call mem_setptr(hpc_names, 'HPC6_FILENAME', simnam_mempath)
226
227
228 hpc_filename = hpc_names(1)
229
230
231 do i = 1, size(mnames_hpc)
232 if (ifind(mnames, mnames_hpc(i)) == -1) then
233 model_name = mnames_hpc(i)
234 write (errmsg, *) "HPC input error: undefined model name (", &
235 trim(model_name), ")"
236 call store_error(errmsg)
237 end if
238 end do
239
240 do i = 1, size(mranks_hpc)
241 target_rank = mranks_hpc(i)
242 if (target_rank < 0 .or. target_rank > nr_procs - 1) then
243 model_name = mnames_hpc(i)
244 write (errmsg, '(a,i0,2a)') "HPC input error: invalid target rank (", &
245 target_rank, ") for model ", trim(model_name)
246 call store_error(errmsg)
247 end if
248 end do
249 if (count_errors() > 0) then
250 call store_error_filename(hpc_filename)
251 end if
252
253
254 do i = 1, size(mnames_hpc)
255 model_idx = ifind(mnames, mnames_hpc(i))
256 this%model_ranks(model_idx) = mranks_hpc(i)
257 end do
258
259
260 do i = 1, size(this%model_ranks)
261 if (this%model_ranks(i) == -1) then
262 model_name = mnames(i)
263 write (errmsg, '(2a)') "HPC input error: no target rank for model ", &
264 trim(model_name)
265 call store_error(errmsg)
266 end if
267 end do
268 if (count_errors() > 0) then
269 call store_error_filename(hpc_filename)
270 end if
271
272
273 allocate (rank_used(nr_procs))
274 rank_used = 0
275 do i = 1, size(this%model_ranks)
276 if (this%model_ranks(i) >= 0 .and. this%model_ranks(i) < nr_procs) then
277 rank_used(this%model_ranks(i) + 1) = 1
278 end if
279 end do
280 do i = 1, size(rank_used)
281 if (rank_used(i) == 0) then
282 write (errmsg, '(a,i0,a)') "HPC input error: rank ", i - 1, &
283 " has no models assigned"
284 call store_error(errmsg)
285 end if
286 end do
287 deallocate (rank_used)
288 if (count_errors() > 0) then
289 call store_error_filename(hpc_filename)
290 end if
291