0

I've tried to set a maximum execution time for matlab function, but none of them succeeded. I have a matlab file loading a model setting from COMSOL (using COMSOL with Matlab livelink).

%filename ‘mymodel.m'

fff = 0;
store{fff+1,1} = 'out1';
store{fff+1,2} = 'out2';
for  i = 1:2
    for j = 1:2
        fff = fff+1;
        %load Model parameter setting
        model_parameter_script_file
        if i == 1;model.param.set('x1',val1);end
        if i == 2;model.param.set('x1',val2);end

        if j == 1;model.param.set('x2',val1);end
        if j == 2;model.param.set('x2',val2);end
        try
        %load model solution script from COMSOL
        model_soulution_script_file
        %store table calculated from the solution into 'store'
        %catch null values
        catch
        store{fff+1,1} = 'null';
        store{fff+1,2} = 'null';
        end
    end
end

The issue is that I cannot figure out a way to tell the computer to terminate the for loop if anyone one of them exceeds the maximum execution time. Is it possible to do with Matlab Parallel Computing Toolbox? This could be used to accelerate program execution, but not sure if it can kill a thread when it finds that particular job exceeds the maximum running time. Thanks a lot for your help in advance.

Orangeblue
  • 229
  • 1
  • 5
  • 15
  • 1
    If you see the second example [here](http://www.mathworks.com/help/matlab/ref/tic.html), you will see a line `t(n) = toc;`. So if `t(n) > threshold`, you could break out of the program. For information on how to terminate the program, see [here](http://www.mathworks.com/help/matlab/ref/exit.html) or [here](http://stackoverflow.com/questions/21925137/how-can-i-abort-program-execution-in-matlab) – Autonomous Jul 10 '16 at 02:34
  • No. This is not the solution. Matlab read code line by line. – Orangeblue Jul 11 '16 at 13:32

0 Answers0