I would like to understand, from the user point of view, the differences in multithreading programming models between Julia >= 1.3 and Python 3.
Is there one that is more efficient than the other (in the sense that rising the thread numbers reduces more the computational time) ? In which situations (e.g. one model may have an edge, but only on computational or memory intensive tasks) ?
Is one that is more practical/provide higher level functions than the other ?
Is one that is more flexible than the other (e.g. it can be applied to a wider set of cases) ?
Python doesn't support multi-threading because Python on the Cpython interpreter does not support true multi-core execution via multithreading. However, Python does have a threading library. The GIL does not prevent threading.
There exists three established multithreading models classifying these relationships are: Many to one multithreading model. One to one multithreading model. Many to Many multithreading models.
Starting Julia with multiple threadsWhen both are specified, then -t / --threads takes precedence. The number of threads can either be specified as an integer ( --threads=4 ) or as auto ( --threads=auto ), where auto sets the number of threads to the number of local CPU threads.
Many to One Model This model is quite efficient as the user space manages the thread management. A disadvantage of the many to one model is that a thread blocking system call blocks the entire process. Also, multiple threads cannot run in parallel as only one thread can access the kernel at a time.
There are several differences between the languages with Julia providing many levels of functionality on this what you can find in Python. You have the following types of parallelism (I am discussing here the standard language features not functionality available via external libraries):
@simd
with @inbounds
(see https://docs.julialang.org/en/v1/manual/performance-tips/)asyncio
(for more details see https://docs.python.org/3/library/asyncio-task.html)Julia: use Threads.@threads
macro to parallelize loops and Threads.@spawn
to launch tasks on separate system threads. Use locks or atomic values to control the parallel execution. (for more details see https://docs.julialang.org/en/v1/manual/parallel-computing/)
Python: not useful for CPU-dominated tasks due to GIL (global-interpreter-lock) (see the comment by @Jim below)
Julia: use macros from the Distibuted
package to parallelize loops and spawn remote processes (for more details see https://docs.julialang.org/en/v1/manual/parallel-computing/)
Python: use multiprocessing
library - for more details see https://docs.python.org/3.8/library/multiprocessing.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With