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

Decouple InteractiveUtils from LinearAlgebra #29978

Merged
merged 1 commit into from
Nov 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion stdlib/InteractiveUtils/Project.toml
Original file line number Diff line number Diff line change
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
40 changes: 14 additions & 26 deletions stdlib/InteractiveUtils/src/InteractiveUtils.jl
Original file line number Diff line number Diff line change
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,25 @@ function dumpsubtypes(io::IO, x::DataType, m::Module, n::Int, indent)
nothing
end

const Distributed_modref = Ref{Module}()

# TODO: @deprecate peakflops to LinearAlgebra
fredrikekre marked this conversation as resolved.
Show resolved Hide resolved
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
# Base.depwarn("`peakflop`s have moved to the LinearAlgebra module, " *
# "add `using LinearAlgebra` to your imports.", :peakflops)
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,8 @@ end
@test ismissing(norm(missing))
end

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

end # module TestGeneric