-
Notifications
You must be signed in to change notification settings - Fork 258
/
Copy pathmatmul.jl
58 lines (50 loc) · 1.12 KB
/
matmul.jl
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
using Sockets
function matgen(n, seed)
tmp = seed / n / n
[tmp * (i - j) * (i + j - 2) for i = 1:n, j = 1:n]
end
function mul(a, b)
c = zeros(size(a, 1), size(b, 2))
M, N = size(c)
K = size(b, 1)
@inbounds Threads.@threads for n ∈ 1:N
for k ∈ 1:K
@simd ivdep for m ∈ 1:M
@fastmath c[m, n] += a[m, k] * b[k, n]
end
end
end
return c
end
function calc(n)
n = n ÷ 2 * 2
a = matgen(n, 1)
b = matgen(n, 2)
c = mul(a, b)
c[n÷2+1, n÷2+1]
end
function notify(msg)
try
socket = connect("localhost", 9001)
write(socket, msg)
close(socket)
catch
# standalone usage
end
end
if abspath(PROGRAM_FILE) == @__FILE__
n = length(ARGS) > 0 ? parse(Int, ARGS[1]) : 100
left = calc(101)
right = -18.67
if abs(left - right) > 0.1
println(stderr, "$(left) != $(right)")
exit(1)
end
notify("Julia (no BLAS)\t$(getpid())")
t = time()
results = calc(n)
elapsed = time() - t
notify("stop")
println(results)
println("time: $(elapsed) s")
end