I'm playing around with win32, v2.069.2 dmd and "dip80-ndslice": "~>0.8.8". If I convert the 2D slice with .array(), should that first dimension then be compatible with parallel foreach?

I find that without using parallel, all the means get computed, but with parallel, only about half of them are computed in this example. The others remain NaN, examined in the debugger in Visual D.

import std.range : iota;
import std.array : array;
import std.algorithm;
import std.datetime;
import std.conv : to;
import std.stdio;
import std.experimental.ndslice;

enum testCount = 1;
double[1000] means;
double[] data;

void f1() {
 import std.parallelism;
 auto sl = data.sliced(1000,100_000);
 auto sla = sl.array();
 foreach(i,vec; parallel(sla)){
  double v=vec.sum(0.0);
  means[i] = v / 100_000;
 }
}

void main() {
 data = new double[100_000_000];
 for(int i=0;i<100_000_000;i++){ data[i] = i/100_000_000.0;}
 auto r = benchmark!(f1)(testCount);
 auto f0Result = to!Duration(r[0] / testCount);
 f0Result.writeln;
 writeln(means[0]);
}

Reply via email to