I played with some examples of the tranlation guide. The ones under Mutation seem incorrect.
Here the code in question:
# OhMyThreads
using OhMyThreads: @tasks
data = rand(10)
@tasks for i in 1:10
data[i] = calc(i)
end
# or
using OhMyThreads: tforeach
tforeach(data) do i
data[i] = calc(i)
end
# or
using OhMyThreads: tmap!
tmap!(data, data) do i # this kind of aliasing is fine
calc(i)
end
tforeach does not work. It errors as i (comming from data) cannot be used to index data. The only working case would be to have data = collect(1:10). I guess it would be best to change the example to be more similar to the @tasks case:
using OhMyThreads: tforeach
tforeach(1:10) do i
data[i] = calc(i)
end
2. the example with `tmap` works but is misleading as a novice use (like I) would assume `i` to be identical between the examples. But here it is the data and not the index. Also, the output would in general be different (depending on `calc`).
I propose to change it to
using OhMyThreads: tmap!
tmap!(data, 1:10) do i # this kind of aliasing is fine
calc(i)
end
It might be wiser to replace `1:10` with `eachindex(data)` but this applies to `@tasks` and `@threads` as well.
I played with some examples of the tranlation guide. The ones under
Mutation
seem incorrect.Here the code in question:
tforeach
does not work. It errors asi
(comming fromdata
) cannot be used to indexdata
. The only working case would be to havedata = collect(1:10)
. I guess it would be best to change the example to be more similar to the@tasks
case:tforeach(1:10) do i data[i] = calc(i) end
using OhMyThreads: tmap!
tmap!(data, 1:10) do i # this kind of aliasing is fine calc(i) end