Thursday, October 18, 2007

Shed Skin and Parallel Python

Shed Skin is an experimental Python to C++ compiler. Parallel Python allows for clean and simple parallelization of Python processes over multiple cores. Wouldn't it be cool if we could combine the two? Of course I wouldn't be writing this if I hadn't tried. Here's how to do it.

Create an extension module with Shed Skin, containing function(s) you'd like to use in parallel. For example, we might use the partial sum function from the Parallel Python website:

def part_sum(start, end):..return sum

For Shed Skin's type inference to work, part_sum must be called from somewhere:

if __name__ == '__main__':part_sum(1, 1)

Creating an extension module is simple (suppose the module is named meuk.py):