Skip to content

Commit

Permalink
Add sparse matvec to perf benchmark (#4707)
Browse files Browse the repository at this point in the history
  • Loading branch information
ViralBShah committed Dec 7, 2013
1 parent 3db073d commit 8ce7dfb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
46 changes: 46 additions & 0 deletions test/perf/kernel/getdivgrad.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# https://github.com/JuliaLang/julia/issues/4707

#----------------- Get the A matrix
function getDivGrad(n1,n2,n3)

# the Divergence
D1 = kron(speye(n3),kron(speye(n2),ddx(n1)))
D2 = kron(speye(n3),kron(ddx(n2),speye(n1)))
D3 = kron(ddx(n3),kron(speye(n2),speye(n1)))
# DIV from faces to cell-centers
Div = [D1 D2 D3]

return Div*Div';
end

#----------------- 1D finite difference on staggered grid
function ddx(n)
# generate 1D derivatives
return d = spdiags(ones(n)*[-1 1],[0,1],n,n+1)
end

#------------- Build a diagonal matrix
function spdiags(B,d,m,n)
# spdiags(B,d,m,n)
# creates a sparse matrix from its diagonals

d = d[:]
p = length(d)

len = zeros(p+1,1)
for k = 1:p
len[k+1] = int(len[k]+length(max(1,1-d[k]):min(m,n-d[k])))
end
a = zeros(int(len[p+1]),3)
for k = 1:p
# Append new d[k]-th diagonal to compact form
i = max(1,1-d[k]):min(m,n-d[k])
a[(int(len[k])+1):int(len[k+1]),:] = [i i+d[k] B[i+(m>=n)*d[k],k]]
end

A = sparse(int(a[:,1]),int(a[:,2]),a[:,3],m,n);

return A

end

16 changes: 11 additions & 5 deletions test/perf/kernel/perf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@ include("gk.jl")

# issue #942
s = sparse(ones(280,280));
@timeit s*s "sparsemul" "Sparse matrix multiplication"

# issue #939
y = [500000:-1:1];
@timeit sortperm(y) "sortperm" "Sorting of a worst-case vector"
@timeit s*s "sparsemul" "Sparse matrix - sparse matrix multiplication"

# issue #938
x = 1:600000;
@timeit sparse(x,x,x) "sparserange" "Construction of a sparse array from ranges"

# issue 4707
include("getdivgrad.jl")
A = getDivGrad(64,64,64)
v = rand(64^3)
@timeit A*v "matvec" "Sparse matrix - dense vector multiplication"

# issue #939
y = [500000:-1:1];
@timeit sortperm(y) "sortperm" "Sorting of a worst-case vector"

# issue #445
include("stockcorr.jl")
@timeit stockcorr() "stockcorr" "Correlation analysis of random matrices"
Expand Down

6 comments on commit 8ce7dfb

@ViralBShah
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staticfloat Do we need to do anything to get speed center to track this newly added benchmark?

@staticfloat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, you can see it already popped up!

@ViralBShah
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@ViralBShah
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is strange that there is a performance difference between different blas libraries, given that this operation does not use any BLAS operations.

@jiahao
Copy link
Member

@jiahao jiahao commented on 8ce7dfb Dec 15, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like that was just a system load issue.

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of that benchmark is pretty misleading since it doesn't in any way indicate that it's a sparse matvec rather than a dense one.

Please sign in to comment.