From 46f8f02148a12ddeb592012809ba18a6a90a4ac3 Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Tue, 28 May 2024 17:23:00 +0200 Subject: [PATCH 1/7] Added reproducer for bug in MatSetPreallocationCOO --- src/api.jl | 1 + test/mpi_array/api_test.jl | 2 ++ test/mpi_array/api_test_defs.jl | 42 +++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/src/api.jl b/src/api.jl index d6954b2..4b9e7b4 100644 --- a/src/api.jl +++ b/src/api.jl @@ -540,6 +540,7 @@ Base.unsafe_convert(::Type{Ptr{Cvoid}},v::Mat) = v.ptr @wrapper(:MatMumpsSetIcntl,PetscErrorCode,(Mat,PetscInt,PetscInt),(mat,icntl,val),"/Mat/MatMumpsSetIcntl.html") @wrapper(:MatMumpsSetCntl,PetscErrorCode,(Mat,PetscInt,PetscReal),(mat,icntl,val),"/Mat/MatMumpsSetCntl.html") @wrapper(:MatMPIAIJSetPreallocation,PetscErrorCode,(Mat,PetscInt,Ptr{PetscInt},PetscInt,Ptr{PetscInt}),(B,d_nz,d_nnz,o_nz,o_nnz),"/Mat/MatMPIAIJSetPreallocation.html") +@wrapper(:MatSetFromOptions,PetscErrorCode,(Mat,),(mat,),"/Mat/MatSetFromOptions.html") # Matrix products related diff --git a/test/mpi_array/api_test.jl b/test/mpi_array/api_test.jl index 969fb9e..551632b 100644 --- a/test/mpi_array/api_test.jl +++ b/test/mpi_array/api_test.jl @@ -12,6 +12,8 @@ include(defs) params = (;nodes_per_dir=(10,10,10),parts_per_dir=(1,1,1)) with_mpi(dist->Defs.main(dist,params)) +xxx + code = quote using MPI; MPI.Init() using PartitionedArrays diff --git a/test/mpi_array/api_test_defs.jl b/test/mpi_array/api_test_defs.jl index d9250cb..0906fae 100644 --- a/test/mpi_array/api_test_defs.jl +++ b/test/mpi_array/api_test_defs.jl @@ -4,6 +4,7 @@ using PartitionedArrays using PetscCall using LinearAlgebra using Test +using SparseArrays function spmv_petsc!(b,A,x) # Convert the input to petsc objects @@ -57,6 +58,42 @@ function test_spmm_petsc(A,B) GC.@preserve ownership PetscCall.@check_error_code PetscCall.MatDestroy(mat_C) end +function petsc_coo(petsc_comm,I,J,V,rows,cols) + m = own_length(rows) + n = own_length(cols) + M = PetscCall.PETSC_DECIDE + N = PetscCall.PETSC_DECIDE + I .= I .- 1 + J .= J .- 1 + ownership = (I,J,V) + ncoo = length(I) + A = Ref{PetscCall.Mat}() + PetscCall.@check_error_code PetscCall.MatCreate(petsc_comm,A) + PetscCall.@check_error_code PetscCall.MatSetType(A[],PetscCall.MATMPIAIJ) + PetscCall.@check_error_code PetscCall.MatSetSizes(A[],m,n,M,N) + PetscCall.@check_error_code PetscCall.MatSetFromOptions(A[]) + PetscCall.@check_error_code PetscCall.MatSetPreallocationCOO(A[],ncoo,I,J) + PetscCall.@check_error_code PetscCall.MatSetValuesCOO(A[],V,PetscCall.ADD_VALUES) + #PetscCall.@check_error_code PetscCall.MatAssemblyBegin(A[],PetscCall.MAT_FINAL_ASSEMBLY) + #PetscCall.@check_error_code PetscCall.MatAssemblyEnd(A[],PetscCall.MAT_FINAL_ASSEMBLY) + GC.@preserve ownership PetscCall.@check_error_code PetscCall.MatDestroy(A) +end + +function generate_coo(args...) + A = PartitionedArrays.laplace_matrix(args...) + row_partition = partition(axes(A,1)) + col_partition = partition(axes(A,2)) + (I,J,V) = map(partition(A),row_partition,col_partition) do myA,rows,cols + Id,Jd,Vd = findnz(myA.blocks.own_own) + Io,Jo,Vo = findnz(myA.blocks.own_ghost) + myI = vcat(map_own_to_global!(Id,rows),map_ghost_to_global!(Io,rows)) + myJ = vcat(map_own_to_global!(Jd,cols),map_ghost_to_global!(Jo,cols)) + myV = vcat(Vd,Vo) + (myI,myJ,myV) + end |> tuple_of_arrays + I,J,V,row_partition,col_partition +end + function main(distribute,params) nodes_per_dir = params.nodes_per_dir parts_per_dir = params.parts_per_dir @@ -80,6 +117,11 @@ function main(distribute,params) @test norm(c)/norm(b1) < tol B = 2*A test_spmm_petsc(A,B) + I,J,V,row_partition,col_partition = generate_coo(nodes_per_dir,parts_per_dir,ranks) + petsc_comm = PetscCall.setup_petsc_comm(ranks) + map(I,J,V,row_partition,col_partition) do args... + petsc_coo(petsc_comm,args...) + end end end #module From 5709dd1c8b124a445f4b23532e8fd6c9f5819048 Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Fri, 19 Jul 2024 10:37:49 +0200 Subject: [PATCH 2/7] Supporting PartitionedArrays 0.5 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 673cd86..fa77987 100644 --- a/Project.toml +++ b/Project.toml @@ -16,7 +16,7 @@ SparseMatricesCSR = "a0a7dd2c-ebf4-11e9-1f05-cf50bc540ca1" [compat] MPI = "0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20" PETSc_jll = "3" -PartitionedArrays = "0.4" +PartitionedArrays = "0.4, 0.5" Preferences = "1" SparseArrays = "1" SparseMatricesCSR = "0.6" From ec2534ae2c1995ef414b72f92a6e23d875521fb7 Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Sat, 27 Jul 2024 09:30:33 +0200 Subject: [PATCH 3/7] Release 0.1.3 --- CHANGELOG.md | 6 ++++++ Project.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1501da9..c8015cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.3] - 2024-07-27 + +### Added + +- Support for PartitionedArrays v0.5. + ## [0.1.2] - 2024-05-18 ### Fixed diff --git a/Project.toml b/Project.toml index fa77987..c0c962d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PetscCall" uuid = "1194c000-87c4-4102-b4a0-a6217ec4849e" authors = ["Francesc Verdugo and contributors"] -version = "0.1.2" +version = "0.1.3" [deps] Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" From 71fe237ade214dd89568698d70b638cbe8478d5d Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Sat, 27 Jul 2024 09:32:04 +0200 Subject: [PATCH 4/7] typo --- test/mpi_array/api_test.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/mpi_array/api_test.jl b/test/mpi_array/api_test.jl index 551632b..969fb9e 100644 --- a/test/mpi_array/api_test.jl +++ b/test/mpi_array/api_test.jl @@ -12,8 +12,6 @@ include(defs) params = (;nodes_per_dir=(10,10,10),parts_per_dir=(1,1,1)) with_mpi(dist->Defs.main(dist,params)) -xxx - code = quote using MPI; MPI.Init() using PartitionedArrays From 8aba9888772f93239a68c1732646ba7f248f0347 Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Sun, 28 Jul 2024 10:26:29 +0200 Subject: [PATCH 5/7] Fixing tests --- test/mpi_array/api_test_defs.jl | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/test/mpi_array/api_test_defs.jl b/test/mpi_array/api_test_defs.jl index 0906fae..539715e 100644 --- a/test/mpi_array/api_test_defs.jl +++ b/test/mpi_array/api_test_defs.jl @@ -61,8 +61,8 @@ end function petsc_coo(petsc_comm,I,J,V,rows,cols) m = own_length(rows) n = own_length(cols) - M = PetscCall.PETSC_DECIDE - N = PetscCall.PETSC_DECIDE + M = global_length(rows) + N = global_length(cols) I .= I .- 1 J .= J .- 1 ownership = (I,J,V) @@ -72,11 +72,13 @@ function petsc_coo(petsc_comm,I,J,V,rows,cols) PetscCall.@check_error_code PetscCall.MatSetType(A[],PetscCall.MATMPIAIJ) PetscCall.@check_error_code PetscCall.MatSetSizes(A[],m,n,M,N) PetscCall.@check_error_code PetscCall.MatSetFromOptions(A[]) - PetscCall.@check_error_code PetscCall.MatSetPreallocationCOO(A[],ncoo,I,J) - PetscCall.@check_error_code PetscCall.MatSetValuesCOO(A[],V,PetscCall.ADD_VALUES) - #PetscCall.@check_error_code PetscCall.MatAssemblyBegin(A[],PetscCall.MAT_FINAL_ASSEMBLY) - #PetscCall.@check_error_code PetscCall.MatAssemblyEnd(A[],PetscCall.MAT_FINAL_ASSEMBLY) - GC.@preserve ownership PetscCall.@check_error_code PetscCall.MatDestroy(A) + GC.@preserve ownership begin + PetscCall.@check_error_code PetscCall.MatSetPreallocationCOO(A[],ncoo,I,J) + PetscCall.@check_error_code PetscCall.MatSetValuesCOO(A[],V,PetscCall.ADD_VALUES) + PetscCall.@check_error_code PetscCall.MatAssemblyBegin(A[],PetscCall.MAT_FINAL_ASSEMBLY) + PetscCall.@check_error_code PetscCall.MatAssemblyEnd(A[],PetscCall.MAT_FINAL_ASSEMBLY) + PetscCall.@check_error_code PetscCall.MatDestroy(A) + end end function generate_coo(args...) @@ -86,10 +88,12 @@ function generate_coo(args...) (I,J,V) = map(partition(A),row_partition,col_partition) do myA,rows,cols Id,Jd,Vd = findnz(myA.blocks.own_own) Io,Jo,Vo = findnz(myA.blocks.own_ghost) - myI = vcat(map_own_to_global!(Id,rows),map_ghost_to_global!(Io,rows)) + myI = vcat(map_own_to_global!(Id,rows),map_own_to_global!(Io,rows)) myJ = vcat(map_own_to_global!(Jd,cols),map_ghost_to_global!(Jo,cols)) myV = vcat(Vd,Vo) - (myI,myJ,myV) + Ti = PetscCall.PetscInt + Tv = PetscCall.PetscScalar + (convert(Vector{Ti},myI),convert(Vector{Ti},myJ),convert(Vector{Tv},myV)) end |> tuple_of_arrays I,J,V,row_partition,col_partition end @@ -118,6 +122,9 @@ function main(distribute,params) B = 2*A test_spmm_petsc(A,B) I,J,V,row_partition,col_partition = generate_coo(nodes_per_dir,parts_per_dir,ranks) + #index_type = PetscCall.PetscInt + #value_type = PetscCall.PetscScalar + #I,J,V,row_partition,col_partition = laplacian_fem(nodes_per_dir,parts_per_dir,ranks;index_type,value_type) petsc_comm = PetscCall.setup_petsc_comm(ranks) map(I,J,V,row_partition,col_partition) do args... petsc_coo(petsc_comm,args...) From 00907ca77349e58e21408afde9dec0c5daf72263 Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Sun, 28 Jul 2024 10:32:11 +0200 Subject: [PATCH 6/7] Using new gallery function laplacian_fem in tests --- test/mpi_array/api_test_defs.jl | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/test/mpi_array/api_test_defs.jl b/test/mpi_array/api_test_defs.jl index 539715e..63066ae 100644 --- a/test/mpi_array/api_test_defs.jl +++ b/test/mpi_array/api_test_defs.jl @@ -81,23 +81,6 @@ function petsc_coo(petsc_comm,I,J,V,rows,cols) end end -function generate_coo(args...) - A = PartitionedArrays.laplace_matrix(args...) - row_partition = partition(axes(A,1)) - col_partition = partition(axes(A,2)) - (I,J,V) = map(partition(A),row_partition,col_partition) do myA,rows,cols - Id,Jd,Vd = findnz(myA.blocks.own_own) - Io,Jo,Vo = findnz(myA.blocks.own_ghost) - myI = vcat(map_own_to_global!(Id,rows),map_own_to_global!(Io,rows)) - myJ = vcat(map_own_to_global!(Jd,cols),map_ghost_to_global!(Jo,cols)) - myV = vcat(Vd,Vo) - Ti = PetscCall.PetscInt - Tv = PetscCall.PetscScalar - (convert(Vector{Ti},myI),convert(Vector{Ti},myJ),convert(Vector{Tv},myV)) - end |> tuple_of_arrays - I,J,V,row_partition,col_partition -end - function main(distribute,params) nodes_per_dir = params.nodes_per_dir parts_per_dir = params.parts_per_dir @@ -121,10 +104,9 @@ function main(distribute,params) @test norm(c)/norm(b1) < tol B = 2*A test_spmm_petsc(A,B) - I,J,V,row_partition,col_partition = generate_coo(nodes_per_dir,parts_per_dir,ranks) - #index_type = PetscCall.PetscInt - #value_type = PetscCall.PetscScalar - #I,J,V,row_partition,col_partition = laplacian_fem(nodes_per_dir,parts_per_dir,ranks;index_type,value_type) + index_type = PetscCall.PetscInt + value_type = PetscCall.PetscScalar + I,J,V,row_partition,col_partition = laplacian_fem(nodes_per_dir,parts_per_dir,ranks;index_type,value_type) petsc_comm = PetscCall.setup_petsc_comm(ranks) map(I,J,V,row_partition,col_partition) do args... petsc_coo(petsc_comm,args...) From 3cb49947b32b27cc21e72a2c5633bae8c3c0f15a Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Sun, 28 Jul 2024 10:34:03 +0200 Subject: [PATCH 7/7] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index c0c962d..a098f24 100644 --- a/Project.toml +++ b/Project.toml @@ -16,7 +16,7 @@ SparseMatricesCSR = "a0a7dd2c-ebf4-11e9-1f05-cf50bc540ca1" [compat] MPI = "0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20" PETSc_jll = "3" -PartitionedArrays = "0.4, 0.5" +PartitionedArrays = "0.4.7, 0.5" Preferences = "1" SparseArrays = "1" SparseMatricesCSR = "0.6"