フィルターのクリア

How to stop a matlab process, if it exceeds certain time threshold?

33 ビュー (過去 30 日間)
Anver Hisham
Anver Hisham 2016 年 9 月 29 日
コメント済み: Walter Roberson 2017 年 5 月 18 日
I'm executing a function f1(), and simulation time for function f1() can be high or low depending upon many random parameters. So I want to kill the process f1(), if it takes more than 1 hour simulation time.
So my code should look something like this,
f1();
wait 1 hour
if f1() still running
Kill process f1();
end
Is there any way to implement this in matlab? I know I can spawn a process using system command, but I'm trying to find a way to do this without invoking system command, since the inputs to the function f1() are too big and comlpicated.

採用された回答

Walter Roberson
Walter Roberson 2016 年 9 月 29 日
If you can change the code that is doing the computation, then you can put in tic/toc or elapsed time checks like Massimo Zanetti shows. Otherwise, unless you have the Parallel Computing Toolbox, the only option to run another copy of MATLAB and use a task killer or similar to kill the process if it is taking too long.
You could, though, run a timer that is set to fire after one hour and which quits MATLAB entirely.
If you have the Parallel Computing Toolbox, then various routines such as parfeval() have the cancel facilities.
Note: if you are doing heavy mathematics operations that take you into the BLAS or LINPACK libraries, then canceling a process or quitting MATLAB might not work until the operation returns.

その他の回答 (2 件)

Massimo Zanetti
Massimo Zanetti 2016 年 9 月 29 日

Anver Hisham
Anver Hisham 2017 年 5 月 18 日
Since I see there is no easy fix for this problem in matlab, I made my own function, and published here, https://se.mathworks.com/matlabcentral/fileexchange/59120-evalwithtimer
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 5 月 18 日
(I note the above will not work on MS Windows. Possibly it might work on OS-X, but it looks like it was written for Linux)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeParallel Computing についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by