@@ -4,6 +4,7 @@ using PartitionedArrays
44using PetscCall
55using LinearAlgebra
66using Test
7+ using SparseArrays
78
89function spmv_petsc! (b,A,x)
910 # Convert the input to petsc objects
@@ -57,6 +58,29 @@ function test_spmm_petsc(A,B)
5758 GC. @preserve ownership PetscCall. @check_error_code PetscCall. MatDestroy (mat_C)
5859end
5960
61+ function petsc_coo (petsc_comm,I,J,V,rows,cols)
62+ m = own_length (rows)
63+ n = own_length (cols)
64+ M = global_length (rows)
65+ N = global_length (cols)
66+ I .= I .- 1
67+ J .= J .- 1
68+ ownership = (I,J,V)
69+ ncoo = length (I)
70+ A = Ref {PetscCall.Mat} ()
71+ PetscCall. @check_error_code PetscCall. MatCreate (petsc_comm,A)
72+ PetscCall. @check_error_code PetscCall. MatSetType (A[],PetscCall. MATMPIAIJ)
73+ PetscCall. @check_error_code PetscCall. MatSetSizes (A[],m,n,M,N)
74+ PetscCall. @check_error_code PetscCall. MatSetFromOptions (A[])
75+ GC. @preserve ownership begin
76+ PetscCall. @check_error_code PetscCall. MatSetPreallocationCOO (A[],ncoo,I,J)
77+ PetscCall. @check_error_code PetscCall. MatSetValuesCOO (A[],V,PetscCall. ADD_VALUES)
78+ PetscCall. @check_error_code PetscCall. MatAssemblyBegin (A[],PetscCall. MAT_FINAL_ASSEMBLY)
79+ PetscCall. @check_error_code PetscCall. MatAssemblyEnd (A[],PetscCall. MAT_FINAL_ASSEMBLY)
80+ PetscCall. @check_error_code PetscCall. MatDestroy (A)
81+ end
82+ end
83+
6084function main (distribute,params)
6185 nodes_per_dir = params. nodes_per_dir
6286 parts_per_dir = params. parts_per_dir
@@ -80,6 +104,13 @@ function main(distribute,params)
80104 @test norm (c)/ norm (b1) < tol
81105 B = 2 * A
82106 test_spmm_petsc (A,B)
107+ index_type = PetscCall. PetscInt
108+ value_type = PetscCall. PetscScalar
109+ I,J,V,row_partition,col_partition = laplacian_fem (nodes_per_dir,parts_per_dir,ranks;index_type,value_type)
110+ petsc_comm = PetscCall. setup_petsc_comm (ranks)
111+ map (I,J,V,row_partition,col_partition) do args...
112+ petsc_coo (petsc_comm,args... )
113+ end
83114end
84115
85116end # module
0 commit comments