So, i have this code below that have a function calculate
that will take 2 numpy arrays as an input and then do some calculation using those 2 array. Now i want to execute that calculate
function multiple times but with multiprocessing and still use the same array as an input, but only part of it. So here's my code below without any multiprocessing:
import numpy as np
def calculate(arr1, arr2):
print(np.dot(arr1,arr2))
def main():
A = np.random.rand(1000,5000)
B = np.random.rand(5000)
calculate(A[:int(len(A)*3/4)],B)
calculate(A[int(len(A)*1/4):],B)
if __name__ == "__main__":
main()
Currently i don't use any multiprocessing stuff , because i don't know how to implement that in the code above. But the important thing is that, i want to execute those calculate
functions simutaniously using multiprocessing and use the part existing array as an input without copying the array and use them in each process.
By the way, please don't mind about the actual calculate
function, it's actually different from my actual code right now, i wrote that just to make it simple.
Ok, so how can i make the code above utilize multiprocessing with the condition i mentioned above?
question from:
https://stackoverflow.com/questions/65936118/python-multiprocessing-with-parts-of-same-input-array-without-copying-the-input 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…