-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
mul.flx
42 lines (32 loc) · 983 Bytes
/
mul.flx
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
include "std/pthread/threadpool";
var x : (double ^ 2000) ^ 2000;
for i in 0..<2000 for j in 0..<2000 perform &x.i.j <- 2.0;
var r : (double ^ 2000) ^ 2000;
for i in 0..<2000 for j in 0..<2000 perform &r.i.j <- 1.0;
fun inner_product (pr: &(double^2000), pc: &(double^2000)) =
{
var sum = 0.0;
for (var k=0; k<2000; ++k;) do
sum = sum + *(pr.k) * *(pc.k);
done
return sum;
}
noinline proc inner_products_proc (var i:int)
{
for (var j=0; j<2000; ++j;) do
var sum = inner_product (&x.i, &x.j);
// should be 400 = 2000 x 2 * 2
&r . j . i <- sum;
done
}
println $ "Starting";
var start= system_clock_now();
for k in 0 .. 1999 perform inner_products_proc k;
var fin = system_clock_now();
println$ "Single thread Done " + (fin - start).double.str;
start = system_clock_now();
ThreadPool::pforloop 0 1999 inner_products_proc;
fin = system_clock_now();
println$ "Thread pool Done " + (fin - start).double.str;
//println$ r;
ThreadPool::stop();