KTH framework for Nek5000 toolboxes; testing version  0.0.1
chkpt.f
Go to the documentation of this file.
1 
6 !=======================================================================
10  subroutine chkpt_register()
11  implicit none
12 
13  include 'SIZE'
14  include 'FRAMELP'
15  include 'CHKPTD'
16 
17  ! local variables
18  integer lpmid
19  real ltim
20 
21  ! functions
22  real dnekclock
23 !-----------------------------------------------------------------------
24  ! timing
25  ltim = dnekclock()
26 
27  ! check if the current module was already registered
28  call mntr_mod_is_name_reg(lpmid,chpt_name)
29  if (lpmid.gt.0) then
30  call mntr_warn(lpmid,
31  $ 'module ['//trim(chpt_name)//'] already registered')
32  return
33  endif
34 
35  ! find parent module
36  call mntr_mod_is_name_reg(lpmid,'FRAME')
37  if (lpmid.le.0) then
38  lpmid = 1
39  call mntr_abort(lpmid,
40  $ 'Parent module ['//'FRAME'//'] not registered')
41  endif
42 
43  ! register module
44  call mntr_mod_reg(chpt_id,lpmid,chpt_name,'Checkpointing I/O')
45 
46  ! register timer
47  call mntr_tmr_is_name_reg(lpmid,'FRM_TOT')
48  call mntr_tmr_reg(chpt_ttot_id,lpmid,chpt_id,
49  $ 'CHP_TOT','Checkpointing total time',.false.)
50 
51  call mntr_tmr_reg(chpt_tini_id,chpt_ttot_id,chpt_id,
52  $ 'CHP_INI','Checkpointing initialisation time',.true.)
53 
54  ! register and set active section
55  call rprm_sec_reg(chpt_sec_id,chpt_id,'_'//adjustl(chpt_name),
56  $ 'Runtime paramere section for checkpoint module')
57  call rprm_sec_set_act(.true.,chpt_sec_id)
58 
59  ! register parameters
60  call rprm_rp_reg(chpt_ifrst_id,chpt_sec_id,'READCHKPT',
61  $ 'Restat from checkpoint',rpar_log,0,0.0,.false.,' ')
62 
63  call rprm_rp_reg(chpt_fnum_id,chpt_sec_id,'CHKPFNUMBER',
64  $ 'Restart file number',rpar_int,1,0.0,.false.,' ')
65 
66  call rprm_rp_reg(chpt_step_id,chpt_sec_id,'CHKPINTERVAL',
67  $ 'Checkpiont saving frequency (number of time steps)',
68  $ rpar_int,500,0.0,.false.,' ')
69 
70  ! set initial step delay
71  call mntr_set_step_delay(1)
72 
73  ! call submodule registration
74  call chkpts_register
75 
76  ! timing
77  ltim = dnekclock() - ltim
78  call mntr_tmr_add(chpt_tini_id,1,ltim)
79 
80  return
81  end subroutine
82 !=======================================================================
86  subroutine chkpt_init()
87  implicit none
88 
89  include 'SIZE'
90  include 'TSTEP'
91  include 'FRAMELP'
92  include 'CHKPTD'
93 
94  ! local variables
95  integer itmp, lstdl
96  real rtmp, ltim
97  logical ltmp
98  character*20 ctmp
99  character*2 str
100  character*200 lstring
101 
102  ! functions
103  logical chkpts_is_initialised
104  real dnekclock
105 !-----------------------------------------------------------------------
106  ! check if the module was already initialised
107  if (chpt_ifinit) then
108  call mntr_warn(chpt_id,
109  $ 'module ['//trim(chpt_name)//'] already initiaised.')
110  ! check submodule intialisation
111  if (.not.chkpts_is_initialised()) then
112  call mntr_abort(chpt_id,
113  $ 'required submodule module not initiaised.')
114  endif
115  return
116  endif
117 
118  ! timing
119  ltim = dnekclock()
120 
121  ! get runtime parameters
122  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,chpt_ifrst_id,rpar_log)
123  chpt_ifrst = ltmp
124  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,chpt_fnum_id,rpar_int)
125  chpt_fnum = itmp
126  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,chpt_step_id,rpar_int)
127  chpt_step = itmp
128 
129  if (chpt_ifrst) then
130  ! get input set number
131  chpt_set_i = chpt_fnum - 1
132  if (chpt_set_i.ge.chpt_nset) then
133  write(str,'(I2)') chpt_nset + 1
134  lstring = 'chpt_fnum must be in the range: 1-'//trim(str)
135  call mntr_abort(chpt_id,lstring)
136  endif
137 
138  chpt_set_o = mod(chpt_set_i+1,chpt_nset)
139  else
140  chpt_set_o = 0
141  endif
142 
143  ! set reset flag
144  chpt_reset = -1
145 
146  ! check number of steps
147  call mntr_get_step_delay(lstdl)
148  if (nsteps.lt.3*lstdl) then
149  call mntr_abort(chpt_id,'too short run for multi-file restart')
150  endif
151 
152  ! check checkpoint frequency
153  if (chpt_step.lt.2*lstdl.or.chpt_step.gt.nsteps) then
154  chpt_step = nsteps
155  call mntr_warn(chpt_id,'wrong chpt_step; resetting to NSTEPS')
156  endif
157 
158  ! set min and max ISTEP for cyclic checkpoint writning
159  ! timesteps outside this bouds require special treatment
160  chpt_istep = lstdl
161  chpt_nstep = nsteps - lstdl - 1
162  ! check if chpt_nstep is in the middle of writing cycle
163  itmp = chpt_nstep + chpt_step -1
164  if (mod(itmp,chpt_step).ge.(chpt_step-lstdl)) then
165  itmp = lstdl + mod(itmp,chpt_step) + 1 - chpt_step
166  chpt_nstep = chpt_nstep - itmp
167  endif
168 
169  ! call submodule initialisation
170  call chkpts_init
171 
172  ! is everything initialised
173  if (chkpts_is_initialised()) chpt_ifinit=.true.
174 
175  ! timing
176  ltim = dnekclock() - ltim
177  call mntr_tmr_add(chpt_tini_id,1,ltim)
178 
179  return
180  end subroutine
181 !=======================================================================
185  logical function chkpt_is_initialised()
186  implicit none
187 
188  include 'SIZE'
189  include 'CHKPTD'
190 !-----------------------------------------------------------------------
191  chkpt_is_initialised = chpt_ifinit
192 
193  return
194  end function
195 !=======================================================================
199 ! after frame_monitor
200  subroutine chkpt_main
201  implicit none
202 
203  include 'SIZE'
204  include 'TSTEP'
205  include 'CHKPTD'
206 
207  ! local variables
208  integer itmp, lstdl
209 !-----------------------------------------------------------------------
210  if(chpt_ifrst.and.istep.le.chpt_istep) then
211  call chkpts_read
212  elseif (istep.gt.chpt_istep) then
213 
214  ! adjust max ISTEP for cyclic checkpoint writning
215  call mntr_get_step_delay(lstdl)
216  chpt_nstep = nsteps - lstdl -1
217  ! check if chpt_nstep is in the middle of writing cycle
218  itmp = chpt_nstep + chpt_step -1
219  if (mod(itmp,chpt_step).ge.(chpt_step-lstdl)) then
220  itmp = lstdl + mod(itmp,chpt_step) + 1 - chpt_step
221  chpt_nstep = chpt_nstep - itmp
222  endif
223 
224  ! count steps to the end of wrting stage
225  itmp = istep + chpt_step -1
226  if (istep.gt.(nsteps-lstdl)) then
227  chpt_stepc = nsteps-istep+1
228  elseif (istep.lt.chpt_nstep.and.
229  $ mod(itmp,chpt_step).ge.(chpt_step-lstdl)) then
230  chpt_stepc = chpt_step - mod(itmp,chpt_step)
231  else
232  chpt_stepc = -1
233  endif
234 
235  ! get the checkpoint set number
236  ! to avoid conflicts with dependent packages I reset chpt_set_o
237  ! during the step after checkpointing
238  if (istep.lt.chpt_nstep.and.mod(istep,chpt_step).eq.0) then
239  chpt_reset = mod(chpt_set_o+1,chpt_nset)
240  elseif (chpt_reset.ge.0) then
241  chpt_set_o = chpt_reset
242  chpt_reset = -1
243  endif
244 
245  call chkpts_write
246  endif
247 
248  return
249  end subroutine
250 !=======================================================================
255  subroutine chkpt_get_fset(step_cnt, set_out)
256  implicit none
257 
258  include 'SIZE'
259  include 'CHKPTD'
260 
261  ! argument list
262  integer step_cnt, set_out
263 !-----------------------------------------------------------------------
264  step_cnt = chpt_stepc
265  set_out = chpt_set_o
266 
267  return
268  end subroutine
269 !=======================================================================
subroutine chkpt_init()
Initilise checkpointing module.
Definition: chkpt.f:87
subroutine chkpt_main
Main checkpoint interface.
Definition: chkpt.f:201
subroutine chkpt_get_fset(step_cnt, set_out)
Get step count to the checkpoint and a set number.
Definition: chkpt.f:256
subroutine chkpt_register()
Register checkpointing module.
Definition: chkpt.f:11
logical function chkpt_is_initialised()
Check if module was initialised.
Definition: chkpt.f:186
subroutine chkpts_init
Dummy replacement for checkpoint initialisation.
Definition: chkptdm.f:18
subroutine chkpts_read
Dummy replacement for checkpoint reader.
Definition: chkptdm.f:37
subroutine chkpts_register
Dummy replacement for checkpoint registration.
Definition: chkptdm.f:10
subroutine chkpts_write
Dummy replacement for checkpoint writer.
Definition: chkptdm.f:45
subroutine mntr_tmr_is_name_reg(mid, mname)
Check if timer name is registered and return its id.
Definition: mntrtmr.f:146
subroutine mntr_warn(mid, logs)
Write warning message.
Definition: mntrlog.f:803
subroutine mntr_tmr_add(mid, icount, time)
Check if timer id is registered. This operation is performed locally.
Definition: mntrtmr.f:237
subroutine mntr_mod_is_name_reg(mid, mname)
Check if module name is registered and return its id.
Definition: mntrlog.f:459
subroutine mntr_abort(mid, logs)
Abort simulation.
Definition: mntrlog.f:837
subroutine mntr_mod_reg(mid, pmid, mname, mdscr)
Register new module.
Definition: mntrlog.f:346
subroutine mntr_get_step_delay(dstep)
Get step delay.
Definition: mntrlog.f:277
subroutine mntr_tmr_reg(mid, pmid, modid, mname, mdscr, ifsum)
Register new timer.
Definition: mntrtmr.f:16
subroutine mntr_set_step_delay(dstep)
Set number of steps necessary to write proper checkpointing.
Definition: mntrlog.f:254
subroutine rprm_rp_get(ipval, rpval, lpval, cpval, rpid, ptype)
Get runtime parameter form active section. This operation is performed locally.
Definition: rprm.f:883
subroutine rprm_rp_reg(rpid, mid, pname, pdscr, ptype, ipval, rpval, lpval, cpval)
Register new runtime parameter.
Definition: rprm.f:484
subroutine rprm_sec_set_act(ifact, rpid)
Set section's activation flag. Master value is broadcasted.
Definition: rprm.f:422
subroutine rprm_sec_reg(rpid, mid, pname, pdscr)
Register new parameter section.
Definition: rprm.f:165