The Python programming language has gained huge popularity over the last decade and is widely used by the research community. Python is comparatively easy to learn and quickly produces prototype code, thanks to a collection of third-party packages such as NumPy that support wide range of research problem domains.
Despite these advantages, Python is not generally considered to be a good choice for computationally intensive research because it is an interpreted language and slow. It is common to speed up Python code by tens or hundreds times by rewriting the code in C.
However, there are alternatives to rewriting Python code, and we have found that the combination of Cython and mpi4py is a cost-effective solution for Python-based research project codes that need computational speed and scalability.
This tutorial intends to provide a hands-on introduction to Cython and mpi4py, and to demonstrate how to optimize a Python program to match the speed of a native C program and how to parallelize a Python code for a multi-core HPC environment.