Software written in C++, must use only Standard C++ library.
Hi, the problem i'm facing is the following: I have to parallelize a software but the multithreaded version completion time is too much randomly, i mean that 50% of the times is faster than the single version and 50% is slower, that's due to a wrong design choice i think, and i would like you to show me how can i correct it.
The software is based on a Tree structure, not binary, that keeps growing and each new node could be a possible solution. Once the software find a solution, the program stops. Now the problem is that in the sequential version, the path that the software follow to compute the nodes is always the same of course, so it need always a fixed time to complete is task. While in the multithreaded version, i have a taskpool where i insert the nodes, and the threads keep fetching the job from the taskpool and pushing back the new nodes, but the order of computation of course is not deterministic, so it happens that sometimes this way of working lead to a greater number of computations that the multithreaded version does, and so it lead to a greater completion time.
So, imagine to have a Tree structure that keeps growing, the root is given and you put all the nodes in a queue, and then you start computing the first node, if it's a solution you terminate otherwise you computer that node and pushback to the queue all the resulting sub-nodes. There are multiple solutions and you don't know in which node they are so you just must to compute each of them until discover a solution. The sequential version will follow always the same path, and so will always need to compute N nodes before reach the first solution, while the multithreaded version can be unlucky, and take differents paths that has no solutions and for that reaching the first solution in more steps.
How could you ensure that the multithreaded version will always do a maximum of N steps before reaching the first solution? Otherwhise the advantage of having multiple threads will be useless if you need to compute a lot more steps.
If needed i will post the code but it's just, as i said, a tree structure and a queue task pool and so on.