Book Image

Python Parallel Programming Cookbook - Second Edition

By : Giancarlo Zaccone
Book Image

Python Parallel Programming Cookbook - Second Edition

By: Giancarlo Zaccone

Overview of this book

<p>Nowadays, it has become extremely important for programmers to understand the link between the software and the parallel nature of their hardware so that their programs run efficiently on computer architectures. Applications based on parallel programming are fast, robust, and easily scalable. </p><p> </p><p>This updated edition features cutting-edge techniques for building effective concurrent applications in Python 3.7. The book introduces parallel programming architectures and covers the fundamental recipes for thread-based and process-based parallelism. You'll learn about mutex, semaphores, locks, queues exploiting the threading, and multiprocessing modules, all of which are basic tools to build parallel applications. Recipes on MPI programming will help you to synchronize processes using the fundamental message passing techniques with mpi4py. Furthermore, you'll get to grips with asynchronous programming and how to use the power of the GPU with PyCUDA and PyOpenCL frameworks. Finally, you'll explore how to design distributed computing systems with Celery and architect Python apps on the cloud using PythonAnywhere, Docker, and serverless applications. </p><p> </p><p>By the end of this book, you will be confident in building concurrent and high-performing applications in Python.</p>
Table of Contents (16 chapters)
Title Page

What this book covers

Chapter 1, Getting Started with Parallel Computing and Python, provides an overview of parallel programming architectures and programming models. The chapter introduces the Python programming language, discussing how the characteristics of the language, its ease of learning and use, its extensibility, and the richness of the available software libraries and applications all make Python a valuable tool for any application, and especially, of course, for parallel computing.

Chapter 2, Thread-Based Parallelism, discusses thread parallelism using the threading Python module. Readers will learn, through full programming examples, how to synchronize and manipulate threads to implement in their multithreading applications. 

Chapter 3, Process-Based Parallelism, guides the reader through the process-based approach to parallelizing a program. A complete set of examples will show readers how to use the multiprocessing Python module. 

Chapter 4, Message Passing, is focused on message-passing exchange communication systems. In particular, the mpi4py library will be described with a lot of application examples. 

Chapter 5, Asynchronous Programmingexplains the asynchronous model for concurrent programming. In some ways, it is simpler than the threaded one because there is a single instruction stream, and tasks explicitly relinquish control instead of being suspended arbitrarily. The chapter shows readers how to use the asyncyio module to organize each task as a sequence of smaller steps that must be executed in an asynchronous manner.

Chapter 6, Distributed Python, introduces the reader to distributed computing, which is the process of aggregating several computing units to collaboratively run a single computational task in a transparent and coherent way. In particular, the example applications provided in the chapter describe the use of the socket and Celery modules to manage distributed tasks. 

Chapter 7, Cloud Computingprovides an overview of the main cloud-computing technologies in relation to the Python programming language.  The PythonAnywhere platform is very useful for deploying Python applications on the cloud, and will be examined in this chapter. This chapter also contains example applications demonstrating the use of containers and serverless technologies.

Chapter 8, Heterogeneous Computing, looks at the modern GPUs that are providing breakthrough performance for numerical computing at the cost of increased programming complexity. In fact, the programming models for GPUs require that the coder manually manage the data transfer between the CPU and GPU.  This chapter will teach the reader, using programming examples and use cases, how to exploit the computing power provided by GPU cards using the powerful Python modules of PyCUDA, Numba, and PyOpenCL.  

Chapter 9, Python Debugging and Testing, is the last chapter that introduces two important topics on software engineering: debugging and testing. In particular, the following Python frameworks will be described: winpdb-reborn for debugging, and unittest and nose for software testing.