Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Conditional @threads macro causing @threads requires a for loop expression error#58875

FrancoisFEM started this conversation inGeneral
Discussion options

Hello,

I frequently use@threads in my code, especially in personal packages. However, I often face tricky-to-debug errors when code is run "behind" a@threads macro. Because of that, I wanted to create a sort of overload or conditional version of@threads, something like @conditionalThreads(cond::Bool, loop).

I came up with this solution:
` using Base.Threads

macro Conditionalthreads(cond, loop)
if loop.head != :for error("@Conditionalthreads must be applied to a for loop.")
end quote
if $(esc(cond))@threads $(esc(loop))
else $(esc(loop))
end end
` end

@Conditionalthreads !isinteractive() for i in 1:5 println("i = ", i)
` end

However, I get this error:

ERROR: LoadError: ArgumentError: @threads requires aforloop expressionStacktrace:
[1] var"@threads"(__source__::LineNumberNode, __module__::Module, args::Vararg{Any}) @ Base.Threads ./threadingconstructs.jl:400
[2] eval @ ./boot.jl:430 [inlined]
[3] include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String) @ Base ./loading.jl:2643
`in expression starting at /home/francois.roux/OPTILE/readnetcdf/testmaybe_thread.jl:9

While I understand the error (there is some kind of verification inside@threads), I do not know how to fix this problem. :(

If anyone has an idea...

You must be logged in to vote

Replies: 0 comments

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
1 participant
@FrancoisFEM

[8]ページ先頭

©2009-2025 Movatter.jp