[Tutor] OpenMP

Alan Gauld alan.gauld at btinternet.com
Sat Oct 9 19:50:40 CEST 2010

"Ahmed AL-Masri" <ahmedn82 at hotmail.com> wrote
> say I have two loops and I want to test in which processer go 
> through...
> my question is how to do that and is it possible in python

No, its not possible to do that explicitly and it shouldn't be. The OS
(and interpreter if applicable) is best placed to decide how the CPUs
should spend their time. An application directly controlling the
CPUs is only sane if its an embedded type application in sole
control of the box.

As a python programmer the best you can do is give the OS
some helpful hints like using threads. So in your case you could
put the two loops in separate threads and hope the OS decides
to run those threads on separate cores.

Now, the bad news is that so far as I know the python interpreter
does not expose its threading model to the OS to even if you use
threads the interpreter itself will still be running on a single CPU
core. :-(

Or is that one of the deeper fixes in Python v3? Does anyone know?

> Really interesting to speed up the process based on no
> of CPUs that we have using python.

Its extremely unlikely you would succeed using that approach, you
are much better off focussing on the higher level optimisation of
your algorithms and logical partitioning along with minmising disk
and network access. These are the real performamce issues
not CPU core usage.


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list