JuliaSIMD / JuliaSIMD/LoopVectorization.jl
Some bugs
- Lenguaje dominante
- Julia
- Estrellas
- 789
- Forks
- 73
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
I was playing around a bit and noticed some bugs. The first two snippets are attempts at MWE of the final snippet which is the desired calculation
```julia
function simulate(x0::Float64; T = 10.0, dt = 0.0001, vt = 1.0)
times = 0.0:dt:T
positions = zeros(length(times))
v = 0.0
a = 0.0
x = x0
@avx for ii in eachindex(times)
x = x + v * dt
positions[ii] = x/x0
end
times, positions
end
simulate(10.0) # UndefVarError, but runs without @avx
```
```julia
function simulate(x0::Float64; T = 10.0, dt = 0.0001, vt = 1.0)
times = 0.0:dt:T
positions = zeros(length(times))
v = 0.0
a = 0.0
x = x0
@avx for ii in eachindex(times)
t = times[ii]
x = x + v * dt
positions[ii] = x/x0
end
times, positions
end
simulate(10.0) # StackOverflowError
```
The final and desired code is the following
```julia
@inline friction(v::Float64, vt::Float64) = v > vt ? -3v : -3vt*sign(v)
function simulate(x0::Float64; T = 10.0, dt = 0.0001, vt = 1.0)
times = 0.0:dt:T
positions = zeros(length(times))
v = 0.0
a = 0.0
x = x0
@avx for ii in eachindex(times)
t = times[ii]
a = friction(v, vt) - 100.0*x
a = - 100.0*x
v = v + a * dt
x = x + v * dt
positions[ii] = x/x0
end
times, positions
end
simulate(10.0)
```
Original code from [discourse thread](https://discourse.julialang.org/t/how-to-optimize-the-following-code/33209/7)
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Reproduce los tres fragmentos de Julia del issue y compara el comportamiento con y sin la macro de bucle @avx. Lee la discusión enlazada de Discourse para obtener contexto y, después, sigue cómo @avx gestiona cada forma de bucle; el trabajo estará terminado cuando se entiendan el UndefVarError y el StackOverflowError indicados, y el cálculo deseado funcione correctamente.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- julia
- Área
- performance, tooling
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 25/100