May-10-2017, 07:03 PM
(This post was last modified: May-10-2017, 10:09 PM by Felipe. Edited 1 time in total.)

Hi guys,

I need to parallelize my code to improve it's velocity. I tried to understand how to do it reading some internet tutorials, but without success. In order to learn how it works, I wrote some basic code with my necessities, as you can see below:

I need to parallelize my code to improve it's velocity. I tried to understand how to do it reading some internet tutorials, but without success. In order to learn how it works, I wrote some basic code with my necessities, as you can see below:

#!/usr/bin/env python3 import numpy as np from concurrent.futures import ProcessPoolExecutor def vet(n): p = np.array([0.]*n) for i in range(n): p[i] = i return p def subprocess(q,func_enter): pool = ProcessPoolExecutor(max_workers=2) results = pool.map(func_enter,q) return results def sum_elements(p): out1 = np.array([0.]) A = p[0] B = p[1] C = p[2] D = p[3] out1 = A + B + C + D return out1 P = vet(8) # creation of 1D array to simulate my real input Q = P.reshape(2,4) # 2D array like a matrix, every line has the information about one model U = subprocess(Q,sum_elements) # Parallel call print(U)My desired output is an array with sum of the elements of every line of the 2D array Q. In other words, its the output of the function sum_elements like this example:

[5 22]The sum of the results of one "line" of the array Q with another one, can be a good result too. Example:

[27]Here's my output at this moment:

itertools.chain object at 0x7fc104ab4d30Thanks for all the help !!