File: simplescale.ml

package info (click to toggle)
parmap 1.2.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 356 kB
  • sloc: ml: 1,329; ansic: 132; makefile: 21
file content (114 lines) | stat: -rw-r--r-- 4,313 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
(**************************************************************************)
(* Sample use of Parmap, a simple library to perform Map computations on  *)
(* a multi-core                                                           *)
(*                                                                        *)
(*  Author(s):  Roberto Di Cosmo                                          *)
(*                                                                        *)
(*  This program is free software: you can redistribute it and/or modify  *)
(*  it under the terms of the GNU General Public License as               *)
(*  published by the Free Software Foundation, either version 2 of the    *)
(*  License, or (at your option) any later version.                       *)
(**************************************************************************)

open Parmap
open Utils
let initsegm n = let rec aux acc = function 0 -> acc | n -> aux (n::acc) (n-1) in aux [] n
;;

let compute p = 
  let r=ref 1 in 
  for i = 1 to 80000 do 
    r:= !r+(p*p)-(p*(p-1))
  done;
  !r
;;

let fcompute p = 
  let r=ref 1. in 
  for i = 1 to 80000 do 
    r:= !r+.(p*.p)-.(p*.(p-.1.))
  done;
  !r
;;

Printf.printf "*** Checking corner cases: call on empty lists and arrays must not raise an exception\n%!";
Printf.printf "*   parmap []\n%!";
parmap (fun x -> x) (L []);;
Printf.printf "*   parmap [| |]\n%!";
parmap (fun x -> x) (A [| |]);;
Printf.printf "*   pariter []\n%!";
pariter (fun x -> ()) (L []);;
Printf.printf "*   pariter [| |]\n%!";
pariter (fun x -> ()) (A [| |]);;


Printf.printf "*** Checking the code for non tail recursive calls: an exception here indicates there are some left\n%!";
scale_test (fun x -> x) (L (initsegm 10000000)) 1 2 2;;


Printf.printf "*** Checking that we properly parallelise execution if we have less tasks than cores: if you do not see 5 processes, there is a problem\n%!";

debugging true;;

(* scale_test (fun x -> x) (L (initsegm 5)) 1 8 8;; *)

Printf.printf "*   Simplemapper 8 cores, 5 elements\n%!";
ignore(parmap ~ncores:8 (fun x -> x) (L (initsegm 5)));;

Printf.printf "*   Simpleiter 8 cores, 5 elements\n%!";
ignore(pariter ~ncores:8 (fun x -> ()) (L (initsegm 5)));;

Printf.printf "*** Checking that we properly handle bogus core numbers\n%!";
Printf.printf "*   Simplemapper 0 cores\n%!";

ignore(parmap ~ncores:0 (fun x -> x) (L (initsegm 5)));;

Printf.printf "*   Simpleiter 0 cores\n%!";
ignore(pariter ~ncores:0 (fun x -> ()) (L (initsegm 5)));;

debugging false;;

Printf.printf "*** Computations on integer lists\n%!";

scale_test compute (L (initsegm 20000)) 2 1 10;;

Printf.printf "*** Computations on integer lists (chunksize=100, keeporder=false)\n%!";

scale_test ~chunksize:100 ~inorder:false compute (L (initsegm 20000)) 2 1 10;;

Printf.printf "*** Computations on integer lists (chunksize=100, keeporder=true)\n%!";

scale_test ~chunksize:100 ~keeporder:true compute (L (initsegm 20000)) 2 1 10;;

Printf.printf "*** Computations on integer arrays\n%!";

scale_test compute (A (Array.init 20000 (fun n -> n+1))) 2 1 10;;

Printf.printf "*** Computations on integer arrays (chunksize=100, keeporder=false)\n%!";

scale_test ~chunksize:100 ~inorder:false compute (A (Array.init 20000 (fun n -> n+1))) 2 1 10;;

Printf.printf "*** Computations on integer arrays (chunksize=100, keeporder=true)\n%!";

scale_test ~chunksize:100 ~keeporder:true compute (A (Array.init 20000 (fun n -> n+1))) 2 1 10;;

Printf.printf "*** Computations on lists of floats\n%!";

scale_test fcompute (L (List.map float_of_int (initsegm 20000))) 2 1 10;;

Printf.printf "*** Computations on lists of floats (chunksize=100, keeporder=false)\n%!";

scale_test  ~chunksize:100 ~inorder:false fcompute (L (List.map float_of_int (initsegm 20000))) 2 1 10;;

Printf.printf "*** Computations on lists of floats (chunksize=100, keeporder=true)\n%!";

scale_test  ~chunksize:100 ~keeporder:true fcompute (L (List.map float_of_int (initsegm 20000))) 2 1 10;;

Printf.printf "*** Computations on arrays of floats\n%!";

scale_test fcompute (A (Array.init 20000 (fun n -> float_of_int (n+1)))) 2 1 10;;

Printf.printf "*** Computations on arrays of floats (chunksize=100)\n%!";

scale_test  ~chunksize:100 ~inorder:false fcompute (A (Array.init 20000 (fun n -> float_of_int (n+1)))) 2 1 10;;