I was following this to get my numpy array shared between multiprocessing threads. My code looks something like this:
param = 'something'
A = 1331
B = 500
iter = [list of things]
shared_arr = mp.Array(ctypes.c_int, A*B)
pool = mp.Pool(initializer=init, initargs=(shared_arr,))
func = partial(foo, param, A, B)
pool.map(func, iter)
pool.close()
pool.join()
def foo(param, A, B, iter):
arr = np.frombuffer(shared_arr.get_obj())
print(arr.shape, len(shared_arr))
def init(shared_arr_):
global shared_arr
shared_arr = shared_arr_
This code prints (332750,) 665500
why is it that np.frombuffer()
returns a value which is not the same size as the original array. Why is this happening?