This repository contains a Python script that demonstrates matrix multiplication with multithreading using Google Colab. The script multiplies 100 random matrices of size 1000x1000 with a constant matrix of the same size and measures the execution time with different numbers of threads. Additionally, it monitors CPU usage during the execution.
The script utilizes the concurrent.futures module in Python to implement multithreading for matrix multiplication. It generates 100 random matrices and a constant matrix of size 1000x1000. Then, it performs matrix multiplication in parallel using the specified number of threads. CPU usage is monitored using the psutil library.
The following table shows the execution time and CPU usage for matrix multiplication with varying numbers of threads:
| Threads | Time taken (s) | CPU Usage (%) |
|---|---|---|
| 1 | 8.25 | 5.05% |
| 2 | 7.27 | 22.0% |
| 3 | 6.13 | 4.0% |
| 4 | 7.54 | 4.0% |
| 5 | 8.95 | 3.5% |
| 6 | 6.83 | 55.1% |
| 7 | 6.13 | 4.5% |
| 8 | 7.77 | 4.5% |
The graph below illustrates the relationship between the number of threads and execution time:
To run the script:
- Open the provided notebook in Google Colab.
- Execute the code cells in the notebook.
- View the results in the output.
- Python 3.x
- NumPy
- concurrent.futures
- matplotlib
- psutil
This project is licensed under the MIT License.
