I am trying to understand what factors impact the performance of Julia code on different hardware. I have two workstations: WS1 is a three old old compute server and WS2 is a two year old desktop, both of which have comparable configuration but the performance of pisum()
and pisumvec()
microbenchmarks from Julia Microbenchmarks suite on the two workstations is very different.
Workstation 1
Basic information:
julia> versioninfo()
Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, sandybridge)
shell> lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 45
Model name: Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz
Stepping: 7
CPU MHz: 3160.205
CPU max MHz: 3300.0000
CPU min MHz: 1200.0000
BogoMIPS: 5199.93
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 20480K
NUMA node0 CPU(s): 0-15
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm ida arat pln pts flush_l1d
shell> uname -vrm
4.15.0-47-generic #50-Ubuntu SMP Wed Mar 13 10:44:52 UTC 2019 x86_64
Microbenchmarks:
julia> function pisum()
sum = 0.0
for j = 1:500
sum = 0.0
for k = 1:10000
sum += 1.0/(k*k)
end
end
sum
end
julia> function pisumvec()
s = 0.0
a = 1:10000
for j = 1:500
s = sum(1 ./ (a .^2))
end
s
end
julia> using BenchmarkTools
julia> @benchmark pisum()
@benchmark pisumvec()
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 33.724 ms (0.00% GC)
median time: 33.788 ms (0.00% GC)
mean time: 34.040 ms (0.00% GC)
maximum time: 36.056 ms (0.00% GC)
--------------
samples: 147
evals/sample: 1
julia> @benchmark pisumvec()
BenchmarkTools.Trial:
memory estimate: 38.20 MiB
allocs estimate: 1500
--------------
minimum time: 18.673 ms (1.68% GC)
median time: 19.625 ms (3.27% GC)
mean time: 19.881 ms (4.00% GC)
maximum time: 62.710 ms (69.23% GC)
--------------
samples: 252
evals/sample: 1
So, pisum()
runs in 33ms and switching to vectorized version runs faster by almost a factor of 2.
Workstation 2
Basic information:
julia> versioninfo()
Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Xeon(R) CPU E5-1603 v4 @ 2.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, broadwell)
shell> lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 46 bits physical, 48 bits virtual
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 1
Core(s) per socket: 4
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 79
Model name: Intel(R) Xeon(R) CPU E5-1603 v4 @ 2.80GHz
Stepping: 1
CPU MHz: 1197.235
CPU max MHz: 2800.0000
CPU min MHz: 1200.0000
BogoMIPS: 5589.81
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 10240K
NUMA node0 CPU(s): 0-3
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap intel_pt xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm arat pln pts
shell> uname -vrm
5.0.7-arch1-1-ARCH #1 SMP PREEMPT Mon Apr 8 10:37:08 UTC 2019 x86_64
Microbenchmark:
julia> function pisum()
sum = 0.0
for j = 1:500
sum = 0.0
for k = 1:10000
sum += 1.0/(k*k)
end
end
sum
end
pisum (generic function with 1 method)
julia> function pisumvec()
s = 0.0
a = 1:10000
for j = 1:500
s = sum(1 ./ (a .^2))
end
s
end
pisumvec (generic function with 1 method)
julia> using BenchmarkTools
julia> @benchmark pisum()
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 8.222 ms (0.00% GC)
median time: 8.226 ms (0.00% GC)
mean time: 8.243 ms (0.00% GC)
maximum time: 11.918 ms (0.00% GC)
--------------
samples: 607
evals/sample: 1
julia> @benchmark pisumvec()
BenchmarkTools.Trial:
memory estimate: 38.20 MiB
allocs estimate: 1500
--------------
minimum time: 9.080 ms (3.22% GC)
median time: 9.398 ms (6.13% GC)
mean time: 9.440 ms (6.40% GC)
maximum time: 51.545 ms (82.85% GC)
--------------
samples: 530
evals/sample: 1
Here pisum()
runs in 8.2ms and vectorizing actually makes it slightly slower.
For other microbenchmarks with for loops (numeric vector sort and mandelbrot set), the performance on the two workstations is almost the same (5-10% difference). I donβt understand why pisum()
performs so poorly (a factor of 4 difference) and why vectorization is qualitatively so different (on workstation 1 it improves performance by a factor of 2; on workstation 2 it slightly deteriorates performance). The two workstations use different linux installations (Ubuntu vs Arch)
Any hints on what might be going on here?