New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The 'optim' function with 'L-BFGS' method fails in multithreading #448
Comments
it is most likely due to the use of global variables in the C code we have imported from GNU R. I thought we had rewritten offending code, but will need to check on this. |
Indeed, one of the support routines declares a large number of static local variables that we missed: renjin/packages/stats/src/main/c/lbfgsb.c Line 320 in fadaedd
I will see if it's easier to refactor the many many global variables into a working data structure, or if we can use the global variable transformer that has worked so well with the graphics package. |
This extends the GlobalVarRewriter to automatically transform the remaining global variables in C and Fortran code in the stats package to use Session-scoped values so that it can be safely called from multiple threads. The performance impact needs to be evaluated before merging.
Hi, |
Hello, Is there a plan to merge the fix? |
Hello,
We faced a problem with multithreading in Renjin. The 'optim' function with 'L-BFGS' method calculates different results when is invoked from many threads.
A simple Java project was prepared to reproduce the problem. Also the code is attached at the bottom of this mail.
https://github.com/tlucz/parallel-optim
When we run the code with THREADS_NUMBER=1 we get following correct results (every time the same):
But when we run it with more threads e.g. THREADS_NUMBER = 2 we get different results for the calls and sometimes even an errors:
Separate ScriptEngine is created for each thread as it is described in Renjin documentation.
code:
The text was updated successfully, but these errors were encountered: