python, how parallelize several calls to the same function without lose execution time
Question: I have some trouble to parallelize a function. I would like use a function
several time in parallel way:

    
    
    def f_diff_coord(vect1,vect2):
        return vect1-vect2
    

This function need to be computed several time with different vectors in a
general for loop. So my code is writing in that way:

    
    
    from multiprocessing import Pool
    
    
    def f_diff_coord(vect1,vect2):
        return vect1-vect2,vect1+vect2
    
    
    if __name__ == '__main__':
        p = Pool(3)
        for _ in manytime
            vect_a = np.arange(10)+2
            vect_b = np.arange(10)
            vect_c = np.arange(10)
            vect_d = np.arange(10)+3
            #vect_ are juste for example
            r1=p.apply_async(f_diff_coord, (vect_a,vect_b,) )
            r2=p.apply_async(f_diff_coord, (vect_c,vect_d,) )
            data_a = r1.get()
            data_b = r2.get()
            #do somthing with data_
    

I run this kind of code with 3 pools and it seems being paralelized (in my
Task Manager on windows). However, the computation time is quite longer than
in the serialized code. Am I missing something or is it the fact that the call
to several processes takes alot of time to be initiated?


Answer: use the [multiprocessing](https://pymotw.com/2/multiprocessing/basics.html)
module to parallelise your calls

