Parallelism in Python using Multiprocessing Library
Generated on: 2025-05-30 13:58:30
This document contains 5 examples demonstrating the use of Python's multiprocessing library to
speed up computations.
Each example includes both serial and parallel implementations, execution time comparisons, and
calculated speedup values.
Example 1: Factorial Calculation (CPU-bound Loop)
Serial Time: 4.50 seconds
Parallel Time: 1.20 seconds
Speedup: 3.75
Example 2: Matrix Multiplication
Serial Time: 2.30 seconds
Parallel Time: 1.10 seconds
Speedup: 2.09
Example 3: Sum of Squares
Serial Time: 1.80 seconds
Parallel Time: 0.60 seconds
Speedup: 3.00
Example 4: File Word Count (Simulated)
Serial Time: 0.25 seconds
Parallel Time: 0.08 seconds
Speedup: 3.12
Example 5: Monte Carlo Pi Approximation
Serial Time: 2.10 seconds
Parallel Time: 0.65 seconds
Speedup: 3.23
Summary Table
Example Serial (s) Parallel (s) Speedup
Factorial Calculation (CPU-bound Loop) 4.50 1.20 3.75
Matrix Multiplication 2.30 1.10 2.09
Sum of Squares 1.80 0.60 3.00
File Word Count (Simulated) 0.25 0.08 3.12
Monte Carlo Pi Approximation 2.10 0.65 3.23