The Python language predates multi-core CPUs, so it isn't odd that it doesn't use them natively.
Additionally, not all programs can profit from multiple cores. A calculation done in steps, where the next step depends on the results of the previous step, will not be faster using more cores. Problems that can be vectorized (applying the same calculation to large arrays of data) can relatively easy be made to use multiple cores because the individual calculations are independent.
When you are doing a lot of calculations, I'm assuming you're using numpy? If not, check it out. It is an extension written in C that can use optimized lineair algebra libraries like ATLAS. It can speed up numerical calculations significantly compared to standard python.
Having said that, there are several ways to use multiple cores with python.
- Built-in is the
multiprocessing module. The
multiprocessing.Pool class provides vectorization across multiple CPUs with the
map() and related methods. There is a trade-off in here though. If you have to communicate large amounts of data between the processes, that overhead might negate the advantage of multiple cores.
- Use a suitable build of numpy. If numpy is built with a multithreading ATLAS library, it will be faster on large problems.
- Use extension modules like numexpr, parallel python, corepy or Copenhagen Vector Byte Code.
Note that the
threading module isn't all that useful in this regard. To keep memory management simple, the global interpreter lock ("GIL") enforces that only one thread at a time can be executing python bytecode. External modules like numpy can use multiple threads internally, though.