Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.78 KB | None | 0 0
  1. import std.stdio;
  2. import std.random;
  3. import std.concurrency;
  4. import std.c.time;
  5. T sum(T)(immutable T[] array) {
  6.     T sum = 0;
  7.     foreach(e; array) {
  8.         sum += e;
  9.     }
  10.     return sum;
  11. }
  12.  
  13. void main() {
  14.     int[] mas =  new int[](98000000);
  15.     foreach(ref e; mas) {
  16.         e = uniform(-20, 21);
  17.     }
  18.     auto p1 = cast(immutable) mas[0 .. $/2];
  19.     auto p2 = cast(immutable) mas[$/2 + 1 .. $];
  20.     auto s = time(null);
  21.     auto t1 = spawn(&tread, p1, thisTid);
  22.     auto t2 = spawn(&tread, p2, thisTid);
  23.     auto r1 = receiveOnly!(int);
  24.     auto r2 = receiveOnly!(int);
  25.     //auto r2 = sum(p2);
  26.     auto f = time(null);
  27.    
  28.     writeln(f - s);
  29.     writeln(r1 + r2);
  30. }
  31.  
  32. void tread(immutable int[] m, Tid parTid) {
  33.     auto res = sum(m);
  34.     send(parTid, res);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement