Multi-threaded tasks, external multi-threaded code, avoiding oversubscription

Regarding the new tread scheduler and external code that uses threads (discussed a lot at JC19) - just a thought I had, no idea if it’s feasible:

What if a partr task could (optionally) request more than one thread? Kinda like requesting a multi-threaded job on a batch cluster? Depending on the external multi-threaded code, those threads could then just stay blocked until the Julia task (and therefore the external code) are done - some external code may even allow for utilizing the blocked threads directly, if it’s C-API has a mechanism for passing (system) thread-ids.

Just an idea, I realize that this is a complex issue.

1 Like

You raise a good point, that I think will also be relevant to figure out how to get multithreaded BLAS calls to play nicely with native Julia tasks. I suppose having a way to link multiple tasks together as a single scheduled unit would be one approach. Another would be to just clone a single task onto multiple threads.

Yes, BLAS would be an obvious candidate - though it seems (discussions at JuliaCon) that a deeper/custom integration may be possible for BLAS and FFTW. However, for less common external code (e.g. some typical scientific multithreaded C-code written by generations of Phd students, code that no one dares touch anymore :slight_smile: ) a simple method of “blocking” multiple Julia threads while the external threads run would be extremely helpful.