News for hackers. Stuff that matters.
Re:Composable multi-threaded parallelism in Julia by opportune on Tuesday July 23, 2019 @07:38PM (#20511175)
I really dislike using Tasks over threads due to the reusability issues. Specifically that Tasks are not reusable and threads are. It makes parallel computational work a headache, because you need to implement the reusability in a higher scope than tasks, then make an effort to prevent race-conditions, double checkouts, etc.

Tasks are really meant for responsive computing, not proactive computing (yes, even TPL and Dataflow), and thus I don't think they are well suited to parallelized computation in areas like e.g. simulation.

Re:Composable multi-threaded parallelism in Julia by minxomat on Tuesday July 23, 2019 @09:05PM (#20511560)
When a program is composed as a Dataflow pipeline, you don't handle tasks at all (unless you want to). I'm not sure what reusability issues you're referring to. Dataflow is very applicable to high CPU-throughput (i.e. efficient) pipelines. Concurrent by default, parallel on-demand. In practice, any I/O in my pipelines takes place in singleton consumers at the end of complex, highly-parallel, CPU-intensive code.

C# code that uses Tasks and C# programs built on Dataflow are very different. The latter benefits you most when you commit entirely to that paradigm.

If you want to get more low-level, low-overhead (for i.e. simulations), the same thing applies to things like Threading Building Blocks[1] in C++. I'd even argue that TBB is one of the best applications of this theory, going so far as to ship with dedicated tooling for the whole lifecycle of designing to implementing to profiling task- and graph-parallel programs [2]. Furthermore, it works well with other HPC libraries. Here [3] is an example of mixing it with OpenMP.

In summary, both Dataflow and TBB (et al) can readily be used to create CPU-intensive, proactive computing pipelines today. Even though they're "just" fancy Task schedulers, which are in turn "just" fancy thread multiplexers.

[1] - https://www.threadingbuildingblocks.org/tutorial-intel-tbb-f...

[2] - https://www.youtube.com/watch?v=9bBqFW5hnVM

[3] - https://software.intel.com/en-us/node/506128

Re:Composable multi-threaded parallelism in Julia by manigandham on Tuesday July 23, 2019 @08:58PM (#20511519)
What do you mean by reusable exactly? And how does proactive computing differ? Do you have an example you can share?
Re:Composable multi-threaded parallelism in Julia by opportune on Tuesday July 23, 2019 @10:20PM (#20511925)
Reusable as in, I can create a datastructure in a thread, do some computation, yield control from the thread (wait for something else to tell it to go again), then come back to the thread with the same datastructure and keep going. With Tasks, you are supposed to let tasks complete rather than let them pause/sync so anything you declare locally is lost when you want to restart it. The workaround is to declare things in a higher scope and pass them into tasks as they are reran - this makes tasks not suited to things where you want to persist data, since tasks are opinionated in that they are only meant to contain logic, not state, so you have to add your own external logic to manage the allocation of state to the tasks that you keep recreating

This trait of tasks makes sense when writing things like web servers because it prevents developers from shooting themselves in the foot by writing something that isn't stateless.

By proactive computing, I mean some program that always has control of the entire execution graph. For example, a simulation may initialize a bunch of datastructures, separate some of them into threads, run the threads, wait for all of them to complete x ticks, do some synchronization or measurement of the total system, then continue y times, and exit.

Re:Composable multi-threaded parallelism in Julia by DNF2 on Wednesday July 24, 2019 @03:37AM (#20513058)
What would be the purpose of yielding control from the thread and tell it to wait, rather than just let it run to completion?
Re:Composable multi-threaded parallelism in Julia by ska on Wednesday July 24, 2019 @01:44PM (#20517643)
Sometimes you don't know where you want to spend your CPU budget until you have more information.
Re:Composable multi-threaded parallelism in Julia by DNF2 on Wednesday July 24, 2019 @02:02PM (#20517864)
Maybe I misunderstand you, but telling the thread to halt is surely a waste of those resources?
Re:Composable multi-threaded parallelism in Julia by opportune on Wednesday July 24, 2019 @04:22PM (#20519250)
Because sometimes you need to sync the entire program state, or some subset of the state, to make measurements or to let disparate parts of the system interact