parallelize and @parameter issue in Mojo 24.5

I am trying to convert my projects to Mojo 24.5. Right now I face the following issue. When running
from algorithm import parallelize

fn main():
var t = 5
@parameter
fn whatever(ip:Int):
print(t)
parallelize[whatever](1)
from algorithm import parallelize

fn main():
var t = 5
@parameter
fn whatever(ip:Int):
print(t)
parallelize[whatever](1)
I get 4507533440 printed as result. In the @parameter doc https://docs.modular.com/mojo/manual/decorators/parameter it says This is an unsafe feature because we currently do not model the lifetimes of capture-by-reference. but up to 24.4 i never had this issue. Did i miss some fundamental change here? Any advice how to handle this would be great. Thx 🙏 ps adding
'_ = t'
'_ = t'
at the end of this demo would solve the issue but that gets complicated and ugly in my projects ...
@parameter | Modular Docs
Executes a function or if statement at compile time.
4 Replies
sora
sora3mo ago
GitHub
[BUG] parallelize won't work with local variables (they turn to uni...
Bug description Calling the following code produces garbage values for s and idx: from algorithm import parallelize fn calc(s: Int, h: Int): var s = 5000 var h = 100 @parameter fn worker(y:Int): ...
Martin Dudek
Martin DudekOP2mo ago
thanks a lot @sora
sora
sora2mo ago
I think this is resolved on the latest nightly
Martin Dudek
Martin DudekOP2mo ago
thanks @sora , i just tried the little demo i posted with the current nightly (mojo 2024.9.2305 - f7b111af) and yeah, it worked as expected
Want results from more Discord servers?
Add your server