# Slow down when running several parallel julia processes which use BLAS (MWE is provided)

**URL:** <https://discourse.julialang.org/t/slow-down-when-running-several-parallel-julia-processes-which-use-blas-mwe-is-provided/8400>\
**Category:** Performance\
**Created:** [January 16, 2018, 1:59pm UTC](https://discourse.julialang.org/t/slow-down-when-running-several-parallel-julia-processes-which-use-blas-mwe-is-provided/8400 "2018-01-16T13:59:56Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Gregstrq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gregstrq/32/20620_2.png) [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Post date:** [January 25, 2018, 4:05pm UTC](https://discourse.julialang.org/t/slow-down-when-running-several-parallel-julia-processes-which-use-blas-mwe-is-provided/8400/4 "2018-01-25T16:05:05Z")

</div>

Ok. Here is a simple MWE to test this out.

Create a file “task1.jl” with the following code

```julia
Base.BLAS.set_num_threads(1)
@inline blas_A_mul_B!(α::T, A::Matrix{T}, B::Vector{T}, β::T, C::Vector{T}) where T<:Number = Base.BLAS.gemv!('N', α, A, B, β, C)

srand(1234)

const D = 720
const A = rand(D,D)

function test_matvec(IM::Matrix{Float64}, N::Int64)
    x = rand(size(IM,1))
    y = rand(size(IM,1))
    t1 = time()
    @inbounds for i=1:N
        blas_A_mul_B!(one(Float64), IM, x, zero(Float64), y)
    end
    return time()-t1
end

test_matvec(A, 1)

t = test_matvec(A,500000)

io = open("out1.txt","w")
print(io, "$t\n")
close(io)

```

After that run in the bash

```julia
for i in `seq 2 4`; do cp task1.jl "task$i.jl"; sed -i -e "s/out1/out$i/g" "task$i.jl"; done

```

You can replace 4 with the number of processes you want.

After that I can start one process with `julia task1.jl`.  
Or I can start all 4 processes in parallel by

```julia
for i in `seq 1 4`; do julia "task$i.jl" & done

```

In the former case, observing the file “out1.txt” reveals execution time of approximately 36 seconds on my machine.  
In the latter case I got approximately 250 seconds in each of out… files.

---

_[View the full topic](https://discourse.julialang.org/t/slow-down-when-running-several-parallel-julia-processes-which-use-blas-mwe-is-provided/8400)._
