www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Parallel ranges, how?

reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
How does the current range system accommodate parallel iteration?

As far as I can see, a context switch could happen between calls to
popFront and front, thus popping a value off the range before we're
able to get its value.

-- 
Simen
May 22 2010
next sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Simen kjaeraas <simen.kjaras gmail.com> wrote:

 How does the current range system accommodate parallel iteration?

 As far as I can see, a context switch could happen between calls to
 popFront and front, thus popping a value off the range before we're
 able to get its value.

Anyone? It seems to me the system is not thread-safe, and a parallel range should have the functions lock() and unlock(), so a foreach would work basically like this: foreach( e; r ) { stuff(e); } => while(true) { r.lock(); if (r.empty) { unlock(); break; } auto e = r.front; r.popFront(); r.unlock(); stuff(e); } Note that this approach does not in any way protect access to the elements, only the range functions. -- Simen
May 30 2010
prev sibling next sibling parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
--0016e65b5f50f3083d0487d646b4
Content-Type: text/plain; charset=ISO-8859-1

On Sun, May 30, 2010 at 22:59, Simen kjaeraas <simen.kjaras gmail.com>wrote:

 Simen kjaeraas <simen.kjaras gmail.com> wrote:

  How does the current range system accommodate parallel iteration?
 As far as I can see, a context switch could happen between calls to
 popFront and front, thus popping a value off the range before we're
 able to get its value.

Anyone? It seems to me the system is not thread-safe, and a parallel range should have the functions lock() and unlock(), so a foreach would work basically like this:

I don't know if that'd help you, but did you have a look at David Simcha's parallelFuture module? http://cis.jhu.edu/~dsimcha/parallelFuture.html --0016e65b5f50f3083d0487d646b4 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <br><br><div class=3D"gmail_quote">On Sun, May 30, 2010 at 22:59, Simen kja= eraas <span dir=3D"ltr">&lt;<a href=3D"mailto:simen.kjaras gmail.com">simen= .kjaras gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote= " style=3D"margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, = 204); padding-left: 1ex;"> <div><div></div><div class=3D"h5">Simen kjaeraas &lt;<a href=3D"mailto:sime= n.kjaras gmail.com" target=3D"_blank">simen.kjaras gmail.com</a>&gt; wrote:= <br> <br> <blockquote class=3D"gmail_quote" style=3D"margin: 0pt 0pt 0pt 0.8ex; borde= r-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"> How does the current range system accommodate parallel iteration?<br> <br> As far as I can see, a context switch could happen between calls to<br> popFront and front, thus popping a value off the range before we&#39;re<br> able to get its value.<br> </blockquote> <br></div></div> Anyone? It seems to me the system is not thread-safe, and a parallel<br> range should have the functions lock() and unlock(), so a foreach<br> would work basically like this:<br></blockquote><div><br>I don&#39;t know i= f that&#39;d help you, but did you have a look at David Simcha&#39;s parall= elFuture module?<br><br><a href=3D"http://cis.jhu.edu/~dsimcha/parallelFutu= re.html">http://cis.jhu.edu/~dsimcha/parallelFuture.html</a><br> <br>=A0<br></div></div> --0016e65b5f50f3083d0487d646b4--
May 30 2010
prev sibling next sibling parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
--001636499fd1c788390487d651e8
Content-Type: text/plain; charset=ISO-8859-1

I don't know if that'd help you, but did you have a look at David Simcha's
parallelFuture module?

 http://cis.jhu.edu/~dsimcha/parallelFuture.html<http://cis.jhu.edu/%7Edsimcha/parallelFuture.html>

Gosh, dsimcha just made a post on it in the Phobos mailing list.That's what I'd call parallel and concurrent :-) --001636499fd1c788390487d651e8 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I don&#39;t know if that&#39;d help you, but did you have a look at David S= imcha&#39;s parallelFuture module?<br><div class=3D"gmail_quote"><blockquot= e class=3D"gmail_quote" style=3D"margin: 0pt 0pt 0pt 0.8ex; border-left: 1p= x solid rgb(204, 204, 204); padding-left: 1ex;"> <div class=3D"gmail_quote"><div><br><a href=3D"http://cis.jhu.edu/%7Edsimch= a/parallelFuture.html" target=3D"_blank">http://cis.jhu.edu/~dsimcha/parall= elFuture.html</a><br>=A0 <br></div></div></blockquote><div><br>Gosh, dsimcha just made a post on it = in the Phobos mailing list.That&#39;s what I&#39;d call parallel and concur= rent :-) <br><br><br></div></div><br> --001636499fd1c788390487d651e8--
May 30 2010
prev sibling next sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Philippe Sigaud <philippe.sigaud gmail.com> wrote:

 I don't know if that'd help you, but did you have a look at David  
 Simcha's
 parallelFuture module?

 http://cis.jhu.edu/~dsimcha/parallelFuture.html<http://cis.jhu.edu/%7Edsimcha/parallelFuture.html>

Gosh, dsimcha just made a post on it in the Phobos mailing list.That's what I'd call parallel and concurrent :-)

Yeah, I noticed as well. Got the message right after my post here. :p -- Simen
May 30 2010
prev sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Philippe Sigaud <philippe.sigaud gmail.com> wrote:
 I don't know if that'd help you, but did you have a look at David  
 Simcha's
 parallelFuture module?

 http://cis.jhu.edu/~dsimcha/parallelFuture.html

Looked at it now. It's not exactly what I was thinking. parallelFuture foes the foreach in one thread, and work in others, whereas my problem is that of iterating over the thread in two or more thread simultaneously, while giving each thread a unique selection of items. Not entirely sure this is a good way to do it, but it certainly is *a* way, and it may have its uses. -- Simen
May 30 2010