-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Multithreading (or rather multiprocessing) #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Alright, the pickling problem has been solved. The issue was in the way manim imported the project module, by spec. Importing it normally works. I've made a new branch with the according edited file, (and again, no PRs and merges for that branch): The changes are simple:
The problems that are still left:
I really need to do other things for a while though, so I'm leaving that cleaned up Proof of Concept file not just for others but also for myself to come back to later as well. |
There's now an issue with the new Tex handling, which will presumably be fixed by #98, so I'm waiting on that to continue. I've worked a bit more on the likely to be implemented structure, and will leave that here mostly for myself, and as a general reference. In order to properly implement multiprocessing we'll likely have to do something like this:
animations = self.compile_play_args_to_animation_list(*args, **kwargs)
self.begin_animations(animations)
self.progress_through_animations(animations)
self.finish_animations(animations)
|
We live in a post-#98 world. Can we revisit this? Also, RE point 1. above: you don't need a bool AND an argument. You can just set the default number of workers to |
Not forgetting about this, but while #98 was brewing I had been working on the 3 new geometry classes (#187) to which I still I need some input too. Since both are pretty much entirely on my shoulders working on one delays the others and I'm not sure which to prioritize. The classes definitely have more general utility.
Right, like I mentioned there. |
Making a note to myself here to also wait for #166 to be finished since it touches the same files multiprocessing has to be spliced into. |
Just wanted to say that there are some changes planned down the line for the config system that would work perfectly with multiprocessing but not with multithreading. So in case there is a change from multiprocessing to multithreading down the line, please let me know first so we can discuss. |
Update here: The next TO DO item on the config system is to make it not global anymore, but local to each Scene class. Once this is done, it should be fairly simple to implement parallel scene rendering using multiprocessing. There have also been refactors in the scene file writer that may make this easier. |
Related to multiprocessing: sphinx has an option to run in parallel. If we make sure our docs can build in parallel, then we should be able to speed up sphinx builds by 2x or 4x (assuming the RTD machines have many CPUs...) |
This isn't ever going to happen though. In terms of performance multiprocessing would be a massive increase in speed for most cases while multithreading would be... well not completely useless, but honestly, mostly.
Speaking of which, how far along is this exactly?
Sounds good. Is my still planned multiprocessing project related to implementing that at all though? If, how? |
Fair!
Honestly, the only thing left to do is make each
Well, the |
Hi all! Is there any update on this? |
Unfortunately not from my side at least. I can't live off of this and have other stuff to attend, especially right now, so I simply can't tackle it. I'd have to reconnect with the current state of the repo too. What originally kept me tethered to Manim was somewhat temporarily severed by the pandemic. I might get back in touch with all of this eventually, but if I do... it will be another year, and that's the optimistic estimate. |
Explicitly add a license : CC BY-NC-SA
A small disclaimer, this is more of a longterm issue with quite a bit of planning before any PR with actual merge intent should ever be attached to this.
First of all, what should we use?
There's the
threading
module, however it does not use additional cores. Using it isn't advised thusly, because it's theoretically possible max performance improvement is just +100% for all scenarios (you know, two threads per core usually), and actual performance increases are expected to be somewhere around +10% to +50%. Nothing irrelevant, but the simple fact is we can do better.There's the
multiprocessing
module, and this is almost what we should use. There's also themultiprocess
module that should generally be more robust (better pickling etc).So
multiprocess
it is.So, can it work? Yes it can. I've had to jump through some hoops but I managed to hack something together to multiprocess 4 simple scenes side by side. Theoretically possible speed bonus is +300% and actual was... +200%. Now that is nothing to scoff at. Obviously with more things processed simultaneously both theoretical and actual speed goes up, capped really only by the running hardware and available splitting. On my hardware with 16 cores I expect to be able to reach an actual improvement of about +1000% for example. That's around an order of magnitude so... it'd change things up a lot.
Alright, we've got the intent and the module, now onto the plan.
First we should enable multiprocessing for scenes. Multithreading is really easy, but multiprocess is a bit more picky. As I said, I have gotten scenes rendered in it but something about the exact implementation in extract_scenes.py is still making it fail while pickling. I'm not sure what it is, I just know that it can be fixed, since I was able to sidestep it.
(Fixed, see next post for that)
Once that is done we should be able to use manim (assuming 4 scenes in a file) with something like this:
manim project -at
And have all 4 scenes dropped into their own process.
Once this is implemented and works well, we can move on to the real prize.
In order to make manim faster in general we can split scenes into intervals, and then have each interval be handled by a separate process. For instance if a scene has 8 animations then we could split them like
[1,2], [3,4], [5,6], [7,8]
and throw each interval into its own process.Now this would mean that some calculations are done multiple times. While the process rendering [1,2] would have no overhead, the one rendering [3,4] would have to do the calculations of [1,2] before it can start rendering. However those calculations are usually very, very short compared to the rendering process, so that's not really much of an issue.
Last but not least, we'll want this multiprocessing to be an option, not replacing the current way of serial rendering. Aside from making sure we have options if something ever causes issues, some people use manim to render stuff that is actually very heavy in calculations, like fractals. For those cases multiprocessing could actually be actively detrimental, and aside from just needlessly hogging computing power could also overflow the RAM. So multiprocessing shouldn't be on by default, but when it's in we should make sure everyone knows it's there. Maybe even drop a small message every time manim runs with just 1 process.
The text was updated successfully, but these errors were encountered: