title: Multiprocessing simple code for numerical calculations
body: <p>I need to implement multiprocessing on this code. Basically it makes a grid of nxn data in the using numpy linspace, and enters on a while loop checking a condition on the t parameter. On each run inside the while loop it calculates z for each point in the grid and refreshes the value of t. It runs until a certain condition for t is met. Then it just plots the data.</p>
  
  <p>I've read about the multiprocessing package but really have no idea how to implement it. I've found the sources a bit obscure for newbies and couldn't find any example to base on.</p>
  
  <p>Any comment is welcome, thanks in advance!</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import time 
  
  ##################
  
  def function(x,y,z):
  
      t=1
  
      while t&lt;20:
  
          for i in range(n):
              for j in range(n):
  
                  z[i,j]=z[i,j]+(i+j)/n**2
  
          t=t+1                                   ### this is just a dummy operation used to
          time.sleep(1.0)                         #### simulate the actual computations
  
      return z
  
  def plot(x,y,z):
  
      plt.contourf(x,y,z,20,cmap="viridis")
      plt.colorbar()
      plt.show()
  
  #################
  
  start_time = time.time()
  
  n=30
  t=1
  
  x=np.linspace(0,10,n)
  y=np.linspace(0,10,n)
  z=np.zeros((n,n))
  
  function(x,y,z)
  plot(x,y,z)
  
  print("--- %s seconds ---" % (time.time() - start_time))
  </code></pre>