You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now, if I want to try out my new multithreading skills on it... This would be perfect for parallel work.
Current idea:
Create PathMaker class (name TBD).
It contains a std::queue
and a thread pool. Let's say a max size of 4 (3? 2?).
So we have max 4 threads calculating paths at any given time.
We hit a branch, if we have an empty thread, great, we create it with our current data, tell it where to go, and let it run. If we don't have an empty thread, then we push it to the queue.
Once a thread finishes, we check if we have any paths in our queue. If so, we give the thread that data, pop the path off the queue, and let the thread run.
Once the queue is empty, we're done.
Also, instead of storing all possible paths like before, we can simply hold one - the current shortest one. If a path ever gets longer than the shortest, we terminate calculating it. If we find a shorter one, we throw away the old shortest, and make set the variable to the new one.
Less memory usage, less calculation, less iteration, less time. What could go wrong? (Don't answer that.)
The text was updated successfully, but these errors were encountered:
Just took a look at some of the code in swift::Path.
Holy crap. I'm kinda surprised it works.
So, need to do a clean up. This looks scary
Could be done more efficiently too probably.
Now, if I want to try out my new multithreading skills on it... This would be perfect for parallel work.
Current idea:
Create PathMaker class (name TBD).
It contains a std::queue
and a thread pool. Let's say a max size of 4 (3? 2?).
So we have max 4 threads calculating paths at any given time.
We hit a branch, if we have an empty thread, great, we create it with our current data, tell it where to go, and let it run. If we don't have an empty thread, then we push it to the queue.
Once a thread finishes, we check if we have any paths in our queue. If so, we give the thread that data, pop the path off the queue, and let the thread run.
Once the queue is empty, we're done.
Also, instead of storing all possible paths like before, we can simply hold one - the current shortest one. If a path ever gets longer than the shortest, we terminate calculating it. If we find a shorter one, we throw away the old shortest, and make set the variable to the new one.
Less memory usage, less calculation, less iteration, less time. What could go wrong? (Don't answer that.)
The text was updated successfully, but these errors were encountered: