title: Python multiprocessing: no performance gain with multiple processes
body: <p>Using multiprocessing, I tried to parallelize a function but I have no performance improvement:</p>
  
  <pre><code>from MMTK import *
  from MMTK.Trajectory import Trajectory, TrajectoryOutput, SnapshotGenerator
  from MMTK.Proteins import Protein, PeptideChain
  import numpy as np
  
  filename = 'traj_prot_nojump.nc'
  
  trajectory = Trajectory(None, filename)
  
  def calpha_2dmap_mult(trajectory = trajectory, t = range(0,len(trajectory))):
      dist = []
      universe = trajectory.universe
      proteins = universe.objectList(Protein)
      chain = proteins[0][0]
      traj = trajectory[t]
      dt = 1000 # calculate distance every 1000 steps
      for n, step in enumerate(traj):
          if n % dt == 0:
              universe.setConfiguration(step['configuration'])
              for i in np.arange(len(chain)-1):
                  for j in np.arange(len(chain)-1):
                      dist.append(universe.distance(chain[i].peptide.C_alpha,
                                                    chain[j].peptide.C_alpha))
      return(dist)
  
  c0 = time.time()
  dist1 = calpha_2dmap_mult(trajectory, range(0,11001))
  c1 = time.time() - c0
  print(c1)
  
  
  # Multiprocessing
  from multiprocessing import Pool, cpu_count
  
  pool = Pool(processes=4)
  c0 = time.time()
  dist_pool = [pool.apply(calpha_2dmap_mult, args=(trajectory, t,)) for t in
               [range(0,2001), range(3000,5001), range(6000,8001),
                range(9000,11001)]]
  c1 = time.time() - c0
  print(c1)
  </code></pre>
  
  <p>The time spent to calculate the distances is the 'same' without (70.1s) or with multiprocessing (70.2s)! I was maybe not expecting an improvement of a factor 4 but I was at least expecting some improvements!
  Is someone knows what I did wrong?</p>