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


The computing industry is characterized by the search for ever-increasing and efficient performance, from high-end applications in the sectors of networking, telecommunications, avionics, to low-power embedded systems in desktop computers, laptops, and video games. This development path has led to multicore systems, where two-, four-, and eight-core processors represent only the beginning of an upcoming expansion to an ever-increasing number of computing cores.

This expansion, however, creates a challenge, not only in the semiconductor industry but also in the development of applications that can be performed with parallel calculations.

Parallel computing, in fact, represents the simultaneous use of multiple computing resources to solve a processing problem, so that it can be executed on multiple CPUs, breaking a problem into discrete parts that can be processed simultaneously, where each is further divided into a series of instructions that can be executed serially on different CPUs.

Computing resources can include a single computer with multiple processors, an arbitrary number of computers connected via a network, or a combination of both approaches. Parallel computing has always been considered the extreme apex or future of computing, and up until a few years ago, it was motivated by numerical simulations of complex systems and situations concerning various sectors: weather and climate forecasts, chemical and nuclear reactions, human genome mapping, seismic and geological activity, the behavior of mechanical devices (from prostheses to space shuttles), electronic circuits, and manufacturing processes.

Today, however, ever more commercial applications are increasingly demanding the development of ever-faster computers to support the processing of large amounts of data in sophisticated ways. Applications for this include data mining and parallel databases, oil exploration, web search engines, and services networked business, computer-aided medical diagnoses, the management of multinational companies, advanced graphics and virtual reality (especially in the video game industry), multimedia and video network technologies, and collaborative work environments.

Last but not least, parallel computing represents an attempt to maximize that infinite, but at the same time, increasingly precious and scarce resource of time. This is why parallel computing is shifting from the world of very expensive supercomputers, reserved for a select few, to more economic and solutions based on multiple processors, Graphics Processing Units (GPUs), or a few interconnected computers that can overcome the constraints of serial computing and the limits of single CPUs.

To introduce the concepts of parallel programming, one of the most popular programming languages ​​has been adopted—Python. Python's popularity is partly due to its flexibility since it is a language used regularly by web and desktop developers, sysadmin and code developers, and more recently, by data scientists and machine learning engineers.

From a technological point of view, in Python, there is no separate compilation phase (as happens in C, for example) that generates an executable file starting from the source. The fact that it is pseudo-interpreted makes Python a portable language. Once a source is written, it can be interpreted and executed on most of the platforms currently used, whether they are from Apple (macOS X) or PC (Microsoft Windows and GNU/Linux). 

Another strength of Python is its ease of learning. Anyone can learn to use it over a couple of days and write their first application. In this context, the open structure of the language plays a fundamental role, without redundant declarations and thus extremely similar to a spoken language. Finally, Python is free software: not only are the Python interpreter and the use of Python in our applications available for free, but Python can also be freely modified and thus redistributed according to the rules of a fully open source license.

Python Parallel Programming Cookbook, Second Edition, contains a wide variety of examples that offer to the reader the opportunity to solve real problems. It examines the principles of software design for parallel architectures, insisting on the importance of clarity of the programs, and avoids the use of complex terminology in favor of clear and direct examples.

Each topic is presented as part of a complete, working Python program, always followed by the output of the program in question. The modular organization of the various chapters provides a proven path along which to move from the simplest arguments to the most advanced, but it is also suitable for those who want to learn only a few specific issues.