# Does SimJulia support parallel computation?

**URL:** https://discourse.julialang.org/t/does-simjulia-support-parallel-computation/31698
**Category:** General Usage
**Tags:** question
**Created:** [November 30, 2019, 6:11pm UTC](https://discourse.julialang.org/t/does-simjulia-support-parallel-computation/31698 "2019-11-30T18:11:15Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![zhangliye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhangliye/32/3208_2.png) [@zhangliye](https://discourse.julialang.org/u/zhangliye)
#### Post date: [November 30, 2019, 6:11pm UTC](https://discourse.julialang.org/t/does-simjulia-support-parallel-computation/31698/1 "2019-11-30T18:11:15Z")

</div>

I have developed a traffic simulation package using SimJulia. When the network is larger, the simulation is not quick enough. Does anyone know whether SimJulia supports the parallel calculation? This is not mentioned in the documentation.  
[SimJulia](https://github.com/BenLauwens/SimJulia.jl)

---

<div class="post-metadata">

### Author: ![zhangliye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhangliye/32/3208_2.png) [@zhangliye](https://discourse.julialang.org/u/zhangliye)
#### Post date: [December 2, 2019, 6:56am UTC](https://discourse.julialang.org/t/does-simjulia-support-parallel-computation/31698/2 "2019-12-02T06:56:27Z")

</div>

I checked the CPU usage on a 72-Core server, only 1 core is fully used. Is there any method to make SimJulia run in a multiple-core mode. I checked the source code of SimJulia, which depends on ResumableFunctions. I currently have no idea on how to use multiple core.  
I need to simulate the movement of millions objects, and thus it is almost does not work using just one core. Can anyone help? Thanks!

---

<div class="post-metadata">

### Author: ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)
#### Post date: [December 2, 2019, 7:40am UTC](https://discourse.julialang.org/t/does-simjulia-support-parallel-computation/31698/3 "2019-12-02T07:40:15Z")

</div>

looking at this example in particular:

```julia
@resumable function start_sim(env::Environment, repair_facility::Resource, spares::Store{Process})
    for i in 1:N
        proc = @process machine(env, repair_facility, spares)
        @yield interrupt(proc)
    end
    for i in 1:S
        proc = @process machine(env, repair_facility, spares)
        @yield put(spares, proc) 
    end
end

```

the amount of variables is defined by the user, so you can try using some parallel methods here. i recommend using the new multithreading capabilities of julia 1.3, adding `Threads.@threads` in any loops that your function may have, and starting the julia process in the server with more threads (72 in your case)

---

<div class="post-metadata">

### Author: ![stustd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stustd/32/21430_2.png) [@stustd](https://discourse.julialang.org/u/stustd)
#### Post date: [December 2, 2019, 8:07am UTC](https://discourse.julialang.org/t/does-simjulia-support-parallel-computation/31698/4 "2019-12-02T08:07:05Z")

</div>

There is a long history of parallellizing discrete event simulations with mixed results. The problem is the synchronization of events at the end of parallel (sub) branches. In order to do this successfully you need to know in advance which events each sub - branch is dependent on, which most often (c. q. in general) is impossible. Most parallel attempts follow the “optimistic” simulation paradigm with rewinding capability. When this becomes too expensive (which it often does) “conservative” i.e. single thread simulation is than the fastest you can get.

---

<div class="post-metadata">

### Author: ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)
#### Post date: [December 2, 2019, 9:09am UTC](https://discourse.julialang.org/t/does-simjulia-support-parallel-computation/31698/5 "2019-12-02T09:09:24Z")

</div>

Exactly. [Here](https://dl.acm.org/citation.cfm?id=3242181.3242198) is a link reference summary of how the research on this topic developed since '70s that was presented during WinterSim in 2017.

The easiest way to speed up DSE in Julia is to switch from process-oriented implementation to event-oriented one (this still will be single threaded). Here is an example implementation I have made some time ago exactly because of this limitation [https://github.com/bkamins/EventSimulation.jl](https://github.com/bkamins/EventSimulation.jl) (but it is essentially a thin wrapper around priority queue so you might as well write your own event scheduler from scratch which should be pretty easy in Julia).

---

<div class="post-metadata">

### Author: ![zhangliye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhangliye/32/3208_2.png) [@zhangliye](https://discourse.julialang.org/u/zhangliye)
#### Post date: [December 2, 2019, 10:33am UTC](https://discourse.julialang.org/t/does-simjulia-support-parallel-computation/31698/6 "2019-12-02T10:33:06Z")

</div>

Thank you so much! I am rewriting the simulation based on [EventSimulation.jl](https://bkamins.github.io/EventSimulation.jl/stable/) to benchmark the simulation speed. I will share the results soon.

---

<div class="post-metadata">

### Author: ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)
#### Post date: [December 2, 2019, 12:48pm UTC](https://discourse.julialang.org/t/does-simjulia-support-parallel-computation/31698/7 "2019-12-02T12:48:04Z")

</div>

Great! Feedback is welcome. Note that if “agent logic” is much more expensive than event scheduling cost there should not be a big difference. I would expect the biggest impact of this change if the action taken is very cheap.
