[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-glpk] Multi-thread questions

From: Joey Rios
Subject: Re: [Help-glpk] Multi-thread questions
Date: Fri, 11 Oct 2013 22:11:17 -0700

> Dear list,
> the Reference Manual of Version 4.38 states that GLPK routines are non-reentrant
> and so they cannot be used in multi-thread programs.
> I was wondering, it is at least possible to solve two different problems in two
> different threads?

Yes, with some modification to the source.

> In my scenario, I have many linear problems and I have to find the one with
> the maximum solution. Parallelism is easy for this scenario since there is
> nothing to share, just find the best.

If there is nothing to share between your problems, you probably should take the advice of Marc and just use scripted calls to glpsol.  Your concern of serialization and deserialization does not really explain why calling glpsol this way would be a problem.

> I read there are previous email in this list about multi-thread
> safety, but they are
> fairly old. So I prefer to send a new one. Thanks.

All of those "old" discussions are still pretty much valid and I'd suggest re-reading them.

> If change the void* tls in tls.c file to have the __thread gcc C
> extension modifier and I replace all the strtok with the posix
> strtok_r in glpsql.c I should have a library that works for my
> purposes. That is, execute different solvers in parallel on
> different problems.

The main thing you should do is replace all of the calls to glpk's custom memory allocation routines with a basic malloc call.  Likewise, replace the glpk custom free calls with regular 'free' calls.  There is one more place that you have to do something, but I forget where it is (somewhere in the TLS stuff like you mention). The code has changed since 4.44, but here is a patch that I used on that version of the code to create a threaded version of the glpk library:

Note that you can download version 4.44 and apply this patch and you should have a library you can use for threaded glpk'ing.  I say that with my fingers crossed, hoping for the best!  Or, you can use the concepts you see in the patch and apply them to the current version of the code.  I did this recently with a new version of GLPK, but it is in my office and I'm currently furloughed and barred from accessing it (hooray politics!).  Anyway, it is possible is what I am trying to say.

Good luck!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]