Closed FelixUhle closed 10 months ago
Hello @FelixUhle ,
I am interested in contributing to your project, specifically in the area of enhancing thread management to adapt dynamically to different system capabilities.
Before I begin, I would like to gather some additional information to ensure my contributions align well with the project's existing standards and practices:
Could you please provide more clarity or any additional specifics regarding the feature for dynamic thread allocation based on system capabilities? Understanding the exact requirements and expectations will help me tailor my approach effectively.
Does the project adhere to any specific coding standards or practices that I should be aware of? Knowing these would help me ensure that my contributions maintain consistency with the existing codebase.
Also, since the feature involves multithreading, I am particularly interested in understanding any existing guidelines or best practices you follow for testing multithreaded applications. This information will be crucial for me to write effective and comprehensive tests for the new feature.
Thank you for your time and consideration. I am eager to contribute and look forward to hearing from you soon.
Best regards,
Hey @gmottajr,
Thank you for your interest. We would be delighted if you could participate in PROLEAD.
As @FelixUhle has already mentioned, we have a bit of information about the current issue. So far, we have been statically specifying the max_no_of_threads
by setting an integer in the config file, which means that the number of threads is not dependent on the actual available threads on the target system. Now, we would like to dynamically determine the number of threads available on the system so that dynamic specifications such as all
or half
could be used for max_no_of_threads
. Parsing these new keywords is not a problem; I can take care of that. PROLEAD would then need to determine the number of threads for these keywords and internally set max_no_of_threads back to an integer.
Regarding coding standards, I recently uploaded a style file that can be easily used in VS Code. In general, we plan to adopt the Google coding style in the future. However, we haven't implemented this in all files yet. For guidance, you can take a look at probing.cpp
.
We are currently thinking about testing. So far, we haven't established a guideline or best practices for it. I have uploaded an initial file for unit tests, which we will gradually supplement. As for testing multithreading, we can collaborate on finding a solution together.
Regards,
Nico
Thank you very much, Nico (@nicolaimueller) for you feedback, I do appreciate the details you provided me. I'll carefully take a look into the file you mentioned. Shall I have this issue assigned to me, please, so that I can start to work on it? Thank you very much, once again!
Hey guys, awesome! ๐ I could enjoy a free window ๐ค here during this holydays I have something for you as a starting point ๐ก. I create ๐ a ThreadManager class designed to manage and optimize thread allocation in C++ applications, especially useful when running the same application on different systems with varying numbers of CPU cores ๐ป . It provides a flexible way to determine the best number of threads to use based on the system's hardware and user-defined preferences. Here is a description of my initial solution for the problem you described:
The ThreadOption enum defines various options for thread allocation:
static unsigned int getOptimalThreadCount(ThreadOption option, unsigned int specificCount = 0);
This method calculates the optimal number of threads based on the selected ThreadOption. It takes two parameters:
Parameters
Return Value Returns the calculated optimal number of threads as an unsigned integer.
Behavior
unsigned int threads = ThreadManager::getOptimalThreadCount(ThreadOption::Half);
// This will set 'threads' to half the number of cores available on the system.
The ThreadManager class provides a patterned solution that is straightforward and intuitive. This design choice ensures that any contributing developer, regardless of their familiarity with the project, can easily understand and work with the class. It streamlines the learning curve and fosters effective collaboration, making it simpler for new contributors to adapt and contribute enhancements or fixes.
Single Responsibility Principle (SRP): Dedicated solely to thread management, ensuring clarity and reducing complexity. Open/Closed Principle (OCP): Easily extendable for new thread allocation strategies without modifying existing code, enhancing flexibility. Liskov Substitution Principle (LSP): Compatible for integration in any relevant context without affecting program correctness. Dependency Inversion Principle (DIP): Relies on abstractions (e.g., enum for thread options), not specific implementations, paving the way for future enhancements.
I am completely open to any modifications or adjustments you deem necessary. My goal is to ensure that this solution meets our project's needs effectively and efficiently.
Additionally, I would like your suggestion on where you prefer this class file to be placed within our project's repository. Your guidance on its optimal location would ensure seamless integration with our existing codebase. ๐งช I've created some unit tests using Google Test. Could you please provide guidance on where you'd like them to be placed within the project structure?
I am looking forward to your valuable feedback and suggestions. Your input is crucial to refining this solution and ensuring it fulfills our project's requirements. Please feel free to reach out if you need any further information or clarifications.
Once again, thank you for considering my contribution ๐.
Best regards ๐, Gerson Jr.
Hi @gmottajr, We sincerely appreciate your prompt response and commitment to addressing the issue. We are thrilled to have you on board and fully endorse your proposals. Let's proceed as follows:
To seamlessly integrate your ThreadManager into PROLEAD and PROLEAD_SW, we propose placing all relevant files under inc/Util
and src/Util
. This aligns with our convention of organizing components not directly tied to hardware or software versions in these directories. Additionally, for enhanced readability, we suggest creating two distinct files: ThreadManager.hpp
and ThreadManager.cpp
, each containing a single class.
For unit testing, we recommend adding a new file ut/Util/ThreadManager.cpp
. Please keep in mind that we currently use Catch2 as unit testing framwork. The only reason for that decision was that we think that using google test is a bit of overkill for or small project. However, if converting the test cases from Google Test to Catch2 poses any challenges, please don't hesitate to reach out.
We genuinely appreciate your dedication to this endeavor. Your contribution is invaluable, and we're delighted to have such capable individuals actively participating in our project. ๐
Once again, thank you for your efforts.
Best regards,
Nico
Is your feature request related to a problem? Please describe. It is frustrating to have to change the
max_no_of_threads
setting every time you run the same test on systems with a vastly different number of cores. If you don't do this, you either incur additional overhead on the system with fewer cores or you don't use all the cores that the stronger system has available.Example: We have two systems, a server and a laptop, and we want to run a configuration on both. The server has 128 CPU cores. Let us now assume that we want to use all cores of the server. Therefore, we set
max_no_of_threads
to 128. If we now run the same config on a laptop with 12 threads (logical cores) we still create 128 threads of which only 12 can be executed in parallel. For each additional specified thread that is also spawned, we generate unnecessary overhead. The alternative is to setmax_no_of_threads
to 12. This might be the best option to run the test with the laptop, but with regard to the server, 116 available cores now remain unused.Describe the solution you'd like Allow to set
max_no_of_threads
to the keywordsall
to select all logical cores of the current system.. Additionally, the keywordhalf
could be used to select the half of all available logical cores.Describe alternatives you've considered An alternative to introducing the
all
keyword is to select all cores whenmax_no_of_threads
is set to0
.