I’m trying to benchmark various parallelization approaches, and realized I’m not sure how to change which macro is called…? Is this possible?
n = Threads.nthreads()
a = zeros(n)
# next line is psuedocode
@macro_name for i = 1:n
a[i] = Threads.threadid()
you can’t because macros are expanded before run time.
But if you want to use different parallelisms (or not) methods, you should probably look into high-level interfaces like
A little-known fact is that macros are represented as values just like functions or anything else, they are just a bit harder to get at. And calling them gives the expanded code.
julia> m = Base.var"@time"
@time (macro with 1 method)
julia> m(LineNumberNode(@__LINE__, @__FILE__), @__MODULE__, :(1+2))
#= timing.jl:206 =#
So you can do what you want if you make
count_threads a generated function.