giordano / Cuba.jl

Library for multidimensional numerical integration with four independent algorithms: Vegas, Suave, Divonne, and Cuhre.
https://giordano.github.io/Cuba.jl/stable
MIT License
77 stars 9 forks source link

Segmentation fault in `vegas` and `suave` with `maxevals` smaller than 256 #49

Closed Hao-Phys closed 7 months ago

Hao-Phys commented 7 months ago

I got segmentation error when trying to pass maxevals to vegas.
Minimal example: vegas((x, f) -> f[1] = cos(x[1]); atol=1e-4, maxevals=20)

All other kwargs seem to work fine. Machine info: Pop!_OS 22.04 LTS and Apple M2 (Sonoma). Cuba version: v2.3.0

giordano commented 7 months ago

I can reproduce the segmentation fault with

vegas((x, f) -> f[1] = cos(x[1]); atol=1e-4, maxevals=255)

but not

vegas((x, f) -> f[1] = cos(x[1]); atol=1e-4, maxevals=256)

So the problem isn't that you can't use maxevals at all, which is completely false (as demonstrated also by the maxevals=256 case), since there's a default value of

julia> Cuba.MAXEVALS
1000000

but that the Cuba C library crashes when you use a too small value for the number of maximum evaluations, the threshold being 256. Also, this is specific to vegas and suave, instead cuhre and divonne work fine. I have changed the title to more accurately describe the issue.

You will have to report the bug to the Cuba library author Thomas Hahn, I can't do anything about it.

giordano commented 7 months ago

Also, this is a duplicate of #12