{"id":15047619,"url":"https://github.com/BardiFarsi/MemoizationMultiThreading","last_synced_at":"2025-05-15T17:30:45.144Z","repository":{"id":243944099,"uuid":"813855797","full_name":"BardiFarsi/MemoizationMultiThreading","owner":"BardiFarsi","description":"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.","archived":false,"fork":false,"pushed_at":"2024-06-17T20:52:33.000Z","size":504,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-19T19:44:04.074Z","etag":null,"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"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BardiFarsi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-11T21:59:14.000Z","updated_at":"2024-06-17T20:48:15.000Z","dependencies_parsed_at":"2024-09-24T21:01:34.769Z","dependency_job_id":"1dcbd440-7a86-44c7-b26b-f0ef6409f47c","html_url":"https://github.com/BardiFarsi/MemoizationMultiThreading","commit_stats":null,"previous_names":["bardiparsi/memoizationmultithreading","bardifarsi/memoizationmultithreading"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BardiFarsi%2FMemoizationMultiThreading","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BardiFarsi%2FMemoizationMultiThreading/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BardiFarsi%2FMemoizationMultiThreading/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BardiFarsi%2FMemoizationMultiThreading/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BardiFarsi","download_url":"https://codeload.github.com/BardiFarsi/MemoizationMultiThreading/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254388036,"owners_count":22062971,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","cpp","cpp17","cpp20","data-structures","dynamic-programming","machine-learning","machine-learning-algorithms","memoization","memory-management","multi-threading","multiprocessing","multithreading","parallel-computing","parallel-programming"],"created_at":"2024-09-24T21:01:27.176Z","updated_at":"2025-05-15T17:30:44.701Z","avatar_url":"https://github.com/BardiFarsi.png","language":"C++","readme":"# Multi-threaded Fibonacci Calculation with Memoization\n\n## Overview\n\nThis 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.\n\n## Features\n\n- **Memoization**: Stores results of expensive function calls and returns the cached result when the same inputs occur again.\n- **Dynamic Programming**: Breaks down complex problems into simpler subproblems and solves them just once, storing their solutions.\n- **Multi-threading**: Uses multiple threads for the computation, improving execution speed.\n\n## Requirements\n\n- **C++ Standard**: The code is compatible with both C++17 and C++20.\n- **Compiler**: The project can be compiled using MinGW G++ compiler or Microsoft Visual Studio MSVC compiler.\n- **Libraries**: \n  - `\u003ciostream\u003e`\n  - `\u003cunordered_map\u003e`\n  - `\u003cexception\u003e`\n  - `\u003cchrono\u003e`\n  - `\u003cfuture\u003e`\n  - `\u003cvector\u003e`\n  - `\u003cmutex\u003e`\n  - `\u003ccondition_variable\u003e`\n  - `\u003ccmath\u003e`\n  - `\u003cstdexcept\u003e`\n  - `\u003ccassert\u003e`\n\n## Installation\n\n### Using MinGW G++\n\n1. Ensure MinGW is installed on your system.\n2. Open the command prompt and navigate to the project directory.\n3. Compile the code using the following command:\n    ```bash\n    g++ -std=c++20 -o fib_multithread main.cpp -pthread\n    ```\n\n### Using Microsoft Visual Studio\n\n1. Open Microsoft Visual Studio.\n2. Create a new C++ project and add the `main.cpp` file to the project.\n3. Configure the project to use C++17 or C++20.\n4. Build and run the project using the built-in compiler.\n\n## Usage\n\nRun the compiled executable. The program calculates the Fibonacci number for given inputs using memoization and multi-threading.\n\n### Sample Output\nThe total time duration to calculate the Fib of 8 is: 70 microseconds\nThe total time duration to calculate the Fib of 21 is: 13 microseconds\nThe number of repeated processes to find Fib of 8 is: 0 (memoized)\nFibonacci(8) = 21\n\n## Code Explanation\n\n### Header Files\n- **\u003ciostream\u003e**: For input and output operations.\n- **\u003cunordered_map\u003e**: For storing the memoization cache.\n- **\u003cexception\u003e**: For handling exceptions.\n- **\u003cchrono\u003e**: For measuring execution time.\n- **\u003cfuture\u003e**: For handling asynchronous operations.\n- **\u003cvector\u003e**: For storing futures.\n- **\u003cmutex\u003e**: For thread synchronization.\n- **\u003ccondition_variable\u003e**: For thread synchronization.\n- **\u003ccmath\u003e**: For mathematical operations.\n- **\u003cstdexcept\u003e**: For throwing runtime errors.\n- **\u003ccassert\u003e**: For assertions.\n\n### Functions\n- `void fibLoop(...)`: Calculates Fibonacci numbers in chunks using multiple threads.\n- `int fib(int target, const int CPUPool, std::unordered_map\u003cint, int\u003e\u0026 memo)`: Calculates Fibonacci number with memoization and multi-threading.\n- `int main()`: Entry point of the program. Initializes the memoization cache, sets up the thread pool, and handles exceptions.\n\n### Multi-threading\n- **Mutex**: Used to synchronize access to shared data (memoization cache).\n- **Condition Variable**: Used to synchronize the completion of tasks.\n\n## License\n\nThis project is licensed under the NUI License.\n\n## Contributing\n\nFeel 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.\n\n## Contact\n\nFor any questions or suggestions, please contact Masoud Farsi at farsi.masoud@gmail.com \n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBardiFarsi%2FMemoizationMultiThreading","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBardiFarsi%2FMemoizationMultiThreading","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBardiFarsi%2FMemoizationMultiThreading/lists"}