@@ -662,8 +662,135 @@ end
662662# Precompilation Workload
663663# ============================================================================
664664
665- # Precompile directives generated by SnoopCompile
666- # Regenerate with: mpiexec -n 1 julia --project=. scripts/generate_precompile.jl
667- include (" precompile.jl" )
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+ # === MPI Jail Escape ===
700+ # When precompiling under mpiexec, the subprocess inherits MPI environment
701+ # variables but isn't part of the MPI job. Clean them to allow MPI.Init()
702+ # to succeed as a fresh single-rank process.
703+ for k in collect (keys (ENV ))
704+ if startswith (k, " PMI" ) || startswith (k, " PMIX" ) || startswith (k, " OMPI_" ) || startswith (k, " MPI_" )
705+ delete! (ENV , k)
706+ end
707+ end
708+
709+ MPI. Init ()
710+
711+ # === VectorMPI operations (Float64) ===
712+ v = VectorMPI (v_f64)
713+ w = VectorMPI (2.0 .* v_f64)
714+ _ = v + w
715+ _ = v - w
716+ _ = 2.0 * v
717+ _ = v * 2.0
718+ _ = norm (v)
719+ _ = dot (v, w)
720+ _ = conj (v)
721+ _ = length (v)
722+ _ = size (v)
723+
724+ # VectorMPI (ComplexF64)
725+ vc = VectorMPI (v_c64)
726+ _ = conj (vc)
727+ _ = norm (vc)
728+
729+ # === SparseMatrixMPI operations (Float64) ===
730+ A = SparseMatrixMPI {Float64} (A_sparse_f64)
731+ B = SparseMatrixMPI {Float64} (A_sparse_f64)
732+ _ = A + B
733+ _ = A - B
734+ _ = 2.0 * A
735+ _ = A * v
736+ _ = A * B
737+ _ = transpose (A)
738+ At = SparseMatrixMPI (transpose (A))
739+ _ = size (A)
740+ _ = nnz (A)
741+ _ = norm (A)
742+
743+ # SparseMatrixMPI (ComplexF64)
744+ Ac = SparseMatrixMPI {ComplexF64} (A_sparse_c64)
745+ _ = Ac * vc
746+
747+ # === MatrixMPI operations (Float64) ===
748+ D = MatrixMPI (A_dense_f64)
749+ _ = 2.0 * D
750+ _ = D * v
751+ _ = transpose (D)
752+ Dt = copy (transpose (D)) # Materialize dense transpose
753+ _ = size (D)
754+ _ = norm (D)
755+
756+ # MatrixMPI (ComplexF64)
757+ Dc = MatrixMPI (A_dense_c64)
758+ _ = Dc * vc
759+
760+ # === Mixed operations ===
761+ _ = A * D # Sparse * Dense
762+
763+ # === Indexing ===
764+ _ = v[1 ]
765+ _ = A[1 , 1 ]
766+ _ = D[1 , 1 ]
767+
768+ # === Factorization (MUMPS) ===
769+ # Make symmetric positive definite: A + A^T + 10I
770+ At_mat = SparseMatrixMPI (transpose (A))
771+ I_dist = SparseMatrixMPI {Float64} (I_sparse)
772+ A_spd = A + At_mat + I_dist * 10.0
773+ F = LinearAlgebra. ldlt (A_spd)
774+ x = F \ v
775+ finalize! (F)
776+
777+ # LU factorization
778+ F_lu = LinearAlgebra. lu (A)
779+ x = F_lu \ v
780+ finalize! (F_lu)
781+
782+ # === Block operations ===
783+ _ = cat (v, w; dims= 1 )
784+ _ = blockdiag (A, B)
785+
786+ # === Conversions ===
787+ _ = Vector (v)
788+ _ = Matrix (D)
789+ _ = SparseMatrixCSC (A)
790+
791+ # Clear caches
792+ clear_plan_cache! ()
793+ end
794+ end
668795
669796end # module LinearAlgebraMPI
0 commit comments