Parallel Simulation with OpenModelica
A detailed introduction to task-graph-based parallelization with respect to the HPCOM-module can be found in the tutorial.
To use the full range of functions, please install the latest OpenModelica NightlyBuild
Parallelisation with hpcom is activated via the debug flag +d=hpcom. Beside this the number of used threads is given via the flag +n= "no. of threads". Using these flags while executing omc enables parallel simulation of your model:
> omc +d=hpcom +n=4 model.mos
If you run the simulation like that, the execution and communication costs are roughly estimated.
The better option is to measure these times. Therefore you have to run the serial simulation using the config-flag +profiling=all :
> omc model.mos +profiling=all
This creates a model_prof.json which includes the execution times of each task. Since the execution time is needed in clock pulses instead of seconds, you have to execute the model with the simulation flag -clock=CYC. (This is not necessary when using C++ codegeneration via +simCodeTarget=Cpp)
> model -clock=CYC
After this, just rename the updated model_prof.json to model_eqs_prof.json.
Now you can use parallel simulation with best preconditions.
There are some other options available which might be useful to try out. You can chosse for instance between different genereated code, namely openmp, pthreads with mutexes or spinlocks whereby pthreads using spinlocks is probably the best option under Windows. For linux, OpenMP works very efficiently. This can be activated via the flag hpcomCode
You can also choose between different scheduling algorithms. This is accessable via hpcomScheduler
> +hpcomScheduler=level (only available with openmp)
You can access some information about the predicted and possible speedUp by activating the debug flag hpcomDump.
If you activate +d=hpcom you will get a bunch of *.graphml files. Our favourite tool to visualize these graphs is yEd. Try out the automatic layouting.
This is really useful to evaluate the parallel potential of your model.
|MCP (Modified Critical Path)||X||X||X|
|BLS (Balanced Level Scheduler)|
|SBS (Single Block Scheduler)||X||X||X|
Splitting Systems of Equations
Big equation systems constitute a big part of the simulation time. They are only parallelizable to a limited extend and therefore its useful to split big systems to several smaller ones, if possible.
There is a compiler module in OpenModelica which can carry this out.
Thats not possible in every case, but especially for electrical models we have seen various use cases. You can activate the module using the debug-flag: