Note that there are some explanatory texts on larger screens.

plurals
  1. POParallelism with SciPy.optimize
    primarykey
    data
    text
    <p>I'm working on some research code which uses <code>scipy.optimize.leastsq</code> to optimize a function. It does this about 18 times per iteration, so I would like call leastsq in parallel to reduce running time. This shouldn't be a problem because the optimizations are almost completely separate so very little synchronization is required. I recently found out about <code>multiprocessing.pool.ThreadPool</code> which would allow me to do this without having to explicitly set up shared memory (a pain since most of my data are in NumPy arrays). So I made a slight rewrite of my code, hoping it would work, but it throws a strange error: <code>SystemError: null argument to internal routine</code>.</p> <p>The following is a simplification of my code:</p> <pre><code>def optfunc(id): def errfunc(x): return somedata[id] - somefunc(x) lock.acquire() x0 = numpy.copy(currentx[id]) lock.release() result = scipy.optimize.leastsq(errfunc, x0) lock.acquire() currentx[id] = result lock.release() ThreadPool(processes=8).map(optfunc, range(idcount)) </code></pre> <p>This should work fine, unless <code>scipy.optimize.leastsq</code> isn't threadsafe. So I tried putting a lock around <code>scipy.optimize.leastsq</code>; lo and behold it works. However, processor utilization is stuck at 100%, so this is useless to me.</p> <p>My question is then what can I do about this? I think my options are:</p> <ol> <li>Find a thread-safe implementation of LM (levmar, maybe?)</li> <li>Try using processes rather than threads (I don't think this would make a difference)</li> </ol> <p>Any help or suggestions would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload