I have a local module, say MyProject
, which has a folder src
with two scripts script1.jl
and script2.jl
.
module MyProject
using Package1
using Package2
using Package3
include("script1.jl")
include("script2.jl")
export function1_in_script1,
function1_in_script2
Now, there is a for
loop in function1_in_script2
that I want to parallelize, which depends on the content in the script1.jl
and Package1
and Package2
.
If I don’t need parallelization, I would generally run the following code:
#Activating the environment
using Pkg
if isfile("Project.toml") && isfile("Manifest.toml")
Pkg.activate(".")
end
using MyProject
using AnyOtherRequiredPackage
# Call the function
function1_in_script2(...)
Now, how do I modify the above code to make sure that the for loop in the function1_in_script2
is available on all worker processes? I am using pmap
to parallelize the for loop. I understand, I can do something like:
using Distributed
addprocs(5)
#Now, I am confused about where to use the @everywhere macro
#Should it be on the entire module, i.e., @everywhere using MyProject
#Or should I use it inside the MyProject module?
Thanks!