Improve performance by using different compilers in Dymola

Sometimes using a different C compiler can result in a model simulating faster, as described in this optimisation blog. In this post we look at how the different Windows compilers, Visual Studio, Visual Studio with Clang, MinGW and MinGW with Clang can be used to compile a Dymola model and potentially create executables that simulate the models faster.

Using Visual Studio

The Visual Studio compiler is supported in Dymola so all that is required is to install a supported version of Visual Studio. A good description of how to just install the Visual Studio Build tools is provided on this Dassault Systemes webpage. A Visual Studio license is needed to use the Build Tools. Once Visual Studio is installed you can go to the Simulation>Setup and on the Compiler tab select the Visual Studio compiler as in Figure 1.

Figure 1. Selecting Visual Studio compiler and setting Compile and Link settings

Figure 1. Selecting Visual Studio compiler and setting Compile and Link settings

In Figure 1, in addition to selecting the compiler on the Compiler tab you can also supply additional Compiler and Linker flags. Recommend Compiler settings are the /O2 (optimise for speed) /GL (whole program optimisation) and recommended Linker settings are /LTCG (Link-time code generation). In addition to these settings profiled optimised compilation is also possible which is not covered in this post.

Visual Studio with Clang

The Clang compiler has generated model executables that are more than 10% faster than using the Visual Studio compiler, however the performance improvement is model dependent.

Clang is supported in Visual Studio by installing the Clang compiler. To use the Clang compiler the clang-cl compiler is called during compilation instead of the cl compiler.
Dymola however does not support Clang so the build file that is being used has to be modified. See the post on the Dymola compilation for more details about the compilation process, in particular note the number of different build bat files that can be used depending on the build options selected.

To support compilation using DASSL, modify the build.bat file by replacing the line:



set COMPILER=clang-cl
) ELSE (
echo COMPILER=%COMPILER% >> dslog.txt

and create an Environment variable called USECLANGCL when you want to use the Clang solver. This environment variable can be created by using the Modelica.Utilities.System.setEnvironmentVariable() function like this:


The Modelica.Utilities.System.getEnvironmentVariable() function can be used to check the environment variable. Remember to remove this environment variable if you want to use the default Visual Studio compiler.

The compiler flags to improve performance are the same as those used in Visual Studio as mentioned in the previous section.

Using MinGW

A popular Linux C/C++ compiler is GCC, MinGW is the Windows version of this compiler. This compiler can be freely downloaded from I recommend the 64bit version without clang from the MSVCRT runtime section.

I found the MinGW compilers less robust than the Visual Studio, especially the Win32 version. However the MinGW compiler can sometimes generate model executables with better performance.

To use MinGW open Simulation>Setup and on the Compiler tab select MinGW and the source for the 64 bit version (preferably don’t use the 32 bit version) as in Figure 2.

Figure 2. Setting up the MinGW compiler

Figure 2. Setting up the MinGW compiler

The equivalent Visual Studio /GL and /LTCG options in MinGW is just the -flto compiler flag and there exists a -O3 compiler option which optimises to give the best speed performance. Note that using the -flto compiler setting can cause the building of the executable to be slow (contact Claytex if you require a solution for this issue).

Note that MinGW does not currently support any of the following solvers Radau, Esdirk23a, Esdirk34a, Esdirk45a, and Sdirk34hw (see Dymola Full User Manual Section 5.7.2).

Using MinGW with Clang

Using MinGW with Clang can generate the best performance in some cases. I recommend using the MSYS2 clang installation, installed as described in the Testing blog.

There is no direct support for clang in Dymola so the gccbuild.bat has been modified to support this. Firstly, create an environment variable called CLANGPATH and provide the path to the MSYS2 clang.exe binary (e.g. Modelica.Utilities.System.setEnvironmentVariable(“CLANGPATH”,”C:\msys64\clang64\bin\clang.exe”) ). Then, modify <Dymola installation directory>\bin\Gccbuild.bat to use this during compilation by changing the line starting with:




And modify the line starting with:

"%GCC64Path%" -shared


"%CLANGPATH%" -shared

Then select the gcc compiler and set the optimisation flags as in Figure 2.


Methods used to compile a Dymola model using different compilers are described. Some models do run faster using these different compiler options however it is model dependent so you will have to try these different compilers to find the best performance.

Note that the modifications to the build files described above could be done in a more complete and user friendly way; however, they were done this way to keep the changes to as few as possible.

Other options to try to improve performance further are to use profile guided compilation, use the Intel compiler and/or the architecture compiler options. Possibly this will be a future blog post.

Hopefully the MinGW compiler will support all the Dymola solvers in later releases of Dymola.

Written by: Garron Fish – Chief Engineer

Please get in touch if you have any questions or have got a topic in mind that you would like us to write about. You can submit your questions / topics via: Tech Blog Questions / Topic Suggestion


Got a question? Just fill in this form and send it to us and we'll get back to you shortly.


© Copyright 2010-2023 Claytex Services Ltd All Rights Reserved

Log in with your credentials

Forgot your details?