In some of my own code I’ve used Meta.eval to call @everywhere from inside a function:
#... Inside a function
Meta.eval("@everywhere using MyUtility")
***Edit, also make sure that addprocs activates the current project so that it has access to MyUtility.
p.s. Is there any reason why you can’t use multithreading for your parallelism instead? Something like:
results = Vector{Any}(undef, length(a))
Threads.@threads for i in 1:length(a)
results[i] = reduce(foo(a[i]))
end
This should have better performance and lower latency and will work as long as foo is not mutating any global state, causing a race condition.