calling matlab function from python- problem with starting engine and parallel pool
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!