On Sunday, 10 January 2016 at 01:54:18 UTC, Jay Norwood wrote:
ok, thanks.  That works. I'll go back to trying ndslice now.

The parallel time for this case is about a 2x speed-up on my corei5 laptop, debug build in windows32, dmd.

D:\ec_mars_ddt\workspace\nd8>nd8.exe
parallel time msec:2495
non_parallel msec:5093

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

shared double[1000] means;
double[] data;

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

void f2() {
    auto sl = data.sliced(1000,100_000);
    foreach(i,vec; sl.array){
        means[i] = vec.sum / 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;}
    StopWatch sw1, sw2;
    sw1.start();
    f1() ;
    auto r1 = sw1.peek().msecs;
    sw2.start();
    f2();
    auto r2 = sw2.peek().msecs;

    writeln("parallel time msec:",r1);
    writeln("non_parallel msec:", r2);
}


Reply via email to