<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jan 25, 2012, at 6:32 PM, Peter Brinkmann wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><br><br><div class="gmail_quote">On Wed, Jan 25, 2012 at 5:38 PM, Charles Henry <span dir="ltr">&lt;<a href="mailto:czhenry@gmail.com">czhenry@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div></div><div class="h5">On Wed, Jan 25, 2012 at 11:46 AM, Peter Brinkmann<br>
&lt;<a href="mailto:peter.brinkmann@googlemail.com">peter.brinkmann@googlemail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; Hi Chuck,<br>
&gt; Check out the early bits of this thread --- various use cases already came<br>
&gt; up along the way:<br>
&gt; <a href="http://lists.puredata.info/pipermail/pd-dev/2012-01/017992.html" target="_blank">http://lists.puredata.info/pipermail/pd-dev/2012-01/017992.html</a>.&nbsp; The short<br>
&gt; version is that libpd is being used in such a wide range of settings that<br>
&gt; you can come up with legitimate use cases for pretty much anything (single<br>
&gt; Pd instance shared between several threads, multiple Pd instances in one<br>
&gt; thread, and anything in between).&nbsp; At the level of the audio library, it's<br>
&gt; impossible to make good assumptions about threading.<br>
<br>
Hi Peter<br>
<br>
That's the part I really don't understand, and I don't really have a<br>
clear picture of how you want to be able to control/choose between<br>
those cases.<br></div></div></blockquote><div><br>Neither do I.&nbsp; That's sort of the point here ;)&nbsp; When it comes to libpd, all sorts of common assumptions go right out the window; a libpd-based application may not be interactive, or real-time, and it may not even run on any familiar hardware (there have been reports of libpd running on an embedded system, for instance).&nbsp; The upshot is that libpd should only be in the business of processing samples and exchanging messages with client code; all other decisions should be made at another level, where more specific information is available.<br>
&nbsp;</div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="h5">
I can also see how there could be more capabilities tied to having<br>
multiple threads generally. &nbsp; &nbsp;But specifically, I can't say. &nbsp;I have<br>
no clue.<br>
<br>
&gt;&gt; I remember a conversation with IOhannes in August about<br>
&gt;&gt; multi-threading audio via sub-canvas user interface object (propose<br>
&gt;&gt; thread~ akin to block~). &nbsp;If all you're after is audio<br>
&gt;&gt; multi-threading--there's no need for multiple instances of Pd.<br>
&gt;&gt; Threads could be used to start a portion of the dsp chain, running<br>
&gt;&gt; asynchronously, and then join/synchronize with Pd when finished.<br>
&gt;<br>
&gt;<br>
&gt; I don't think a patch is the place where decisions about threading should be<br>
&gt; made.&nbsp; Threading is an implementation detail that users shouldn't have to<br>
&gt; worry about, and besides, whether you have anything to gain from threading<br>
&gt; will depend on a number of factors that users won't necessarily be able to<br>
&gt; control or even know about.<br>
<br>
I have a different view. &nbsp;Every sort of use for Pd is like writing a<br>
program--you should assume Pd users are writing programs with every<br>
sort of tool you give them--the flipside to having to control<br>
threading explicitly is that you get to control how finely grained the<br>
threading is. &nbsp;Putting it on the patching level is just the user<br>
interface--and it can work out nicely for grouping. &nbsp;Even if you have<br>
some automatic tools, you may still want to have explicit control<br>
through another available interface (e.g. for debugging).<br></div></div></blockquote><div><br>I don't think users have anything to gain from fine-grained control of threads.&nbsp; That seems like an optimization hint that may or may not be helpful, depending on a lot of factors that are not obvious and will differ from machine to machine.&nbsp; In any case, I don't want to have to think about threads when patching any more than I want to think about, say, NEON optimizations.<br>
&nbsp;</div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="h5">
<br>
&gt; I believe it's much simpler than that.&nbsp; It should be enough to just do a<br>
&gt; topological sort of the signal processing graph; that'll tell you which<br>
&gt; objects are ready to run at any given time, and then you can parallelize the<br>
&gt; invocation of their perform functions (or not, depending on how many<br>
&gt; processors are available).&nbsp; I don't think there's any need to explicitly<br>
&gt; synchronize much; tools like OpenMP should be able to handle this<br>
&gt; implicitly.<br>
&gt; Cheers,<br>
&gt; &nbsp;&nbsp;&nbsp;&nbsp; Peter<br>
<br>
For that--the dspchain (an array of int*) makes a very bad structure.<br>
So, you'll want to re-write a handful of functions and data structures<br>
around having multiple concurrent branches of computations. &nbsp;I<br>
actually really like this problem :D &nbsp;I can picture a linked list of<br>
dspchains to do this. &nbsp;But... the description of the sort algorithm<br>
really will determine what the data structure ought to be.<br></div></div></blockquote><div><br>Hmm, I think that's a pretty standard scheduling problem.&nbsp; All the necessary information is already in Pd, and it's being used when dsp_chain is computed.&nbsp; It's just a matter of representing it as a dependency tree rather than a list, and then traversing the tree in the correct order.<br>
<br>The real question is whether there's anything to gain from this at all, or whether the overhead from parallelization will destroy any gains.&nbsp; I always remember the cautionary tale of a complex system that was carefully designed to work with an arbitrary number n of threads, until it was profiled and the designers found that it works best when n == 1.<br></div></div></blockquote></div><div><br class="webkit-block-placeholder"></div><div><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>What I see as the most difficult challenge of parallelizing Pd dsp processing is how to ensure it remains deterministic. &nbsp;That seems like it would add a lot of overhead. &nbsp;The pd~ model seems like a good compromise: it allows you to break up patches into sections that will run on separate execution units, while providing only basic attempts at guaranteeing deterministic execution. &nbsp;So that means, for example, your audio can be on one CPU, your video on another, yet each logical chunk is all running together as one process.</div><div><br></div><div>.hc</div><div><br class="Apple-interchange-newline">----------------------------------------------------------------------------<br></div></div><div style="font-size: medium; "><br></div></div></span>“We must become the change we want to see. - Mahatma Gandhi</span>
</div>
<br></body></html>