1

I am currently working on parallel timing function, as a timing threshold, that can be applied to the main function. A maximum running time is needed. Once the threshold is reached, the main function would break and enter the next loop. My original idea was to call timer from another independent function so that a parallel function would be possible. But it fails to do so.

function timeStop()
time = cputime;
time = cputime-time;
a = timer;
set (a, 'executionMode', 'fixedRate')
set (a,'timerfcn','disp(time)')
start(a)
timeStop = time;
end

Then calling this timeStop,

function fucx()
for i = 1:3
    for j = 1:3
        for k = 1:3
            try
                %MainFuc()

                timeStop
                if (timeStop>60) % in seconds
                    disp('RunOutOfTime: Program terminated');
                    stop(a)
                    break;
                end;

            catch
                %%Err()
            end
        end
     end
end
end

It is a huge collection of model setting, study, and solutions in MainFunc(), without loops. I was thinking about directly putting the tic/toc function into the MainFuc(). But I am not sure whether MATLAB internally would work the way that I want it to. Because I do not know which step or code line the infinite time was trapped in MainFunc(). I cannot simply put the tic/toc function with it if it is not determined in parallel.

I have considered using tic/toc, but I was told that internally MATLAB would only know the running time after the full execution of MainFuc(). I am not sure if this is true, but found posts with a similar meaning in different locations.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Orangeblue
  • 229
  • 1
  • 5
  • 15
  • I did `tic/toc` inside a `parfor` loop: http://stackoverflow.com/questions/32146555/saving-time-and-memory-using-parfor-in-matlab/32146700#32146700 Seemed a reasonable result, provided you don't want millisecond accuracy. – Adriaan May 08 '16 at 18:58
  • You certainly can't abort `MainFuc()` after calling it from outside (i.e. from `funcx()` within the loop). So you'd have to place the if-statement inside of `MainFunc()` and break within there as soon as a maximum execution time is over. Furthermore you'd have to declare `time ` within `timeStop()` as a persistent variable and initialize it properly before using. The way you do it now will not measure the runtime between two consecutive calls to `timeStop()` as you wish to do it. – tim May 08 '16 at 19:02
  • The goal is to make a parallel running TIMING function to terminate the infinite running loops and proceed to next one. It seems parfor only works to partition the MainFunc() into concurrent jobs. – Orangeblue May 08 '16 at 19:18
  • Cant simply put the if-statement inside the MainFunc(). Because we do not know which line inside the MainFunc() is causing the infinite time issue. – Orangeblue May 08 '16 at 19:39

0 Answers0