I want to save the running state of the program and resume it after restarting.

Asked 2 years ago, Updated 2 years ago, 42 views

I'm a beginner in Linux programming.

I'm using a program that takes more than a few days to run for my research experiment, but I heard that there will be a power outage on campus, so I have to interrupt the process due to the shutdown.

The professor asked me if I could improve the program to write down the state of the calculation in a file and load it back up after rebooting, but I have no idea how it can be achieved.

I might be able to write down the contents of the memory, but can I load it into the memory?

The operating system is Ubuntu 16.04 LTS.
I just need to know if there is a way, so I don't care about the language.

By the way, I know that there is a kind of hibernation, so I'd like something else.

I look forward to your kind cooperation.

Additional
I don't think it's possible to incorporate the above mechanisms into the non-commercial solver, but it was an interesting question, for example, to implement algorithms and solve optimization problems for a long time, so I was wondering if I could do this.

linux ubuntu

2022-09-30 20:18

1 Answers

Are you doing numerical simulation (hydrodynamics, etc.) shyly?

In the case of numerical simulations, it seems common to create a program that saves the results in the middle of the calculation and restarts them later.

The simulation program should have variables that represent the simulation object (such as arrays that hold the flow velocity at the nodes of the mesh, if fluid).

These variables are initialized at the start of the simulation and updated as the simulation repeats.
The flow of the program is roughly like this

Initialize variable;
Repeat as many times as required:
  One-step simulation (usually calculated to advance the time increment tt)
  output intermediate results to a file as needed
print the final result to a file

To allow these programs to be interrupted/restarted, perform the following:

(1) At the time of starting the program, a time to terminate the calculation processing can be specified, the time is checked every time a loop is made, and when the specified time arrives, the contents of a variable to be simulated at that time are stored in a file in a form that can be read later.
(2) In addition to a mode for starting simulation from scratch, the contents of a previously stored file are read to reproduce a "state at the time of stopping" and two start modes for resuming simulation from a halfway turn are selected.

The point here is not to write to a file without being aware of the contents of the memory, but to write the contents of the variables you prepared as numerical values.If that's the case, you can restart it by creating a "read numeric data into variables" process.

Now, the program will stop when the specified time comes.

By the way, the question says, "I'm using a program," so I guess it's not a program that I created myself.If that's the case, it might be a high hurdle to change the program.

If it's a great program (such as a commercial package), you may already have the ability to save/restore.


2022-09-30 20:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.