I’m using `Distributed`

and `pmap`

together for some fairly standard problems, but I realized that, to get my code to run, I am putting `@everywhere`

on just about every line of code, and I’m trying to see if I can simplify this or otherwise clean up what I’m doing.

As an example, suppose I have a function `f(x,y)`

, and I want to apply

```
x1vals = pmap(x->f(x,y0), x0vals)
```

for some fixed value of `y0`

and some array `x0vals`

. In my case, `y0`

is the solution of an optimization problem, minimizing another function, `g(y)`

. Currently, I have to do:

```
@everywhere using Optim
@everywhere function g(y)
# code for g goes here
end
@everywhere y_guess = #starting guess for y
@everywhere min = optimize(g, y_guess)
@everywhere y0 = min.minimizer
```

Again, this code works fine, but:

- It would appear I am running the minimization problem on each worker, which seems a bit wasteful
- IMO, the code is getting a bit cluttered with the
`@everywhere`

lines everywhere.