# Dynamic scheduling in @sync @distributed for constructions

**URL:** https://discourse.julialang.org/t/dynamic-scheduling-in-sync-distributed-for-constructions/22301
**Category:** Julia at Scale
**Created:** [March 25, 2019, 12:52pm UTC](https://discourse.julialang.org/t/dynamic-scheduling-in-sync-distributed-for-constructions/22301 "2019-03-25T12:52:28Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![MMalakhov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmalakhov/32/10138_2.png) [@MMalakhov](https://discourse.julialang.org/u/MMalakhov)
#### Post date: [March 25, 2019, 12:52pm UTC](https://discourse.julialang.org/t/dynamic-scheduling-in-sync-distributed-for-constructions/22301/1 "2019-03-25T12:52:28Z")

</div>

Hello!  
Maybe it is a too simple question, but I couldn’t find it in the documentation.

Constructions like

> @sync @distributed for j=1:N  
> (body)  
> end

make static schedule of iterations by default. But my iterations can take different time, some are very long, some are short. In OpenMP I can easily set the schedule to dynamic before the loop to optimize performance. Do you have an analog for it?

---

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [March 26, 2019, 1:45am UTC](https://discourse.julialang.org/t/dynamic-scheduling-in-sync-distributed-for-constructions/22301/2 "2019-03-26T01:45:04Z")

</div>

Maybe you can use `pmap`.

[https://docs.julialang.org/en/v1/manual/parallel-computing/index.html#Parallel-Map-and-Loops-1](https://docs.julialang.org/en/v1/manual/parallel-computing/index.html#Parallel-Map-and-Loops-1)

[https://docs.julialang.org/en/v1.1/stdlib/Distributed/#Distributed.pmap](https://docs.julialang.org/en/v1.1/stdlib/Distributed/#Distributed.pmap)

---

<div class="post-metadata">

### Author: ![MMalakhov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmalakhov/32/10138_2.png) [@MMalakhov](https://discourse.julialang.org/u/MMalakhov)
#### Post date: [March 26, 2019, 10:34am UTC](https://discourse.julialang.org/t/dynamic-scheduling-in-sync-distributed-for-constructions/22301/3 "2019-03-26T10:34:46Z")

</div>

Thanks. So it seems that there is no easy OpenMP style solution. Bad, static/dynamic schedule seems to be a very simple and useful option.

---

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [March 27, 2019, 12:33am UTC](https://discourse.julialang.org/t/dynamic-scheduling-in-sync-distributed-for-constructions/22301/4 "2019-03-27T00:33:41Z")

</div>

Could you explain more why `pmap` is not suitable?

Is it the syntax?  
Do you want to dynamically switch between static/dynamic load scheduling?

Could you use something like:

```julia
pmap(1:N) do j
   (body)
end

```

---

<div class="post-metadata">

### Author: ![MMalakhov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmalakhov/32/10138_2.png) [@MMalakhov](https://discourse.julialang.org/u/MMalakhov)
#### Post date: [March 27, 2019, 10:46am UTC](https://discourse.julialang.org/t/dynamic-scheduling-in-sync-distributed-for-constructions/22301/5 "2019-03-27T10:46:57Z")

</div>

It’s suitable but makes very simple things more complicated. I want my loop to start from the word “for” because it’s simple.

---

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [March 27, 2019, 10:54am UTC](https://discourse.julialang.org/t/dynamic-scheduling-in-sync-distributed-for-constructions/22301/6 "2019-03-27T10:54:42Z")

</div>

Ha, maybe some clever person can write a macro `@pfor` to sweeten your syntax.

---

<div class="post-metadata">

### Author: ![MMalakhov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmalakhov/32/10138_2.png) [@MMalakhov](https://discourse.julialang.org/u/MMalakhov)
#### Post date: [March 27, 2019, 11:08am UTC](https://discourse.julialang.org/t/dynamic-scheduling-in-sync-distributed-for-constructions/22301/7 "2019-03-27T11:08:25Z")

</div>

=) May be, but it seems to me that Julia creators are inventing the bicycle in this area. People do not come to Julia from nowhere, and have experience with such old and common things like MPI or OpenMP.  
I think problem is also that Julia documentation is very poor, with so few examples. Like now I still don’t get why you need “@sync @distributed for” and “pmap”. Which of this function will vanish in Julia 2.0?
