sliced().array compatibility with parallel?

Jay Norwood via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 9 17:46:03 PST 2016


On Sunday, 10 January 2016 at 00:47:29 UTC, Ilya Yaroshenko wrote:
> This is a bug in std.parallelism :-)

ok, thanks.  I'm using your code and reduced it a bit.  Looks 
like it has some interaction with executing vec.sum.  If I 
substitute a simple assign of a double value, then all the values 
are updated in the parallel version also.


import std.algorithm;

double[1000] dvp;
double[1000] dv2;
double[] data;

void f1() {
     import std.parallelism;
     auto sla = new double[][1000];
     foreach(i, ref e; sla)
     {
         e = data[i * 100_000 .. (i+1) * 100_000];
     }

     // calculate sums in parallel
     foreach(i, vec; parallel(sla)){
         dvp[i] = vec.sum;
     }

     // calculate same values non-parallel
     foreach(i, vec; sla){
         dv2[i] = vec.sum;
     }
}

int main() {
     data = new double[100_000_000];
     for(int i=0;i<100_000_000;i++){ data[i] = i/100_000_000.0;}
     f1();

     // processed non-parallel works ok
     foreach( dv; dv2){
         if(dv != dv){ // test for NaN
             return 1;
         }
     }

     // calculated parallel leaves out processing of many values
     foreach( dv; dvp){
         if(dv != dv){ // test for NaN
             return 1;
         }
     }
     return(0);
}


More information about the Digitalmars-d-learn mailing list