1 | initial version |
First of all you cheat a bit since you create a list and sort it in the first case which costs some time
sage: %timeit l = range(1000000)
100 loops, best of 3: 14 ms per loop
If the time to execute once the function f is very small then it seems that you do not have any gain in using parallelization! Strange... If instead you factor in a much higher range (like numbers between $2^{128}$ and $2^{128} + 1000$) then you will see a gain.
To have a look at the source code you can do
sage: parallel??
You will see that it uses the class Parallel. I did not know where this class belongs. One way to obtain that is
sage: import_statements('Parallel')
from sage.parallel.decorate import Parallel
Then you can have a look at the code again
sage: from sage.parallel.decorate import Parallel
sage: Parallel??
and then continue the introspection this way. You can also have a look directly in the source code which in that case belongs to $SAGE_ROOT/src/sage/parallel/*
Vincent