Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- import std.random;
- import std.concurrency;
- import std.c.time;
- T sum(T)(immutable T[] array) {
- T sum = 0;
- foreach(e; array) {
- sum += e;
- }
- return sum;
- }
- void main() {
- int[] mas = new int[](98000000);
- foreach(ref e; mas) {
- e = uniform(-20, 21);
- }
- auto p1 = cast(immutable) mas[0 .. $/2];
- auto p2 = cast(immutable) mas[$/2 + 1 .. $];
- auto s = time(null);
- auto t1 = spawn(&tread, p1, thisTid);
- auto t2 = spawn(&tread, p2, thisTid);
- auto r1 = receiveOnly!(int);
- auto r2 = receiveOnly!(int);
- //auto r2 = sum(p2);
- auto f = time(null);
- writeln(f - s);
- writeln(r1 + r2);
- }
- void tread(immutable int[] m, Tid parTid) {
- auto res = sum(m);
- send(parTid, res);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement