I'm trying to use Python multiprocessing library with multiple arguments on a void function that does not return anything. Here is my minimal working example.
import numpy as np
from multiprocessing import Pool
dim1 = 2
dim2 = 2
test1 = np.zeros((dim1,dim2))
test2 = np.zeros((dim1,dim2))
iteration = []
for i in range(0,dim1):
for j in range(0,dim2):
iteration.append((i,j))
def testing(num1,num2):
test1[num1,num2] = 1
test2[num1,num2] = 2
if __name__ == '__main__':
pool = Pool(processes=4)
pool.starmap(testing, iteration)
print(test1)
print(test2)
The problem here is that variable test1 and test2 prints zero array as first initialized. Instead, what I what for test1 is an array of 1s and an array of 2s for test2. What I would like the code
if __name__ == '__main__':
pool = Pool(processes=4)
pool.starmap(testing, iteration)
to do is this:
testing(0,0)
testing(1,0)
testing(0,1)
testing(1,1)
I've seen some related posts like this. The difference between this post and mine is that my function is a void function, and rather than returning the variables, I'd like the function to just change the values of the variables.