You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use the @batch as an alternative to the Base.Threads.@threads but inside my loops I need to define some closures which produced an UndefVarError. A MWE is the following
functionfunc()
@batchfor i in1:5f(x)=x
endendfunc()
will produce:
ERROR: UndefVarError:`x` not defined
Stacktrace:
[1] macro expansion
@ ~/.julia/packages/Polyester/HaBfT/src/closure.jl:387 [inlined]
[2] func()
@ Main ./REPL[90]:2
[3] top-level scope
@ REPL[91]:1
[4] top-level scope
@ ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:1428
Is there a workaround or its a case that I cannot use @batch?
The text was updated successfully, but these errors were encountered:
julia>struct Mul{T}
x::Tend
julia> (x::Mul)(y) = x.x * y
julia>using Polyester
julia>functionfunc!(y,x)
@batchfor i =eachindex(y,x)
y[i] =Mul(i)(x[i])
endend
func! (generic function with 1 method)
julia> x =rand(1000); y =similar(x);
julia>func!(y, x)
julia> y == x .*eachindex(y,x)
true
thanks for your reply! That solves my issue, thank you.
although it worked and I got 0 allocations with @batch, for my case
the performace was worse than @threads but this should be due to my
definitions of the function-like objects etc.
I am trying to use the
@batch
as an alternative to theBase.Threads.@threads
but inside my loops I need to define some closures which produced an UndefVarError. A MWE is the followingwill produce:
Is there a workaround or its a case that I cannot use
@batch
?The text was updated successfully, but these errors were encountered: