# Error using GLM and Distributed

**URL:** https://discourse.julialang.org/t/error-using-glm-and-distributed/45459
**Category:** General Usage
**Tags:** question, distributed, glm
**Created:** [August 24, 2020, 3:43pm UTC](https://discourse.julialang.org/t/error-using-glm-and-distributed/45459 "2020-08-24T15:43:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![drarnau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drarnau/32/4476_2.png) [@drarnau](https://discourse.julialang.org/u/drarnau)
#### Post date: [August 24, 2020, 3:43pm UTC](https://discourse.julialang.org/t/error-using-glm-and-distributed/45459/1 "2020-08-24T15:43:00Z")

</div>

Dear all,

I am trying to parallelise my code and I find this kind of problem.

My not-parallelised code can be represented as:

```julia
using DataFrames, GLM

function foo(df::DataFrame)
    ols = lm(@formula(A ~ 1.0), df)
    return coef(ols)
end

df = DataFrame(A = 1.0:50.0)
foo(df)

```

I parallelise by doing:

```julia
using Distributed
@everywhere function foo(df::DataFrame)
    ols = lm(@formula(A ~ 1.0), df)
    return coef(ols)
end

```

I get this error:

```julia
On worker 2:
LoadError: UndefVarError: @formula not defined
top-level scope
eval at ./boot.jl:331
#103 at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Distributed/src/process_messages.jl:290
run_work_thunk at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Distributed/src/process_messages.jl:79
run_work_thunk at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Distributed/src/process_messages.jl:88
#96 at ./task.jl:356
in expression starting at /home/arnau/Dropbox/black_white_transitions/revision/New_Model/Tests.jl:40

...and 3 more exception(s).

sync_end(::Channel{Any}) at task.jl:314
macro expansion at task.jl:333 [inlined]
remotecall_eval(::Module, ::Array{Int64,1}, ::Expr) at macros.jl:218
top-level scope at macros.jl:202
include_string(::Function, ::Module, ::String, ::String) at loading.jl:1088

```

Any ideas? Thank you.

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [August 24, 2020, 3:43pm UTC](https://discourse.julialang.org/t/error-using-glm-and-distributed/45459/2 "2020-08-24T15:43:51Z")

</div>

> [@drarnau](#):
>
> `using Distributed`

`@everywhere using GLM`

---

<div class="post-metadata">

### Author: ![drarnau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drarnau/32/4476_2.png) [@drarnau](https://discourse.julialang.org/u/drarnau)
#### Post date: [August 24, 2020, 5:53pm UTC](https://discourse.julialang.org/t/error-using-glm-and-distributed/45459/3 "2020-08-24T17:53:01Z")

</div>

I’ve tried that. The problem is still there.

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [August 24, 2020, 6:02pm UTC](https://discourse.julialang.org/t/error-using-glm-and-distributed/45459/4 "2020-08-24T18:02:46Z")

</div>

```julia
julia> using Distributed

julia> addprocs()
12-element Array{Int64,1}:
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15

julia> using DataFrames, GLM

julia> @everywhere function foo(df::DataFrame)
           ols = lm(@formula(A ~ 1.0), df)
           return coef(ols)
       end
ERROR: On worker 2:
LoadError: UndefVarError: @formula not defined
...

julia> @everywhere using DataFrames, GLM

julia> @everywhere function foo(df::DataFrame)
           ols = lm(@formula(A ~ 1.0), df)
           return coef(ols)
       end

julia>

```

Working.
