Cuba.jl icon indicating copy to clipboard operation
Cuba.jl copied to clipboard

Lots of allocations

Open jw3126 opened this issue 5 years ago • 1 comments

Cuba produces a lot of allocations, 4 per iteration in the example below. Is there a way to avoid this?

julia> using Cuba

julia> f!(x,ret ) = ret
f! (generic function with 1 method)

julia> vegas(f!); # warmup

julia> @time vegas(f!)
  0.001090 seconds (4.01 k allocations: 187.984 KiB)
Component:
 1: 0.0 ± 7.025180405943273e-18 (prob.: -999.0)
Integrand evaluations: 1000

jw3126 avatar Nov 09 '18 16:11 jw3126

I'll have a look but I'm not sure there is anything I can do about this. The only suggestion I can give you is to use cuhre instead of vegas as the former is more accurate and requires fewer evaluations (thus fewer allocations):

julia> using Cuba, BenchmarkTools

julia> @btime cuhre((x, f) -> f[1] = x[1])
  25.231 μs (784 allocations: 36.89 KiB)
Component:
 1: 0.5 ± 4.291960664289122e-15 (prob.: 0.0)
Integrand evaluations: 195
Fail:                  0
Number of subregions:  2

julia> @btime vegas((x, f) -> f[1] = x[1])
  21.588 ms (928004 allocations: 42.48 MiB)
Component:
 1: 0.4999999506146127 ± 4.969630652405548e-5 (prob.: 2.559630372933608e-5)
Integrand evaluations: 232000
Fail:                  0
Number of subregions:  0

giordano avatar Nov 09 '18 21:11 giordano