I have a specific function that displays an array of MxN. The array is very large, so I want to use this function to create small arrays (M1xN, M2xN, M3xN --- MixN. M1 + M2 + M3 + --- + Mi = M) simultaneously using multiprocessing / these arrays form an mxn array . Since Mr. Boardrider rightfully proposed a viable example, what I intend to do will be widely conveyed in the following example.
import numpy as n def mult(y,x): r = n.empty([len(y),len(x)]) for i in range(len(r)): r[i] = y[i]*x return r x = n.random.rand(10000) y = n.arange(0,100000,1) test = mult(y=y,x=x)
As the lengths of x and y increase, the system will take longer. Regarding this example, I want to run this code in such a way that if I have 4 cores, I can give a quarter of the task to everyone, i.e. Give a task to calculate the elements r[0] to r[24999] to the 1st core, r[25000] to r[49999] to the second core, from r[50000] to r[74999] to the third core and from r[75000] to r[99999] to the 4th core. As a result, combine the results, add them to get one array r[0] to r[99999] .
I hope this example clarifies the situation. If my problem is still not clear, let me know.
python arrays multithreading multiprocessing
Ishan tomar
source share