Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Julia Base Norm Changes #302

Closed
ChrisRackauckas opened this issue Jun 7, 2018 · 2 comments
Closed

Julia Base Norm Changes #302

ChrisRackauckas opened this issue Jun 7, 2018 · 2 comments

Comments

@ChrisRackauckas
Copy link
Member

@ranocha JuliaLang/julia#27401 It seems like your default norm matches your recursive norm, so we should change the default on v0.7 to just using norm?

https://github.com/JuliaDiffEq/DiffEqBase.jl/blob/master/src/common_defaults.jl#L2-L7

@ranocha
Copy link
Member

ranocha commented Jun 8, 2018

In the defaults you cited, there is a division by length(u) which is not included in the new norm. Moreover, there are some additional security means (checks for possible overflows etc.) in norm that make sqrt(sum(abs2, u) / length(u)) faster. Since this part is performance critical and you use @fastmath a lot, sacrificing accuracy for speed, I'm not sure whether the new norm should be used.

ulia> using LinearAlgebra, BenchmarkTools

julia> v = rand(2^10);

julia> @benchmark norm($v)
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     272.331 ns (0.00% GC)
  median time:      272.432 ns (0.00% GC)
  mean time:        272.589 ns (0.00% GC)
  maximum time:     354.695 ns (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     308

julia> @benchmark sqrt(sum(abs2, $v) / length($v))
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     132.341 ns (0.00% GC)
  median time:      133.145 ns (0.00% GC)
  mean time:        133.314 ns (0.00% GC)
  maximum time:     151.387 ns (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     878

julia> v = rand(2^15);

julia> @benchmark norm($v)
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     9.397 μs (0.00% GC)
  median time:      10.060 μs (0.00% GC)
  mean time:        10.076 μs (0.00% GC)
  maximum time:     27.636 μs (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     1

julia> @benchmark sqrt(sum(abs2, $v) / length($v))
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     4.811 μs (0.00% GC)
  median time:      4.847 μs (0.00% GC)
  mean time:        4.854 μs (0.00% GC)
  maximum time:     8.283 μs (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     7


julia> v = rand(2^20);

julia> @benchmark norm($v)
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     356.202 μs (0.00% GC)
  median time:      367.955 μs (0.00% GC)
  mean time:        370.762 μs (0.00% GC)
  maximum time:     662.704 μs (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     1

julia> @benchmark sqrt(sum(abs2, $v) / length($v))
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     236.158 μs (0.00% GC)
  median time:      239.394 μs (0.00% GC)
  mean time:        240.769 μs (0.00% GC)
  maximum time:     562.734 μs (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     1

julia> v = rand(2^30);

julia> @benchmark norm($v)
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     569.887 ms (0.00% GC)
  median time:      571.031 ms (0.00% GC)
  mean time:        570.924 ms (0.00% GC)
  maximum time:     571.777 ms (0.00% GC)
  --------------
  samples:          9
  evals/sample:     1

julia> @benchmark sqrt(sum(abs2, $v) / length($v))
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     465.854 ms (0.00% GC)
  median time:      466.278 ms (0.00% GC)
  mean time:        466.621 ms (0.00% GC)
  maximum time:     468.110 ms (0.00% GC)
  --------------
  samples:          11
  evals/sample:     1

julia> versioninfo()
Julia Version 0.7.0-alpha.27
Commit 58a8931684 (2018-06-06 03:53 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, haswell)
Environment:
  JULIA_NUM_THREADS = 4

@ChrisRackauckas
Copy link
Member Author

ChrisRackauckas commented Jun 8, 2018

Yup, the norm is just for a crude error estimate so it definitely wants speed >> accuracy. Looks to be worth keeping. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants