Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple @local statements #98

Open
mkoculak opened this issue Mar 26, 2024 · 4 comments
Open

Support multiple @local statements #98

mkoculak opened this issue Mar 26, 2024 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers idea macro-api

Comments

@mkoculak
Copy link

Hey.
First of all, just upgraded to 0.5 and the improvements in code clarity thanks to the macro shorthands are awesome!

While translating my code, I tried inserting multiple local variables in a similar manner:

function localtest()
    @tasks for i in 1:100
        @local x = 0
        @local y = 0.
        x += i
        y += i
        println("x; $x, y: $y")
    end
end

which throws an error:

ERROR: LoadError: The @local macro may only be used inside of a @tasks block.

Wrapping both calls in a @local begin ... end block fixes it, but since documentation does not mention it and there are no examples, it might be good to either fix it or include it in the docs.
(though I see e.g. that Trapezoidal Integration example has multiple calls to local that work - is this equivalent to the macro?)

@carstenbauer
Copy link
Member

carstenbauer commented Mar 26, 2024

(though I see e.g. that Trapezoidal Integration example has multiple calls to local that work - is this equivalent to the macro?)

No, this is not the same, as it has nothing to do with TaskLocalValue (although it also defines task local variables/values). In fact, it's just "good practice", the local keywords could just be dropped in this example.

@carstenbauer carstenbauer added bug Something isn't working and removed bug Something isn't working labels Mar 26, 2024
@carstenbauer
Copy link
Member

Actually, this is not a bug because we clearly document that multiple @local blocks are not allowed:

help?> @local
  @local name = value
  
  @local name::T = value


  Can be used inside a @tasks for ... end block to specify task-local values (TLV) via
  explicitly typed assignments. These values will be allocated once per task (rather
  than once per iteration) and can be re-used between different task-local iterations.

  There can only be a single @local block in a @tasks for ... end block. To specify
  multiple TLVs, use @local begin ... end. Compared to regular assignments, there are
  some limitations though, e.g. TLVs can't reference each other.

[...]

However, I don't remember if there was a good reason for it or whether we should try to support it (one thing that comes to mind is name clashes). I'll convert this issue into a feature request.

@carstenbauer carstenbauer changed the title Error with multiple @local calls Support multiple @local statements Mar 26, 2024
@carstenbauer carstenbauer added enhancement New feature or request idea labels Mar 26, 2024
@carstenbauer
Copy link
Member

(though I see e.g. that Trapezoidal Integration example has multiple calls to local that work - is this equivalent to the macro?)

No, this is not the same, as it has nothing to do with TaskLocalValue (although it also defines task local variables/values). In fact, it's just "good practice", the local keywords could just be dropped in this example.

f704536

@mkoculak
Copy link
Author

Right, sorry - it did not occur to me I can also check the docstring of the macro. :)
So yeah - I don't think it is necessary, just maybe having it also stated in the documentation or inside of a code block example would make things clear for people that would miss the docstring like I did.

@carstenbauer carstenbauer added the good first issue Good for newcomers label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers idea macro-api
Projects
None yet
Development

No branches or pull requests

2 participants