필터 지우기
필터 지우기

Matlab engine for python with shared session

조회 수: 15 (최근 30일)
Jordan Brouns
Jordan Brouns 2016년 9월 29일
댓글: Alessandro 2023년 11월 3일
Hello,
I want to run multiple matlab engines for python at the beginning of my application, because the library I developed embeds many large functions that have to be loaded at the beginning of the app. This is well described in the documentation:
# initialization
engines = []
# load engines
for i in range(3):
engines.append(matlab.engine.start_matlab())
# use one engine
result = engines[1].MyFunction(arg1,arg2)
I also found in the documentation the possibility to use shared matlab sessions:
matlab.engine.shareEngine('MATLABEngineName')
engine = matlab.engine.connect_matlab('MATLABEngineName')
What is this?! There is no information about these shared sessions.
Does it allow to simultaneously run multiple functions in the same engine? What about the execution times (for comparable configurations between shared and classic sessions)?
Thanks

답변 (1개)

Bo Li
Bo Li 2016년 9월 29일
You can send multiple requests to the same engine, they will be queued up and executed one by one. To run multiple functions simultaneously, you may start multiple MATLAB through matlab.engine.start_matlab in Python, or launch multiple shared MATLAB session and connect to them using matlab.engine.connect_matlab. There is no difference between a shared and classic session regarding the performance of running a MATLAB function.
Following MATLAB command can be used to share a MATLAB session:
>>matlab.engine.shareEngine
Or you can launch a MATLAB session as shared from system prompt using "-r" argument:
%matlab -r matlab.engine.shareEngine
Reference:
  댓글 수: 1
Alessandro
Alessandro 2023년 11월 3일
Hi @Bo Li, I was investigating the use of the matlab engine with python. According to this answer it is possible to connect from Python to multiple shared Matlab sessions. This means that I can simulate models in parallel?

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

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by