Why does "parsim" or "batchsim" with a postSimFcn that accepts a SimulationInput cause an "out of memory error during serialization" error?

19 ビュー (過去 30 日間)
I am attempting to run simulations using "parsim" or "batchsim". I notice that the simulations take up an extraordinarily large amount of memory, significantly more than what would be expected from their input and output data. Then I receive the error:
"out of memory during serialization"

採用された回答

MathWorks Support Team
MathWorks Support Team 2025 年 10 月 7 日 0:00
編集済み: MathWorks Support Team 2025 年 10 月 7 日 15:08
The issue is triggered by passing a SimulationInput object as an argument to a postSimFcn:
>>SimIn(idx) = SimIn(idx).setPostSimFcn(@(x) postsim(x, SimIn(idx)));
Using the SimulationInput object as an input argument of the anonymous function in this callback can cause a circular reference which led to runaway memory usage during the serialization of parsim and batchsim initialization.
In R2024a and later releases, parsim and batchsim can automatically pass the SimulationInput as a second argument on its call to your postSimFcn. See argument "y" in the pseudocode below. This syntax will avoid this problem. 
>>simIn = setPostSimFcn(simIn,@(x,y) postsim(x,y)); 
function new_out = postsim(curr_out,curr_in)
    %your code here
end
In earlier releases, a workaround is to use a temporary variable for the SimIn element instead of passing the simulation input object itself.
>>tmpSimIn = SimIn(idx);>>SimIn(idx) = SimIn(idx).setPostSimFcn(@(x) postsim(x, tmpSimIn));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRun Multiple Simulations についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by