This document provides an introduction to parallel programming using Python. It discusses the motivation for parallel programming being to utilize idle CPU capacity. The two main ways to run tasks in parallel in Python are using process forks and spawned threads. It then covers forking processes, threads, interprocess communication, and the multiprocessing module in Python for parallel programming.
4. Motivation -Cont.
Solution:
Running more than one program at a
time.
Dividing the CPU attention among a
set of tasks.
Parallel Processing, Multiprocessing,
or Multitasking.
Friday, July 12, 13
5. Parallel Processing in
Python
Two main ways to run tasks:
Process forks
Spawned threads
Python built-in tools like: os.fork, threading,
queue, and multiprocessing.
Third Party domains offers more advanced
tools.
Friday, July 12, 13
6. Forking Processes
Traditional ways to structure parallel
tasks.
Straight forward way to start an
independent program.
What is forking?
Copying programs.
Python Module - os.fork
Friday, July 12, 13
11. Python Modules
Python Modules:
_thread module
threading modules
Both modules provide tools for
synchronizing access to shared objects
with locks.
Friday, July 12, 13
12. The _thread Module
Start new independent threads of
execution within a process.
Doesn't support OOP
Platform independent module.
Friday, July 12, 13
15. Synchronizing access to
shared objects and names
What is the problem?
Objects and namespaces in a process
that span the life of threads are
shared by all spawned threads.
Solution:
Threads automatically come with a
cross-task communications
Friday, July 12, 13
17. Threading Module
Internally uses the _thread module to
implement objects that represent
threads and common synchronization
tools.
Manage threads with high-level class-
based objects.
Friday, July 12, 13
18. Interprocess
Communication - Overview
Other solutions don’t support cross-
program communication
Sockets, Pipes, and Signals
Enable performing Inter-Process
Communication (IPC)
Friday, July 12, 13
19. The multiprocessing
Module - Overview
Provide the best of processes and threads.
Platform independent.
Uses processes instead of threads.
Provide synchronizations tools.
Leverage the capacity of multiple
processors.
Friday, July 12, 13