Skip to content

Commit 0c7aaac

Browse files
committed
Decouple InteractiveUtils from LinearAlgebra, schedule peakflops for move to LinearAlgebra.
1 parent 25d0dfc commit 0c7aaac

File tree

5 files changed

+47
-27
lines changed

5 files changed

+47
-27
lines changed

stdlib/InteractiveUtils/Project.toml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
33

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

87
[extras]
98
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

stdlib/InteractiveUtils/src/InteractiveUtils.jl

+12-26
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module InteractiveUtils
44

55
export apropos, edit, less, code_warntype, code_llvm, code_native, methodswith, varinfo,
6-
versioninfo, subtypes, peakflops, @which, @edit, @less, @functionloc, @code_warntype,
6+
versioninfo, subtypes, @which, @edit, @less, @functionloc, @code_warntype,
77
@code_typed, @code_lowered, @code_llvm, @code_native, clipboard
88

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

1414
using Markdown
15-
using LinearAlgebra # for peakflops
1615

1716
include("editless.jl")
1817
include("codeview.jl")
@@ -308,36 +307,23 @@ function dumpsubtypes(io::IO, x::DataType, m::Module, n::Int, indent)
308307
nothing
309308
end
310309

311-
const Distributed_modref = Ref{Module}()
312-
310+
# TODO: @deprecate peakflops to LinearAlgebra
311+
export peakflops
313312
"""
314313
peakflops(n::Integer=2000; parallel::Bool=false)
315314
316315
`peakflops` computes the peak flop rate of the computer by using double precision
317-
[`gemm!`](@ref LinearAlgebra.BLAS.gemm!). By default, if no arguments are specified, it
318-
multiplies a matrix of size `n x n`, where `n = 2000`. If the underlying BLAS is using
319-
multiple threads, higher flop rates are realized. The number of BLAS threads can be set with
320-
[`BLAS.set_num_threads(n)`](@ref).
321-
322-
If the keyword argument `parallel` is set to `true`, `peakflops` is run in parallel on all
323-
the worker processors. The flop rate of the entire parallel computer is returned. When
324-
running in parallel, only 1 BLAS thread is used. The argument `n` still refers to the size
325-
of the problem that is solved on each processor.
316+
[`gemm!`](@ref LinearAlgebra.BLAS.gemm!). For more information see
317+
[`LinearAlgebra.peakflops`](@ref).
318+
319+
!!! note
320+
This function will move to the `LinearAlgebra` standard library in the
321+
future, and is already available as `LinearAlgebra.peakflops`.
326322
"""
327323
function peakflops(n::Integer=2000; parallel::Bool=false)
328-
a = fill(1.,100,100)
329-
t = @elapsed a2 = a*a
330-
a = fill(1.,n,n)
331-
t = @elapsed a2 = a*a
332-
@assert a2[1,1] == n
333-
if parallel
334-
if !isassigned(Distributed_modref)
335-
Distributed_modref[] = Base.require(Base, :Distributed)
336-
end
337-
Dist = Distributed_modref[]
338-
sum(Dist.pmap(peakflops, fill(n, Dist.nworkers())))
339-
else
340-
2*Float64(n)^3 / t
324+
let LinearAlgebra = Base.require(Base.PkgId(
325+
Base.UUID((0x37e2e46d_f89d_539d,0xb4ee_838fcccc9c8e)), "LinearAlgebra"))
326+
return LinearAlgebra.peakflops(n; parallel = parallel)
341327
end
342328
end
343329

stdlib/LinearAlgebra/docs/src/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ LinearAlgebra.adjoint!
415415
Base.copy(::Union{Transpose,Adjoint})
416416
LinearAlgebra.stride1
417417
LinearAlgebra.checksquare
418+
LinearAlgebra.peakflops
418419
```
419420

420421
## Low-level matrix operations

stdlib/LinearAlgebra/src/LinearAlgebra.jl

+30
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,36 @@ const ⋅ = dot
379379
const × = cross
380380
export , ×
381381

382+
"""
383+
LinearAlgebra.peakflops(n::Integer=2000; parallel::Bool=false)
384+
385+
`peakflops` computes the peak flop rate of the computer by using double precision
386+
[`gemm!`](@ref LinearAlgebra.BLAS.gemm!). By default, if no arguments are specified, it
387+
multiplies a matrix of size `n x n`, where `n = 2000`. If the underlying BLAS is using
388+
multiple threads, higher flop rates are realized. The number of BLAS threads can be set with
389+
[`BLAS.set_num_threads(n)`](@ref).
390+
391+
If the keyword argument `parallel` is set to `true`, `peakflops` is run in parallel on all
392+
the worker processors. The flop rate of the entire parallel computer is returned. When
393+
running in parallel, only 1 BLAS thread is used. The argument `n` still refers to the size
394+
of the problem that is solved on each processor.
395+
"""
396+
function peakflops(n::Integer=2000; parallel::Bool=false)
397+
a = fill(1.,100,100)
398+
t = @elapsed a2 = a*a
399+
a = fill(1.,n,n)
400+
t = @elapsed a2 = a*a
401+
@assert a2[1,1] == n
402+
if parallel
403+
let Distributed = Base.require(Base.PkgId(
404+
UUID((0x8ba89e20_285c_5b6f, 0x9357_94700520ee1b)), "Distributed"))
405+
return sum(Distributed.pmap(peakflops, fill(n, Distributed.nworkers())))
406+
end
407+
else
408+
return 2*Float64(n)^3 / t
409+
end
410+
end
411+
382412

383413
function versioninfo(io::IO=stdout)
384414
if Base.libblas_name == "libopenblas" || BLAS.vendor() == :openblas || BLAS.vendor() == :openblas64

stdlib/LinearAlgebra/test/generic.jl

+4
Original file line numberDiff line numberDiff line change
@@ -382,4 +382,8 @@ end
382382
@test ismissing(norm(missing))
383383
end
384384

385+
@testset "peakflops" begin
386+
@test LinearAlgebra.peakflops() > 0
387+
end
388+
385389
end # module TestGeneric

0 commit comments

Comments
 (0)