1 | initial version |
Workaround: use sharedmemory and multiprocessing packages (sharedmemory is available via pip). I tried the following code within a separate .py file:
import sharedmem
import multiprocessing as mp
import numpy as np
N = 1024 * 2
K = 256
_lock = mp.Lock()
def f(_shared_buffer):
partial_result = np.ones((N, N), dtype=np.complex128)
_lock.acquire()
_shared_buffer += partial_result
_lock.release()
def test():
shared_buffer = sharedmem.empty((N, N), dtype=np.complex128)
pool = mp.Pool(4)
pool.map(f, [shared_buffer for _ in range(K)])
return shared_buffer
Advantages of this workaround:
Disadvantages: