-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathread_input.f90
361 lines (316 loc) · 12.8 KB
/
read_input.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
!Crown Copyright 2014 AWE.
!
! This file is part of TeaLeaf.
!
! TeaLeaf is free software: you can redistribute it and/or modify it under
! the terms of the GNU General Public License as published by the
! Free Software Foundation, either version 3 of the License, or (at your option)
! any later version.
!
! TeaLeaf is distributed in the hope that it will be useful, but
! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
! FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
! details.
!
! You should have received a copy of the GNU General Public License along with
! TeaLeaf. If not, see http://www.gnu.org/licenses/.
!> @brief Reads the user input
!> @author David Beckingsale, Wayne Gaudin
!> @details Reads and parses the user input from the processed file and sets
!> the variables used in the generation phase. Default values are also set
!> here.
SUBROUTINE read_input()
USE tea_module
USE parse_module
USE report_module
IMPLICIT NONE
INTEGER :: state,stat,state_max,n,tiles_per_problem
!$ INTEGER :: omp_get_num_threads
REAL(KIND=8) :: dx,dy
CHARACTER(LEN=500) :: word
test_problem=0
state_max=0
grid%xmin= 0.0
grid%ymin= 0.0
grid%xmax=100.0
grid%ymax=100.0
grid%x_cells=10
grid%y_cells=10
end_time=10.0
end_step=g_ibig
complete=.FALSE.
visit_frequency=0
summary_frequency=10
dtinit=0.1
max_iters=1000
eps=1.0e-10
use_fortran_kernels=.TRUE.
coefficient = CONDUCTIVITY
profiler_on=.FALSE.
profiler%timestep=0.0
profiler%visit=0.0
profiler%summary=0.0
profiler%halo_exchange=0.0
profiler%halo_update=0.0
profiler%internal_halo_update=0.0
profiler%tea_init=0.0
profiler%tea_solve=0.0
profiler%tea_reset=0.0
profiler%dot_product=0.0
tiles_per_task = 1
sub_tiles_per_tile = 1
!$OMP PARALLEL
!$OMP MASTER
!$ tiles_per_task = omp_get_num_threads()
!$OMP END MASTER
!$OMP ENDPARALLEL
tl_ch_cg_presteps = 25
tl_ch_cg_epslim = 1.0
tl_check_result = .FALSE.
tl_preconditioner_type = TL_PREC_NONE
reflective_boundary = .FALSE.
tl_ppcg_inner_steps = -1
tl_use_chebyshev = .FALSE.
tl_use_cg = .FALSE.
tl_use_ppcg = .FALSE.
tl_use_jacobi = .TRUE.
verbose_on = .FALSE.
chunk%halo_exchange_depth=1
IF(parallel%boss)WRITE(g_out,*) 'Reading input file'
IF(parallel%boss)WRITE(g_out,*)
stat=parse_init(g_in,'*tea')
DO
stat=parse_getline(dummy)
IF (stat.ne.0) exit
DO
word=parse_getword(.FALSE.)
IF(word.EQ.'')EXIT
IF (word.EQ.'state') THEN
state_max=MAX(state_max,parse_getival(parse_getword(.TRUE.)))
EXIT
ENDIF
ENDDO
ENDDO
number_of_states=state_max
IF(number_of_states.LT.1) CALL report_error('read_input','No states defined.')
stat=parse_init(g_in,'*tea')
ALLOCATE(states(number_of_states))
states(:)%defined=.FALSE.
states(:)%energy=0.0
states(:)%density=0.0
DO
stat=parse_getline(dummy)
IF(stat.NE.0)EXIT
DO
word=parse_getword(.FALSE.)
IF(word.EQ.'')EXIT
SELECT CASE(word)
CASE('initial_timestep')
dtinit=parse_getrval(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,e12.4)")'initial_timestep ',dtinit
CASE('end_time')
end_time=parse_getrval(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,e12.4)")'end_time',end_time
CASE('end_step')
end_step=parse_getival(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,i12)")'end_step',end_step
CASE('xmin')
grid%xmin=parse_getrval(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,e12.4)")'xmin',grid%xmin
CASE('xmax')
grid%xmax=parse_getrval(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,e12.4)")'xmax',grid%xmax
CASE('ymin')
grid%ymin=parse_getrval(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,e12.4)")'ymin',grid%ymin
CASE('ymax')
grid%ymax=parse_getrval(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,e12.4)")'ymax',grid%ymax
CASE('x_cells')
grid%x_cells=parse_getival(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,i12)")'x_cells',grid%x_cells
CASE('y_cells')
grid%y_cells=parse_getival(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,i12)")'y_cells',grid%y_cells
CASE('visit_frequency')
visit_frequency=parse_getival(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,i12)")'visit_frequency',visit_frequency
CASE('summary_frequency')
summary_frequency=parse_getival(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,i12)")'summary_frequency',summary_frequency
CASE('tiles_per_task')
tiles_per_task=parse_getival(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,i12)")'tiles_per_task',tiles_per_task
CASE('sub_tiles_per_tile')
sub_tiles_per_tile=parse_getival(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,i12)")'sub_tiles_per_tile',sub_tiles_per_tile
CASE('tiles_per_problem')
tiles_per_problem=parse_getival(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,i12)")'tiles_per_problem',tiles_per_problem
tiles_per_task=tiles_per_problem/parallel%max_task
IF(mod(tiles_per_problem,parallel%max_task) /= 0)THEN
tiles_per_problem=tiles_per_task*parallel%max_task
IF(parallel%boss)WRITE(g_out,"(1x,a92,i12)") &
'WARNING: tiles_per_problem should be divisible by the number of MPI ranks - value reset to ',tiles_per_problem
IF(tiles_per_task == 0)THEN
IF(parallel%boss)WRITE(g_out,"(1x,a80)") 'WARNING: tiles_per_task reset to 1 instead of 0'
tiles_per_task=1
ENDIF
ENDIF
CASE('tl_ch_cg_presteps')
tl_ch_cg_presteps=parse_getival(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,i12)")'tl_ch_cg_presteps',tl_ch_cg_presteps
CASE('tl_ppcg_inner_steps')
tl_ppcg_inner_steps=parse_getival(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,i12)")'tl_ppcg_inner_steps',tl_ppcg_inner_steps
CASE('tl_ch_cg_epslim')
tl_ch_cg_epslim=parse_getrval(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,e12.4)")'tl_ch_cg_epslim',tl_ch_cg_epslim
CASE('tl_check_result')
tl_check_result = .TRUE.
CASE('tl_preconditioner_type')
DO
word=parse_getword(.FALSE.)
IF(word.EQ.'') EXIT
SELECT CASE(word)
CASE('none')
tl_preconditioner_type=TL_PREC_NONE
CASE('jac_diag')
tl_preconditioner_type=TL_PREC_JAC_DIAG
CASE('jac_block')
tl_preconditioner_type=TL_PREC_JAC_BLOCK
CASE DEFAULT
CALL report_error('read_input', 'Invalid preconditioner type specified: '//word)
END SELECT
IF(parallel%boss)WRITE(g_out,"(1x,a25,' ',a25)")'tl_preconditioner_type',word
enddo
CASE('use_fortran_kernels')
use_fortran_kernels=.TRUE.
CASE('verbose_on')
verbose_on=.TRUE.
CASE('tl_use_jacobi')
tl_use_chebyshev = .FALSE.
tl_use_cg = .FALSE.
tl_use_ppcg=.FALSE.
tl_use_jacobi = .TRUE.
CASE('tl_use_cg')
tl_use_chebyshev = .FALSE.
tl_use_cg = .TRUE.
tl_use_ppcg=.FALSE.
tl_use_jacobi = .FALSE.
CASE('tl_use_ppcg')
tl_use_chebyshev = .FALSE.
tl_use_cg = .FALSE.
tl_use_ppcg=.TRUE.
tl_use_jacobi = .FALSE.
CASE('tl_use_chebyshev')
tl_use_chebyshev = .TRUE.
tl_use_cg = .FALSE.
tl_use_ppcg=.FALSE.
tl_use_jacobi = .FALSE.
CASE('reflective_boundary')
reflective_boundary=.TRUE.
CASE('profiler_on')
profiler_on=.TRUE.
IF(parallel%boss)WRITE(g_out,"(1x,a25)")'Profiler on'
CASE('halo_depth')
chunk%halo_exchange_depth = parse_getival(parse_getword(.TRUE.))
IF(chunk%halo_exchange_depth .lt. 1) CALL report_error('read_input', 'Invalid halo exchange depth specified')
IF(parallel%boss)WRITE(g_out,"(1x,a25,i12)")'halo_depth',chunk%halo_exchange_depth
CASE('tl_max_iters')
max_iters = parse_getival(parse_getword(.TRUE.))
CASE('tl_eps')
eps = parse_getrval(parse_getword(.TRUE.))
CASE('tl_coefficient_density')
coefficient = CONDUCTIVITY
IF(parallel%boss)WRITE(g_out,"(1x,a29)")'Diffusion coefficient density'
CASE('tl_coefficient_inverse_density')
coefficient = RECIP_CONDUCTIVITY
IF(parallel%boss)WRITE(g_out,"(1x,a40)")'Diffusion coefficient reciprocal density'
CASE('test_problem')
test_problem=parse_getival(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,i12)")'test_problem',test_problem
CASE('state')
state=parse_getival(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,*)'Reading specification for state ',state
IF (states(state)%defined) CALL report_error('read_input','State defined twice.')
IF(parallel%boss) WRITE(g_out,*)
states(state)%defined=.TRUE.
DO
word=parse_getword(.FALSE.)
IF(word.EQ.'') EXIT
SELECT CASE(word)
CASE('xmin')
states(state)%xmin=parse_getrval(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,e12.4)")'state xmin ',states(state)%xmin
CASE('ymin')
states(state)%ymin=parse_getrval(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,e12.4)")'state ymin ',states(state)%ymin
CASE('xmax')
states(state)%xmax=parse_getrval(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,e12.4)")'state xmax ',states(state)%xmax
CASE('ymax')
states(state)%ymax=parse_getrval(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,e12.4)")'state ymax ',states(state)%ymax
CASE('radius')
states(state)%radius=parse_getrval(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,e12.4)")'state radius ',states(state)%radius
CASE('density')
states(state)%density=parse_getrval(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,e12.4)")'state density ',states(state)%density
CASE('energy')
states(state)%energy=parse_getrval(parse_getword(.TRUE.))
IF(parallel%boss)WRITE(g_out,"(1x,a25,e12.4)")'state energy ',states(state)%energy
CASE('geometry')
word=TRIM(parse_getword(.TRUE.))
SELECT CASE(word)
CASE("rectangle")
states(state)%geometry=g_rect
IF(parallel%boss)WRITE(g_out,"(1x,a26)")'state geometry rectangular'
CASE("circle")
states(state)%geometry=g_circ
IF(parallel%boss)WRITE(g_out,"(1x,a25)")'state geometry circular'
CASE("point")
states(state)%geometry=g_point
IF(parallel%boss)WRITE(g_out,"(1x,a25)")'state geometry point'
END SELECT
END SELECT
ENDDO
IF(parallel%boss) WRITE(g_out,*)
END SELECT
ENDDO
ENDDO
! Simple guess - better than a default of 10
if (tl_ppcg_inner_steps .eq. -1 .and. tl_use_ppcg) then
tl_ppcg_inner_steps = 4*INT(SQRT(SQRT(REAL(grid%x_cells*grid%y_cells))))
IF(parallel%boss)WRITE(g_out,"(1x,a25,i12)")'tl_ppcg_inner_steps',tl_ppcg_inner_steps
endif
if ((chunk%halo_exchange_depth .gt. 1) .and. (tl_preconditioner_type .eq. TL_PREC_JAC_BLOCK)) then
call report_error('read_input', 'Unable to use nonstandard halo depth with block jacobi preconditioner')
endif
IF(parallel%boss) THEN
WRITE(g_out,"(1x,a25,i12)")'tiles per task ',tiles_per_task
WRITE(g_out,*)
IF(use_fortran_kernels) THEN
WRITE(g_out,"(1x,a)")'Using Fortran Kernels'
ENDIF
WRITE(g_out,*)
WRITE(g_out,*) 'Input read finished.'
WRITE(g_out,*)
ENDIF
CALL flush(g_out)
! If a state boundary falls exactly on a cell boundary then round off can
! cause the state to be put one cell further that expected. This is compiler
! /system dependent. To avoid this, a state boundary is reduced/increased by a 100th
! of a cell width so it lies well with in the intended cell.
! Because a cell is either full or empty of a specified state, this small
! modification to the state extents does not change the answers.
dx=(grid%xmax-grid%xmin)/REAL(grid%x_cells)
dy=(grid%ymax-grid%ymin)/REAL(grid%y_cells)
DO n=2,number_of_states
states(n)%xmin=states(n)%xmin+(dx/100.0_8)
states(n)%ymin=states(n)%ymin+(dy/100.0_8)
states(n)%xmax=states(n)%xmax-(dx/100.0_8)
states(n)%ymax=states(n)%ymax-(dy/100.0_8)
ENDDO
END SUBROUTINE read_input