FMU Crash in Python with OMSimulator
Application crashes, when the OMSimulator method (stepUntil) is called inside the loop in Python code,
error: [fmi2logger] D:/TestFMU/test_tmp/test-nv1eatv0/temp/0001_A (logFmi2Call): fmi2CompletedIntegratorStep: terminated by an assertion.
idx : 6595
idx : 6596
idx : 6597
idx : 6598
LOG_ASSERT | debug | C:/Users/Demo/AppData/Local/Temp/OpenModelica/OMEdit/Test_X11/Test_X11.fmutmp/sources/gc/memory_pool.c:100: pool_expand: Assertion `0 && "Attempt to allocate an unusually large memory. The memory management does not seem to be working as intended. Please create an issue on https://github.com/OpenModelica/OpenModelica/issues."` failed.
- Version: `OMSimulator-V2.1.1Post257
- OS: Win11, 64bit
@lochel Can you take a look on this issue as you are working on FMU memory issues
@Primkins can you please attach a new zip file, when downloading the zip file, it says virus detected, Can you please tell the name of the Model, so that we can generate the fmu's ourself
@lochel
generate the FMU and test.
model Test_X11
function fraction
input Integer size "Array size";
input Real Y[size] "input array 1";
output Real Z[size] "Sum of products value";
algorithm
for i in 1:size loop
Z[i] := Y[i]/sum(Y);
end for;
end fraction;
function SumProd
//Calculates sum of products for two arrays
input Integer size "Array size";
input Real X[size] "input array 1";
input Real Y[size] "input array 2";
output Real Z "Sum of products value";
algorithm
Z := sum(X[:].*Y[:]);
end SumProd;
constant Real MWs[10]={44.0095,18.015,28.014,28.01,2.01588,1,17,16,30.006,31.999};
Real x[:]={2.823840247,3.849832585,19.95975706,0.176159753,0.046351706,0.066372392,0.141259026,0.001503924,0.08048587,0.051539174};
output Real MoleFrac[10](each min=0, each max=1);
output Real ppmCO(min=0);
output Real ppmNO(min=0);
output Real MW ;
equation
MoleFrac=fraction(size=10, Y=x);
MW=SumProd(size=10, X=MoleFrac, Y=MWs);
ppmCO = MoleFrac[4]*1E6;
ppmNO = MoleFrac[9]*1E6;
end Test_X11;
@Primkins The model works just fine. So maybe it is connected to how you run it. Can you provide a python script to reproduce your problem?
I tested with standard settings, and changing stopTime to 2000. Both simulations went fine.
@lochel: Attached the test script Test.zip
@Primkins I can reproduce the issue and will keep you updated. Thanks for reporting the issue.
I ran the example with valgrind (reducing the number of steps to 2000), and no memory leaks were detected:
==44603== HEAP SUMMARY:
==44603== in use at exit: 0 bytes in 0 blocks
==44603== total heap usage: 6,027,224 allocs, 6,027,224 frees, 3,918,693,264 bytes allocated
==44603==
==44603== All heap blocks were freed -- no leaks are possible
However, when simulating the model directly in OpenModelica, it seems there is no reason for the memory pool to grow to such an extent. @OpenModelica/developers, can anyone with knowledge of the memory pool investigate this issue?
@Primkins I have removed the zip file because it warns about virus