0%

Book Description

Implement effective programming techniques in Python to build scalable software that saves time and memory

Key Features

  • Design distributed computing systems and massive computational tasks coherently
  • Learn practical recipes with concise explanations that address development pain points encountered while coding parallel programs
  • Understand how to host your parallelized applications on the cloud

Book Description

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.

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.

By the end of this book, you will be confident in building concurrent and high-performing applications in Python.

What you will learn

  • Synchronize multiple threads and processes to manage parallel tasks
  • Use message passing techniques to establish communication between processes to build parallel applications
  • Program your own GPU cards to address complex problems
  • Manage computing entities to execute distributed computational task
  • Write efficient programs by adopting the event-driven programming model
  • Explore cloud technology with Django and Google App Engine
  • Apply parallel programming techniques that can lead to performance improvements

Who this book is for

The Python Parallel Programming Cookbook is for software developers who are well-versed with Python and want to use parallel programming techniques to write powerful and efficient code. This book will help you master the basics and the advanced of parallel computing.

Downloading the example code for this ebook: You can download the example code files for this ebook on GitHub at the following link: https://github.com/PacktPublishing/Python-Parallel-Programming-Cookbook-Second-Edition. If you require support please email: [email protected]

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Python Parallel Programming Cookbook Second Edition
  3. Dedication
  4. About Packt
    1. Why subscribe?
  5. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Get in touch
      1. Reviews
  7. Getting Started with Parallel Computing and Python
    1. Why do we need parallel computing?
    2. Flynn's taxonomy
      1. Single Instruction Single Data (SISD)
      2. Multiple Instruction Single Data (MISD)
      3. Single Instruction Multiple Data (SIMD)
      4. Multiple Instruction Multiple Data (MIMD)
    3. Memory organization
      1. Shared memory
      2. Distributed memory
      3. Massively Parallel Processing (MPP)
      4. Clusters of workstations
      5. Heterogeneous architectures
    4. Parallel programming models
      1. Shared memory model
      2. Multithread model
      3. Message passing model
      4. Data-parallel model
        1. Designing a parallel program
          1. Task decomposition
          2. Task assignment
          3. Agglomeration
          4. Mapping
          5. Dynamic mapping
    5. Evaluating the performance of a parallel program
      1. Speedup
      2. Efficiency
      3. Scaling
      4. Amdahl's law
      5. Gustafson's law
    6. Introducing Python
      1. Help functions
      2. Syntax
      3. Comments
      4. Assignments
      5. Data types
      6. Strings
      7. Flow control
      8. Functions
      9. Classes
      10. Exceptions
      11. Importing libraries
      12. Managing files
      13. List comprehensions
      14. Running Python scripts
      15. Installing Python packages using pip
        1. Installing pip
        2. Updating pip
        3. Using pip
    7. Introducing Python parallel programming
      1. Processes and threads
  8. Thread-Based Parallelism
    1. What is a thread?
    2. Python threading module
    3. Defining a thread
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Determining the current thread
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Defining a thread subclass
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Thread synchronization with a lock
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Thread synchronization with RLock
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Thread synchronization with semaphores
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    9. Thread synchronization with a condition
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    10. Thread synchronization with an event
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Thread synchronization with a barrier
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Thread communication using a queue
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  9. Process-Based Parallelism
    1. Understanding Python's multiprocessing module 
    2. Spawning a process 
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Naming a process
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Running processes in the background
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Killing a process
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Defining processes in a subclass
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Using a queue to exchange data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Using pipes to exchange objects
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5.  See also
    9. Synchronizing processes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    10. Using a process pool
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more...
      5. See also
  10. Message Passing
    1. Technical requirements
    2. Understanding the MPI structure
    3. Using the mpi4py Python module
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Implementing point-to-point communication
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Avoiding deadlock problems
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Collective communication using a broadcast
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Collective communication using the scatter function
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    8. Collective communication using the gather function
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Collective communication using Alltoall
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    10. The reduction operation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    11. Optimizing communication
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  11. Asynchronous Programming
    1. Using the concurrent.futures Python module
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    2. Managing the event loop with asyncio
      1. Understanding event loops
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Handling coroutines with asyncio
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Manipulating tasks with asyncio
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Dealing with asyncio and futures
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  12. Distributed Python
    1. Introducing distributed computing
    2. Types of distributed applications
      1. Client-server applications
        1. Client-server architecture
        2. Client-server communications
        3. TCP/IP client-server architecture
      2. Multi-level applications
    3. Using the Python socket module
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Types of sockets
          1. Stream sockets
      5. See also
    4. Distributed task management with Celery
      1. Getting ready
        1. Windows setup
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. RMI with Pyro4
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Implementing chain topology
      5. See also
  13. Cloud Computing
    1. What is cloud computing?
    2. Understanding the cloud computing architecture
      1. Service models
        1. SaaS
        2. PaaS
        3. IaaS
      2. Distribution models
        1. Public cloud
        2. Private cloud
        3. Cloud community
        4. Hybrid cloud
      3. Cloud computing platforms
    3. Developing web applications with PythonAnywhere
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Dockerizing a Python application
      1. Getting ready
        1. Installing Docker for Windows
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Introducing serverless computing
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. What is a Lambda function?
        2. Why serverless?
        3. Possible problems and limitations
      5. See also
  14. Heterogeneous Computing
    1. Understanding heterogeneous computing
    2. Understanding the GPU architecture
    3. Understanding GPU programming
      1. CUDA
      2. OpenCL
    4. Dealing with PyCUDA
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Heterogeneous programming with PyCUDA
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Implementing memory management with PyCUDA
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Introducing PyOpenCL
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Building applications with PyOpenCL
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    9. Element-wise expressions with PyOpenCL
      1. Getting started
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    10. Evaluating PyOpenCL applications
      1. Getting started
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Pros of OpenCL and PyOpenCL
        2. Cons of OpenCL and PyOpenCL
        3. Pros of CUDA and PyCUDA
        4. Cons of CUDA and PyCUDA
      5. See also
    11. GPU programming with Numba
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  15. Python Debugging and Testing
    1. What is debugging?
    2. What is software testing?
    3. Debugging using Winpdb Reborn
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Interacting with pdb
      1. Getting ready
        1. Interacting with the command line
        2. Using the Python interpreter
        3. Inserting a directive in the code to debug
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Implementing rpdb for debugging
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Dealing with unittest
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Application testing using nose
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  16. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
54.221.43.155