libprima / prima

PRIMA is a package for solving general nonlinear optimization problems without using derivatives. It provides the reference implementation for Powell's derivative-free optimization methods, i.e., COBYLA, UOBYQA, NEWUOA, BOBYQA, and LINCOA. PRIMA means Reference Implementation for Powell's methods with Modernization and Amelioration, P for Powell.
http://libprima.net
BSD 3-Clause "New" or "Revised" License
307 stars 42 forks source link

BOBYQA recursion problem #179

Open asenzz opened 7 months ago

asenzz commented 7 months ago

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

zaikunzhang commented 7 months ago

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.

asenzz commented 6 months ago

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.

zaikunzhang commented 6 months ago

Could you provide a minimal example? Thank you.