if __name__ == '__main__':
    p = Pool(5)
result = np.zeros((4, 4))
im = p.imap_unordered(f, list(range(30)), chunksize=5)
for x in im:
    result += x
print(result)
Python multiprocessing for parallel processes