# How to use Dagger in remote machines?

**URL:** <https://discourse.julialang.org/t/how-to-use-dagger-in-remote-machines/89793>\
**Category:** Julia at Scale\
**Tags:** dagger\
**Created:** [November 4, 2022, 10:07pm UTC](https://discourse.julialang.org/t/how-to-use-dagger-in-remote-machines/89793 "2022-11-04T22:07:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Noel\_Araujo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/noel_araujo/32/4862_2.png) [@Noel\_Araujo](https://discourse.julialang.org/u/Noel_Araujo)\
**Post date:** [November 4, 2022, 10:07pm UTC](https://discourse.julialang.org/t/how-to-use-dagger-in-remote-machines/89793/1 "2022-11-04T22:07:33Z")

</div>

I began using `Dagger.jl` and I want to run some tests it with my local host machines, but those tests only runs in multithreading in my notebook.

I know that my local machines work, because I can run them with `Distributed.jl` and everything goes according to expected. **Then I wish to know an equivalent syntax with `Dagger.jl`**

```julia
# (...) load packages and add process (...)

# WORKS: this piece of code runs into my machines
map(1:10) do i
    Distributed.@spawn println("inside machine: $(pwd())")
end;

# HERE is the part that I need help
map(1:10) do i
    Dagger.@spawn println("inside machine: $(pwd())")
end;

```

As far I am aware, I should use `Dagger.tochunk` in some way and `Scopes`, but I got a lot of error messages, and I don’t even know what I’m doing.

To avoid more confusing, I’m here asking for some basic guidance, and maybe help people in the future with the same problem will benefit from reading the answer.

Thank you

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [November 5, 2022, 1:20pm UTC](https://discourse.julialang.org/t/how-to-use-dagger-in-remote-machines/89793/2 "2022-11-05T13:20:44Z")

</div>

Can you please provide the error and stacktrace that you receive? Also, `Dagger.@spawn` expects just a single function call right now (will change once I address [`@spawn` has confusing move semantics · Issue #357 · JuliaParallel/Dagger.jl · GitHub](https://github.com/JuliaParallel/Dagger.jl/issues/357)), but you have `println`, string interpolation (which is a call to `Base.string`), and `pwd`. You should instead write this as:

```julia
f() = println("inside machine $(pwd())")
map(1:10) do i
    Dagger.@spawn f()
end;

```

---

<div class="post-metadata">

**Author:** ![Noel\_Araujo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/noel_araujo/32/4862_2.png) [@Noel\_Araujo](https://discourse.julialang.org/u/Noel_Araujo)\
**Post date:** [November 5, 2022, 2:49pm UTC](https://discourse.julialang.org/t/how-to-use-dagger-in-remote-machines/89793/3 "2022-11-05T14:49:44Z")

</div>

Thank you, your example works once I add an `everywhere` in front of the function name.

What I was trying to do, was to modify the example of [Union Scopes](https://juliaparallel.org/Dagger.jl/dev/scopes/), but the command `Dagger.thunk_processor()` does not work. The error message is:

```julia
using Distributed, Dagger
@everywhere using Distributed, Dagger

> Dagger.thunk_processor()
ERROR: KeyError: key :_dagger_processor not found
Stacktrace:
 [1] getindex
   @ ./iddict.jl:108 [inlined]
 [2] task_local_storage
   @ ./task.jl:270 [inlined]
 [3] thunk_processor()
   @ Dagger ~/.julia/packages/Dagger/y0NVO/src/processor.jl:304

```

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [November 5, 2022, 4:07pm UTC](https://discourse.julialang.org/t/how-to-use-dagger-in-remote-machines/89793/4 "2022-11-05T16:07:34Z")

</div>

`Dagger.thunk_processor()` is intended to be used within a thunk, such as when defining `f`: `f() = println("running on processor $(Dagger.thunk_processor())")`. Using it outside of a Dagger thunk doesn’t work because Dagger doesn’t have any control of which processor is being used.
