JuliaSmoothOptimizers / PartitionedStructures.jl

Partitioned derivatives storage and partitioned quasi-Newton updates
Other
10 stars 1 forks source link

allocation free partitioned matrix vector product #53

Closed paraynaud closed 2 years ago

paraynaud commented 2 years ago

The following script compare the partitioned matrix vector product:

#main
BenchmarkTools.Trial: 336 samples with 1 evaluation.
 Range (min … max):  11.610 ms … 22.156 ms  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     12.579 ms              ┊ GC (median):    0.00%
 Time  (mean ± σ):   14.884 ms ±  3.455 ms  ┊ GC (mean ± σ):  0.01% ± 0.18%
    █▅                
  ▆███▆█▆▃▃▃▂▂▂▃▃▃▃▃▁▂▃▂▁▂▃▃▂▂▂▁▁▃▂▁▁▃▂▁▃▃▃▃▃▃▃▃▄▆▇▅▄▄▃▃▂▂▁▂▂ ▃
  11.6 ms         Histogram: frequency by time        21.6 ms <
 Memory estimate: 148.44 KiB, allocs estimate: 500.

# pray-partitioned-prod
BenchmarkTools.Trial: 428 samples with 1 evaluation.
 Range (min … max):  10.677 ms …  18.350 ms  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     11.746 ms               ┊ GC (median):    0.00%
 Time  (mean ± σ):   11.673 ms ± 564.442 μs  ┊ GC (mean ± σ):  0.00% ± 0.00%
         ▁ ▁            ▄▁▄▅▄█▂▂▃
  ▃▄▂▄▆▄▆█▇█▇█▄▅▃▃▂▃▂▄▇███████████▇█▆▅▄▃▃▂▃▃▁▁▂▁▂▁▁▁▁▁▁▁▁▁▁▁▁▃ ▄
  10.7 ms         Histogram: frequency by time         13.2 ms <
 Memory estimate: 0 bytes, allocs estimate: 0.

The change is not significative, ut there is not allocation anymore.

from the script:

using PartitionedStructures
using BenchmarkTools
using LinearAlgebra
using StatsBase

N = 500
n = 200
ni = 30
element_variables = map(i -> sample(1:n, ni, replace = false) ,1:N)

epm = identity_epm(element_variables)
epv = epv_from_epm(epm)
epv_y = similar(epv)
epv_from_v!(epv_y, ones(n))
epv_res = similar(epv)

@benchmark PartitionedStructures.mul_epm_epv!(epv_res, epm, epv)