1
votes

I want to limit execution runtime of a function I am using in my code. Is it possible?

I am using Windows 10 with MATLAB R2015a (unlike in this question asked before: Matlab time limit for function execution), so has there been any changes to make it possible or are there any tweaks to make it possible?

For example:

H = transpose(homograpyMatrix);
t = projective2d(homograpyMatrix);
result = imwarp(img, t);  % If execution takes more than X seconds - stop running

If imwarp is taking too long to compute (more than predefined X seconds) I want MATLAB to stop the running process. Is it possible?

Please note that I don't want to use tic-toc within a loop as a stopping condition, because this is not the case.

1
difficult, Matlab does offer you the tool to compute the time needed to run a function - but to do what you ask, you will need a multi-thread environment where one thread execute the code while another thread keeps the timer. As far as I know, there are limited option on controlling this variable. Here is something you might want to read blogs.mathworks.com/pick/2008/05/05/… - GameOfThrows
There is no generic matlab wrapper for this. Some matlab functions such as eig are builtin and there's no hook for interrupts for those functions. - hiandbaii
If you run on linux I think you should be able to force a program to shutdown after a certain time. Not sure how to do it, but I have seen it being done. - patrik

1 Answers

1
votes

You have two options:

Parallel Computing Toolbox

With the Parallel Computing Toolbox, you can define a timeout for idle calculations. It is important to remember that this timeout is reset whenever your process enters a parfor loop or uses parfeval.

Hard-coded Timeout

In this instance you would implement a hard-coded timeout variable and check it at a regular interval to assess if you have to stop the running process or not.