forked from kostya/benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatmul.tcl
51 lines (41 loc) · 1013 Bytes
/
matmul.tcl
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
package require Tcl 8.6
package require math::linearalgebra
proc generate {n seed} {
set M {}
set t [expr { $seed / $n / $n }]
for {set i 0} {$i < $n} {incr i} {
set v {}
for {set j 0} {$j < $n} {incr j} {
lappend v [expr { $t * ($i - $j) * ($i + $j) }]
}
lappend M $v
}
return $M
}
proc calc n {
set size [expr int($n / 2) * 2]
set A [generate $size 1.0]
set B [generate $size 2.0]
set C [::math::linearalgebra::matmul $A $B]
set halfN [expr { $size / 2 }]
return [lindex $C $halfN $halfN]
}
proc notify msg {
catch {
set sock [socket "localhost" 9001]
puts $sock $msg
close $sock
}
}
apply {{{n 100}} {
set left [calc 101]
set right -18.67
if {[expr abs($left - $right)] > 0.1} {
puts stderr [format "%f != %f" $left $right]
exit 1
}
notify [format "%s\t%d" "Tcl" [pid]]
set results [calc $n]
notify "stop"
puts $results
}} {*}$argv