# Saving local variables on processor during \`pmap\`

**URL:** <https://discourse.julialang.org/t/saving-local-variables-on-processor-during-pmap/70064>\
**Category:** General Usage\
**Tags:** distributed\
**Created:** [October 19, 2021, 8:39pm UTC](https://discourse.julialang.org/t/saving-local-variables-on-processor-during-pmap/70064 "2021-10-19T20:39:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tictaccat](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tictaccat](https://discourse.julialang.org/u/tictaccat)\
**Post date:** [October 19, 2021, 8:39pm UTC](https://discourse.julialang.org/t/saving-local-variables-on-processor-during-pmap/70064/1 "2021-10-19T20:39:52Z")

</div>

Hey, I have a small issue that I haven’t been able to solve for hours. I have a simple pmap,

```julia
arr2 = pmap(f, arr).

```

Later on, after a bunch of computation on `arr2`, I get an array `arr3` of length equal to `arr`. I need to do another pmap on it,

```julia
arr4 = pmap(g, arr3).

```

However, the key point is that **one of the intermediate values computed during the function `f(arr[i])` needs to be used by the function `g(arr3[i])`. Moreover, this intermediate value is very expensive to communicate between processors.** Since both of these pmaps operate on the same worker pool, what I would like to do is save this intermediate value locally on the processor when computing `f`, and have `g` access this variable.

If it makes things simpler, my worker pool is larger than the size of `arr`, so each processor does at most one task. Also, I understand that a solution may not be possible using `pmap`’s, as if a processor is assigned to `arr[i]` in the first pmap, I need the same processor to be assigned to `arr3[i]` in the second pmap; I don’t think `pmap`s offer this level of control. However, at this point, I would be overjoyed with just any solution at all. I’m still getting used to distributed computing in Julia, and would really appreciate help on how to do this 🙂

---

<div class="post-metadata">

**Author:** ![tictaccat](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tictaccat](https://discourse.julialang.org/u/tictaccat)\
**Post date:** [October 19, 2021, 10:03pm UTC](https://discourse.julialang.org/t/saving-local-variables-on-processor-during-pmap/70064/2 "2021-10-19T22:03:45Z")

</div>

Resolved. I saved a global variable during the function `f` and returned the processor ID in addition to the usual returned value. Then, I replaced the second `pmap` with a bunch of `@spawnat`’s which match processor IDs to the correct task, and access the global variable saved by `f`.
