prima icon indicating copy to clipboard operation
prima copied to clipboard

BOBYQA recursion problem

Open asenzz opened this issue 1 year ago • 6 comments

If I run a BOBYQA instance from within a BOBYQA cost function, the call-back pointer, which in turn calls a lambda expression with captured references to variables, seems to be overwriting the memory of the lambda expression object and the captured variables are full of junk data. I can help debug this issue, but from what I gather so far, the problem is in the Fortran code. Thanks, Z

asenzz avatar Mar 23 '24 16:03 asenzz

Hi,

Which interface are you using?

PRIMA is designed to be recursion-safe and thread-safe. This is tested during CI:

https://github.com/libprima/prima/blob/main/fortran/tests/test_bobyqa.f90#L289-L303

A more extensive test (also included in the CI) is done via the MATLAB interface:

https://github.com/libprima/prima/blob/main/matlab/tests/recursive.m

Of course, bugs may exist.

I can help debug this issue, but from what I gather so far, the problem is in the Fortran code.

It would be nice if you could help debug it, or provide a minimal working example.

One thing to check: did you use proper compiler options to enforce recursion-safety when building the Fortran library? For gfortran, it is -frecursive, and for Intel oneAPI, it is -assume recursion (Unix) or /assume:recursion (Win).

Thank you.

zaikunzhang avatar Mar 23 '24 16:03 zaikunzhang

Hmm seems that the C interface does give problems when used in multiple threads at once. I'll let you know as soon as I have something. It happens with LINCOA. Haven't retested BOBYQUA.

asenzz avatar May 17 '24 18:05 asenzz

Could you provide a minimal example? Thank you.

zaikunzhang avatar May 17 '24 23:05 zaikunzhang