Skip to content

Commit 95317b6

Browse files
KristofferCclaude
andauthored
1.12: Backport CI test time improvements (#742)
Need this on Base CI because it times out a lot --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2 parents e9baab7 + d27f7f4 commit 95317b6

6 files changed

Lines changed: 73 additions & 71 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ jobs:
6868
version: ${{ matrix.julia-version }}
6969
arch: ${{ matrix.julia-arch }}
7070
- uses: julia-actions/cache@v2
71-
- uses: julia-actions/julia-buildpkg@v1
72-
- uses: julia-actions/julia-runtest@v1
73-
env:
74-
SPARSEARRAYS_AQUA_TEST: true
71+
- name: Run Aqua and ambiguity tests
72+
run: |
73+
julia --color=yes -e 'using Pkg; Pkg.activate(temp=true); Pkg.develop(path=pwd()); Pkg.add(name="Aqua", version="0.8"); include(joinpath(pwd(), "test", "ambiguous.jl"))'
7574
docs:
7675
runs-on: ubuntu-latest
7776
steps:

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Dates = "<0.0.1, 1"
1515
InteractiveUtils = "<0.0.1, 1"
1616
Libdl = "<0.0.1, 1"
1717
LinearAlgebra = "<0.0.1, 1"
18+
ParallelTestRunner = "2"
1819
Pkg = "<0.0.1, 1"
1920
Printf = "<0.0.1, 1"
2021
Random = "<0.0.1, 1"
@@ -27,9 +28,10 @@ julia = "1.11"
2728
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
2829
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
2930
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
31+
ParallelTestRunner = "d3525ed8-44d0-4b2c-a655-542cee43accc"
3032
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
3133
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
3234
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3335

3436
[targets]
35-
test = ["Aqua", "Dates", "InteractiveUtils", "Pkg", "Printf", "Test"]
37+
test = ["Aqua", "Dates", "InteractiveUtils", "ParallelTestRunner", "Pkg", "Printf", "Test"]

test/runtests.jl

Lines changed: 20 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,32 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
23
using Test, LinearAlgebra, SparseArrays
34

45
include("util/gha.jl")
56

6-
if Base.get_bool_env("SPARSEARRAYS_AQUA_TEST", false)
7-
include("ambiguous.jl")
8-
end
9-
10-
include("allowscalar.jl")
11-
include("fixed.jl")
12-
include("higherorderfns.jl")
13-
include("sparsematrix_constructors_indexing.jl")
14-
include("sparsematrix_ops.jl")
15-
include("sparsevector.jl")
16-
include("issues.jl")
7+
testfiles = ["allowscalar.jl", "fixed.jl", "higherorderfns.jl",
8+
"sparsematrix_constructors_indexing.jl", "sparsematrix_ops.jl",
9+
"sparsevector.jl", "issues.jl"]
1710

1811
if Base.USE_GPL_LIBS
19-
20-
include("cholmod.jl")
21-
include("umfpack.jl")
22-
include("spqr.jl")
23-
include("linalg.jl")
24-
include("linalg_solvers.jl")
25-
26-
nt = @static if isdefined(Threads, :maxthreadid)
27-
Threads.maxthreadid()
28-
else
29-
Threads.nthreads()
30-
end
31-
32-
# 1. If the OS is Windows and we are in GitHub Actions CI, we do NOT run
33-
# the `threads` tests.
34-
# 2. If the OS is Windows and we are NOT in GitHub Actions CI, we DO run
35-
# the `threads` tests.
36-
# - So, just as an example, if the OS is Windows and we are in
37-
# Buildkite CI, we DO run the `threads` tests.
38-
# 3. If the OS is NOT Windows, we DO run the `threads` tests.
12+
append!(testfiles, ["cholmod.jl", "umfpack.jl", "spqr.jl", "linalg.jl",
13+
"linalg_solvers.jl"])
3914
if Sys.iswindows() && is_github_actions_ci()
4015
@warn "Skipping `threads` tests on Windows on GitHub Actions CI"
41-
@test_skip false
4216
else
43-
@debug "Beginning the `threads` tests..."
44-
45-
# Test multithreaded execution
46-
@testset "threaded SuiteSparse tests" verbose = true begin
47-
@testset "threads = $nt" begin
48-
include("threads.jl")
49-
end
50-
# test both nthreads==1 and nthreads>1. spawn a process to test whichever
51-
# case we are not running currently.
52-
other_nthreads = nt == 1 ? 4 : 1
53-
@testset "threads = $other_nthreads" begin
54-
let p, cmd = `$(Base.julia_cmd()) --depwarn=error --startup-file=no threads.jl`
55-
p = run(
56-
pipeline(
57-
setenv(
58-
cmd,
59-
"JULIA_NUM_THREADS" => other_nthreads,
60-
dir=@__DIR__()),
61-
stdout = stdout,
62-
stderr = stderr),
63-
wait = false)
64-
if !success(p)
65-
error("SuiteSparse threads test failed with nthreads == $other_nthreads")
66-
else
67-
@test true # mimic the one @test in threads.jl
68-
end
69-
end
70-
end
71-
end
72-
73-
@debug "Finished the `threads` tests..."
17+
push!(testfiles, "threads_suite.jl")
7418
end
7519
end
20+
21+
# ParallelTestRunner comes from the Pkg.test target; Julia base CI runs this
22+
# file without it and falls back to the serial path.
23+
if Base.find_package("ParallelTestRunner") !== nothing
24+
using ParallelTestRunner
25+
# Auto CPU thread count detection in ParallelTestRunner is bad
26+
push!(ARGS, "--jobs=$(Sys.CPU_THREADS)")
27+
testsuite = Dict{String,Expr}(splitext(f)[1] => :(include($(joinpath(@__DIR__, f))))
28+
for f in testfiles)
29+
runtests(SparseArrays, ARGS; testsuite)
30+
else
31+
foreach(include, testfiles)
32+
end

test/sparsematrix_constructors_indexing.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,9 @@ end
834834
times = Float64[0,0,0]
835835
best = [typemax(Float64), 0]
836836
for searchtype in [0, 1, 2]
837-
GC.gc()
837+
# stabilizes the debug timings below, but forces 180 full
838+
# collections across these loops which dominates the file's GC time
839+
# GC.gc()
838840
tres = @timed test_getindex_algs(S, I, J, searchtype)
839841
res[searchtype+1] = tres[1]
840842
times[searchtype+1] = tres[2]
@@ -890,9 +892,9 @@ end
890892
for I in IA
891893
Isorted = sort(I)
892894
for S in SA
893-
GC.gc()
895+
# GC.gc() # see comment above
894896
ru = @timed S[I, J]
895-
GC.gc()
897+
# GC.gc()
896898
rs = @timed S[Isorted, Jsorted]
897899
if debug
898900
@printf(" %7d | %7d | %7d | %4.2e | %4.2e | %4.2e | %4.2e |\n", round(Int,nnz(S)/size(S, 2)), length(I), length(J), rs[2], ru[2], rs[3], ru[3])

test/sparsevector.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,10 @@ end
13371337
floattypes = (Float32, Float64, BigFloat)
13381338
complextypes = (ComplexF32, ComplexF64)
13391339
eltypes = (inttypes..., floattypes..., complextypes...)
1340+
# The full eltype cross product compiles thousands of specializations
1341+
# (several CI minutes); do it only for the core types and pair the
1342+
# remaining eltypes with Float64.
1343+
coretypes = (Int64, Float64, ComplexF64)
13401344

13411345
for eltypemat in eltypes
13421346
(densemat, sparsemat) = eltypemat in inttypes ? (denseintmat, sparseintmat) :
@@ -1350,6 +1354,8 @@ end
13501354
LinearAlgebra.UnitLowerTriangular(sparsemat), LinearAlgebra.UnitUpperTriangular(sparsemat) )
13511355

13521356
for eltypevec in eltypes
1357+
(eltypemat in coretypes && eltypevec in coretypes) ||
1358+
eltypemat == Float64 || eltypevec == Float64 || continue
13531359
spvecs = eltypevec in inttypes ? sparseintvecs :
13541360
eltypevec in floattypes ? sparsefloatvecs :
13551361
eltypevec in complextypes && sparsecomplexvecs

test/threads_suite.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
using Test, SparseArrays
4+
5+
nt = @static if isdefined(Threads, :maxthreadid)
6+
Threads.maxthreadid()
7+
else
8+
Threads.nthreads()
9+
end
10+
11+
@testset "threaded SuiteSparse tests" verbose = true begin
12+
@testset "threads = $nt" begin
13+
include("threads.jl")
14+
end
15+
# test both nthreads==1 and nthreads>1. spawn a process to test whichever
16+
# case we are not running currently.
17+
other_nthreads = nt == 1 ? 4 : 1
18+
@testset "threads = $other_nthreads" begin
19+
let p, cmd = `$(Base.julia_cmd()) --depwarn=error --startup-file=no threads.jl`
20+
p = run(
21+
pipeline(
22+
setenv(
23+
cmd,
24+
"JULIA_NUM_THREADS" => other_nthreads,
25+
dir=@__DIR__()),
26+
stdout = stdout,
27+
stderr = stderr),
28+
wait = false)
29+
if !success(p)
30+
error("SuiteSparse threads test failed with nthreads == $other_nthreads")
31+
else
32+
@test true # mimic the one @test in threads.jl
33+
end
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)