title: Python multiprocessing same function with different arguments
body: <p>I have a program that is designed to calculate order parameter from coarse-grained molecular system. In the system the I have different beads, which represents different parts of molecule. Each of these beads have a xyz-coordinates that represent their place in the system. The program works, but it is very slow since I have to calculate the number of beads type i around beads type j within a certain cutoff distance.</p>
  <p><strong>Function to calculate Euclidean distance between bead a and b:</strong></p>
  <pre><code>def distance_ab(a, b):
  n_beads = 0
  for i in range(len(a)):
      for j in range(len(b)):
          # Euclidean distance
          dist = np.sqrt(np.sum((a[i] - b[j])** 2, axis=0))
          if dist &lt;= 1.0 and dist &gt; 0.0: # cut-off distance
              n_beads += 1
  
  return n_beads
  </code></pre>
  <p>So I decided to fasten the process of calculating the distance between different beads by using python multiprocessing library. But for some reason I can not get the multiprocessing to work for repeating the same distance calculation function with different parameters (xyz-data of beads). Multiprocessing returns a list of some numbers, when the idea is to return only one number (the number of beads in certain cut-off distance). What I do wrong and could someone help me to understand where the problem is?</p>
  <p><strong>The part where I am trying to use multiprocessing:</strong></p>
  <pre><code>with multiprocessing.Pool(os.cpu_count()) as pool:
  
      # go through certain number of molecular simulation frames (e.g. 100 frames)
      for i in range(frames)):  
          
          # Calculating euclidean distances between different types of beads 
          # for each frame 
          a_b = pool.starmap(calculate_distances, zip(bead_a_array, bead_b_array))
          a_c = pool.starmap(calculate_distances, zip(bead_a_array, bead_c_array))
              
  </code></pre>