I’m trying to measure the execution time of linear algebra expressions, and I’m seeing strange patterns in the results. This is a MWE that reproduces this behavior for me:
using DelimitedFiles
using LinearAlgebra
BLAS.set_num_threads(1)
M100 = rand(500, 200)
M101 = rand(500, 200)
M102 = tril(rand(500, 500))
M103 = triu(rand(500, 500))
function fun(M102::Array{Float64,2}, M100::Array{Float64,2}, M101::Array{Float64,2}, M103::Array{Float64,2})
start = time_ns()
out = M102+M100*transpose(M101)+transpose(M103);
finish = time_ns()
return (finish-start)*1e-9
end
iters = 500
timings = Array{Float64}(undef, iters)
for i = 1:iters
time = fun(M102, M100, M101, M103)
timings[i] = time
end
file = open("timings.txt", "w")
writedlm(file, timings)
close(file)
Plotting the results, I get this:
Can anyone explain where those periodic fluctuations come from, and does anyone know if there’s anything I can do to remove them? Given that there is almost a 2x difference between the slow and fast cases, it seems like something is a bit off.
Some more details about the problem:
- I’m running a large number of similar experiments, and this behavior only shows up for a few of them, so I don’t think this comes from the hardware.
- I was suspecting that it’s related to garbage collection, because that’s something that may run periodically, but even temporarily disabling garbage collection and calling
GC.gc()
in between doesn’t remove the pattern. I also used@timev
and the garbage collection times didn’t explain the fluctuations. - I see similar fluctuations when I run this code on my laptop, but that’s obviously in general a much more noisy system.
- I don’t want to use something like BenchmarkTools because I’m running the same experiments in other languages (for example Matlab); for the sake of consistency, I need to be able to do the exact same thing across all languages.
Some more details about the setup:
- I’m running the code on a cluster machine with CentOS 7.6 and Turbo Boost disabled.
- The Julia version is 1.1.0-DEV.468 (For historic reason. I don’t mind changing that if it helps.)
JULIA_NUM_THREADS
is set to 1.