calling matlab function from python- problem with starting engine and parallel pool

1 vue (au cours des 30 derniers jours)
Hello Everyone,
I'm calling a matlab function from the python but the problem is that matlab engine and parallel poll starts during every call which take some time and is significant.
Do you have any recommendation to have the matlab always in background so as to remove necessity for starting in every call?
code in python calling matlab:
eng = matlab.engine.start_matlab()
eng.Res_SS_2DToy_problem(nargout=0)
simul_obs = eng.workspace['Temperature_trend']
code in matlab:
myPool = gcp('nocreate');
if isempty(myPool)
myPool = parpool(50);
end
parfor i=1:size(rock.perm_all,2)
H{i}=ss(i);
end
Regards,
Behzad

Réponses (1)

Zhi Zeng
Zhi Zeng le 11 Fév 2020
Hei, I am now encountering the same problem. I think I can give you an awkwark solution. That is: "interacting with Matlab using your file system by constantly checking file names ." For example, you want Matlab to calculate f(x). Then, the Python program saves a file named x.mat to a native folder and wait for the existence of another file named f_x. While Matlab is constantly checking whether there is a file named x.mat. If there is one, Matlab load the file and delete x.mat. After calculation, Matlab save the result as f_x.mat. On the other hand, Python program is constantly checking whether there is a file named f_x.mat. If there is one, it load the file and delete it.

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by