r/pythontips • u/DnDeeker • Sep 19 '22
Module Use all cores when Multiprocessing?
I’m working on a quad-core Jetson Nano, and I want to split the tasks in a pipeline into processes. Can I safely use four processes, or should one core be left to run the main Python file that manages the processes?
3
u/saltyhasp Sep 19 '22
Other way is to keep adding processes until your throughput stops rising significantly or until your computer is too slow to do interactive work.
Every system is different and every work load is different. I use to use a high end compute cluster that limited clock speed based on thermal load so for one of my work loads it actually ran faster to leave some cores idle. Then there is the whole hyperthreading thing. Often does not make sense to use more cores then true cores not hyper threads.
0
u/ApatheistHeretic Sep 19 '22
Is it still limited by the GIL?
3
6
u/steil867 Sep 19 '22
In short, you can run more than 4 if your computer has resources to run all of them.
You won't be limited to processes by cores. Your OS will manage the distribution of resources/CPU cycles for processes. Think of opening chrome, Spotify, a python script, teams, and a text editor. Although you only have 4 cores, you can open and operate many more programs. Often a computer, at least with windows, will have dozens running at any time.
You are thinking of threading which is a different concept. That is running different parts of the same program across multiple threads/cores all using a shared memory.
Multiprocessing will create a completely independent program that'll run independently. It will still use your computers resources but would be the same as opening chrome while your program runs. Linking via pipes is a bit different than sharing memory as well as this is essentially a communication between programs using a file.
Hope this helps.