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):
idx = y * s
print(y, s, idx)
parallelize[worker](h,1)
def main():
calc(1000, 300)
like the following:
0 140731463405744 0
1 140731463405744 140731463405744
2 140731463405744 281462926811488
3 140731463405744 422194390217232
4 140731463405744 562925853622976
5 140731463405744 703657317028720
6 140731463405744 844388780434464
7 140731463405744 985120243840208
...
if I use s_
within worker function - print produces expected result:
0 1000 0
1 1000 1000
2 1000 2000
3 1000 3000
4 1000 4000
5 1000 5000
6 1000 6000
7 1000 7000
8 1000 8000
9 1000 9000
10 1000 10000
I expect them to work in a similar way.
Steps to reproduce
- Include relevant code snippet or link to code that did not work as expected.
- If applicable, add screenshots to help explain the problem.
- If using the Playground, name the pre-existing notebook that failed and the steps that led to failure.
- Include anything else that might help us debug the issue.
System information
- What OS did you do install Mojo on ?
Ubuntu 24.04
- Provide version information for Mojo by pasting the output of `mojo -v`
mojo 24.5.0 (e8aacb95)
- Provide Modular CLI version by pasting the output of `modular -v`
magic 0.2.3