Can someone please explain why the following errors?
macro d(np::Integer) quote using Distributed addprocs($np) @everywhere begin using Pkg Pkg.activate(".") end end end julia> @d 2 ERROR: LoadError: UndefVarError: @everywhere not defined
(I often add the body of the macro as boiler-plate code when I want to parallelize my code, so I was hoping to write a macro to reduce the number of lines of code I have to add.)
If I split it into two macros (one with
using Distributed; addprocs($np), and the other with the
@everywhere block) it works. It also works if I use
using Distributed before calling
I also don’t know why the call to
addprocs doesn’t error. If
@everywhere isn’t defined, I would expect
addprocs to be undefined as well.