haskell-numerics / hmatrix

Linear algebra and numerical computation
379 stars 105 forks source link

is hmatrix-glpk thread-safe? #32

Open jwaldmann opened 11 years ago

jwaldmann commented 11 years ago

I have an application where I forkIO some threads, each calling Numeric.LinearProgramming.simplex.

Using +RTS -N I get segfaults, e.g.,

glp_free: memory allocation error
Error detected in file glpenv05.c at line 145

When I do this with the non-threaded RTS, it works fine.

hmatrix-glpk-0.3.1 , ghc-7.6.2 , linux-amd64 , kernel 3.5.0 , libglpk0 4.45

albertoruiz commented 11 years ago

I am afraid GLPK is not thread-safe. In the Reference Manual it says "Currently GLPK API routines are non-reentrant and therefore cannot be used in multi-threaded programs". Which is too bad for a functional interface. I didn't notice it.

jwaldmann commented 11 years ago

Ouch. Short of rewriting glpk, perhaps we can do the following:

for my present application, IO would be acceptable.

albertoruiz commented 11 years ago

Yes, we can do something like this, otherwise the library is very unsafe. No parallelism but at least we avoid the segfault. If I had time I would be tempted to write a reference simplex implementation using hmatrix...