This repository provides an extensive collection of Python examples and scripts that delve into various aspects of parallel, distributed, and asynchronous programming. It serves as a practical guide to understanding core concepts such as multithreading, multiprocessing, message passing, and asynchronous programming with hands-on examples.
- Chapter 1: Parallel and Concurrent Programming
- Chapter 2: Multithreading Examples in Python
- Chapter 3: Multiprocessing Examples in Python
- Chapter 4: Message Passing Interface (MPI)
- Chapter 5: Asynchronous Programming
This chapter introduces the foundational concepts of parallel and concurrent programming and demonstrates their implementation using Python libraries.
- Data Parallelism
- Task Parallelism
- Serial and Parallel Programming
- Process Creation and Synchronization
Data Parallelism.py: Implements efficient data parallel computation with NumPy.Do_something.py: Contains utility functions for multiprocessing and multithreading examples.Multiprocessing_test.py: Compares multiprocessing and multithreading performance.Semaphore.py: Demonstrates semaphore-based synchronization.
This chapter delves into multithreading, highlighting thread synchronization techniques, locking mechanisms, and basic thread operations.
- Thread Synchronization
- Locking Mechanisms (
Lock,RLock,Semaphore) - Thread Creation and Management
barrier.py: Synchronizes threads using theBarrierobject.Condition.py: Implements producer-consumer synchronization withCondition.MyThreadClass_lock_2.py: Demonstrates safe thread operations with locks.Threading_with_queue.py: Showcases a producer-consumer pattern usingQueue.
Explore the power of multiprocessing in Python, including process creation, inter-process communication, and process pools.
- Process Synchronization
- Inter-Process Communication (
Pipe,Queue) - Daemon and Non-Daemon Processes
- Custom Processes and Process Pools
communicating_with_pipe.py: Demonstrates communication usingPipe.naming_processes.py: Explains the importance of process naming.process_pool.py: Utilizes a pool of worker processes for parallel computation.run_background_processes.py: Highlights the difference between daemon and non-daemon processes.
This chapter provides examples of using the Message Passing Interface (MPI) for distributed computing and inter-process communication.
- Point-to-Point Communication
- Collective Communication (
bcast,scatter,gather) - Avoiding Deadlocks
Avoiding_Deadlock.py: Demonstrates deadlock-free point-to-point communication.Collective_Communication_using_Broadcast.py: Explains data broadcasting withbcast.Collective_Communication_Using_Scatter_function.py: Demonstrates data distribution usingscatter.Point-to-Point Implementation.py: Implements direct communication between processes.
Learn about asynchronous programming in Python using asyncio, including task scheduling, coroutine management, and event-driven programming.
asyncioCoroutines- Event Loops and Scheduling
- ThreadPoolExecutor for Concurrent Task Execution
asyncio_coroutine.py: Simulates a finite state machine with coroutines.asyncio_event_looop.py: Implements event-driven task scheduling withasyncio.HeavyComputationSimulation.py: Compares sequential, thread pool, and process pool execution.ThreadPoolExecutor.py: Demonstrates task execution usingThreadPoolExecutor.