Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiprocessing with numpy makes Python quit unexpectedly on OSX

I've run into a problem, where Python quits unexpectedly, when running multiprocessing with numpy. I've isolated the problem, so that I can now confirm that the multiprocessing works perfect when running the code stated below:

import numpy as np
from multiprocessing import Pool, Process
import time
import cPickle as p

def test(args):
    x,i = args
    if i == 2:
        time.sleep(4)
    arr = np.dot(x.T,x)
    print i

if __name__ == '__main__':
    x = np.random.random(size=((2000,500)))
    evaluations = [(x,i) for i in range(5)]
    p = Pool()
    p.map_async(test,evaluations)
    p.close()
    p.join()

The problem occurs when I try to evaluate the code below. This makes Python quit unexpectedly:

import numpy as np
from multiprocessing import Pool, Process
import time
import cPickle as p

def test(args):
    x,i = args
    if i == 2:
        time.sleep(4)
    arr = np.dot(x.T,x)
    print i

if __name__ == '__main__':
    x = np.random.random(size=((2000,500)))
    test((x,4)) # Added code
    evaluations = [(x,i) for i in range(5)]
    p = Pool()
    p.map_async(test,evaluations)
    p.close()
    p.join()

Please help someone. I'm open to all suggestions. Thanks. Note: I have tried two different machines and the same problem occurs.

like image 661
Maal Avatar asked Oct 31 '13 11:10

Maal


1 Answers

This is a known issue with multiprocessing and numpy on MacOS X, and a bit of a duplicate of:

segfault using numpy's lapack_lite with multiprocessing on osx, not linux

http://mail.scipy.org/pipermail/numpy-discussion/2012-August/063589.html

The answer seems to be to use a different BLAS other than the Apple accelerate framework when linking Numpy... unfortunate :(

like image 86
Joe Avatar answered Oct 22 '22 14:10

Joe