Hello. My question is how I include an external file within a distributed loop.
For example, the following works:
using Distributed
addprocs(2);
#Parameters:
par1 = 5;
par2 = 2;
@everywhere begin
using CSV, DataFrames;
end
@everywhere mod_pars = Dict("par1"=>$par1,"par2"=>$par2);
@everywhere par_values = collect(1:10);
@distributed for iv = 1:10
mod_pars["par1"] = par_values[iv];
df_tmp = DataFrame();
df_tmp[!,:values1] = ones(10)*mod_pars["par1"];
df_tmp[!,:values2] = ones(10)*mod_pars["par2"];
CSV.write(joinpath("figures","data_"*string(iv)*".csv"),df_tmp);
end
rmprocs(workers())
but including what’s inside the distributed loop into a separate file, called new_file.jl
, will not work:
@distributed for iv = 1:10
mod_pars["par1"] = par_values[iv];
include("new_file.jl")
end
Is there some syntax I am getting wrong?