~ubuntu-branches/ubuntu/trusty/ocamlnet/trusty

« back to all changes in this revision

Viewing changes to examples/rpc/matrixmult/simple.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu
  • Date: 2011-09-02 14:12:33 UTC
  • mfrom: (18.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110902141233-zbj0ygxb92u6gy4z
Tags: 3.4-1
* New upstream release
  - add a new NetcgiRequire directive to ease dependency management
    (Closes: #637147)
  - remove patches that were applied upstream:
    + Added-missing-shebang-lines-in-example-shell-scripts
    + Try-also-ocamlc-for-POSIX-threads

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(* For comparison: a non-clustered multiplication *)
 
2
 
 
3
open Printf
 
4
 
 
5
let fill m rows cols =
 
6
  for j = 0 to rows-1 do
 
7
    for k = 0 to cols-1 do
 
8
      m.(j).(k) <- Random.float 1.0
 
9
    done
 
10
  done
 
11
 
 
12
 
 
13
let test lrows rcols rrows =
 
14
  let lcols = rrows in
 
15
  let lmatrix = Array.make_matrix lrows lcols 0.0 in
 
16
  let rmatrix = Array.make_matrix rrows rcols 0.0 in
 
17
  fill lmatrix lrows lcols;
 
18
  fill rmatrix rrows rcols;
 
19
  let res = Array.make_matrix rrows lcols 0.0 in
 
20
 
 
21
  for row = 0 to rrows-1 do
 
22
    for col = 0 to lcols - 1 do
 
23
      let s = ref 0.0 in
 
24
      for j = 0 to lrows-1 do
 
25
        s := !s +. lmatrix.(j).(col) *. rmatrix.(row).(j)
 
26
      done;
 
27
      res.(row).(col) <- !s
 
28
    done
 
29
  done
 
30
 
 
31
 
 
32
let main() =
 
33
  Random.self_init();
 
34
 
 
35
  let lrows = ref 1000 in
 
36
  let rcols = ref 1000 in
 
37
  let rrows = ref 1000 in
 
38
  Arg.parse
 
39
    [ "-size", Arg.Tuple [ Arg.Set_int lrows;
 
40
                           Arg.Set_int rcols;
 
41
                           Arg.Set_int rrows
 
42
                         ],
 
43
      "<P> <Q> <R>   Size of test: Multiply a PxR with a RxQ matrix"
 
44
    ]
 
45
    (fun arg -> raise(Arg.Bad("Bad argument: " ^ arg)))
 
46
    (sprintf "usage: %s <options>" Sys.argv.(0));
 
47
 
 
48
  test !lrows !rcols !rrows
 
49
 
 
50
 
 
51
let () =
 
52
  main()