[SciPy-Dev] ODE solvers
Sturla Molden
sturla.molden at gmail.com
Fri Jun 12 11:16:24 EDT 2015
On 12/06/15 12:39, Benny Malengier wrote:
> Warning
> This integrator is not re-entrant. You cannot have two ode
> <http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.integrate.ode.html#scipy.integrate.ode>
> instances using the “lsoda” integrator at the same time.
By the way, no Fortran code can be assumed re-entrant because Fortran
compilers are allowed to use an implicit SAVE attribute on local
variables. One of the compilers which uses this misfeature is gfortran.
In gfortran, local variables larger than 32768 bytes have by default the
SAVE attribute in gfortran. This is from the gfortran documentation:
-fmax-stack-var-size=n
This option specifies the size in bytes of the largest array that will
be put on the stack; if the size is exceeded static memory is used
(except in procedures marked as RECURSIVE). Use the option -frecursive
to allow for recursive procedures which do not have a RECURSIVE
attribute or for parallel programs. Use -fno-automatic to never use the
stack. This option currently only affects local arrays declared with
constant bounds, and may not apply to all character variables. Future
versions of GNU Fortran may improve this behavior.
The default value for n is 32768.
And this is what happens when you try to use gfortran with pthreads and
don't know about this "feature":
http://icl.cs.utk.edu/lapack-forum/viewtopic.php?t=1930
There is also a terrible WTF in the language which mandates that all
local variables initialized within a procedure have the SAVE attribute.
So if you write something like
real :: foo(3) = [1., 2., 3.]
real :: bar = 4.
the subroutine is no longer re-entrant. OuchFortran mandates that foo
and bar are kept in static storage. Ouch!
In fact, there should be no difference between
real, save :: bar = 4.
and
real :: bar = 4.
Can you spot a bug like this in thousands of lines of Fortran code
before you declare it thread-safe?
If we are to assume a piece of Fortran code is reentrant we should check
it in the test suite. Because implicit SAVE is allowed, this is actually
compiler dependent.
Sturla
More information about the SciPy-Dev
mailing list