3

I'm working in Jupyter (Anaconda) with Python 2.7.

I'm trying to get an odeint function I wrote to run multiple times, however it takes an incredible amount of time.

While trying to figure out how to decrease the run time, I realized that when I ran it only took up about 12% of my CPU.

I operate off of an Intel Core i7-3740QM @ 2.70GHz: https://www.cpubenchmark.net/cpu.php?cpu=Intel+Core+i7-3740QM+%40+2.70GHz&id=1481

So, I'm assuming this is because of Python's GIL causing my script to only run off of one core.

After some research on parallel processing in Python, I thought I found the answer by using this code:

import sys
import multiprocessing as mp


Altitude = np.array([[550],[500],[450],[400],[350],[300]])

    if __name__ == "__main__":
    processes = 4
    p = mp.Pool(processes)
    mp_solutions = p.map(calc, Altitude)

This doesn't seem to work though. Once I run it, Jupyter just becomes constantly busy. My first thought was that it was just a high computation level so it was taking a long time, but then I looked at my CPU usage and although there were multiple instances of Python processes, none of them were using any CPU.

I can't figure out what the reasoning for this is. I found this post as well and tried using their code but it simply did the same thing:

Multiple scipy.integrate.ode instances

Any help would be much appreciated.

Thanks!

Community
  • 1
  • 1
Greg Castaldi
  • 355
  • 1
  • 4
  • 11
  • 3
    Have you tried running it from a terminal instead of from Jupyter? – Warren Weckesser Aug 14 '16 at 23:06
  • could be the shape of your array is confusing the `map`, can you refactor your code so you're just passing in a plain list like `altitude = [550,500,450,400,350,300]` – maxymoo Aug 14 '16 at 23:15
  • @Warren Weckesser Just the guy I was looking for. I would've commented on the original post but I don't have the rep. This completely worked. Thank you for the suggestion. I should've tried that in the first place. Why do you think it only works in terminal and not Jupyter? – Greg Castaldi Aug 14 '16 at 23:37
  • Greg, I don't know what the problem might be. You could try searching here and on the jupyter/ipython github pages for issues related to jupyter and multiprocessing, or ask on the ipython mailing list. – Warren Weckesser Aug 15 '16 at 01:31
  • @Warren Weckesser Okay, thank you. Would you like to write an answer to this so I can make it an answered questions? Or should I? – Greg Castaldi Aug 16 '16 at 02:53
  • 1
    My suggestion is a work-around for the problem. I think the real question is why doesn't it work in jupyter, and that doesn't have an answer. Perhaps a jupyter expert will come along and solve the problem... – Warren Weckesser Aug 16 '16 at 03:09
  • 1
    You might want to replace the "function" tag (which seems pretty pointless) with the "jupyter" tag. – Warren Weckesser Aug 16 '16 at 03:11

0 Answers0