On May 3, 2010, at 11:21 AM, Dmitri Tchikine wrote:
When using the library in any non-trivial system, it would be great if its entry points were re-enterable, and thread-safe. They are now - unless you want to use the features which are currently supported via static variables:
- initialisation of random-number generator,
- setting the size of stochastic population, and
- changing local search algorithm options.
It would be nice if they could be supported via a call parameter, like stop conditions are.


Hi Dmitri,

As it turns out, I'm getting ready to release a new version of NLopt that has a new object-style C API, which is more re-entrant and extensible than the old one (which will continue to be supported but will be deprecated). The new API will work something like:

nlopt_opt opt = nlopt_create(algorithm, ndim);
nlopt_set_min_objective(opt, f, f_data);
nlopt_set_lower_bounds(opt, lb);
nlopt_set_ftol_rel(opt, tol);
nlopt_optimize(opt, x, &minf);
nlopt_destroy(opt);

Most of the things that are currently global variables, like the stochastic population and the local search options, are converted into parameters that you can set re-entrantly for a specific nlopt_opt object.

In my current snapshot, the random seed is still a global parameter; my thinking is that this wouldn't have a practical impact on re- entrancy since random numbers are supposed to be random/uncorrelated anyway. Is there a use case where this matters?

A more serious obstacle to complete re-entrancy is that I'm not sure all of the pre-existing programs that NLopt wraps are re-entrant, especially the Fortran-derived ones. One would have to review the source code of each to look for global/static variables.

Steven

_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss

Reply via email to