1 static char help[] = "Tests assembly of a matrix from another matrix's hash table.\n\n"; 2 3 #include <petscmat.h> 4 5 int main(int argc, char **argv) 6 { 7 Mat A, B; 8 PetscInt m, n, i, j; 9 PetscScalar v; 10 11 PetscFunctionBeginUser; 12 PetscCall(PetscInitialize(&argc, &argv, NULL, help)); 13 14 /* ------- Set values in A --------- */ 15 PetscCall(MatCreate(PETSC_COMM_WORLD, &A)); 16 PetscCall(MatSetSizes(A, 1, 1, PETSC_DETERMINE, PETSC_DETERMINE)); 17 PetscCall(MatSetFromOptions(A)); 18 PetscCall(MatSetUp(A)); 19 PetscCall(MatGetSize(A, &m, &n)); 20 for (i = 0; i < m; i++) { 21 for (j = 0; j < n; j++) { 22 v = 10.0 * i + j + 1; 23 PetscCall(MatSetValues(A, 1, &i, 1, &j, &v, ADD_VALUES)); 24 } 25 } 26 27 /* Create B */ 28 PetscCall(MatDuplicate(A, MAT_DO_NOT_COPY_VALUES, &B)); 29 PetscCall(MatCopyHashToXAIJ(A, B)); 30 PetscCall(MatView(B, PETSC_VIEWER_STDOUT_WORLD)); 31 32 PetscCall(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY)); 33 PetscCall(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY)); 34 PetscCall(MatView(A, PETSC_VIEWER_STDOUT_WORLD)); 35 36 PetscCall(MatDestroy(&A)); 37 PetscCall(MatDestroy(&B)); 38 PetscCall(PetscFinalize()); 39 return 0; 40 } 41 42 /*TEST 43 44 test: 45 suffix: seq 46 args: -mat_type seqaij 47 filter: grep -v "Mat Object" 48 49 test: 50 suffix: mpi 51 args: -mat_type mpiaij 52 nsize: 4 53 filter: grep -v "Mat Object" 54 55 TEST*/ 56