how to run parallel job script called from python

8 Ansichten (letzte 30 Tage)
Michael
Michael am 6 Dez. 2018
Beantwortet: Mohan Feng am 11 Dez. 2018
I tried to call a matlab script from python.
I cannot launch multiple processes for the parfor command.
It seems like the jvm was not launched since when I tried to call the following commands in the matlab script:
myPool = gcp('nocreate');
if isempty(myPool)
myPool = parpool(4);
end
I got the following error;
Undefined variable "com" or class "com.mathworks.toolbox.distcomp.pmode.SessionInfo.NULL_SESSION_INFO".
And I used this command in python to launch the matlab engine
matlabengine = matlab.engine.start_matlab()
Is there any solution for that?
Thank you for your help.

Akzeptierte Antwort

Mohan Feng
Mohan Feng am 11 Dez. 2018
The code does not run into error on my end. So, one possible reason is that you might not install the right MATLAB engine. Could you check that the MATLAB engine you installed the one that you have license for PCT.
If the installation is correct, you could try the following code to see whether it works by using local cluster.
b = zeros(1,10)
parfor i = 1 : 10
b(i) = i
end
save the above code as test1.m. In the folder contains tes1.m, run the following code in Python, the code should work.
import matlab.engine
eng = matlab.engine.start_matlab()
x = eng.test1(nargout = 0)
eng.eval('b')

Weitere Antworten (0)

Kategorien

Mehr zu Call MATLAB from Python finden Sie in Help Center und File Exchange

Produkte


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by