Skip to content

Commit

Permalink
Decouple InteractiveUtils from LinearAlgebra, schedule peakflops for …
Browse files Browse the repository at this point in the history
…move to LinearAlgebra.
  • Loading branch information
fredrikekre committed Nov 16, 2018
1 parent 25d0dfc commit 5c30d71
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 27 deletions.
1 change: 0 additions & 1 deletion stdlib/InteractiveUtils/Project.toml
Expand Up @@ -3,7 +3,6 @@ uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[deps]
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
38 changes: 12 additions & 26 deletions stdlib/InteractiveUtils/src/InteractiveUtils.jl
Expand Up @@ -3,7 +3,7 @@
module InteractiveUtils

export apropos, edit, less, code_warntype, code_llvm, code_native, methodswith, varinfo,
versioninfo, subtypes, peakflops, @which, @edit, @less, @functionloc, @code_warntype,
versioninfo, subtypes, @which, @edit, @less, @functionloc, @code_warntype,
@code_typed, @code_lowered, @code_llvm, @code_native, clipboard

import Base.Docs.apropos
Expand All @@ -12,7 +12,6 @@ using Base: unwrap_unionall, rewrap_unionall, isdeprecated, Bottom, show_unquote
to_tuple_type, signature_type, format_bytes

using Markdown
using LinearAlgebra # for peakflops

include("editless.jl")
include("codeview.jl")
Expand Down Expand Up @@ -308,36 +307,23 @@ function dumpsubtypes(io::IO, x::DataType, m::Module, n::Int, indent)
nothing
end

const Distributed_modref = Ref{Module}()

# TODO: @deprecate peakflops to LinearAlgebra
export peakflops
"""
peakflops(n::Integer=2000; parallel::Bool=false)
`peakflops` computes the peak flop rate of the computer by using double precision
[`gemm!`](@ref LinearAlgebra.BLAS.gemm!). By default, if no arguments are specified, it
multiplies a matrix of size `n x n`, where `n = 2000`. If the underlying BLAS is using
multiple threads, higher flop rates are realized. The number of BLAS threads can be set with
[`BLAS.set_num_threads(n)`](@ref).
If the keyword argument `parallel` is set to `true`, `peakflops` is run in parallel on all
the worker processors. The flop rate of the entire parallel computer is returned. When
running in parallel, only 1 BLAS thread is used. The argument `n` still refers to the size
of the problem that is solved on each processor.
[`gemm!`](@ref LinearAlgebra.BLAS.gemm!). For more information see
[`LinearAlgebra.peakflops`](@ref).
!!! note
This function will move to the `LinearAlgebra` standard library in the
future, and is already available as `LinearAlgebra.peakflops`.
"""
function peakflops(n::Integer=2000; parallel::Bool=false)
a = fill(1.,100,100)
t = @elapsed a2 = a*a
a = fill(1.,n,n)
t = @elapsed a2 = a*a
@assert a2[1,1] == n
if parallel
if !isassigned(Distributed_modref)
Distributed_modref[] = Base.require(Base, :Distributed)
end
Dist = Distributed_modref[]
sum(Dist.pmap(peakflops, fill(n, Dist.nworkers())))
else
2*Float64(n)^3 / t
let LinearAlgebra = Base.require(Base.PkgId(
Base.UUID((0x37e2e46d_f89d_539d,0xb4ee_838fcccc9c8e)), "LinearAlgebra"))
return LinearAlgebra.peakflops(n; parallel = parallel)
end
end

Expand Down
1 change: 1 addition & 0 deletions stdlib/LinearAlgebra/docs/src/index.md
Expand Up @@ -415,6 +415,7 @@ LinearAlgebra.adjoint!
Base.copy(::Union{Transpose,Adjoint})
LinearAlgebra.stride1
LinearAlgebra.checksquare
LinearAlgebra.peakflops
```

## Low-level matrix operations
Expand Down
30 changes: 30 additions & 0 deletions stdlib/LinearAlgebra/src/LinearAlgebra.jl
Expand Up @@ -379,6 +379,36 @@ const ⋅ = dot
const × = cross
export , ×

"""
LinearAlgebra.peakflops(n::Integer=2000; parallel::Bool=false)
`peakflops` computes the peak flop rate of the computer by using double precision
[`gemm!`](@ref LinearAlgebra.BLAS.gemm!). By default, if no arguments are specified, it
multiplies a matrix of size `n x n`, where `n = 2000`. If the underlying BLAS is using
multiple threads, higher flop rates are realized. The number of BLAS threads can be set with
[`BLAS.set_num_threads(n)`](@ref).
If the keyword argument `parallel` is set to `true`, `peakflops` is run in parallel on all
the worker processors. The flop rate of the entire parallel computer is returned. When
running in parallel, only 1 BLAS thread is used. The argument `n` still refers to the size
of the problem that is solved on each processor.
"""
function peakflops(n::Integer=2000; parallel::Bool=false)
a = fill(1.,100,100)
t = @elapsed a2 = a*a
a = fill(1.,n,n)
t = @elapsed a2 = a*a
@assert a2[1,1] == n
if parallel
let Distributed = Base.require(Base.PkgId(
Base.UUID((0x8ba89e20_285c_5b6f, 0x9357_94700520ee1b)), "Distributed"))
return sum(Distributed.pmap(peakflops, fill(n, Distributed.nworkers())))
end
else
return 2*Float64(n)^3 / t
end
end


function versioninfo(io::IO=stdout)
if Base.libblas_name == "libopenblas" || BLAS.vendor() == :openblas || BLAS.vendor() == :openblas64
Expand Down
4 changes: 4 additions & 0 deletions stdlib/LinearAlgebra/test/generic.jl
Expand Up @@ -382,4 +382,8 @@ end
@test ismissing(norm(missing))
end

@testset "peakflops" begin
@test LinearAlgebra.peakflops() > 0
end

end # module TestGeneric

0 comments on commit 5c30d71

Please sign in to comment.