M
Modular15mo ago
Janks

Multi threading in Mojo

Hi I am new to mojo but I would really like to speed up my pipeline by doing what python can't, multi threading. Could someone show a simple example of multi threading? An example like calling the same function with different parameters at the same time to process data.
6 Replies
roopesh puthalath
Modular Docs - Mandelbrot in Mojo with Python plots
Learn how to write high-performance Mojo code and import Python packages.
santagada
santagada12mo ago
this is not multithreading right? this example uses simd instructions but there's no real user controllable threads. Are real independent multhithread support in mojo? Is it planned? What I mean is for cases where SIMD instructions are not enough or even usable, for example to run multiple syscalls, multiple sockets in a client/server application?
guidorice
guidorice12mo ago
In mojo, "parallelize" is the same as threading: https://docs.modular.com/mojo/notebooks/Mandelbrot.html#parallelizing-mandelbrot btw as an aside, it looks very well done- I was able to get ~ 100% utilization on all of my laptops cores in one code experiment https://docs.modular.com/mojo/stdlib/algorithm/functional.html
Modular Docs - Mandelbrot in Mojo with Python plots
Learn how to write high-performance Mojo code and import Python packages.
santagada
santagada12mo ago
it is not the same as threading, map maps an iterator and parallelize also take a width. I don't see any threads or semaphores or mutexes yet, so it seems you can't use mojo for general multi threading. At least it seems because it keeps saying it can everywhere, but I haven't seen a single example of two threads doing unrelated work. or channels or acotors or fibers... anything for real multi threading.
guidorice
guidorice12mo ago
@santagada yes that's a good point. I have been assuming that async_parallelize is how you would perform more heterogeneous threaded workloads, but I have not tried it (have not seen any code examples, either) . Definitely submit feature requests to https://github.com/modularml/mojo/issues/new/choose Somewhere it was stated that Mojo has a lightweight threading model, (maybe actors/channels/fibers?) but it seems kind of a black box currently.
GitHub
Build software better, together
GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 420 million projects.
guidorice
guidorice12mo ago
GitHub
[BUG]: async_parallelize segfault / docs improvement request · Issu...
Bug description Can some examples be published for async_parallelize and also OutputChainPtr? These are currently somewhat opaque, they are documented in the API docs, but there are no examples aro...
Want results from more Discord servers?
Add your server