Save data from interrupted computation

Hi,

I have a sophisticated computation that I would like to halt. The function is like the one below. If I stop the function, I lose the result output. Apart from rewriting the function (it is part of a package…), is there a tool (macro…) to access the local variable output in the function?

Thank you for your suggestions,

Best regards


function solve()
   while condition
      update!(output)
  end
  return output
end

What if you make output a global variable?
In that case it should be available after the interruption (I think).

Alternatively (this is not necessarily very elegant) you could maybe store it somewhere after each update. Depending on the form of output this could be done by JLD, HDF5, writedlm, …
Of course things may go wrong if you interrupt while saving

EDIT: if interrupting the function during the ‘save’ process creates an issue (i.e. the save takes a long time), maybe you could alternate between two save files in order to assure that at least one of them is valid (i.e. is not affected by the interrupt)

2 Likes

That’s probably the easiest to do indeed