Skip to content

Commit d628eeb

Browse files
Sébastien LoiselSébastien Loisel
authored andcommitted
Add precompilation workload using PrecompileTools
Precompiles key operations for both Float64 and ComplexF64: - VectorMPI: construction, arithmetic, norms, dot, conj - SparseMatrixMPI: construction, arithmetic, multiplication, transpose - MatrixMPI: construction, scalar mult, matrix-vector mult, transpose - MUMPS factorization: ldlt, lu, solve, finalize - Block operations: cat, blockdiag - Conversions: Vector, Matrix, SparseMatrixCSC Workload runs with single MPI rank during precompilation.
1 parent e48f38e commit d628eeb

2 files changed

Lines changed: 128 additions & 0 deletions

File tree

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ Blake3Hash = "8f478455-a32d-4928-b0e4-72b19a7d5574"
88
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
99
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
1010
MUMPS = "55d2b088-9f4e-11e9-26c0-150b02ea6a46"
11+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1112
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1213

1314
[compat]
1415
Blake3Hash = "0.3"
1516
MPI = "0.20"
1617
MUMPS = "1.5"
18+
PrecompileTools = "1"
1719
julia = "1.10"
1820

1921
[extras]

src/LinearAlgebraMPI.jl

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,4 +658,130 @@ function Base.show(io::IO, ::MIME"text/plain", A::SparseMatrixMPI{T}) where T
658658
show(io, MIME("text/plain"), full_A)
659659
end
660660

661+
# ============================================================================
662+
# Precompilation Workload
663+
# ============================================================================
664+
665+
using PrecompileTools
666+
667+
@setup_workload begin
668+
# Small test data for precompilation (runs with single MPI rank)
669+
n = 8
670+
671+
# Sparse matrix (tridiagonal) - Float64
672+
I_sp = Int[]; J_sp = Int[]; V_sp = Float64[]
673+
for i in 1:n
674+
push!(I_sp, i); push!(J_sp, i); push!(V_sp, 4.0)
675+
if i > 1
676+
push!(I_sp, i); push!(J_sp, i-1); push!(V_sp, -1.0)
677+
push!(I_sp, i-1); push!(J_sp, i); push!(V_sp, -1.0)
678+
end
679+
end
680+
A_sparse_f64 = sparse(I_sp, J_sp, V_sp, n, n)
681+
682+
# Sparse matrix - ComplexF64
683+
A_sparse_c64 = sparse(I_sp, J_sp, ComplexF64.(V_sp), n, n)
684+
685+
# Dense matrix - Float64
686+
A_dense_f64 = Float64[i == j ? 4.0 : (abs(i-j) == 1 ? -1.0 : 0.0) for i in 1:n, j in 1:n]
687+
688+
# Dense matrix - ComplexF64
689+
A_dense_c64 = ComplexF64.(A_dense_f64)
690+
691+
# Vectors
692+
v_f64 = ones(Float64, n)
693+
v_c64 = ones(ComplexF64, n)
694+
695+
# Identity for SPD construction
696+
I_sparse = sparse(1.0 * LinearAlgebra.I, n, n)
697+
698+
@compile_workload begin
699+
# Initialize MPI (works in single-process mode during precompilation)
700+
MPI.Init()
701+
702+
# === VectorMPI operations (Float64) ===
703+
v = VectorMPI(v_f64)
704+
w = VectorMPI(2.0 .* v_f64)
705+
_ = v + w
706+
_ = v - w
707+
_ = 2.0 * v
708+
_ = v * 2.0
709+
_ = norm(v)
710+
_ = dot(v, w)
711+
_ = conj(v)
712+
_ = length(v)
713+
_ = size(v)
714+
715+
# VectorMPI (ComplexF64)
716+
vc = VectorMPI(v_c64)
717+
_ = conj(vc)
718+
_ = norm(vc)
719+
720+
# === SparseMatrixMPI operations (Float64) ===
721+
A = SparseMatrixMPI{Float64}(A_sparse_f64)
722+
B = SparseMatrixMPI{Float64}(A_sparse_f64)
723+
_ = A + B
724+
_ = A - B
725+
_ = 2.0 * A
726+
_ = A * v
727+
_ = A * B
728+
_ = transpose(A)
729+
At = materialize_transpose(A)
730+
_ = size(A)
731+
_ = nnz(A)
732+
_ = norm(A)
733+
734+
# SparseMatrixMPI (ComplexF64)
735+
Ac = SparseMatrixMPI{ComplexF64}(A_sparse_c64)
736+
_ = Ac * vc
737+
738+
# === MatrixMPI operations (Float64) ===
739+
D = MatrixMPI(A_dense_f64)
740+
_ = 2.0 * D
741+
_ = D * v
742+
_ = transpose(D)
743+
Dt = copy(transpose(D)) # Materialize dense transpose
744+
_ = size(D)
745+
_ = norm(D)
746+
747+
# MatrixMPI (ComplexF64)
748+
Dc = MatrixMPI(A_dense_c64)
749+
_ = Dc * vc
750+
751+
# === Mixed operations ===
752+
_ = A * D # Sparse * Dense
753+
754+
# === Indexing ===
755+
_ = v[1]
756+
_ = A[1, 1]
757+
_ = D[1, 1]
758+
759+
# === Factorization (MUMPS) ===
760+
# Make symmetric positive definite: A + A^T + 10I
761+
At_mat = materialize_transpose(A)
762+
I_dist = SparseMatrixMPI{Float64}(I_sparse)
763+
A_spd = A + At_mat + I_dist * 10.0
764+
F = LinearAlgebra.ldlt(A_spd)
765+
x = F \ v
766+
finalize!(F)
767+
768+
# LU factorization
769+
F_lu = LinearAlgebra.lu(A)
770+
x = F_lu \ v
771+
finalize!(F_lu)
772+
773+
# === Block operations ===
774+
_ = cat(v, w; dims=1)
775+
_ = blockdiag(A, B)
776+
777+
# === Conversions ===
778+
_ = Vector(v)
779+
_ = Matrix(D)
780+
_ = SparseMatrixCSC(A)
781+
782+
# Clear caches
783+
clear_plan_cache!()
784+
end
785+
end
786+
661787
end # module LinearAlgebraMPI

0 commit comments

Comments
 (0)