../_images/book_cover.jpg

This notebook contains an excerpt from the Python Programming and Numerical Methods - A Guide for Engineers and Scientists, the content is also available at Berkeley Python Numerical Methods.

The copyright of the book belongs to Elsevier. We also have this interactive book online for a better learning experience. The code is released under the MIT license. If you find this content useful, please consider supporting the work on Elsevier or Amazon!

< 13.3 Use joblib | Contents | CHAPTER 14. Linear Algebra and Systems of Linear Equations >

Summary

  1. Parallel computing can reduce our execution time by using multiple cores in our computer.

  2. There is a difference between process and thread, and it is easier to use process-based approach in Python to achieve parallelism.

  3. Multiprocessing package is easy to use to solve your problems on multiple cores.

  4. We can also use joblib to simplify our parallel computing code for many common tasks.

Problems

  1. What’s parallel computing?

  2. Please specify the difference between process and thread.

  3. Find out the number of your processors on your computer using the multiprocessing package.

  4. Use multiprocessing package to parallel the following code, and record the running time. Hint: You may need to check out the pool.apply function.

def plus_cube(x, y):
    return (x+y)**3

for x, y in zip(range(100), range(100)):
    results.append(plus_cube(x, y))
  1. Can you provide an example to illustrate the difference of pool.map and pool.map_async?

  2. What is Python’s GIL?

  3. Use joblib to parallel the above example, and use the multiprocessing as the backend.

< 13.3 Use joblib | Contents | CHAPTER 14. Linear Algebra and Systems of Linear Equations >