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
289 stars 35 forks source link

LINCOA in multiple threads odd results #206

Open asenzz opened 1 month ago

asenzz commented 1 month ago

Hi Zhang, first thank you for the great library. I'm using LINCOA as it's giving me good results compared to other optimization algorithms, but when I start Prima with LINCOA in several different threads (C++ Intel compiler) I notice memory corruption issues. I'm investigating now what exactly is the cause but not proficient with Fortran.

zaikunzhang commented 1 month ago

Hi,

Which interface are you using? Could you provide a minimal example?

PRIMA is designed to be 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/parallel.m

Of course, bugs may exist.

One thing to check: did you use proper compiler options to enforce thread-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 2 weeks ago

Hi, Zaikun I found the bug yesterday, sorry for the delayed response and it was in my code, not in yours. I apologize for alarming you for no reason. I create a macro algorithm using your library that starts several optimizers in parallel at even parameter distances and selects the best ones at several points in time. This way I am able to boost the precision of the result by a significant amount (sacrificing computational resources). If you are interested I can contribute the code back to you so you will integrate it in Prima. I named it PPrima, stands for Parallel Prima, and it provides a C plus plus interface to Prima-C. Thanks for understanding, Žarko