Accompanies OnCFD Newsletter #165
Here's a quick OpenFOAM function that makes running on AWS spot instances a whole lot nicer.
It uses two standard function objects (plus curl) to check whether your instance has recieved a termination notice.
If it has, it stops your simulation & writes your current data.
If it hasn't, it keeps on iterating (& checking).
checker
{
type systemCall;
libs (utilityFunctionObjects);
master true;
executeControl clockTime;
executeInterval 10;
writeControl $executeControl;
writeInterval $executeInterval;
executeCalls
(
"echo Checking for spot interrupt"
"curl --fail --silent --output OF.interrupt http://169.254.169.254/latest/meta-data/spot/instance-action"
);
}
interupt
{
type abort;
libs (utilityFunctionObjects);
file "OF.interrupt";
action writeNow;
}
Save it to your system
directory, add it to the functions
section of your controlDict
& give it a go.
For more info see the original article 👋