Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bardifarsi/memoizationmultithreading
Sample project demonstrating the use of memoization, dynamic programming, and multi-threading to efficiently handle repeated heavy tasks and optimize performance. Results are cached for quick retrieval, and Multi-Threaded processing accelerates computation.
https://github.com/bardifarsi/memoizationmultithreading
algorithms cpp cpp17 cpp20 data-structures dynamic-programming machine-learning machine-learning-algorithms memoization memory-management multi-threading multiprocessing multithreading parallel-computing parallel-programming
Last synced: 10 days ago
JSON representation
Sample project demonstrating the use of memoization, dynamic programming, and multi-threading to efficiently handle repeated heavy tasks and optimize performance. Results are cached for quick retrieval, and Multi-Threaded processing accelerates computation.
- Host: GitHub
- URL: https://github.com/bardifarsi/memoizationmultithreading
- Owner: BardiFarsi
- License: gpl-3.0
- Created: 2024-06-11T21:59:14.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-06-17T20:52:33.000Z (7 months ago)
- Last Synced: 2024-12-22T02:29:17.206Z (18 days ago)
- Topics: algorithms, cpp, cpp17, cpp20, data-structures, dynamic-programming, machine-learning, machine-learning-algorithms, memoization, memory-management, multi-threading, multiprocessing, multithreading, parallel-computing, parallel-programming
- Language: C++
- Homepage:
- Size: 492 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Multi-threaded Fibonacci Calculation with Memoization
## Overview
This project demonstrates the use of memoization, dynamic programming, and multi-threading to efficiently handle repeated heavy tasks and optimize performance. The results of computations are cached for quick retrieval, and parallel processing accelerates computation.
## Features
- **Memoization**: Stores results of expensive function calls and returns the cached result when the same inputs occur again.
- **Dynamic Programming**: Breaks down complex problems into simpler subproblems and solves them just once, storing their solutions.
- **Multi-threading**: Uses multiple threads for the computation, improving execution speed.## Requirements
- **C++ Standard**: The code is compatible with both C++17 and C++20.
- **Compiler**: The project can be compiled using MinGW G++ compiler or Microsoft Visual Studio MSVC compiler.
- **Libraries**:
- ``
- ``
- ``
- ``
- ``
- ``
- ``
- ``
- ``
- ``
- ``## Installation
### Using MinGW G++
1. Ensure MinGW is installed on your system.
2. Open the command prompt and navigate to the project directory.
3. Compile the code using the following command:
```bash
g++ -std=c++20 -o fib_multithread main.cpp -pthread
```### Using Microsoft Visual Studio
1. Open Microsoft Visual Studio.
2. Create a new C++ project and add the `main.cpp` file to the project.
3. Configure the project to use C++17 or C++20.
4. Build and run the project using the built-in compiler.## Usage
Run the compiled executable. The program calculates the Fibonacci number for given inputs using memoization and multi-threading.
### Sample Output
The total time duration to calculate the Fib of 8 is: 70 microseconds
The total time duration to calculate the Fib of 21 is: 13 microseconds
The number of repeated processes to find Fib of 8 is: 0 (memoized)
Fibonacci(8) = 21## Code Explanation
### Header Files
- ****: For input and output operations.
- ****: For storing the memoization cache.
- ****: For handling exceptions.
- ****: For measuring execution time.
- ****: For handling asynchronous operations.
- ****: For storing futures.
- ****: For thread synchronization.
- ****: For thread synchronization.
- ****: For mathematical operations.
- ****: For throwing runtime errors.
- ****: For assertions.### Functions
- `void fibLoop(...)`: Calculates Fibonacci numbers in chunks using multiple threads.
- `int fib(int target, const int CPUPool, std::unordered_map& memo)`: Calculates Fibonacci number with memoization and multi-threading.
- `int main()`: Entry point of the program. Initializes the memoization cache, sets up the thread pool, and handles exceptions.### Multi-threading
- **Mutex**: Used to synchronize access to shared data (memoization cache).
- **Condition Variable**: Used to synchronize the completion of tasks.## License
This project is licensed under the NUI License.
## Contributing
Feel free to fork this repository and contribute by submitting pull requests. For major changes, please open an issue first to discuss what you would like to change.
## Contact
For any questions or suggestions, please contact Masoud Farsi at [email protected]