I've a matlab code that needs to be run for different set of "independent" inputs. I want to run the matlab code through unix bash script, and then run the script in multiple computers parallelly to get the speed-up.
I am fairly new to this. Does any of you have any idea on how to go about it?
.

 채택된 답변

Walter Roberson
Walter Roberson 2020년 8월 13일

0 개 추천

You need to find your MATLAB command line executable. For Mac it would be /Applications/MATLAB_R2020a.app/bin/matlab . You would invoke it with -nojvm and -nodesktop . With sufficiently new MATLAB releases you might instead prefer to use -batch
/Applications/MATLAB_R2020a.app/bin/matlab -nojvm -nodesktop %older
/Applications/MATLAB_R2020a.app/bin/matlab -batch
You would then follow that on the command line with a -r option and then the quoted command to execute. It is safest to put the command within try/catch if you are not using the -batch command: For example,
/Applications/MATLAB_R2020a.app/bin/matlab -nojvm -nodesktop -r "try; cd('/Appropriate/Place'); AppriopriateFunction(WithParameters);catch; end; quit"

댓글 수: 4

YOGENDRA SINGH BHANDARI
YOGENDRA SINGH BHANDARI 2020년 8월 14일
편집: YOGENDRA SINGH BHANDARI 2020년 8월 14일
One another doubt I had is does the matlab executable query the license server? I wanted to run the jobs in batch, but not query the license server due to limitations. Hence the executable approach.
Yes, the executable referred to above is a complete interactive MATLAB, just with the desktop turned off. It does want licenses including possibly talking to license servers.
In order to not query the license server, you would need MATLAB Compiler or MATLAB Coder to generate a compiled executable. The compiled executable would have to be pre-programmed to run a particular function entry point and only pre-compiled scripts and functions could be used. The executables can however, accept command line arguments, including possibly naming a data file to process.
YOGENDRA SINGH BHANDARI
YOGENDRA SINGH BHANDARI 2020년 8월 14일
편집: YOGENDRA SINGH BHANDARI 2020년 8월 14일
As an extension to your second argument, can I generate the compiled executable using -mcc command? Upon doing mcc -m mycode.m -o mycode, two files(one executable, another .sh file) get generated. Will that work?
I do not know if .sh will get generated, but an executable would be generated . The executable would not need license checks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by