<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Correct</div><div><br></div><div>-Steve<br></div><div><br>On Oct 30, 2013, at 3:18 AM, Ilya Sazonov <<a href="mailto:poxvuibr@gmail.com">poxvuibr@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div><div><div>Sorry, i made the code as short as I could to ask the question and it looks broken now :(.<br></div>It should have been something like:<br><br>import std.parallelism;<br><br>void main() {<br>    int[] data = new int[1000_000_00];<br>
    int[] new_data = new int[1000_000_00];<br><br>    foreach(i, ref el; parallel(new_data)) {<br>        if (i > 10 && i < 1000_000_00 - 10)<br>            el = data[i-10] + data[i+10];<br>    }<br>}<br><br>
</div>I read from one array and write results to another.<br><br><br></div><div>Thank you for your answer, it solved my issue, I didn't know about slices.<br></div><div>Am I right, than I'll have to add an offset to index, because foreach always starts with zero?<br>
Like that?<br>    foreach(i, ref el; parallel(new_data[10..$-10)) {<br>         el = data[i + 10 -10] + data[i + 10 +10];<br>    }<br></div><div><br>Or there is some way to start foreach with specified index? <br></div><div>
<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Oct 30, 2013 at 12:56 AM, Steven Schveighoffer <span dir="ltr"><<a href="mailto:schveiguy@yahoo.com" target="_blank">schveiguy@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Right, I didn't check over the full code.<br>
<br>
The code is broken with or without my change, but with my change it's shorter broken code :)<br>
<br>
-Steve<br>
<div class="HOEnZb"><div class="h5"><br>
On Oct 29, 2013, at 4:33 PM, Brad Roberts <<a href="mailto:braddr@puremagic.com">braddr@puremagic.com</a>> wrote:<br>
<br>
> That will eliminate the if, but over looks a larger issue.. parallel assumes that there's no interdependencies and that the order of execution is irrelevant.  That's very much not the case in the code below.  Each value in that code depends on other elements.  Unless you notice that all values are 0 and can thus just be replaced with the foreach entirely removed.<br>

><br>
> On 10/29/13 6:41 AM, Steven Schveighoffer wrote:<br>
>> Slice it.<br>
>><br>
>> foreach(i, ref el; parallel(data[10..$-10]))<br>
>><br>
>> -Steve<br>
>><br>
>> On Oct 29, 2013, at 3:49 AM, Ilya Sazonov <<a href="mailto:poxvuibr@gmail.com">poxvuibr@gmail.com</a>> wrote:<br>
>><br>
>>> Suppose I have the following piece of code<br>
>>><br>
>>> import std.parallelism;<br>
>>><br>
>>> void main() {<br>
>>>     int[] data = new int[1000_000_00];<br>
>>><br>
>>>     foreach(i, ref el; parallel(data)) {<br>
>>>         if (i > 10 && i < 1000_000_00 - 10)<br>
>>>             data[i] = data[i-10] + data[i+10];<br>
>>>     }<br>
>>> }<br>
>>><br>
>>> That's right, I want to process all the elements of the array, except for first 10 and last 10.<br>
>>> Is there a way to do that without if statement?<br>
>>><br>
>>> I mean something like foreach starting from element with index 10 and ending with lendth - 10<br>
>>><br>
><br>
> _______________________________________________<br>
> dmd-concurrency mailing list<br>
> <a href="mailto:dmd-concurrency@puremagic.com">dmd-concurrency@puremagic.com</a><br>
> <a href="http://lists.puremagic.com/mailman/listinfo/dmd-concurrency" target="_blank">http://lists.puremagic.com/mailman/listinfo/dmd-concurrency</a><br>
<br>
_______________________________________________<br>
dmd-concurrency mailing list<br>
<a href="mailto:dmd-concurrency@puremagic.com">dmd-concurrency@puremagic.com</a><br>
<a href="http://lists.puremagic.com/mailman/listinfo/dmd-concurrency" target="_blank">http://lists.puremagic.com/mailman/listinfo/dmd-concurrency</a><br>
</div></div></blockquote></div><br></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>dmd-concurrency mailing list</span><br><span><a href="mailto:dmd-concurrency@puremagic.com">dmd-concurrency@puremagic.com</a></span><br><span><a href="http://lists.puremagic.com/mailman/listinfo/dmd-concurrency">http://lists.puremagic.com/mailman/listinfo/dmd-concurrency</a></span></div></blockquote></body></html>