# Why Julia is much slower than MATLAB on GPU computing?

**URL:** <https://discourse.julialang.org/t/why-julia-is-much-slower-than-matlab-on-gpu-computing/106450>\
**Category:** GPU\
**Tags:** matlab, cuda\
**Created:** [November 20, 2023, 6:30am UTC](https://discourse.julialang.org/t/why-julia-is-much-slower-than-matlab-on-gpu-computing/106450 "2023-11-20T06:30:20Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![maxfreu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxfreu/32/17468_2.png) [@maxfreu](https://discourse.julialang.org/u/maxfreu)\
**Post date:** [November 20, 2023, 9:24am UTC](https://discourse.julialang.org/t/why-julia-is-much-slower-than-matlab-on-gpu-computing/106450/8 "2023-11-20T09:24:31Z")

</div>

Oh and try to use a scratch array to store the intermediate result:

```julia
ulia> function main(N)
           x = CuArray(DGP(N))
           V0 = CUDA.ones(Float64, N); idx = ()
           a = 0.5
           max_iter = 100
           iter = 0
           tmp = x .+ a * V0'
           while iter < max_iter
               V1 = V0
               tmp .= x .+ a * V1'
               V0, idx = findmax(tmp, dims=2)
               iter += 1
           end
           return V0, idx, iter
       end

```

That should get rid of most of the memory management time.

---

_[View the full topic](https://discourse.julialang.org/t/why-julia-is-much-slower-than-matlab-on-gpu-computing/106450)._
