__gshared size_t[] values1;
__gshared size_t[] values2;
__gshared size_t[] results;
immutable SIZE = 1024*1024;
import std.random : uniform;
values1[i] = uniform(1,100);
values2[i] = uniform(1,100);
results[i] = values1[i] * values2[i];
import std.parallelism: parallel;
foreach(i ; iota(0,SIZE).parallel)
results[i] = values1[i] * values2[i];
import std.concurrency: spawn;
import std.parallelism: totalCPUs;
import core.thread: thread_joinAll;
auto chunk = SIZE / totalCPUs;
foreach( cpu ; 0 .. totalCPUs )
auto start = cpu * chunk;
auto end = (cpu + 1) * chunk;
spawn((size_t start, size_t end)
foreach(i ; start .. end )
results[i] = values1[i] * values2[i];
import std.parallelism: totalCPUs;
import core.thread: Thread, thread_joinAll;
foreach(i ; _start .. _end )
results[i] = values1[i] * values2[i];
auto chunk = SIZE / totalCPUs;
foreach( cpu ; 0 .. totalCPUs )
auto start = cpu * chunk;
auto end = (cpu + 1) * chunk;
new MyThread(start,end).start;
import std.datetime.stopwatch: benchmark;
import std.random: uniform;
import std.stdio : print = writeln;
auto r = benchmark!( _base, _parallel, _concurrency, _thread )(64);
print("_parallel : ", r[1]);
print("_concurrency : ", r[2]);
print("_thread : ", r[3]);