@@ -4,6 +4,7 @@ using PartitionedArrays
4
4
using PetscCall
5
5
using LinearAlgebra
6
6
using Test
7
+ using SparseArrays
7
8
8
9
function spmv_petsc! (b,A,x)
9
10
# Convert the input to petsc objects
@@ -57,6 +58,29 @@ function test_spmm_petsc(A,B)
57
58
GC. @preserve ownership PetscCall. @check_error_code PetscCall. MatDestroy (mat_C)
58
59
end
59
60
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
+
60
84
function main (distribute,params)
61
85
nodes_per_dir = params. nodes_per_dir
62
86
parts_per_dir = params. parts_per_dir
@@ -80,6 +104,13 @@ function main(distribute,params)
80
104
@test norm (c)/ norm (b1) < tol
81
105
B = 2 * A
82
106
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
83
114
end
84
115
85
116
end # module
0 commit comments