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

6 ビュー (過去 30 日間)
Behzad Pouladi
Behzad Pouladi 2019 年 5 月 17 日
回答済み: Zhi Zeng 2020 年 2 月 11 日
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

回答 (1 件)

Zhi Zeng
Zhi Zeng 2020 年 2 月 11 日
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.

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by