Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
150 views
in Technique[技术] by (71.8m points)

Python multiprocessing with parts of same input array without copying the input array?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...