Description
Contrary to v3p's README, some VNL netlib optimizers still have static variables declared in functions. The differences are especially easy to spot when comparing the ITK repository with the VXL repository.
https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/ThirdParty/VNL/src/vxl/v3p/netlib/README.md
The v3p_netlib library contains updated netlib code converted with f2c in a thread-safe manner. Sources have been modified to use the v3p_*.h headers in this directory. Types and function names have been mangled to start with a v3p_netlib_ prefix. This distinguishes them from other netlib libraries and keeps the code grouped and isolated.
Example non-thread-safe netlib code in ITK:
https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/ThirdParty/VNL/src/vxl/v3p/netlib/opt/lbfgsb.c
Example thread-safe netlib code in VXL
https://sourceforge.net/p/vxl/svn/HEAD/tree/trunk/v3p/netlib/opt/lbfgsb.c
Here's a thread-safe VNL netlib library fix announcement on the VXL mailing list:
https://sourceforge.net/p/vxl/mailman/vxl-maintainers/thread/44CF9607.6090804%40kitware.com/
Maybe someone re-ran f2c and clobbered those changes in ITK?
Steps to Reproduce
- In several threads, instantiate one thread-local vnl_lbfgsb solver (vnl_lbfgs is actually thread-safe!).
- Run the solver in each thread and hope it crashes by chance.
- Or... check that deterministic code is not giving the same output for the same inputs when running multiple threads (example attached).
See attached.
LetsCrashVNL.zip
Try the following:
vnl_lfbgs and observe that it works (line 39)
vnl_lfbgsb and observe that it's not working (lots of different answers).
uncomment num_threads(1) (line 32) directive and observe vnl_lfbgsb works now.
When it works, there should be no "Different answer" messages as this is deterministic code being fed the same input over and over again.
Expected behavior
When presenting the user with a class as the interface to a solver, I would expect isolation between multiple instantiations of the solver.
Actual behavior
Using one instantiation of a solver may have side effects on a different instantiation of the solver.
Reproducibility
Random. May even appear to work!
Versions
ITK 4.13, but I've seen mysterious crashes when using OpenMP with VNL solvers (one per thread) as far back as ITK 4.7.
Environment
Windows 7, 10, Ubuntu 14.04, FreeBSD 11.2
Additional Information
https://sourceforge.net/p/vxl/mailman/vxl-maintainers/thread/44CF9607.6090804%40kitware.com/
https://sourceforge.net/p/vxl/svn/HEAD/tree/trunk/v3p/netlib/opt/lbfgsb.c
This problem may not be unique to vnl_lbfgsb. This problem will obviously affect users of std::thread, pthreads, etc... L-BFGS-B is especially nice as it performs constrained optimization while L-BFGS does not.
Description
Contrary to v3p's README, some VNL netlib optimizers still have static variables declared in functions. The differences are especially easy to spot when comparing the ITK repository with the VXL repository.
https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/ThirdParty/VNL/src/vxl/v3p/netlib/README.md
Example non-thread-safe netlib code in ITK:
https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/ThirdParty/VNL/src/vxl/v3p/netlib/opt/lbfgsb.c
Example thread-safe netlib code in VXL
https://sourceforge.net/p/vxl/svn/HEAD/tree/trunk/v3p/netlib/opt/lbfgsb.c
Here's a thread-safe VNL netlib library fix announcement on the VXL mailing list:
https://sourceforge.net/p/vxl/mailman/vxl-maintainers/thread/44CF9607.6090804%40kitware.com/
Maybe someone re-ran f2c and clobbered those changes in ITK?
Steps to Reproduce
See attached.
LetsCrashVNL.zip
Try the following:
vnl_lfbgs and observe that it works (line 39)
vnl_lfbgsb and observe that it's not working (lots of different answers).
uncomment num_threads(1) (line 32) directive and observe vnl_lfbgsb works now.
When it works, there should be no "Different answer" messages as this is deterministic code being fed the same input over and over again.
Expected behavior
When presenting the user with a class as the interface to a solver, I would expect isolation between multiple instantiations of the solver.
Actual behavior
Using one instantiation of a solver may have side effects on a different instantiation of the solver.
Reproducibility
Random. May even appear to work!
Versions
ITK 4.13, but I've seen mysterious crashes when using OpenMP with VNL solvers (one per thread) as far back as ITK 4.7.
Environment
Windows 7, 10, Ubuntu 14.04, FreeBSD 11.2
Additional Information
https://sourceforge.net/p/vxl/mailman/vxl-maintainers/thread/44CF9607.6090804%40kitware.com/
https://sourceforge.net/p/vxl/svn/HEAD/tree/trunk/v3p/netlib/opt/lbfgsb.c
This problem may not be unique to vnl_lbfgsb. This problem will obviously affect users of std::thread, pthreads, etc... L-BFGS-B is especially nice as it performs constrained optimization while L-BFGS does not.