running matlab function multiple times from windows command line
조회 수: 5 (최근 30일)
이전 댓글 표시
My matlab code is heavy in terms of memory and cpu cycles and takes days to finish. I need to re-run the code for 10 times. I am doing that using a matlab script, but the machine crashes due to out of memory error. Matlab help documentation recommends for such type of codes to save the work space and restart matlab frequently to avoid memory fragmentation. Therefore, I created the following simple windows script to automate restarting matlab:
@echo off
for /l %%x in (1, 1, 10) do (
matlab -nodisplay -nojvm -nosplash -nodesktop -r "Matlab_function(,);exit"
timeout 30 >nul
)
pause
It seems to me that still multiple instances of matlab are running together. My question is how to ensure that the next call to the matlab function do not happen until the current call is completely finished and the matlab command window is closed? any idea?
댓글 수: 0
답변 (3개)
Prasanth Sunkara
2018년 1월 22일
Hello Mustafa, What I understand is you basically want to restart MATLAB every 30 min through a windows shell script. I would suggest you to modify the code a little as shown below: @Line 4: TIMEOUT /T 1800 /NOBREAK
-Prasanth
Benjamin Marechal
2018년 3월 29일
Hello!
Just add '-wait' option to the command line: matlab -wait -nodisplay -nojvm -nosplash -nodesktop -r "Matlab_function(,);exit"
Without this option, your batch script will continue even if the matlab function hasn't finished.
You can check it by writing the command : matlab -help which gives :
-wait - MATLAB is started by a separate starter program
which normally launches MATLAB and then immediately
quits. Using the -wait option tells the starter
program not to quit until MATLAB has terminated.
This option is useful when you need to process the
the results from MATLAB in a script. The call to
MATLAB with this option will block the script from
continuing until the results are generated.
Using "-wait", you don't really need the timeout.
댓글 수: 0
Steven Lord
2018년 3월 29일
When you say " I am doing that using a matlab script, but the machine crashes due to out of memory error. " do you mean MATLAB crashes, the machine on which you're running MATLAB crashes, or MATLAB throws an error indicating it is out of memory? In the first two cases, that obviously shouldn't happen and you should send any crash log you received from MATLAB to Technical Support for further investigation.
In the last case, how large a block of data are you trying to process? Are you using a release that supports datastore and tall, whose main purpose is to work with data so large it can't fit in memory as one piece? If you are using a release that includes tall and you want to try to see if it avoids the out of memory error, check the documentation included in your installation to make sure the functions you want to use are supported for tall. [The list of functions that support tall increases every release, so if you're not using the most recent release the list on the page to which I linked earlier will include functionality that won't work on your older release.]
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!