title: Python multithreading and multiprocessing to speed up loops
body: <p>I implemented function with 4 for loops and it take a long time to compute, so i'm trying to speed this up by using multithreading. </p>
  
  <p>My function looks like this:</p>
  
  <pre><code>def loops(start, end):  
      for h in range(start, end):
          for w in range(0, width):
              for h2 in range(h-radius, h+radius):
                  for w2 in range(w-radius, w+radius):
                      compute_something()
  </code></pre>
  
  <p>with multithreading i tried this:</p>
  
  <pre><code>t1 = threading.Thread(target=loops, args=(0, 150))
  t2 = threading.Thread(target=loops, args=(150, 300))
  t1.start()
  t2.start()
  t1.join()
  t2.join()
  </code></pre>
  
  <p>there is no change in computation time if i just used main thread with 0-300  </p>
  
  <p>i also used joblib multiprocessing like this:</p>
  
  <pre><code>inputs = range(300)
  Parallel(n_jobs=core_num)(delayed(loops)(i) for i in inputs)
  </code></pre>
  
  <p>in this case computation time was even higher  </p>
  
  <p>am i doing something wrong or is there different way to spped up for loops by multithreading?<br>
  range here is just an example, size of loops is usually 2000*1800*6*6 a it takes +5mins to finish what i'm doing </p>