JuliaPerf / BenchmarksGame.jl

Other
43 stars 13 forks source link

fyi spectral-norm 4 separate functions / procedures / methods #25

Closed igouy closed 5 years ago

igouy commented 5 years ago
for i = 1:10
        Au(u,w)
        Atu(w,v)
        Au(v,w)
        Atu(w,u)
end

needs to be something like

for (int i=0; i<10; i++) {
    MultiplyAtAv(n,u,v);
    MultiplyAtAv(n,v,u);
}
KristofferC commented 5 years ago

Could you elaborate? What do you mean when you say "needs to be"?

igouy commented 5 years ago

The Julia programs were written to avoid defining one function and a few function calls, but the program will not be shown on the benchmarks game website unless that function is defined and those function calls are performed.

KristofferC commented 5 years ago

So just something like

diff --git a/spectralnorm/spectralnorm-fast.jl b/spectralnorm/spectralnorm-fast.jl
index 87982f2..e1438f8 100644
--- a/spectralnorm/spectralnorm-fast.jl
+++ b/spectralnorm/spectralnorm-fast.jl
@@ -31,16 +31,19 @@ end
     end
 end

+@inline function AtAu!(w, v, u)
+    Au!(w, u)
+    Atu!(v, w)
+end
+
 function perf_spectralnorm(n::Int=100)
     u = ones(Float64, n)
     v = zeros(Float64 ,n)
     w = zeros(Float64, n)
     vv = vBv = 0
     for i = 1:10
-        Au!(w, u)
-        Atu!(v, w)
-        Au!(w, v)
-        Atu!(u, w)
+        AtAu!(w, v, u)
+        AtAu!(w, u, v)
     end
     @inbounds @simd for i = 1:n
         vBv += u[i]*v[i]

?

igouy commented 5 years ago

Yes.