# How to Use ModelingToolkit.jl Tearing Parallelism

**URL:** https://discourse.julialang.org/t/how-to-use-modelingtoolkit-jl-tearing-parallelism/62576
**Category:** Modelling & Simulations
**Created:** [June 8, 2021, 12:45pm UTC](https://discourse.julialang.org/t/how-to-use-modelingtoolkit-jl-tearing-parallelism/62576 "2021-06-08T12:45:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Brad\_Carman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brad_carman/32/17631_2.png) [@Brad\_Carman](https://discourse.julialang.org/u/Brad_Carman)
#### Post date: [June 8, 2021, 12:45pm UTC](https://discourse.julialang.org/t/how-to-use-modelingtoolkit-jl-tearing-parallelism/62576/1 "2021-06-08T12:45:08Z")

</div>

In the documentation for ModelingToolkit.jl - [Exposing More Parallelism By Tearing Algebraic Equations in ODESystems](https://mtk.sciml.ai/dev/tutorials/tearing_parallelism/#Exposing-More-Parallelism-By-Tearing-Algebraic-Equations-in-ODESystems-1) I read

> you can construct the `ODEProblem` / `ODAEProblem` and set `parallel_form` to use the exposed parallelism in multithreaded function constructions

I’m assuming this means that I should setup the problem as

```julia
prob = ODEProblem(sys, [], (0.0, 1.0); parallel=ModelingToolkit.MultithreadedForm())

```

Is my assumption correct here, or am I missing something?

I don’t see any speed improvements using `MultithreadedForm()`, in fact the solver is slower this way compared with using `SerialForm()`.

Also, side note, I see a couple bugs in the copy/paste code, will submit an issue on Github.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [June 8, 2021, 12:48pm UTC](https://discourse.julialang.org/t/how-to-use-modelingtoolkit-jl-tearing-parallelism/62576/2 "2021-06-08T12:48:20Z")

</div>

> [@Brad\_Carman](#):
>
> I don’t see any speed improvements using `MultithreadedForm()` , in fact the solver is slower this way compared with using `SerialForm()` .

The speed will greatly depend on the model. That tutorial is too small to overcome thread overhead and is just a demo.

---

<div class="post-metadata">

### Author: ![Brad\_Carman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brad_carman/32/17631_2.png) [@Brad\_Carman](https://discourse.julialang.org/u/Brad_Carman)
#### Post date: [June 8, 2021, 1:14pm UTC](https://discourse.julialang.org/t/how-to-use-modelingtoolkit-jl-tearing-parallelism/62576/3 "2021-06-08T13:14:10Z")

</div>

Ah I see, so looks like I’m using the correct keyword arg.

I also see in ModelingToolkit.jl there is a `ParallelForm()` but this doesn’t seem to be supported yet. Is this setting another possibility that will leverage the tearing parallelism?

A little background, I’ve now successfully moved my large system model from Matlab SimScape to ModelingToolkit.jl, but I’m not getting the same speed. In SimScape I use the Partitioning Solver ([Increase Simulation Speed Using the Partitioning Solver - MATLAB & Simulink](https://www.mathworks.com/help/physmod/simscape/ug/increase-simulation-speed-using-the-partitioning-solver.html)) which I’m assuming is similar to the Tearing Parallelism of ModelingToolkit. I may of course not be getting the same speed because of some inefficiencies I need to clean up, but I just wanted to confirm that theoretically, I should be able to match, if not exceed the SimScape speed.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [June 8, 2021, 1:29pm UTC](https://discourse.julialang.org/t/how-to-use-modelingtoolkit-jl-tearing-parallelism/62576/4 "2021-06-08T13:29:20Z")

</div>

> [@Brad\_Carman](#):
>
> I also see in ModelingToolkit.jl there is a `ParallelForm()` but this doesn’t seem to be supported yet. Is this setting another possibility that will leverage the tearing parallelism?

It was there, but in the great Symbolics.jl change I think @shashi broke it and didn’t fix it… but it’s hard to get a speedup with distributed parallelism in that anyways: our serial form is too optimized. We’ll need to add it back and try it on 100,000+ equation models.
