How can I use a local module for parallel computing in julia
Asked Answered
W

2

5

I have a local module that i wrote in my machine, I am using julia 1.7 and when I want to use this module I write something like this:

@everywhere include("Foo.jl")
using .Foo

this is the Error that I get:

UndefVarError: Foo not defined

Stacktrace:
 [1] top-level scope
   @ /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Distributed/src/macros.jl:200
 [2] eval
   @ ./boot.jl:373 [inlined]
 [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1196

Now I don't understand why it is not defined even tho it is written in the local machine in the same directory.

Wavawave answered 7/12, 2022 at 18:13 Comment(0)
M
7

Assuming this is just a module (I run this code addprocs(4)):

shell> more Foo.jl
module Foo
   x = 5
end

julia> @everywhere include("Foo.jl")

julia> @everywhere using .Foo

If you have rather a local package:

@everywhere using Pkg
@everywhere pkg"activate ."
@everywhere using Pkg

In both cases the paths need to be available to all workers.

Mimimimic answered 7/12, 2022 at 19:19 Comment(0)
W
1

I guess right now it is working, but with warning messages:

From worker 4:  ┌ Warning: The Pkg REPL mode is intended for interactive use only, and should not be used from scripts. It is recommended to use the functional API instead.
      From worker 4:    └ @ Pkg.REPLMode /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/Pkg/src/REPLMode/REPLMode.jl:377
      From worker 4:      Activating new project at `~/Downloads`
      From worker 2:    ┌ Warning: The Pkg REPL mode is intended for interactive use only, and should not be used from scripts. It is recommended to use the functional API instead.
      From worker 2:    └ @ Pkg.REPLMode /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/Pkg/src/REPLMode/REPLMode.jl:377
      From worker 2:      Activating new project at `~/Downloads`
      From worker 3:    ┌ Warning: The Pkg REPL mode is intended for interactive use only, and should not be used from scripts. It is recommended to use the functional API instead.
      From worker 3:    └ @ Pkg.REPLMode /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/Pkg/src/REPLMode/REPLMode.jl:377
      From worker 3:      Activating new project at `~/Downloads`
  Activating new project at `~/Downloads`
In [ ]:
Wavawave answered 8/12, 2022 at 15:3 Comment(1)
You do not want to activate a Julia project at ~/Downloads. Create some new Julia package and pkg"activate /folder/to/new/package". You really strongly need to perfectly follow this text: pkgdocs.julialang.org/v1/creating-packages Once you have it if something still does not work for you let me know.Mimimimic

© 2022 - 2024 — McMap. All rights reserved.