File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ (* Copied from https://github.com/kayceesrk/ocaml5-tutorial *)
2+ module T = Domainslib. Task
3+
4+ let rec fib0 n = if n < 2 then 1 else fib0 (n - 1 ) + fib0 (n - 2 )
5+
6+ let rec fib_par pool n =
7+ if n > 20 then begin
8+ let a = T. async pool (fun _ -> fib_par pool (n - 1 )) in
9+ let b = T. async pool (fun _ -> fib_par pool (n - 2 )) in
10+ T. await pool a + T. await pool b
11+ end else fib0 n
12+
13+ let fib num_domains n =
14+ let pool = T. setup_pool ~num_domains: (num_domains - 1 ) () in
15+ let res = T. run pool (fun _ -> fib_par pool n) in
16+ T. teardown_pool pool;
17+ res
Original file line number Diff line number Diff line change 1+ open OUnit
2+
3+ let suite = [
4+ " fib tests" > :::
5+ [
6+ " Testing 42 (1 domain)" > :: (fun _ -> assert_equal 433494437 (Solution. fib 1 42 ) ~printer: string_of_int);
7+ " Testing 42 (2 domains)" > :: (fun _ -> assert_equal 433494437 (Solution. fib 2 42 ) ~printer: string_of_int);
8+ " Testing 42 (3 domains)" > :: (fun _ -> assert_equal 433494437 (Solution. fib 3 42 ) ~printer: string_of_int);
9+ " Testing 42 (4 domains)" > :: (fun _ -> assert_equal 433494437 (Solution. fib 4 42 ) ~printer: string_of_int);
10+ ];
11+ ]
You can’t perform that action at this time.
0 commit comments