output

phil@d64:~/oc4mc/tests/Threads/Join$ time ./compute3.exe ; echo ; echo "========" ; echo ; time ./compute3.exe_orig 
start of 1
start of 2
start of 3
start of 4
start of 5
start of 6
start of 8
start of 7
end of 1
end of 7
end of 8
end of 3
end of 4
end of 6
end of 5
end of 2
end of all!

real	0m30.740s
user	2m7.312s
sys	0m0.392s

========

start of 1
start of 2start of 3start of 4start of 5
start of 6
start of 8
start of 7



end of 1
end of 3
end of 8end of 6
end of 4

end of 2
end of 7
end of 5
end of all!

real	4m45.049s
user	4m41.454s
sys	0m4.456s

compute3.ml

 
 
let id = ref 0
 
let compute () =
  let x = incr id ; !id in
  print_endline ("start of " ^ string_of_int x);
  Thread.yield ();
  let t = Array.make 1_000_000 0. in
  flush stdout;
  Thread.yield ();
  List.iter
    Thread.join
    (List.map
     (fun e -> Thread.create e ())
     (List.map
       (fun _ e ->
         for z = 0 to 100 do
	   Thread.yield();
           for i = 0 to Array.length t - 1 do
             t.(i|>) <- t.(i|>) *. t.(i|>) +. 42.;
             t.(i|>) <- t.(i|>) *. t.(i|>) +. 42.;
             t.(i|>) <- t.(i|>) *. t.(i|>) +. 42.;
             t.(i|>) <- t.(i|>) *. t.(i|>) +. 42.;
	     t.(i|>) <- t.(i|>) *. t.(i|>) +. 42.;
             t.(i|>) <- t.(i|>) *. t.(i|>) +. 42.
           done;
         done)
      [1;2;3;4;5;6;7;8;9;10;]));
  print_endline ("end of " ^ string_of_int x);
  flush stdout;
  let t = Array.make 1_000_000 0 in
  Thread.yield ()
 
let _ =
  let l = List.map (Thread.create compute) [
     () ;
     () ;
     () ;
     () ;
     () ;
     () ;
     () ;
     () ;
  ]
  in List.map Thread.join l
 
 
let _ = print_endline "end of all!"
 
seatmark.txt · Last modified: 2009/02/02 15:00 by philippe