Execute run phase of Simulink model in parallel

조회 수: 2 (최근 30일)
Osama Maqbool
Osama Maqbool 2016년 9월 30일
편집: Osama Maqbool 2016년 10월 6일
I want to get the output using the function model(t,x,u,'outputs'). I have a large set of inputs, which I normally pass to the model in a for loop. I have already compiled the model before the loop using model([],[],[],'compile'). When I replaced the for with a parfor loop, it does not see the model as 'compiled'. I get the error: Error, 'model' must be compiled before it can be accessed programmatically.
I don't want to compile the model inside the loop as it would make it very slow and destroy the whole purpose of using parallelization. How can I solve this?

답변 (1개)

Edric Ellis
Edric Ellis 2016년 10월 3일
You can use parfevalOnAll to run the 'compile' and 'term' phases, like so:
parfevalOnAll(@vdp, 0, [], [], [], 'compile');
parfor t = 1:10
out{t} = vdp(t, [0; 0], [], 'outputs');
end
parfevalOnAll(@vdp, 0, [], [], [], 'term');
  댓글 수: 3
Edric Ellis
Edric Ellis 2016년 10월 5일
Strange. Did it fail the second time in a MATLAB session, or when you restarted MATLAB?
Osama Maqbool
Osama Maqbool 2016년 10월 6일
In the same session. I can't seem to find a pattern on what gives the error. Many a times, I have made it work by deleting the contents of a folder generated automatically, called 'slprj', specifically the subfolder '_jitprj'.

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

카테고리

Help CenterFile Exchange에서 Model Compatibility에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by