Skip to 0 minutes and 11 secondsHi, we hope that you have enjoyed the course and learned a lot during these four weeks! Python is very efficient for the programmer, but the dynamic features come with a cost in performance. By restricting the flexibility of Python,
Skip to 0 minutes and 28 secondsone can get the best out of both worlds: good programmer performance as well as good computer performance.
Skip to 0 minutes and 36 secondsThe four steps for this are:
Skip to 0 minutes and 40 secondsOne: Measure before you optimize. Even though some of the performance aspects can be taken into account when designing the program, the first priority is get the proram working correctly. Premature optimization is the root of all evil! When the program is working as expected, one should use application's own timers and the cProfile tool to find out where the time is actually spent in the program. Then, one should focus optimizing only these parts.
Skip to 1 minute and 12 secondsTwo: Use NumPy arrays for numerical data. Python's built-in data structures are not optimal for number crunching. NumPy offers a static multidimensional array that is perfectly suited for numerical calculations. To get the most performance from Python use NumPy arrays whenever you can.
Skip to 1 minute and 38 secondsThree: Use Cython or external code for the most time consuming parts of the program. If all the flebility of Python is not needed, some parts of the application may be greatly speed up by introducing static type definitions and Cythonizing the code. Python provides also different ways for interfacing with code written in another, more performant languages. These languages can then be used for speeding up the most time critical parts of the Python program.
Skip to 2 minutes and 9 secondsFour: Use MPI for parallel computing. Once you have squeezed out all the performance from a single CPU, or you have run out o the memory in a single CPU, you can gain further speed ups by using multiple CPUs in parallel. The mpi4py package offers a convenient Python interface to parallel computing using the message passing interface. Thanks for attending the course! Happy hacking in Python!
Congratulations for finishing the course!
Please complete the post-course survey and see also the other courses in FutureLearn provided by PRACE.
© CSC - IT Center for Science Ltd.