Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

C compiler optimization for generated Modelica code

C compiler optimization for generated Modelica code

Hello: I am interested to possibly speed-up simulations.  I am running Mac 10.10, so the compiler is Clang.

In the experiment makeflie, I can see this comment below:

Code:

# Simulations use -O3 by default

However, there is actually no -O3 flag being passed to the compiler (or at least it is not apparent).  I also checked the .c and .h  files to see if optimization pragmas were used, but they were not.  I think this should be an easy thing to fix.

Re: C compiler optimization for generated Modelica code

Set env.var MODELICAUSERCFLAGS=-O3 or use setCFlags(getCFlags() + " -O3")
Or better yet, use -Os or -O2. That runs faster than O3 in most cases. Usually, the overall time is slower though (the simulation runtime is already optimized and it takes a lot of extra effort to optimize all of the generated code, some which is never run).

Re: C compiler optimization for generated Modelica code

Thank you, I will do that.

I have a very large model that I need to simulate.  I am converting it from another format to Modelica, and just learning Modelica.  I would say there are about 250 differential equations and about 750 algebraic.  Out of curiosity, what would be your best-guess time to build the simulation?

Re: C compiler optimization for generated Modelica code

https://test.openmodelica.org/libraries … rsive.html
https://test.openmodelica.org/libraries … ptions.err has 2404 states, around 4000 equations.Takes 1 minute to compile the C-code with -O0, and runs in 13 seconds.

https://test.openmodelica.org/libraries … rsive.html
https://test.openmodelica.org/libraries … yAdder.err on the other hand has 324 states, 1649 equations (some which are torn non-linear systems). 1m18s to compile the C-code with -O0, and runs into a timeout (on the same machine it would take around 9 minutes or so to finish). But the slowness here is that the non-linear solvers take long to converge. They are already optimized.

So... It depends a lot on other structures in your model.

There are 0 guests and 0 other users also viewing this topic
You are here: