Testing restart functionality in C/C++

Hello!

I am trying to implement "restart" functionality in my code, where if for some reason the code stops (i.e. iterations drop) I can pick up from where I started.

Here's what I did so far:

1. Load last iteration data files as my initial conditions in main ICs loop
2. Load last iteration time as well, as my start time before starting iterations loop
3. Use last iteration time as initial time + dt and update
4. Update all variables with iteration loop and save

Now, this logic works fine for me and returns correct output for the first iteration only before it restarts everything from the start for the following iterations.

Here's an example output from my code, assume these are the expected "correct" output:

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
  Iteration = 1812    t = 5450.6521821332    phi_iter = 17
1.1069
1.66477
Iteration = 1813    t = 5452.3169561963    phi_iter = 13
2.60262
1.61918
Iteration = 1814    t = 5453.9361334358    phi_iter = 13
1.54781
1.54845
Iteration = 1815    t = 5455.4845819193    phi_iter = 17
1.00293
1.54042
Iteration = 1816    t = 5457.0250001012    phi_iter = 18
1.13051
1.54354
Iteration = 1817    t = 5458.5685399664    phi_iter = 19
2.35307
1.46759
Iteration = 1818    t = 5460.0361342678    phi_iter = 37
1.26484
1.18761
Iteration = 1819    t = 5461.2237438787    phi_iter = 1
1.46792
0.31029
Iteration = 1820    t = 5461.2547728417    phi_iter = 1

the two numbers I am printing out after each iteration, are for checks and represent speed and dt in my code respectively. Now, what I have implemented returns the following:
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
  Starting time at restart iteration (1812): 5448.964896
0.0001039246709
1.664772331
Iteration = 1812    t = 5450.6296687157   phi_iter = 10
7.39507552e-05
3.124999991
Iteration = 1813    t = 5453.7546687067   phi_iter = 5
7.54156341e-05
3.124999991
Iteration = 1814    t = 5456.8796686977   phi_iter = 5
7.398175426e-05
3.124999991
Iteration = 1815    t = 5460.0046686885   phi_iter = 5
7.552663193e-05
3.124999991
Iteration = 1816    t = 5463.1296686792   phi_iter = 5
7.750841083e-05
3.124999991
Iteration = 1817    t = 5466.2546686697   phi_iter = 5
7.821350503e-05
3.12499999
Iteration = 1818    t = 5469.3796686600   phi_iter = 5
7.954733822e-05
3.12499999
Iteration = 1819    t = 5472.5046686499   phi_iter = 5
8.031665434e-05
3.12499999

where for the first iteration : iteration, t, phi_iter, and dt look about right or correct, but everything else resets to my original initial conditions, as if I am overwriting something. The issue is testing this code on small scale, i.e updating time and what not works but the moment I implement on large-scale things get messed up. I have no idea what I am doing wrong with my logic.

The full code can be found here:
https://www.zipshare.com/download/eyJhcmNoaXZlSWQiOiJjYzAzZTMzNi03MzU4LTRiMjUtODdmYy00ZTg2MmM2NGEyZTAiLCJlbWFpbCI6ImFzdHJvbHVqeUBnbWFpbC5jb20ifQ==

Thanks!
Last edited on
Registered users can post here. Sign in or register to post.