Skip to content

Vec/Mat: fix transposed products and norms, take any vector - #304

Open
filoferra wants to merge 3 commits into
JuliaParallel:mainfrom
filoferra:vecmat-contract
Open

filoferra wants to merge 3 commits into
JuliaParallel:mainfrom
filoferra:vecmat-contract

Conversation

@filoferra

Copy link
Copy Markdown
Collaborator

Fixes found while checking the Vec and Mat methods against what Base and LinearAlgebra.

Bugs

  • A' * x, transpose(A) * x and mul!(y, A', x) threw a MethodError. They now call MatMultHermitianTranspose / MatMultTranspose.
  • On a PetscVec built from a Julia array, every norm after the first came back as 0 (norm(v) gave 5, then norm(v, NORM_1) gave 0). PETSc saw the other norm types as already cached. The vector is now assembled once when it's created.
  • isapprox(v, w; rtol = …) threw a MethodError.
  • An MPI run started against a stale precompile cache could hang forever at 0% CPU: src/PETSc.jl called MPI.Init at top level, which runs inside the precompile process. The call is gone; initialize still sets up MPI.
  • DMDA and DMStag with more than three dimensions hit an UndefVarError; they now throw an ArgumentError.

Additions

  • norm(v, p) for p = 1, 2, Inf; norm(A, 2); opnorm(A, 1) and opnorm(A, Inf).
  • size(_, d), axes and ndims on vectors and matrices, as for Julia arrays.
  • set_values!, ksp \ b, the CSR PetscMat constructor and dof_slot accept any vector or integer type (views, other element types, offset arrays). Exact-type Vectors still pass to PETSc without a copy.

src/PETSc.jl called MPI.Init at module top level, which runs only while the package precompiles. Under mpiexec with a stale cache, the rank that precompiled started a worker that inherited the launcher's environment and waited forever for its peers in MPI_Init, so the run sat at 0% CPU with no error.

The call is gone; initialize still sets up MPI at run time. Loading PETSc on 2 ranks against a stale cache now takes about 30 s.
A' * x and transpose(A) * x threw a MethodError: the transposed products existed but no method could reach them. isapprox(v, w; rtol) threw too, and on a vector made from a Julia array every norm type after the first came back as 0, because PETSc took them as already cached.
set_values!, ksp \ b, the CSR PetscMat constructor and dof_slot only took Vectors of the library's exact element types, so a view, an Int32 index vector or an offset array was a MethodError or an ArgumentError.

They now take any vector or integer. Vectors that already have the library's types still go to PETSc without a copy; anything else is copied once.
ksp \ b returns x with the axes of b. set_values! also checks that num_rows and num_cols fit the index vectors it is given.

Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant